Class Nice

  • All Implemented Interfaces:
    Invoke, java.io.Serializable, java.rmi.Remote

    public final class Nice
    extends java.lang.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:
    Serialized Form
    • Field Summary

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

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

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Object invoke​(java.lang.String method, java.lang.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 Detail

      • item

        public final java.lang.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 Detail

      • Nice

        public Nice​(java.lang.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 Detail

      • invoke

        public java.lang.Object invoke​(java.lang.String method,
                                       java.lang.Object args)
                                throws java.lang.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:
        java.lang.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.