org.globus.wsrf.container
Class ServiceDispatcher

java.lang.Object
  extended by org.globus.wsrf.container.ServiceDispatcher
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
GSIServiceDispatcher

public class ServiceDispatcher
extends java.lang.Object
implements java.lang.Runnable

Dispatcher reading requests off the socket and putting them into a request queue.


Field Summary
private  java.lang.String configDir
           
private  java.lang.String configProfile
           
protected  org.apache.axis.server.AxisServer engine
           
private  java.lang.String homeDir
           
(package private) static org.globus.util.I18n i18n
           
protected  java.lang.ClassLoader loader
           
(package private) static org.apache.commons.logging.Log logger
           
protected  org.apache.axis.MessageContext msgContext
           
protected  java.util.Map properties
           
protected  ServiceRequestQueue queue
           
private  java.util.LinkedList registerQueue
           
protected  Semaphore reloadLock
           
private  java.nio.channels.Selector selector
           
private  Semaphore semaphore
           
private  java.net.ServerSocket serverSocket
           
private  boolean stopped
           
protected  ServiceThreadPool threadPool
           
private  UsageConfig usageConfig
           
private  java.lang.Thread worker
           
 
Constructor Summary
protected ServiceDispatcher()
           
  ServiceDispatcher(java.util.Map properties)
           
 
Method Summary
protected  void addRegisterRequest(ServiceRequest request)
           
private  int addThread()
           
private  void bindServerSocket(java.lang.String bindAddress, int port)
           
protected static void cleanCaches(java.lang.ClassLoader loader)
           
protected  void clearRegisterRequests()
           
private static void clearSoftCache(java.lang.Class clazz, java.lang.String fieldName)
          Workaround for a bug related to: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6232010
private  void closeServerSocket()
           
protected  org.apache.axis.MessageContext createMessageContext()
           
private  java.lang.ClassLoader createServiceClassLoader()
           
 org.apache.axis.AxisEngine getAxisEngine()
           
private static int getOptionAsInt(ContainerConfig config, java.lang.String property, int defaultValue)
           
 java.net.ServerSocket getServerSocket()
           
protected  java.lang.ClassLoader getServiceClassLoader()
           
 ServiceRequestQueue getServiceRequestQueue()
           
 ServiceThreadPool getServiceThreadPool()
           
protected  boolean hasServiceThread(java.lang.Thread thread)
           
protected  void init()
           
private  void initialize()
           
protected  void initServerSocket()
           
 boolean isReloadable()
          Returns true if container reloading is enabled, false otherwise.
 boolean isReloading()
          Returns true if container is currently reloading, false otherwise.
 boolean isStopped()
           
protected  void preformReload(ReloadAction action, int timeout)
           
private  void processRegisterRequests()
           
 void reload(ReloadAction action, int timeout)
          Tells the container to reload its services.
private  void removeThread()
           
 void run()
           
protected  void setupThreadPool()
           
 void start(boolean daemon)
          Start this dispatcher.
private  void startServices()
           
 void stop()
           
private  void stopServices()
           
 void waitForInit()
           
 void waitForStop()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

static org.apache.commons.logging.Log logger

i18n

static org.globus.util.I18n i18n

worker

private volatile java.lang.Thread worker

stopped

private volatile boolean stopped

serverSocket

private java.net.ServerSocket serverSocket

selector

private java.nio.channels.Selector selector

semaphore

private Semaphore semaphore

registerQueue

private java.util.LinkedList registerQueue

queue

protected ServiceRequestQueue queue

threadPool

protected ServiceThreadPool threadPool

engine

protected org.apache.axis.server.AxisServer engine

msgContext

protected org.apache.axis.MessageContext msgContext

properties

protected java.util.Map properties

loader

protected java.lang.ClassLoader loader

reloadLock

protected Semaphore reloadLock

homeDir

private java.lang.String homeDir

configDir

private java.lang.String configDir

configProfile

private java.lang.String configProfile

usageConfig

private UsageConfig usageConfig
Constructor Detail

ServiceDispatcher

protected ServiceDispatcher()

ServiceDispatcher

public ServiceDispatcher(java.util.Map properties)
                  throws java.lang.Exception
Throws:
java.lang.Exception
Method Detail

initialize

private void initialize()
                 throws org.apache.axis.ConfigurationException,
                        java.io.IOException
Throws:
org.apache.axis.ConfigurationException
java.io.IOException

createMessageContext

protected org.apache.axis.MessageContext createMessageContext()

getServiceClassLoader

protected java.lang.ClassLoader getServiceClassLoader()

createServiceClassLoader

private java.lang.ClassLoader createServiceClassLoader()
                                                throws java.io.IOException
Throws:
java.io.IOException

isReloadable

public boolean isReloadable()
Returns true if container reloading is enabled, false otherwise.


isReloading

public boolean isReloading()
Returns true if container is currently reloading, false otherwise.


reload

public void reload(ReloadAction action,
                   int timeout)
            throws ContainerException
Tells the container to reload its services. If the container does not support reloading or reloading is already in progress, an exception is returned. A timeout value can be specified that indicates the maximum amount of time to wait for each service thread to finish processing its request (if any) before reloading the container. For example, if there are 3 service threads and timeout if 5 minutes, the server will wait a maximum of 15 minutes before proceeding with the reload operation.

Parameters:
action - an action to perform after the services are shutdown but before a new services classloader is obtained.
timeout - the maximum amount of time to wait for each service thread to finish processing its request (if any) before reloading.
Throws:
ContainerException - if reloading is not supported or reloading fails.
ReloadActionException - if reload action fails
AlreadyReloadingException - if reloading is already under way.

cleanCaches

protected static void cleanCaches(java.lang.ClassLoader loader)

clearSoftCache

private static void clearSoftCache(java.lang.Class clazz,
                                   java.lang.String fieldName)
Workaround for a bug related to: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6232010


preformReload

protected void preformReload(ReloadAction action,
                             int timeout)
                      throws ContainerException
Throws:
ContainerException

initServerSocket

protected void initServerSocket()
                         throws java.io.IOException
Throws:
java.io.IOException

init

protected void init()
             throws java.lang.Exception
Throws:
java.lang.Exception

setupThreadPool

protected void setupThreadPool()
                        throws java.lang.Exception
Throws:
java.lang.Exception

addRegisterRequest

protected void addRegisterRequest(ServiceRequest request)

clearRegisterRequests

protected void clearRegisterRequests()

processRegisterRequests

private void processRegisterRequests()

getAxisEngine

public org.apache.axis.AxisEngine getAxisEngine()

getServerSocket

public java.net.ServerSocket getServerSocket()

getServiceThreadPool

public ServiceThreadPool getServiceThreadPool()

getServiceRequestQueue

public ServiceRequestQueue getServiceRequestQueue()

getOptionAsInt

private static int getOptionAsInt(ContainerConfig config,
                                  java.lang.String property,
                                  int defaultValue)

run

public void run()
Specified by:
run in interface java.lang.Runnable

waitForInit

public void waitForInit()
                 throws java.lang.InterruptedException
Throws:
java.lang.InterruptedException

waitForStop

public void waitForStop()
                 throws java.lang.InterruptedException
Throws:
java.lang.InterruptedException

addThread

private int addThread()

removeThread

private void removeThread()

hasServiceThread

protected boolean hasServiceThread(java.lang.Thread thread)

stop

public void stop()
          throws java.io.IOException
Throws:
java.io.IOException

isStopped

public boolean isStopped()

stopServices

private void stopServices()

startServices

private void startServices()
                    throws java.lang.Exception
Throws:
java.lang.Exception

closeServerSocket

private void closeServerSocket()
                        throws java.io.IOException
Throws:
java.io.IOException

bindServerSocket

private void bindServerSocket(java.lang.String bindAddress,
                              int port)
                       throws java.io.IOException
Throws:
java.io.IOException

start

public void start(boolean daemon)
Start this dispatcher. Spawns a worker thread to listen for HTTP requests.

Parameters:
daemon - a boolean indicating if the thread should be a daemon.