jrunx.scheduler
Interface RunnableFactory

All Known Implementing Classes:
SchedulerService, NetworkService

public interface RunnableFactory

This class encapsulates the characteristics source of work for the threading engine. This could be a queue of scheduled tasks, a socket that receives requests, or even a message queue.

Classes that implement this interface can count on "conservation of runnables". Every object created using createRunnable will eventually be returned to the factory either via swapRunnable, in the normal case, or destroyRunnable, in case of error.

This interface is the natural evolution of the ServiceEndpoint class of JRun 2.3. ServiceEndpoint was essentially an interface for a listen socket, but a RunnableFactory has been generalized.

Author:
Paul Colton, Edwin Smith

Field Summary
static int BUSY
          Signifies destroy was called due to being too busy.
static int EXCEPTION
          Signifies destroy was called due to an exception.
static int SHUTDOWN
          Signifies destroy was called due to a shutdown.
 
Method Summary
 java.lang.Runnable createRunnable()
          Returns an Runnable object by doing a protocol-specific accept or receive; the Runnable encapsulates an atomic unit of work.
 void destroyRunnable(java.lang.Runnable r, int reason)
          destroy the given runnable.
 void invokeRunnable(java.lang.Runnable r)
          process this request.
 java.lang.Runnable swapRunnable(java.lang.Runnable r)
          this is an alternative method for sourcing runnables, letting the runnable factory take care of creation and destruction of the runnable objects.
 

Field Detail

BUSY

public static final int BUSY
Signifies destroy was called due to being too busy.

SHUTDOWN

public static final int SHUTDOWN
Signifies destroy was called due to a shutdown.

EXCEPTION

public static final int EXCEPTION
Signifies destroy was called due to an exception.
Method Detail

createRunnable

public java.lang.Runnable createRunnable()
                                  throws java.lang.InterruptedException
Returns an Runnable object by doing a protocol-specific accept or receive; the Runnable encapsulates an atomic unit of work. Subclasses implement this method for the protocol they support. If the factory encapsulates a listen socket, this is the place to call accept()
Returns:
an endpoint for requests and responses. never null.
Throws:
java.lang.InterruptedException - if a timeout or interrupt occurs

swapRunnable

public java.lang.Runnable swapRunnable(java.lang.Runnable r)
                                throws java.lang.InterruptedException
this is an alternative method for sourcing runnables, letting the runnable factory take care of creation and destruction of the runnable objects. If the runnable encapsulates a connected socket, this is the natural place to read the next request or message from the socket.

returning null from this method is an efficient way to signal no more swapping can be done, without throwing an exception.

Parameters:
ep - a previously used endpoint for recycling
Returns:
a new runnable object, or null if no more exist.
Throws:
java.lang.InterruptedException - if an interrupt or timeout occurs.

destroyRunnable

public void destroyRunnable(java.lang.Runnable r,
                            int reason)
destroy the given runnable. This is called by the thread pool when we resource limits have been exceeded, an exception has occured, or a shutdown has been issued. The BUSY case is where you should implement any "we are too busy" logic.

invokeRunnable

public void invokeRunnable(java.lang.Runnable r)
process this request. entry point into filter pattern


Copyright � 2002 Macromedia Corporation. All Rights Reserved.