javax.realtime
Class MemoryParameters

java.lang.Object
  extended byjavax.realtime.MemoryParameters
All Implemented Interfaces:
Cloneable

public class MemoryParameters
extends Object
implements Cloneable

Memory parameters can be given on the constructor of RealtimeThread and AsyncEventHandler. These can be used both for the purposes of admission control by the scheduler and for the purposes of pacing the garbage collector to satisfy all of the thread allocation rates. When a reference to a MemoryParameters object is given as a parameter to a constructor, the MemoryParameters object becomes bound to the object being created. Changes to the values in the MemoryParameters object affect the constructed object. If given to more than one constructor, then changes to the values in the MemoryParameters object affect all of the associated objects. Note that this is a one-to- many relationship and not a many-to-many.

Caution: This class is explicitly unsafe in multithreaded situations when it is being changed. No synchronization is done. It is assumed that users of this class who are mutating instances will be doing their own synchronization at a higher level.

Author:
Angelo Corsaro, Morgan Deters

Field Summary
protected  long allocationRate
           
protected  long maxImmortal
           
protected  long maxMemoryArea
           
static long NO_MAX
          Specifies no maximum limit for a given memory area.
 
Constructor Summary
MemoryParameters(long maxMemoryArea, long maxImmortal)
          Create a MemoryParameters object with the given values.
MemoryParameters(long maxMemoryArea, long maxImmortal, long allocationRate)
          Creates a new MemoryParameters instance.
 
Method Summary
 Object clone()
          Clone this MemoryParameters object.
 long getAllocationRate()
          Get the allocation rate.
 long getMaxImmortal()
          Get the limit on the amount of memory the thread may allocate in the immortal area.
 long getMaxMemoryArea()
          Get the limit on the amount of memory the thread may allocate in its initial memory area.
 void setAllocationRate(long allocationRate)
          A limit on the rate of allocation in the heap.
 boolean setAllocationRateIfFeasible(int allocationRate)
          Change the limit on the rate of allocation in the heap.
 boolean setMaxImmortalIfFeasible(long maxImmortal)
          A limit on the amount of memory associated Schedulable objects may allocate in the immortal memory area.
 boolean setMaxMemoryAreaIfFeasible(long maxMemoryArea)
          A limit on the amount of memory associated Schedulable objects may allocate in the memory area with which they were initialized.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

maxMemoryArea

protected long maxMemoryArea

maxImmortal

protected long maxImmortal

allocationRate

protected long allocationRate

NO_MAX

public static final long NO_MAX
Specifies no maximum limit for a given memory area.

See Also:
Constant Field Values
Constructor Detail

MemoryParameters

public MemoryParameters(long maxMemoryArea,
                        long maxImmortal)
Create a MemoryParameters object with the given values.

Parameters:
maxMemoryArea - A limit on the amount of memory the thread may allocate in the memory area. Units are in bytes. If zero, no allocation allowed in the memory area. To specify no limit, use NO_MAX or a value less than zero.
maxImmortal - A limit on the amount of memory the thread may allocate in the immortal area. Units are in bytes. If zero, no allocation allowed in immortal. To specify no limit, use NO_MAX or a value less than zero.
Throws:
IllegalArgumentException - if either maxMemoryArea or maxImmortal is not a valid value (valid values are nonnegative integers or NO_MAX)

MemoryParameters

public MemoryParameters(long maxMemoryArea,
                        long maxImmortal,
                        long allocationRate)
Creates a new MemoryParameters instance.

Parameters:
maxMemoryArea - A limit on the amount of memory the thread may allocate in the memory area. Units are in bytes. If zero, no allocation allowed in the memory area. To specify no limit, use NO_MAX or a value less than zero.
maxImmortal - A limit on the amount of memory the thread may allocate in the immortal area. Units are in bytes. If zero, no allocation allowed in immortal. To specify no limit, use NO_MAX or a value less than zero.
allocationRate - A limit on the rate of allocation in the heap. Units are in bytes per second. If zero, no allocation is allowed in the heap. To specify no limit, use NO_MAX or a value less than zero.
Throws:
IllegalArgumentException - if any of maxMemoryArea, maxImmortal, or allocationRate is not a valid value (valid values are nonnegative integers or NO_MAX)
Method Detail

getAllocationRate

public long getAllocationRate()
Get the allocation rate. Units are in bytes per second.

Returns:
the allocation rate in byte/sec.

setAllocationRate

public void setAllocationRate(long allocationRate)
A limit on the rate of allocation in the heap. Though the limiting value is shared among all the Schedulables that share this MemoryParameters object, the limit itself applies to each Schedulable independently, not as a collective.

Parameters:
allocationRate - Units are in bytes per second. If zero, no allocation is allowed in the heap. To specify no limit, use NO_MAX or a value less than zero.
Throws:
IllegalArgumentException - if allocationRate is not a valid value (valid values are nonnegative integers and NO_MAX)

setAllocationRateIfFeasible

public boolean setAllocationRateIfFeasible(int allocationRate)
Change the limit on the rate of allocation in the heap. If this MemoryParameters object is currently associated with one or more realtime threads that have been passed admission control, this change in allocation rate will be submitted to admission control. The scheduler (in conjunction with the garbage collector) will either admit all the effected threads with the new allocation rate, or leave the allocation rate unchanged and cause this method to return false.

Though the limiting value is shared among all the Schedulables that share this MemoryParameters object, the limit itself applies to each Schedulable independently, not as a collective.

Parameters:
allocationRate - Units are in bytes per second. If zero, no allocation is allowed in the heap. To specify no limit, use NO_MAX or a value less than zero.
Returns:
true if the request was fulfilled.
Throws:
IllegalArgumentException - if allocationRate is not a valid value (valid values are nonnegative integers and NO_MAX)

getMaxImmortal

public long getMaxImmortal()
Get the limit on the amount of memory the thread may allocate in the immortal area. Units are in bytes.

Returns:
the maximum amount of immortal memory that should be used.

setMaxImmortalIfFeasible

public boolean setMaxImmortalIfFeasible(long maxImmortal)
A limit on the amount of memory associated Schedulable objects may allocate in the immortal memory area. Though the limiting value is shared among all the Schedulables that share this MemoryParameters object, the limit itself applies to each Schedulable independently, not as a collective.

Parameters:
maxImmortal - Units are in bytes. If zero, no allocation allowed in immortal. To specify no limit, use NO_MAX or a value less than zero.
Returns:
False if any of the threads have already allocated more than the given value. In this case the call has no effect.
Throws:
IllegalArgumentException - if maxImmortal is not a valid value (valid values are nonnegative integers and NO_MAX)

getMaxMemoryArea

public long getMaxMemoryArea()
Get the limit on the amount of memory the thread may allocate in its initial memory area. Units are in bytes.

Returns:
the maximum amount of memory allocable in an initial memory area

setMaxMemoryAreaIfFeasible

public boolean setMaxMemoryAreaIfFeasible(long maxMemoryArea)
A limit on the amount of memory associated Schedulable objects may allocate in the memory area with which they were initialized. Though the limiting value is shared among all the Schedulables that share this MemoryParameters object, the limit itself applies to each Schedulable independently, not as a collective.

Parameters:
maxMemoryArea - Units are in bytes. If zero, no allocation allowed in the memory area. To specify no limit, use NO_MAX or a value less than zero.
Returns:
False if any of the threads have already allocated more than the given value. In this case the call has no effect.
Throws:
IllegalArgumentException - if maxMemoryArea is not a valid value (valid values are nonnegative integers and NO_MAX)

clone

public Object clone()
Clone this MemoryParameters object. The returned MemoryParameters object is not yet bound to a Schedulable object.



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