QuickServer
v1.4.7

org.quickserver.net.server.impl
Class NonBlockingClientHandler

java.lang.Object
  extended byorg.quickserver.net.server.impl.BasicClientHandler
      extended byorg.quickserver.net.server.impl.NonBlockingClientHandler
All Implemented Interfaces:
ClientHandler, java.lang.Runnable

public class NonBlockingClientHandler
extends BasicClientHandler


Field Summary
protected  ClientWriteHandler clientWriteHandler
           
protected  java.util.ArrayList readByteBuffer
           
protected  java.nio.channels.SelectionKey selectionKey
           
protected  int threadAccessCount
           
protected  boolean waitingForFinalWrite
           
protected  boolean willReturn
           
protected  java.util.ArrayList writeByteBuffer
           
 
Fields inherited from class org.quickserver.net.server.impl.BasicClientHandler
appLogger, authenticator, authorised, b_in, b_out, bufferedReader, charset, clientAuthenticationHandler, clientBinaryHandler, clientCommandHandler, clientConnectedTime, clientData, clientEventHandler, clientEvents, clientExtendedEventHandler, clientObjectHandler, closeOrLostNotified, communicationLogging, connection, counAuthTry, dataModeIN, dataModeOUT, in, lastCommunicationTime, lockObj, lost, maxAuthTry, maxAuthTryMsg, maxConnectionMsg, NEW_LINE, NEW_LINE_BYTES, o_in, o_out, out, quickServer, secure, socket, socketTimeout, threadEvent, timeoutMsg, unprocessedClientEvents, willClean
 
Constructor Summary
NonBlockingClientHandler()
           
NonBlockingClientHandler(int instanceCount)
           
 
Method Summary
protected  boolean checkReturnClientHandler()
           
 void clean()
           
 void closeConnection()
          Closes client socket associated.
protected  void finalize()
           
 java.io.BufferedReader getBufferedReader()
          Returns the BufferedReader associated with the Client being handled.
static int getMaxThreadAccessCount()
          Returns the maximum count of thread allowed to run objects of this class at a time.
 java.nio.channels.SelectionKey getSelectionKey()
          Returns client SelectionKey associated, if any.
 java.nio.channels.SocketChannel getSocketChannel()
          Returns client socket channel associated, if any.
 int getThreadAccessCount()
          Returns number of thread currently in this object.
static boolean getWakeupSelectorAfterRegisterRead()
          Returns wakeupSelectorAfterRegisterRead the flag that controls if wakeup is called on Selector after RegisterForRead is called.
static boolean getWakeupSelectorAfterRegisterWrite()
          Returns wakeupSelectorAfterRegisterWrite the flag that controls if wakeup is called on Selector after RegisterForWrite is called.
 void handleClient(TheClient theClient)
          Associates the ClientHanlder with the client encapsulated by theClient.
protected  byte[] readInputStream()
          Read the byte input.
 void registerForRead()
          Register OP_READ with the SelectionKey associated with the channel.
 void registerForWrite()
          Register OP_WRITE with the SelectionKey associated with the channel.
 void registerWrite()
           
protected  void returnClientHandler()
           
protected  void returnThread()
           
 void run()
           
protected  void setClientWriteHandler(ClientWriteHandler handler)
          Sets the ClientWriteHandler class that interacts with client sockets.
 void setDataMode(DataMode dataMode, DataType dataType)
          Sets the DataMode for the ClientHandler Note: When mode is DataMode.OBJECT and type is DataType.IN this call will block until the client ObjectOutputStream has written and flushes the header.
protected  void setInputStream(java.io.InputStream in)
          Sets the InputStream associated with the Client being handled.
static void setMaxThreadAccessCount(int count)
          Sets the maximum count of thread allowed to run objects of this class at a time.
 void setSelectionKey(java.nio.channels.SelectionKey selectionKey)
          Sets client SelectionKey associated, if any.
 void setSocketChannel(java.nio.channels.SocketChannel socketChannel)
          Sets client socket channel associated, if any.
static void setWakeupSelectorAfterRegisterRead(boolean flag)
          Sets the flag to wakeup Selector After RegisterForRead is called.
static void setWakeupSelectorAfterRegisterWrite(boolean flag)
          Sets the flag to wakeup Selector After RegisterForWrite is called.
 void updateInputOutputStreams()
          Updates the InputStream and OutputStream for the ClientHandler for the set Socket.
 void waitTillFullyWritten()
          waitTillFullyWritten
 
Methods inherited from class org.quickserver.net.server.impl.BasicClientHandler
addEvent, assertionSystemExit, checkDataModeSet, forceClose, getAppLogger, getBufferedInputStream, getBufferedOutputStream, getBufferedWriter, getCharset, getClientConnectedTime, getClientData, getClientIdentifiable, getCommunicationLogging, getConnection, getDataMode, getHostAddress, getInputStream, getInstanceCount, getLastCommunicationTime, getMaxConnectionMsg, getName, getObjectInputStream, getObjectOutputStream, getOutputStream, getServer, getSocket, getThreadEvent, getTimeout, getWillClean, handleTimeout, hasEvent, info, isClientEventNext, isClosed, isConected, isConnected, isOpen, isSecure, makeSecure, makeSecure, makeSecure, notifyCloseOrLost, prepareForRun, processAuthorisation, processMaxConnection, readBinary, readBytes, readInputStream, removeEvent, returnClientData, sendClientBinary, sendClientBinary, sendClientBytes, sendClientMsg, sendClientObject, sendSystemMsg, sendSystemMsg, sendSystemMsg, setAuthenticator, setCharset, setClientAuthenticationHandler, setClientBinaryHandler, setClientCommandHandler, setClientData, setClientEventHandler, setClientExtendedEventHandler, setClientObjectHandler, setCommunicationLogging, setMaxConnectionMsg, setOutputStream, setSecure, setServer, setSocket, setTimeout, toString, updateLastCommunicationTime
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

clientWriteHandler

protected ClientWriteHandler clientWriteHandler

readByteBuffer

protected java.util.ArrayList readByteBuffer

writeByteBuffer

protected java.util.ArrayList writeByteBuffer

selectionKey

protected java.nio.channels.SelectionKey selectionKey

threadAccessCount

protected volatile int threadAccessCount

willReturn

protected volatile boolean willReturn

waitingForFinalWrite

protected volatile boolean waitingForFinalWrite
Constructor Detail

NonBlockingClientHandler

public NonBlockingClientHandler(int instanceCount)

NonBlockingClientHandler

public NonBlockingClientHandler()
Method Detail

setWakeupSelectorAfterRegisterWrite

public static void setWakeupSelectorAfterRegisterWrite(boolean flag)
Sets the flag to wakeup Selector After RegisterForWrite is called.

Since:
1.4.7

getWakeupSelectorAfterRegisterWrite

public static boolean getWakeupSelectorAfterRegisterWrite()
Returns wakeupSelectorAfterRegisterWrite the flag that controls if wakeup is called on Selector after RegisterForWrite is called.

Since:
1.4.7

setWakeupSelectorAfterRegisterRead

public static void setWakeupSelectorAfterRegisterRead(boolean flag)
Sets the flag to wakeup Selector After RegisterForRead is called.

Since:
1.4.7

getWakeupSelectorAfterRegisterRead

public static boolean getWakeupSelectorAfterRegisterRead()
Returns wakeupSelectorAfterRegisterRead the flag that controls if wakeup is called on Selector after RegisterForRead is called.

Since:
1.4.7

setMaxThreadAccessCount

public static void setMaxThreadAccessCount(int count)
Sets the maximum count of thread allowed to run objects of this class at a time.

Since:
1.4.7

getMaxThreadAccessCount

public static int getMaxThreadAccessCount()
Returns the maximum count of thread allowed to run objects of this class at a time.

Since:
1.4.7

clean

public void clean()
Specified by:
clean in interface ClientHandler
Overrides:
clean in class BasicClientHandler

finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class BasicClientHandler
Throws:
java.lang.Throwable

handleClient

public void handleClient(TheClient theClient)
Description copied from class: BasicClientHandler
Associates the ClientHanlder with the client encapsulated by theClient.

Specified by:
handleClient in interface ClientHandler
Overrides:
handleClient in class BasicClientHandler
Parameters:
theClient - object that encapsulates client socket and its configuration details.

setInputStream

protected void setInputStream(java.io.InputStream in)
                       throws java.io.IOException
Description copied from class: BasicClientHandler
Sets the InputStream associated with the Client being handled.

Specified by:
setInputStream in class BasicClientHandler
Throws:
java.io.IOException
See Also:
BasicClientHandler.getInputStream()

getBufferedReader

public java.io.BufferedReader getBufferedReader()
Description copied from class: BasicClientHandler
Returns the BufferedReader associated with the Client being handled. Note that this is only available under blocking mode.

Specified by:
getBufferedReader in interface ClientHandler
Specified by:
getBufferedReader in class BasicClientHandler
See Also:
BasicClientHandler.getBufferedWriter()

closeConnection

public void closeConnection()
Description copied from class: BasicClientHandler
Closes client socket associated.

Specified by:
closeConnection in interface ClientHandler
Specified by:
closeConnection in class BasicClientHandler

waitTillFullyWritten

public void waitTillFullyWritten()
waitTillFullyWritten

Since:
1.4.7

run

public void run()
Specified by:
run in interface ClientHandler
Specified by:
run in class BasicClientHandler

checkReturnClientHandler

protected boolean checkReturnClientHandler()

returnThread

protected void returnThread()

returnClientHandler

protected void returnClientHandler()
Overrides:
returnClientHandler in class BasicClientHandler

setDataMode

public void setDataMode(DataMode dataMode,
                        DataType dataType)
                 throws java.io.IOException
Description copied from class: BasicClientHandler
Sets the DataMode for the ClientHandler Note: When mode is DataMode.OBJECT and type is DataType.IN this call will block until the client ObjectOutputStream has written and flushes the header.

Specified by:
setDataMode in interface ClientHandler
Specified by:
setDataMode in class BasicClientHandler
Parameters:
dataMode - mode of data exchange - String or Object.
dataType - type of data for which mode has to be set.
Throws:
java.io.IOException - if mode could not be changed.

readInputStream

protected byte[] readInputStream()
                          throws java.io.IOException
Description copied from class: BasicClientHandler
Read the byte input. This will block till some data is received from the stream.

Specified by:
readInputStream in class BasicClientHandler
Returns:
The data as a String
Throws:
java.io.IOException

updateInputOutputStreams

public void updateInputOutputStreams()
                              throws java.io.IOException
Description copied from class: BasicClientHandler
Updates the InputStream and OutputStream for the ClientHandler for the set Socket.

Specified by:
updateInputOutputStreams in interface ClientHandler
Specified by:
updateInputOutputStreams in class BasicClientHandler
Throws:
java.io.IOException
See Also:
BasicClientHandler.setSocket(java.net.Socket)

setSocketChannel

public void setSocketChannel(java.nio.channels.SocketChannel socketChannel)
Description copied from class: BasicClientHandler
Sets client socket channel associated, if any.

Specified by:
setSocketChannel in interface ClientHandler
Specified by:
setSocketChannel in class BasicClientHandler

getSocketChannel

public java.nio.channels.SocketChannel getSocketChannel()
Description copied from class: BasicClientHandler
Returns client socket channel associated, if any.

Specified by:
getSocketChannel in interface ClientHandler
Specified by:
getSocketChannel in class BasicClientHandler

setSelectionKey

public void setSelectionKey(java.nio.channels.SelectionKey selectionKey)
Description copied from class: BasicClientHandler
Sets client SelectionKey associated, if any.

Specified by:
setSelectionKey in interface ClientHandler
Specified by:
setSelectionKey in class BasicClientHandler

getSelectionKey

public java.nio.channels.SelectionKey getSelectionKey()
Description copied from class: BasicClientHandler
Returns client SelectionKey associated, if any.

Specified by:
getSelectionKey in interface ClientHandler
Specified by:
getSelectionKey in class BasicClientHandler

registerForRead

public void registerForRead()
                     throws java.io.IOException,
                            java.nio.channels.ClosedChannelException
Description copied from class: BasicClientHandler
Register OP_READ with the SelectionKey associated with the channel. If SelectionKey is not set then it registers the channel with the Selector.

Specified by:
registerForRead in interface ClientHandler
Specified by:
registerForRead in class BasicClientHandler
Throws:
java.io.IOException
java.nio.channels.ClosedChannelException

registerForWrite

public void registerForWrite()
                      throws java.io.IOException,
                             java.nio.channels.ClosedChannelException
Description copied from class: BasicClientHandler
Register OP_WRITE with the SelectionKey associated with the channel.

Specified by:
registerForWrite in interface ClientHandler
Specified by:
registerForWrite in class BasicClientHandler
Throws:
java.io.IOException
java.nio.channels.ClosedChannelException

registerWrite

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

setClientWriteHandler

protected void setClientWriteHandler(ClientWriteHandler handler)
Description copied from class: BasicClientHandler
Sets the ClientWriteHandler class that interacts with client sockets.

Specified by:
setClientWriteHandler in class BasicClientHandler
Parameters:
handler - fully qualified name of the class that implements ClientWriteHandler

getThreadAccessCount

public int getThreadAccessCount()
Returns number of thread currently in this object.

Since:
1.4.6

QuickServer
v1.4.7

Copyright © 2003-2006 QuickServer.org