javax.realtime
Class PrivateScopedMemory

java.lang.Object
  extended byjavax.realtime.MemoryArea
      extended byjavax.realtime.ScopedMemory
          extended byjavax.realtime.PrivateScopedMemory
Direct Known Subclasses:
CTPrivateMemory, LTPrivateMemory

public abstract class PrivateScopedMemory
extends ScopedMemory

The class PrivateScopedMemory refines the ScopedMemory by restricting the number of active thread within a memory to one.

Author:
Angelo Corsaro

Field Summary
protected  RealtimeThread owner
           
 
Fields inherited from class javax.realtime.ScopedMemory
joinSynchronizer
 
Fields inherited from class javax.realtime.MemoryArea
logic, parent, sizeInBytes
 
Constructor Summary
PrivateScopedMemory(long size)
          Creates a new PrivateScopedMemory instance.
PrivateScopedMemory(long size, Runnable logic)
          Creates a new PrivateScopedMemory instance.
PrivateScopedMemory(SizeEstimator size)
          Creates a new PrivateScopedMemory instance.
PrivateScopedMemory(SizeEstimator size, Runnable logic)
          Creates a new PrivateScopedMemory instance.
 
Method Summary
 void enter(Runnable logic)
          Associate this memory area to the current real-time thread for the duration of the execution of the run() method of the given Runnable.
 void join()
          Wait until the reference count of this PrivateScopedMemory goes down to zero.
 void join(HighResolutionTime time)
          Wait at most until the time designated by the time parameter for the reference count of this PrivateScopedMemory to go down to zero.
 void joinAndEnter()
          Combine join();enter(); such that no enter from another thread can intervene between the two method invocations.
 void joinAndEnter(HighResolutionTime time)
          Combine join(time);enter(); such that no enter from another thread can intervene between the two method invocations.
 void joinAndEnter(Runnable logic)
          Combine join();enter(logic); such that no enter from another thread can intervene between the two method invocations.
 void joinAndEnter(Runnable logic, HighResolutionTime time)
          Combine join(time);enter(logic); such that no enter from another thread can intervene between the two method invocations.
protected  void resetOwner()
           
protected  void setOwner()
           
 String toString()
          Returns a user-friendly representation of this PrivateScopedMemory.
 
Methods inherited from class javax.realtime.ScopedMemory
getMaximumSize, getPortal, getReferenceCount, setPortal
 
Methods inherited from class javax.realtime.MemoryArea
enter, executeInArea, finalize, fini, getMemoryArea, guardedRun, init, memoryConsumed, memoryRemaining, newArray, newInstance, newInstance, size
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

owner

protected RealtimeThread owner
Constructor Detail

PrivateScopedMemory

public PrivateScopedMemory(long size)
Creates a new PrivateScopedMemory instance.

Parameters:
size - The size of MemoryArea to allocate, in bytes. If size is less than or equal to zero an IllegalArgumentException is thrown.

PrivateScopedMemory

public PrivateScopedMemory(long size,
                           Runnable logic)
Creates a new PrivateScopedMemory instance.

Parameters:
size - The size of MemoryArea to allocate, in bytes. If size is less than or equal to zero an IllegalArgumentException is thrown.
logic - -The java.lang.Runnable whose run() method is invoked when any of the variations of enter() which do not take a java.lang.Runnable is called.

PrivateScopedMemory

public PrivateScopedMemory(SizeEstimator size)
Creates a new PrivateScopedMemory instance.

Parameters:
size - A SizeEstimator object which indicates the amount of memory required by this MemoryArea.

PrivateScopedMemory

public PrivateScopedMemory(SizeEstimator size,
                           Runnable logic)
Creates a new PrivateScopedMemory instance.

Parameters:
size - The size of MemoryArea to allocate, in bytes.
logic - The run() method of this object will be called whenever enter() called.
Method Detail

join

public void join()
          throws InterruptedException
Wait until the reference count of this PrivateScopedMemory goes down to zero.

Overrides:
join in class ScopedMemory
Throws:
InterruptedException - If another thread interrupts this thread while it is waiting.

join

public void join(HighResolutionTime time)
          throws InterruptedException
Wait at most until the time designated by the time parameter for the reference count of this PrivateScopedMemory to go down to zero.

Overrides:
join in class ScopedMemory
Parameters:
time - If this time is an absolute time, the wait is bounded by that point in time. If the time is a relative time (or a member of the RationalTime subclass of RelativeTime the wait is bounded by a the specified interval from some time between the time join is called and the time it starts waiting for the reference count to reach zero.
Throws:
InterruptedException - if another thread interrupts this thread while it is waiting.

joinAndEnter

public void joinAndEnter()
                  throws InterruptedException,
                         ScopedCycleException
Combine join();enter(); such that no enter from another thread can intervene between the two method invocations. The resulting method will wait for the reference count on this PrivateScopedMemory to reach zero, then enter the PrivateScopedMemory and execute the run method from logic passed in the constructor. If no Runnable was passed, the method returns immediately.

Overrides:
joinAndEnter in class ScopedMemory
Throws:
InterruptedException - If another thread interrupts this thread while it is waiting.
ScopedCycleException - If entering this PrivateScopedMemory would violate the single parent rule.

joinAndEnter

public void joinAndEnter(HighResolutionTime time)
                  throws InterruptedException,
                         ScopedCycleException
Combine join(time);enter(); such that no enter from another thread can intervene between the two method invocations. The resulting method will wait for the reference count on this PrivateScopedMemory to reach zero, or for the current time to reach the designated time, then enter the PrivateScopedMemory and execute the run method from Runnable object passed at constructin time. If no Runnable was passed then this method returns immediately.

Overrides:
joinAndEnter in class ScopedMemory
Parameters:
time - The time that bounds the wait.
Throws:
InterruptedException - if another thread interrupts this thread while it is waiting.
ScopedCycleException - If entering this PrivateScopedMemory would violate the single parent rule.

joinAndEnter

public void joinAndEnter(Runnable logic)
                  throws InterruptedException,
                         ScopedCycleException
Combine join();enter(logic); such that no enter from another thread can intervene between the two method invocations. The resulting method will wait for the reference count on this PrivateScopedMemory to reach zero, then enter the PrivateScopedMemory and execute the run method from logic

Overrides:
joinAndEnter in class ScopedMemory
Parameters:
logic - The Runnable object which contains the code to execute.
Throws:
InterruptedException - If another thread interrupts this thread while it is waiting.
ScopedCycleException - If entering this PrivateScopedMemory would violate the single parent rule.

joinAndEnter

public void joinAndEnter(Runnable logic,
                         HighResolutionTime time)
                  throws InterruptedException,
                         ScopedCycleException
Combine join(time);enter(logic); such that no enter from another thread can intervene between the two method invocations. The resulting method will wait for the reference count on this PrivateScopedMemory to reach zero, or for the current time to reach the designated time, then enter the PrivateScopedMemory and execute the run method from logic.

Overrides:
joinAndEnter in class ScopedMemory
Parameters:
logic - The Runnable object which contains the code to execute.
time - The time that bounds the wait.
Throws:
InterruptedException - if another thread interrupts this thread while it is waiting.
ScopedCycleException - If entering this PrivateScopedMemory would violate the single parent rule.

toString

public String toString()
Returns a user-friendly representation of this PrivateScopedMemory.

Overrides:
toString in class ScopedMemory
Returns:
The string representation

enter

public void enter(Runnable logic)
           throws ScopedCycleException
Associate this memory area to the current real-time thread for the duration of the execution of the run() method of the given Runnable. During this bound period of execution, all objects are allocated from the memory area until another one takes effect, or the enter() method is exited. A runtime exception is thrown if this method is called from thread other than a RealtimeThread or NoHeapRealtimeThread.

Overrides:
enter in class ScopedMemory
Parameters:
logic - The Runnable object whose run() method should be invoked.
Throws:
ScopedCycleException - If entering this PrivateScopedMemory would violate the single parent rule.

setOwner

protected void setOwner()

resetOwner

protected void resetOwner()


jRate is developed and maintained by the jRate project development team.
Copyright (c) 2001-2005 Angelo Corsaro and Morgan Deters.