org.jppf.server.nio.multiplexer.generic
Class MultiplexerContext

java.lang.Object
  extended by org.jppf.server.nio.AbstractNioContext<S>
      extended by org.jppf.server.nio.SimpleNioContext<MultiplexerState>
          extended by org.jppf.server.nio.multiplexer.generic.MultiplexerContext
All Implemented Interfaces:
NioContext<MultiplexerState>

public class MultiplexerContext
extends SimpleNioContext<MultiplexerState>

Context obect associated with a socket channel used by the multiplexer.

Author:
Laurent Cohen

Field Summary
 boolean eof
          Determines whether end of stream was reached during the last read operation.
 
Fields inherited from class org.jppf.server.nio.AbstractNioContext
connectionUuid, message, readByteCount, state, uuid, writeByteCount
 
Constructor Summary
MultiplexerContext()
           
 
Method Summary
 void addPendingMessage(ByteBufferWrapper message)
          Add a message to the list of pending messages.
 int getBoundPort()
          Get the application port to which the channel may be bound.
 ByteBuffer getCurrentMessage()
          Get the message currently being sent.
 ChannelWrapper getLinkedKey()
          Get the request currently processed.
 int getMultiplexerPort()
          Get the multiplexer port to which the channel may be bound.
 void handleException(ChannelWrapper channel)
          Handle the cleanup when an exception occurs on the channel.
 boolean hasPendingMessage()
          Determine if this context has any pending message waiting to be sent.
 boolean isApplicationPort()
          Determine whether the associated channel is connected to an application port.
 boolean isEof()
          Determine whether end of stream was reached during the last read operation.
 boolean isMultiplexerPort()
          Determine whether the associated channel is connected to a multiplexer port.
 int newReadMessageCount()
          Generate a new read meessage count value.
 ByteBufferWrapper nextPendingMessage()
          Retrieve, and remove from the list, the next pending message.
 ByteBuffer readMultiplexerMessage(ChannelWrapper<?> wrapper)
          Read data from a channel.
 int readOutBoundPort()
          Get the port outbound port number for this channel, sent as the initial message.
 void setBoundPort(int boundPort)
          Set the application port to which the channel may be bound.
 void setCurrentMessage(ByteBuffer message)
          Set the message currently being sent.
 void setEof(boolean eof)
          Specifiy whether end of stream was reached during the last read operation.
 void setLinkedKey(ChannelWrapper key)
          Set the request currently processed.
 void setMultiplexerPort(int multiplexerPort)
          Set the multiplexer port to which the channel may be bound.
 boolean writeMultiplexerMessage(ChannelWrapper<?> wrapper)
          Write the current message to a 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

eof

public boolean eof
Determines whether end of stream was reached during the last read operation.

Constructor Detail

MultiplexerContext

public MultiplexerContext()
Method Detail

handleException

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

Parameters:
channel - the channel that threw the exception.

getLinkedKey

public ChannelWrapper getLinkedKey()
Get the request currently processed.

Returns:
a ChannelWrapper instance.

setLinkedKey

public void setLinkedKey(ChannelWrapper key)
Set the request currently processed.

Parameters:
key - a ChannelWrapper instance.

getBoundPort

public int getBoundPort()
Get the application port to which the channel may be bound.

Returns:
the port as an int value, or a negative value if the channel is not bound to an application port.

setBoundPort

public void setBoundPort(int boundPort)
Set the application port to which the channel may be bound.

Parameters:
boundPort - the port as an int value, or a negative value if the channel is not bound to an application port.

getMultiplexerPort

public int getMultiplexerPort()
Get the multiplexer port to which the channel may be bound.

Returns:
the port as an int value, or a negative value if the channel is not bound to a multiplexer port.

setMultiplexerPort

public void setMultiplexerPort(int multiplexerPort)
Set the multiplexer port to which the channel may be bound.

Parameters:
multiplexerPort - the port as an int value, or a negative value if the channel is not bound to a multiplexer port.

isApplicationPort

public boolean isApplicationPort()
Determine whether the associated channel is connected to an application port.

Returns:
true if the channel is bound to an application port, false otherwise.

isMultiplexerPort

public boolean isMultiplexerPort()
Determine whether the associated channel is connected to a multiplexer port.

Returns:
true if the channel is bound to a multiplexer port, false otherwise.

readOutBoundPort

public int readOutBoundPort()
Get the port outbound port number for this channel, sent as the initial message.

Returns:
the port number as an int, or -1 if it could not be read.

readMultiplexerMessage

public ByteBuffer readMultiplexerMessage(ChannelWrapper<?> wrapper)
                                  throws Exception
Read data from a channel.

Parameters:
wrapper - the channel to read the data from.
Returns:
a ByteBuffer containing the data read from the channel, or null if no data was read.
Throws:
Exception - if an error occurs while reading the data.

writeMultiplexerMessage

public boolean writeMultiplexerMessage(ChannelWrapper<?> wrapper)
                                throws Exception
Write the current message to a channel.

Parameters:
wrapper - the channel to write the data to.
Returns:
true if the current message was completely written, false otherwise.
Throws:
Exception - if an error occurs while reading the data.

addPendingMessage

public void addPendingMessage(ByteBufferWrapper message)
Add a message to the list of pending messages.

Parameters:
message - the message to add to the list.

nextPendingMessage

public ByteBufferWrapper nextPendingMessage()
Retrieve, and remove from the list, the next pending message.

Returns:
the next message, or null if there is no message.

hasPendingMessage

public boolean hasPendingMessage()
Determine if this context has any pending message waiting to be sent.

Returns:
true if there is at least one pending message, false otherwise.

getCurrentMessage

public ByteBuffer getCurrentMessage()
Get the message currently being sent.

Returns:
a ByteBuffer instance.

setCurrentMessage

public void setCurrentMessage(ByteBuffer message)
Set the message currently being sent.

Parameters:
message - a ByteBuffer instance.

isEof

public boolean isEof()
Determine whether end of stream was reached during the last read operation.

Returns:
true if EOF was reached, false otherwise.

setEof

public void setEof(boolean eof)
Specifiy whether end of stream was reached during the last read operation.

Parameters:
eof - true to specify that EOF was reached, false otherwise.

newReadMessageCount

public int newReadMessageCount()
Generate a new read meessage count value.

Returns:
the read message count incremented by one.


Copyright © 2005-2010 JPPF Team.