org.jppf.server.nio.classloader
Class ClassContext

java.lang.Object
  extended by org.jppf.server.nio.AbstractNioContext<S>
      extended by org.jppf.server.nio.SimpleNioContext<ClassState>
          extended by org.jppf.server.nio.classloader.ClassContext
All Implemented Interfaces:
NioContext<ClassState>
Direct Known Subclasses:
LocalClassContext

public class ClassContext
extends SimpleNioContext<ClassState>

Context object associated with a socket channel used by the class server of the JPPF driver.

Author:
Laurent Cohen

Field Summary
protected  ChannelWrapper<?> currentRequest
          The request currently processed.
protected  List<ChannelWrapper<?>> pendingRequests
          The list of pending resource requests for a resource provider.
protected  boolean provider
          Determines whether this context relates to a provider or node connection.
protected  JPPFResourceWrapper resource
          The resource read from or written to the associated channel.
 
Fields inherited from class org.jppf.server.nio.AbstractNioContext
connectionUuid, message, readByteCount, state, uuid, writeByteCount
 
Constructor Summary
ClassContext()
           
 
Method Summary
 void addRequest(ChannelWrapper<?> request)
          Add a new pending request to this resource provider.
 JPPFResourceWrapper deserializeResource()
          Deserialize a resource wrapper from an array of bytes.
 ChannelWrapper<?> getCurrentRequest()
          Get the request currently processed.
 int getNbPendingRequests()
          Get the number of pending resource requests for a resource provider.
 List<ChannelWrapper<?>> getPendingRequests()
          Get the list of pending resource requests for a resource provider.
 JPPFResourceWrapper getResource()
          Get the resource read from or written to the associated channel.
 void handleException(ChannelWrapper<?> channel)
          Handle the cleanup when an exception occurs on the channel.
protected  void handleProviderError()
          Handle the scenario where an exception occurs while sendinf a request to or receiving a response from a provider, and a node channel is wating for the response.
 boolean isProvider()
          Determine whether this context relates to a provider or node connection.
protected  void resetNodeState(ChannelWrapper<?> request, ClassNioServer server)
          Reset the state of the requesting node channel, after an error occurred on the provider which attempted to provide a response.
protected  void sendNullResponse(ChannelWrapper<?> request)
          Send a null response to a request node connection.
 void serializeResource(ChannelWrapper<?> wrapper)
          Serialize a resource wrapper to an array of bytes.
 void setCurrentRequest(ChannelWrapper<?> currentRequest)
          Set the request currently processed.
 void setPendingRequests(List<ChannelWrapper<?>> pendingRequests)
          Set the list of pending resource requests for a resource provider.
 void setProvider(boolean provider)
          Specify whether this context relates to a provider or node connection.
 void setResource(JPPFResourceWrapper resource)
          Set the resource read from or written to the associated channel.
 
Methods inherited from class org.jppf.server.nio.SimpleNioContext
readMessage, writeMessage
 
Methods inherited from class org.jppf.server.nio.AbstractNioContext
getChannel, getConnectionUuid, getMessage, getShortClassName, getState, getUuid, setChannel, setConnectionUuid, setMessage, setState, setUuid
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

resource

protected JPPFResourceWrapper resource
The resource read from or written to the associated channel.


pendingRequests

protected List<ChannelWrapper<?>> pendingRequests
The list of pending resource requests for a resource provider.


currentRequest

protected ChannelWrapper<?> currentRequest
The request currently processed.


provider

protected boolean provider
Determines whether this context relates to a provider or node connection.

Constructor Detail

ClassContext

public ClassContext()
Method Detail

deserializeResource

public JPPFResourceWrapper deserializeResource()
                                        throws Exception
Deserialize a resource wrapper from an array of bytes.

Returns:
a JPPFResourceWrapper instance.
Throws:
Exception - if an error occurs while deserializing.

serializeResource

public void serializeResource(ChannelWrapper<?> wrapper)
                       throws Exception
Serialize a resource wrapper to an array of bytes.

Parameters:
wrapper - the channel through which the resource is sent.
Throws:
Exception - if an error occurs while serializing.

handleException

public void handleException(ChannelWrapper<?> channel)
Handle the cleanup when an exception occurs on the channel.

Parameters:
channel - the channel that threw the exception.

getResource

public JPPFResourceWrapper getResource()
Get the resource read from or written to the associated channel.

Returns:
the resource a JPPFResourceWrapper instance.

setResource

public void setResource(JPPFResourceWrapper resource)
Set the resource read from or written to the associated channel.

Parameters:
resource - a JPPFResourceWrapper instance.

addRequest

public void addRequest(ChannelWrapper<?> request)
Add a new pending request to this resource provider.

Parameters:
request - the request as a SelectionKey instance.

getCurrentRequest

public ChannelWrapper<?> getCurrentRequest()
Get the request currently processed.

Returns:
a SelectionKey instance.

setCurrentRequest

public void setCurrentRequest(ChannelWrapper<?> currentRequest)
Set the request currently processed.

Parameters:
currentRequest - a SelectionKey instance.

getNbPendingRequests

public int getNbPendingRequests()
Get the number of pending resource requests for a resource provider.

Returns:
a the number of requests as an int.

getPendingRequests

public List<ChannelWrapper<?>> getPendingRequests()
Get the list of pending resource requests for a resource provider.

Returns:
a List of SelectionKey instances.

setPendingRequests

public void setPendingRequests(List<ChannelWrapper<?>> pendingRequests)
Set the list of pending resource requests for a resource provider.

Parameters:
pendingRequests - a List of SelectionKey instances.

isProvider

public boolean isProvider()
Determine whether this context relates to a provider or node connection.

Returns:
true if this is a provider context, false otherwise.

setProvider

public void setProvider(boolean provider)
Specify whether this context relates to a provider or node connection.

Parameters:
provider - true if this is a provider context, false otherwise.

handleProviderError

protected void handleProviderError()
Handle the scenario where an exception occurs while sendinf a request to or receiving a response from a provider, and a node channel is wating for the response.


resetNodeState

protected void resetNodeState(ChannelWrapper<?> request,
                              ClassNioServer server)
Reset the state of the requesting node channel, after an error occurred on the provider which attempted to provide a response.

Parameters:
request - the requestinhg node channel.
server - the server handling the node.

sendNullResponse

protected void sendNullResponse(ChannelWrapper<?> request)
Send a null response to a request node connection. This method is called for a provider that was disconnected but still has pending requests, so as not to block the requesting channels.

Parameters:
request - the selection key wrapping the requesting channel.


Copyright © 2005-2010 JPPF Team.