org.jppf.server.nio.classloader
Class ClassNioServer

java.lang.Object
  extended by java.lang.Thread
      extended by org.jppf.server.nio.NioServer<ClassState,ClassTransition>
          extended by org.jppf.server.nio.classloader.ClassNioServer
All Implemented Interfaces:
Runnable, EventListener, ReaperListener

public class ClassNioServer
extends NioServer<ClassState,ClassTransition>
implements ReaperListener

Instances of this class serve class loading requests from the JPPF nodes.

Author:
Laurent Cohen

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
protected  Map<String,List<ChannelWrapper<?>>> providerConnections
          A mapping of the remote resource provider connections handled by this socket server, to their unique uuid.
 
Fields inherited from class org.jppf.server.nio.NioServer
CLASS_SERVER, factory, lock, NODE_SERVER, ports, resourceProvider, selector, selectTimeout, transitionManager
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ClassNioServer(int port)
          Initialize this class server with the port it will listen to.
ClassNioServer(int[] ports)
          Initialize this class server with a specified list of port numbers.
 
Method Summary
 void addProviderConnection(String uuid, ChannelWrapper<?> channel)
          Add a provider connection to the map of existing available providers.
static void closeConnection(ChannelWrapper<?> channel)
          Close the specified connection.
 void connectionFailed(ReaperEvent event)
          Called when the Reaper detects that a connection is broken.
protected  NioServerFactory<ClassState,ClassTransition> createFactory()
          Create the factory holding all the states and transition mappings.
 NioContext<?> createNioContext()
          Define a context for a newly created channel.
protected  boolean externalStopCondition()
          Determine whether a stop condition external to this server has been reached.
 byte[] getCacheContent(String uuid, String name)
          Get a resource definition from the resource cache.
 int getInitialInterest()
          Get the IO operations a connection is initially interested in.
 List<ChannelWrapper<?>> getProviderConnections(String uuid)
          Get all the provider connections for the specified client uuid.
 ResourceProvider getResourceProvider()
          Get the resource provider for this server.
 void initLocalChannel(ChannelWrapper<?> localChannel)
          Initialize the local channel connection.
 void postAccept(ChannelWrapper<?> wrapper)
          Process a channel that was accepted by the server socket channel.
 void removeAllConnections()
          Close and remove all connections accepted by this server.
 void removeProviderConnection(String uuid, ChannelWrapper channel)
          Add a provider connection to the map of existing available providers.
 void setCacheContent(String uuid, String name, byte[] content)
          Add a resource content to the class cache.
 
Methods inherited from class org.jppf.server.nio.NioServer
end, getFactory, getLock, getPorts, getSelector, getTransitionManager, go, init, isStopped, postAccept, postSelect, run, setStopped
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

providerConnections

protected Map<String,List<ChannelWrapper<?>>> providerConnections
A mapping of the remote resource provider connections handled by this socket server, to their unique uuid.
Provider connections represent connections form the clients only. The mapping to a uuid is required to determine in which application classpath to look for the requested resources.

Constructor Detail

ClassNioServer

public ClassNioServer(int port)
               throws JPPFException
Initialize this class server with the port it will listen to.

Parameters:
port - the port number as an int value.
Throws:
JPPFException - if this server could not be initialized.

ClassNioServer

public ClassNioServer(int[] ports)
               throws JPPFException
Initialize this class server with a specified list of port numbers.

Parameters:
ports - the list of port this server accepts connections from.
Throws:
JPPFException - if the underlying server socket can't be opened.
Method Detail

initLocalChannel

public void initLocalChannel(ChannelWrapper<?> localChannel)
Initialize the local channel connection.

Parameters:
localChannel - the local channel to use.

createFactory

protected NioServerFactory<ClassState,ClassTransition> createFactory()
Create the factory holding all the states and transition mappings.

Specified by:
createFactory in class NioServer<ClassState,ClassTransition>
Returns:
an NioServerFactory instance.

externalStopCondition

protected boolean externalStopCondition()
Determine whether a stop condition external to this server has been reached.

Overrides:
externalStopCondition in class NioServer<ClassState,ClassTransition>
Returns:
true if the driver is shutting down, false otherwise.
See Also:
NioServer.externalStopCondition()

createNioContext

public NioContext<?> createNioContext()
Define a context for a newly created channel.

Specified by:
createNioContext in class NioServer<ClassState,ClassTransition>
Returns:
an NioContext instance.

getInitialInterest

public int getInitialInterest()
Get the IO operations a connection is initially interested in.

Specified by:
getInitialInterest in class NioServer<ClassState,ClassTransition>
Returns:
a bit-wise combination of the interests, taken from SelectionKey constants definitions.

postAccept

public void postAccept(ChannelWrapper<?> wrapper)
Process a channel that was accepted by the server socket channel.

Specified by:
postAccept in class NioServer<ClassState,ClassTransition>
Parameters:
wrapper - the selection key for the socket channel to process.

removeAllConnections

public void removeAllConnections()
Close and remove all connections accepted by this server.

Overrides:
removeAllConnections in class NioServer<ClassState,ClassTransition>
See Also:
NioServer.removeAllConnections()

getResourceProvider

public ResourceProvider getResourceProvider()
Get the resource provider for this server.

Returns:
a ResourceProvider instance.

addProviderConnection

public void addProviderConnection(String uuid,
                                  ChannelWrapper<?> channel)
Add a provider connection to the map of existing available providers.

Parameters:
uuid - the provider uuid as a string.
channel - the provider's communication channel.

removeProviderConnection

public void removeProviderConnection(String uuid,
                                     ChannelWrapper channel)
Add a provider connection to the map of existing available providers.

Parameters:
uuid - the provider uuid as a string.
channel - the provider's communication channel.

getProviderConnections

public List<ChannelWrapper<?>> getProviderConnections(String uuid)
Get all the provider connections for the specified client uuid.

Parameters:
uuid - the uuid of the client for which to get connections.
Returns:
a list of connection channels.

setCacheContent

public void setCacheContent(String uuid,
                            String name,
                            byte[] content)
Add a resource content to the class cache.

Parameters:
uuid - uuid of the resource provider.
name - name of the resource.
content - content of the resource.

getCacheContent

public byte[] getCacheContent(String uuid,
                              String name)
Get a resource definition from the resource cache.

Parameters:
uuid - uuid of the reosurce provider.
name - name of the resource.
Returns:
the content of the resource as an array of bytes.

closeConnection

public static void closeConnection(ChannelWrapper<?> channel)
Close the specified connection.

Parameters:
channel - the channel representing the connection.

connectionFailed

public void connectionFailed(ReaperEvent event)
Called when the Reaper detects that a connection is broken.

Specified by:
connectionFailed in interface ReaperListener
Parameters:
event - encapsulates the server-side connection to a remote peer.


Copyright © 2005-2010 JPPF Team.