Class Nice

java.lang.Object
gnu.cajo.utils.extra.Nice
All Implemented Interfaces:
Invoke, Serializable, Remote

public final class Nice extends Object implements Invoke
This class wraps an object, and dynamically alters the priority of the invocation thread at runtime. Normally, the thread is moved to lowest priority, to reduce the burden on the serving JVM for methods requiring a lot of processing resources. However the wrapper can also be used escalate the invocation thread to maximum priority, for time critical tasks.
Version:
1.0, 07-Mar-09
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final boolean
    A flag to indicate if this wrapper is maximising or minimising the priority of the invocation thread.
    final Object
    The presumably local object reference, for which invocation thread priority will be managed.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Nice(Object item, boolean fast)
    The constuctor wraps an object reference, and allows invocations to execute at either minumum or maximum priority.
  • Method Summary

    Modifier and Type
    Method
    Description
    invoke(String method, Object args)
    This method intercepts the remote invocation thread, and alters its priority from normal.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • item

      public final Object item
      The presumably local object reference, for which invocation thread priority will be managed.
    • fast

      public final boolean fast
      A flag to indicate if this wrapper is maximising or minimising the priority of the invocation thread.
  • Constructor Details

    • Nice

      public Nice(Object item, boolean fast)
      The constuctor wraps an object reference, and allows invocations to execute at either minumum or maximum priority.
      Parameters:
      item - The object reference to be invoked
      fast - True to execute invocations at maximum priority, false to invoke at minimum priorty.
  • Method Details

    • invoke

      public Object invoke(String method, Object args) throws Exception
      This method intercepts the remote invocation thread, and alters its priority from normal. Typically the invocation thread is set to minimum priority, but can also be used to evelate the thread to maximum priority, if desired. When the invocation is complete, the thread will be restored to its original priority, to prevent potential side affects if an invocation is local.
      Specified by:
      invoke in interface Invoke
      Parameters:
      method - The name of the method to invoke on the wrapped object
      args - The data relevant to the invocation. It can be a single object, an array, or null
      Returns:
      The method result defined by a wrapped object's implementation, if any
      Throws:
      Exception - As needed by the object, also, a java.rmi.RemoteException can be thrown for network related reasons, also a SecurityException can be thrown, if the codebase does not have permission from the SecurityManager to alter thread priority.