QuickServer
v1.4.7

org.quickserver.net.server.impl
Class BasicClientHandler

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

public abstract class BasicClientHandler
extends java.lang.Object
implements ClientHandler

Basic implementation of ClientHandler that handles clients for QuickServer.

This class is used by QuickServer to handle each new client connected. This class is responsible to handle client sockets. It can operate in both blocking mode and non-blocking mode (java nio).

Contributions By: Martin Benns : BYTE Mode

Author:
Akshathkumar Shetty, Martin Benns : Added BYTE mode

Field Summary
protected  java.util.logging.Logger appLogger
           
protected  Authenticator authenticator
           
protected  boolean authorised
          Client authorisation status
protected  java.io.BufferedInputStream b_in
           
protected  java.io.BufferedOutputStream b_out
           
protected  java.io.BufferedReader bufferedReader
           
protected  java.lang.String charset
           
protected  ClientAuthenticationHandler clientAuthenticationHandler
           
protected  ClientBinaryHandler clientBinaryHandler
           
protected  ClientCommandHandler clientCommandHandler
           
protected  java.util.Date clientConnectedTime
           
protected  ClientData clientData
           
protected  ClientEventHandler clientEventHandler
           
protected  java.util.Set clientEvents
           
protected  ClientExtendedEventHandler clientExtendedEventHandler
           
protected  ClientObjectHandler clientObjectHandler
           
protected  boolean closeOrLostNotified
           
protected  boolean communicationLogging
           
protected  boolean connection
           
protected  int counAuthTry
          Count of client login attempts
protected  DataMode dataModeIN
           
protected  DataMode dataModeOUT
           
protected  java.io.InputStream in
           
protected  java.util.Date lastCommunicationTime
           
protected  java.lang.Object lockObj
           
protected  boolean lost
           
protected  int maxAuthTry
          max allowed login attempts
protected  java.lang.String maxAuthTryMsg
          Message to be displayed when max login attempt reaches.
protected  java.lang.String maxConnectionMsg
           
protected static java.lang.String NEW_LINE
           
protected static byte[] NEW_LINE_BYTES
           
protected  java.io.ObjectInputStream o_in
           
protected  java.io.ObjectOutputStream o_out
           
protected  java.io.OutputStream out
           
protected  QuickServer quickServer
           
protected  boolean secure
           
protected  java.net.Socket socket
          Client socket
protected  int socketTimeout
           
protected static java.lang.ThreadLocal threadEvent
           
protected  java.lang.String timeoutMsg
          timeout message
protected  java.util.List unprocessedClientEvents
           
protected  boolean willClean
           
 
Constructor Summary
BasicClientHandler()
           
BasicClientHandler(int instanceCount)
           
 
Method Summary
 void addEvent(ClientEvent event)
          Adds the ClientEvent.
protected  void assertionSystemExit()
           
protected  void checkDataModeSet(DataMode dataMode, DataType dataType)
           
 void clean()
           
abstract  void closeConnection()
          Closes client socket associated.
protected  void finalize()
           
 void forceClose()
          Force the closing of the client by closing the associated socket.
 java.util.logging.Logger getAppLogger()
          Returns client SelectionKey associated, if any.
 java.io.BufferedInputStream getBufferedInputStream()
          Returns the BufferedInputStream associated with the Client being handled.
 java.io.BufferedOutputStream getBufferedOutputStream()
          Returns the BufferedOutputStream associated with the Client being handled.
abstract  java.io.BufferedReader getBufferedReader()
          Returns the BufferedReader associated with the Client being handled.
 java.io.BufferedWriter getBufferedWriter()
          Deprecated. since 1.4.5 use getOutputStream()
 java.lang.String getCharset()
          Returns Charset to be used for String decoding and encoding..
 java.util.Date getClientConnectedTime()
          Returns the date/time when the client socket was assigned to this ClientHanlder.
 ClientData getClientData()
          Returns the ClientData object associated with this ClientHandler, if not set will return null
protected static java.lang.String getClientIdentifiable(ClientHandler foundClientHandler)
           
 boolean getCommunicationLogging()
          Returns the communication logging flag.
 java.sql.Connection getConnection(java.lang.String id)
          Deprecated. as of v1.4.5 use getServer().getDBPoolUtil().getConnection(id)
 DataMode getDataMode(DataType dataType)
          Returns the DataMode of the ClientHandler for the DataType.
 java.lang.String getHostAddress()
          Returns cached socket host ip address.
 java.io.InputStream getInputStream()
          Returns the InputStream associated with the Client being handled.
 int getInstanceCount()
           
 java.util.Date getLastCommunicationTime()
          Returns the date/time when the client socket last sent a data to this ClientHanlder.
 java.lang.String getMaxConnectionMsg()
          Returns message to be displayed to the client when maximum connection reaches.
 java.lang.String getName()
          Returns the ClientHandler name
 java.io.ObjectInputStream getObjectInputStream()
          Returns the ObjectInputStream associated with the Client being handled.
 java.io.ObjectOutputStream getObjectOutputStream()
          Returns the ObjectOutputStream associated with the Client being handled.
 java.io.OutputStream getOutputStream()
          Returns the OutputStream associated with the Client being handled.
abstract  java.nio.channels.SelectionKey getSelectionKey()
          Returns client SelectionKey associated, if any.
 QuickServer getServer()
          Returns the QuickServer object that created it.
 java.net.Socket getSocket()
          Returns client socket associated.
abstract  java.nio.channels.SocketChannel getSocketChannel()
          Returns client socket channel associated, if any.
protected  ClientEvent getThreadEvent()
          Returns threads current event for this client.
 int getTimeout()
          Returns the Client socket timeout in milliseconds.
 boolean getWillClean()
           
 void handleClient(TheClient theClient)
          Associates the ClientHanlder with the client encapsulated by theClient.
protected  void handleTimeout(java.net.SocketTimeoutException e)
           
 boolean hasEvent(ClientEvent event)
          Checks if this client has the event.
 java.lang.String info()
          Returns the ClientHandler detailed information.
 boolean isClientEventNext(ClientEvent clientEvent)
          Checks if the passed ClientEvent is the one next for processing if a thread is allowed through this object.
 boolean isClosed()
          Checks if the client is closed.
 boolean isConected()
          Deprecated. since 1.4.5 Use isConnected()
 boolean isConnected()
          Checks if the client is still connected.
 boolean isOpen()
          Checks if the client is still connected and if socket is open.
 boolean isSecure()
          Returns flag indicating if the client is connected in secure mode (SSL or TLS).
 void makeSecure()
          Makes current Client connection to secure protocol based on the secure configuration set to the server.
 void makeSecure(boolean useClientMode, boolean needClientAuth, boolean autoClose, java.lang.String protocol)
          Makes current Client connection to secure protocol.
 void makeSecure(java.lang.String protocol)
          Makes current Client connection to secure protocol.
protected  void notifyCloseOrLost()
           
protected  void prepareForRun()
           
protected  AuthStatus processAuthorisation()
           
protected  void processMaxConnection(ClientEvent currentEvent)
           
 byte[] readBinary()
          Read the binary input.
 java.lang.String readBytes()
          Read the byte input.
protected abstract  byte[] readInputStream()
          Read the byte input.
protected static byte[] readInputStream(java.io.InputStream _in)
           
abstract  void registerForRead()
          Register OP_READ with the SelectionKey associated with the channel.
abstract  void registerForWrite()
          Register OP_WRITE with the SelectionKey associated with the channel.
 void removeEvent(ClientEvent event)
          Removes the ClientEvent.
protected  void returnClientData()
           
protected  void returnClientHandler()
           
abstract  void run()
           
 void sendClientBinary(byte[] data)
          Send a binary data to the connected client.
 void sendClientBinary(byte[] data, int off, int len)
          Send a binary data to the connected client.
 void sendClientBytes(java.lang.String msg)
          Send a String message to the connected client as a string of bytes.
 void sendClientMsg(java.lang.String msg)
          Send a String message to the connected client it adds a new line{\r\n} to the end of the string.
 void sendClientObject(java.lang.Object msg)
          Send a Object message to the connected client.
 void sendSystemMsg(java.lang.String msg)
          Send a String message to the logger associated with QuickServer.getAppLogger() with Level.INFO as its level.
 void sendSystemMsg(java.lang.String msg, boolean newline)
          Deprecated. Use sendSystemMsg(java.lang.String), since it uses Logging.
 void sendSystemMsg(java.lang.String msg, java.util.logging.Level level)
          Send a String message to the logger associated with QuickServer.getAppLogger().
protected  void setAuthenticator(Authenticator authenticator)
          Sets the Authenticator class that handles the authentication of a client.
 void setCharset(java.lang.String charset)
          Sets the Charset to be used for String decoding and encoding.
protected  void setClientAuthenticationHandler(ClientAuthenticationHandler clientAuthenticationHandler)
          Sets the ClientAuthenticationHandler class that handles the authentication of a client.
protected  void setClientBinaryHandler(ClientBinaryHandler handler)
          Sets the ClientBinaryHandler class that interacts with client sockets.
protected  void setClientCommandHandler(ClientCommandHandler handler)
          Sets the ClientCommandHandler class that interacts with client sockets.
protected  void setClientData(ClientData data)
          Sets the ClientData object associated with this ClientHandler
protected  void setClientEventHandler(ClientEventHandler handler)
          Sets the ClientEventHandler class that gets notified of client events.
protected  void setClientExtendedEventHandler(ClientExtendedEventHandler handler)
          Sets the ClientExtendedEventHandler class that gets notified of extended client events.
protected  void setClientObjectHandler(ClientObjectHandler handler)
          Sets the ClientObjectHandler class that interacts with client sockets.
protected abstract  void setClientWriteHandler(ClientWriteHandler handler)
          Sets the ClientWriteHandler class that interacts with client sockets.
 void setCommunicationLogging(boolean communicationLogging)
          Sets the communication logging flag.
abstract  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 abstract  void setInputStream(java.io.InputStream in)
          Sets the InputStream associated with the Client being handled.
 void setMaxConnectionMsg(java.lang.String msg)
          Sets message to be displayed when maximum connection reaches.
 void setOutputStream(java.io.OutputStream out)
          Set the OutputStream associated with the Client being handled.
 void setSecure(boolean secure)
          Sets flag indicating if the client is connected in secure mode (SSL or TLS).
abstract  void setSelectionKey(java.nio.channels.SelectionKey selectionKey)
          Sets client SelectionKey associated, if any.
protected  void setServer(QuickServer server)
          Sets the QuickServer object associated with this ClientHandler.
 void setSocket(java.net.Socket socket)
          Returns client socket associated.
abstract  void setSocketChannel(java.nio.channels.SocketChannel socketChannel)
          Sets client socket channel associated, if any.
 void setTimeout(int time)
          Sets the client socket's timeout.
 java.lang.String toString()
          Returns the ClientHandler information.
abstract  void updateInputOutputStreams()
          Updates the InputStream and OutputStream for the ClientHandler for the set Socket.
 void updateLastCommunicationTime()
          Updates the last communication time for this client
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NEW_LINE

protected static final java.lang.String NEW_LINE

NEW_LINE_BYTES

protected static final byte[] NEW_LINE_BYTES

socket

protected java.net.Socket socket
Client socket


authorised

protected volatile boolean authorised
Client authorisation status


counAuthTry

protected int counAuthTry
Count of client login attempts


maxAuthTry

protected int maxAuthTry
max allowed login attempts


timeoutMsg

protected java.lang.String timeoutMsg
timeout message


maxAuthTryMsg

protected java.lang.String maxAuthTryMsg
Message to be displayed when max login attempt reaches.


socketTimeout

protected int socketTimeout

connection

protected volatile boolean connection

lost

protected boolean lost

quickServer

protected QuickServer quickServer

authenticator

protected Authenticator authenticator

clientAuthenticationHandler

protected ClientAuthenticationHandler clientAuthenticationHandler

clientEventHandler

protected ClientEventHandler clientEventHandler

clientExtendedEventHandler

protected ClientExtendedEventHandler clientExtendedEventHandler

clientCommandHandler

protected ClientCommandHandler clientCommandHandler

clientObjectHandler

protected ClientObjectHandler clientObjectHandler

clientBinaryHandler

protected ClientBinaryHandler clientBinaryHandler

clientData

protected ClientData clientData

in

protected java.io.InputStream in

out

protected java.io.OutputStream out

bufferedReader

protected java.io.BufferedReader bufferedReader

o_out

protected java.io.ObjectOutputStream o_out

o_in

protected java.io.ObjectInputStream o_in

b_in

protected java.io.BufferedInputStream b_in

b_out

protected java.io.BufferedOutputStream b_out

appLogger

protected java.util.logging.Logger appLogger

dataModeIN

protected DataMode dataModeIN

dataModeOUT

protected DataMode dataModeOUT

communicationLogging

protected boolean communicationLogging

clientConnectedTime

protected java.util.Date clientConnectedTime

lastCommunicationTime

protected java.util.Date lastCommunicationTime

secure

protected boolean secure

threadEvent

protected static final java.lang.ThreadLocal threadEvent

maxConnectionMsg

protected java.lang.String maxConnectionMsg

clientEvents

protected java.util.Set clientEvents

unprocessedClientEvents

protected java.util.List unprocessedClientEvents

closeOrLostNotified

protected volatile boolean closeOrLostNotified

lockObj

protected java.lang.Object lockObj

willClean

protected volatile boolean willClean

charset

protected java.lang.String charset
Constructor Detail

BasicClientHandler

public BasicClientHandler(int instanceCount)

BasicClientHandler

public BasicClientHandler()
Method Detail

getInstanceCount

public int getInstanceCount()

clean

public void clean()
Specified by:
clean in interface ClientHandler

finalize

protected void finalize()
                 throws java.lang.Throwable
Throws:
java.lang.Throwable

handleClient

public void handleClient(TheClient theClient)
Associates the ClientHanlder with the client encapsulated by theClient.

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

getServer

public QuickServer getServer()
Returns the QuickServer object that created it.

Specified by:
getServer in interface ClientHandler
See Also:
setServer(org.quickserver.net.server.QuickServer)

setServer

protected void setServer(QuickServer server)
Sets the QuickServer object associated with this ClientHandler.

See Also:
getServer()

setClientData

protected void setClientData(ClientData data)
Sets the ClientData object associated with this ClientHandler

See Also:
ClientData, getClientData()

getClientData

public ClientData getClientData()
Returns the ClientData object associated with this ClientHandler, if not set will return null

Specified by:
getClientData in interface ClientHandler
See Also:
ClientData, setClientData(org.quickserver.net.server.ClientData)

setClientAuthenticationHandler

protected void setClientAuthenticationHandler(ClientAuthenticationHandler clientAuthenticationHandler)
Sets the ClientAuthenticationHandler class that handles the authentication of a client.

Parameters:
clientAuthenticationHandler - fully qualified name of the class that implements ClientAuthenticationHandler.
Since:
1.4.6

setAuthenticator

protected void setAuthenticator(Authenticator authenticator)
Sets the Authenticator class that handles the authentication of a client.

Parameters:
authenticator - fully qualified name of the class that implements Authenticator.
Since:
1.3

getInputStream

public java.io.InputStream getInputStream()
Returns the InputStream associated with the Client being handled.

Specified by:
getInputStream in interface ClientHandler
See Also:
setInputStream(java.io.InputStream)

setInputStream

protected abstract void setInputStream(java.io.InputStream in)
                                throws java.io.IOException
Sets the InputStream associated with the Client being handled.

Throws:
java.io.IOException
Since:
1.1
See Also:
getInputStream()

getOutputStream

public java.io.OutputStream getOutputStream()
Returns the OutputStream associated with the Client being handled.

Specified by:
getOutputStream in interface ClientHandler
See Also:
setOutputStream(java.io.OutputStream)

setOutputStream

public void setOutputStream(java.io.OutputStream out)
                     throws java.io.IOException
Set the OutputStream associated with the Client being handled.

Specified by:
setOutputStream in interface ClientHandler
Throws:
java.io.IOException - if ObjectOutputStream could not be created.
Since:
1.1
See Also:
getOutputStream()

getBufferedReader

public abstract java.io.BufferedReader getBufferedReader()
Returns the BufferedReader associated with the Client being handled. Note that this is only available under blocking mode.

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

getBufferedWriter

public java.io.BufferedWriter getBufferedWriter()
Deprecated. since 1.4.5 use getOutputStream()

Returns the BufferedWriter associated with the Client being handled.

Specified by:
getBufferedWriter in interface ClientHandler

getObjectOutputStream

public java.io.ObjectOutputStream getObjectOutputStream()
Returns the ObjectOutputStream associated with the Client being handled. It will be null if no ClientObjectHandler was set in QuickServer.

Specified by:
getObjectOutputStream in interface ClientHandler
Since:
1.2
See Also:
getObjectInputStream()

getObjectInputStream

public java.io.ObjectInputStream getObjectInputStream()
Returns the ObjectInputStream associated with the Client being handled. It will be null if no ClientObjectHandler was set in QuickServer.

Specified by:
getObjectInputStream in interface ClientHandler
Since:
1.2
See Also:
getObjectOutputStream()

setClientEventHandler

protected void setClientEventHandler(ClientEventHandler handler)
Sets the ClientEventHandler class that gets notified of client events.

Since:
1.4.6

setClientExtendedEventHandler

protected void setClientExtendedEventHandler(ClientExtendedEventHandler handler)
Sets the ClientExtendedEventHandler class that gets notified of extended client events.

Since:
1.4.6

setClientCommandHandler

protected void setClientCommandHandler(ClientCommandHandler handler)
Sets the ClientCommandHandler class that interacts with client sockets.


setClientObjectHandler

protected void setClientObjectHandler(ClientObjectHandler handler)
Sets the ClientObjectHandler class that interacts with client sockets.

Parameters:
handler - fully qualified name of the class that implements ClientObjectHandler
Since:
1.2

closeConnection

public abstract void closeConnection()
Closes client socket associated.

Specified by:
closeConnection in interface ClientHandler

getSocket

public java.net.Socket getSocket()
Returns client socket associated.

Specified by:
getSocket in interface ClientHandler

setSocket

public void setSocket(java.net.Socket socket)
Returns client socket associated.

Specified by:
setSocket in interface ClientHandler
Since:
1.4.0
See Also:
updateInputOutputStreams()

isConected

public boolean isConected()
                   throws java.net.SocketException
Deprecated. since 1.4.5 Use isConnected()

Checks if the client is still connected.

Specified by:
isConected in interface ClientHandler
Throws:
java.net.SocketException - if Socket is not open.

isConnected

public boolean isConnected()
                    throws java.net.SocketException
Checks if the client is still connected.

Specified by:
isConnected in interface ClientHandler
Throws:
java.net.SocketException - if Socket is not open.
Since:
1.4.5

isOpen

public boolean isOpen()
Checks if the client is still connected and if socket is open. This is same as isConnected() but does not throw SocketException.

Specified by:
isOpen in interface ClientHandler
Since:
1.4.6

isClosed

public boolean isClosed()
Checks if the client is closed.

Specified by:
isClosed in interface ClientHandler
Since:
1.4.1

sendClientMsg

public void sendClientMsg(java.lang.String msg)
                   throws java.io.IOException
Send a String message to the connected client it adds a new line{\r\n} to the end of the string. If client is not connected it will just return.

Specified by:
sendClientMsg in interface ClientHandler
Throws:
java.io.IOException - if Socket IO Error or Socket was closed by the client.

sendClientBytes

public void sendClientBytes(java.lang.String msg)
                     throws java.io.IOException
Send a String message to the connected client as a string of bytes. If client is not connected it will just return.

Specified by:
sendClientBytes in interface ClientHandler
Throws:
java.io.IOException - if Socket IO Error or Socket was closed by the client.
Since:
1.3.1

sendClientObject

public void sendClientObject(java.lang.Object msg)
                      throws java.io.IOException
Send a Object message to the connected client. The message Object passed must be serializable. If client is not connected it will just return.

Specified by:
sendClientObject in interface ClientHandler
Throws:
java.io.IOException - if Socket IO Error or Socket was closed by the client.
java.lang.IllegalStateException - if DataType.OUT is not in DataMode.OBJECT
Since:
1.2
See Also:
setDataMode(org.quickserver.net.server.DataMode, org.quickserver.net.server.DataType)

sendSystemMsg

public void sendSystemMsg(java.lang.String msg)
Send a String message to the logger associated with QuickServer.getAppLogger() with Level.INFO as its level.

Specified by:
sendSystemMsg in interface ClientHandler

sendSystemMsg

public void sendSystemMsg(java.lang.String msg,
                          java.util.logging.Level level)
Send a String message to the logger associated with QuickServer.getAppLogger().

Specified by:
sendSystemMsg in interface ClientHandler
Since:
1.2

sendSystemMsg

public void sendSystemMsg(java.lang.String msg,
                          boolean newline)
Deprecated. Use sendSystemMsg(java.lang.String), since it uses Logging.

Send a String message to the system output stream.

Specified by:
sendSystemMsg in interface ClientHandler
Parameters:
newline - indicates if new line required at the end.

run

public abstract void run()
Specified by:
run in interface ClientHandler

prepareForRun

protected void prepareForRun()
                      throws java.net.SocketException,
                             java.io.IOException
Throws:
java.net.SocketException
java.io.IOException

processMaxConnection

protected void processMaxConnection(ClientEvent currentEvent)
                             throws java.io.IOException
Throws:
java.io.IOException

processAuthorisation

protected AuthStatus processAuthorisation()
                                   throws java.net.SocketException,
                                          java.io.IOException,
                                          AppException
Throws:
java.net.SocketException
java.io.IOException
AppException

notifyCloseOrLost

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

returnClientData

protected void returnClientData()

returnClientHandler

protected void returnClientHandler()

getName

public java.lang.String getName()
Returns the ClientHandler name

Specified by:
getName in interface ClientHandler
Since:
1.4.6

info

public java.lang.String info()
Returns the ClientHandler detailed information. If ClientData is present and is ClientIdentifiable will return ClientInfo else it will return Clients InetAddress and port information.

Specified by:
info in interface ClientHandler

toString

public java.lang.String toString()
Returns the ClientHandler information. If ClientData is present and is ClientIdentifiable will return ClientInfo else it will return Clients InetAddress and port information.

Specified by:
toString in interface ClientHandler

getClientIdentifiable

protected static java.lang.String getClientIdentifiable(ClientHandler foundClientHandler)

setDataMode

public abstract void setDataMode(DataMode dataMode,
                                 DataType dataType)
                          throws java.io.IOException
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
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.
Since:
1.2

checkDataModeSet

protected void checkDataModeSet(DataMode dataMode,
                                DataType dataType)

getDataMode

public DataMode getDataMode(DataType dataType)
Returns the DataMode of the ClientHandler for the DataType.

Specified by:
getDataMode in interface ClientHandler
Since:
1.2

getConnection

public java.sql.Connection getConnection(java.lang.String id)
                                  throws java.lang.Exception
Deprecated. as of v1.4.5 use getServer().getDBPoolUtil().getConnection(id)

Returns the Connection object for the DatabaseConnection that is identified by id passed. If id passed does not match with any connection loaded by this class it will return null. This just calls getServer().getDBPoolUtil().getConnection(id)

Specified by:
getConnection in interface ClientHandler
Throws:
java.lang.Exception
Since:
1.3

getClientConnectedTime

public java.util.Date getClientConnectedTime()
Returns the date/time when the client socket was assigned to this ClientHanlder. If no client is currently connected it will return null

Specified by:
getClientConnectedTime in interface ClientHandler
Since:
1.3.1

readInputStream

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

Returns:
The data as a String
Throws:
java.io.IOException
Since:
1.3.1

readInputStream

protected static byte[] readInputStream(java.io.InputStream _in)
                                 throws java.io.IOException
Throws:
java.io.IOException

readBytes

public java.lang.String readBytes()
                           throws java.io.IOException
Read the byte input. This will block till some data is received from the stream. Allowed only when DataType.IN is in DataMode.BYTE mode.

Specified by:
readBytes in interface ClientHandler
Returns:
The data as a String
Throws:
java.io.IOException
Since:
1.3.2

setCommunicationLogging

public void setCommunicationLogging(boolean communicationLogging)
Sets the communication logging flag.

Specified by:
setCommunicationLogging in interface ClientHandler
Since:
1.3.2
See Also:
getCommunicationLogging()

getCommunicationLogging

public boolean getCommunicationLogging()
Returns the communication logging flag.

Specified by:
getCommunicationLogging in interface ClientHandler
Since:
1.3.2
See Also:
setCommunicationLogging(boolean)

getLastCommunicationTime

public java.util.Date getLastCommunicationTime()
Returns the date/time when the client socket last sent a data to this ClientHanlder. If no client is currently connected it will return null

Specified by:
getLastCommunicationTime in interface ClientHandler
Since:
1.3.3

updateLastCommunicationTime

public void updateLastCommunicationTime()
Updates the last communication time for this client

Specified by:
updateLastCommunicationTime in interface ClientHandler
Since:
1.3.3

forceClose

public void forceClose()
                throws java.io.IOException
Force the closing of the client by closing the associated socket.

Specified by:
forceClose in interface ClientHandler
Throws:
java.io.IOException
Since:
1.3.3

isSecure

public boolean isSecure()
Returns flag indicating if the client is connected in secure mode (SSL or TLS).

Specified by:
isSecure in interface ClientHandler
Returns:
secure flag
Since:
1.4.0

setSecure

public void setSecure(boolean secure)
Sets flag indicating if the client is connected in secure mode (SSL or TLS).

Specified by:
setSecure in interface ClientHandler
Parameters:
secure -
Since:
1.4.0

updateInputOutputStreams

public abstract void updateInputOutputStreams()
                                       throws java.io.IOException
Updates the InputStream and OutputStream for the ClientHandler for the set Socket.

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

makeSecure

public void makeSecure()
                throws java.io.IOException,
                       java.security.NoSuchAlgorithmException,
                       java.security.KeyManagementException
Makes current Client connection to secure protocol based on the secure configuration set to the server. This method will just call makeSecure(false, false, true, null).

Specified by:
makeSecure in interface ClientHandler
Throws:
java.io.IOException
java.security.NoSuchAlgorithmException
java.security.KeyManagementException
Since:
1.4.0

makeSecure

public void makeSecure(java.lang.String protocol)
                throws java.io.IOException,
                       java.security.NoSuchAlgorithmException,
                       java.security.KeyManagementException
Makes current Client connection to secure protocol. This method will just call makeSecure(false, false, true, protocol).

Specified by:
makeSecure in interface ClientHandler
Throws:
java.io.IOException
java.security.NoSuchAlgorithmException
java.security.KeyManagementException
Since:
1.4.0

makeSecure

public void makeSecure(boolean useClientMode,
                       boolean needClientAuth,
                       boolean autoClose,
                       java.lang.String protocol)
                throws java.io.IOException,
                       java.security.NoSuchAlgorithmException,
                       java.security.KeyManagementException
Makes current Client connection to secure protocol.

Specified by:
makeSecure in interface ClientHandler
Parameters:
useClientMode - falg if the socket should start its first handshake in "client" mode.
needClientAuth - flag if the clients must authenticate themselves.
autoClose - close the underlying socket when this socket is closed
protocol - the standard name of the requested protocol. If null will use the protocol set in secure configuration of the server.
Throws:
java.io.IOException
java.security.NoSuchAlgorithmException
java.security.KeyManagementException
Since:
1.4.0

sendClientBinary

public void sendClientBinary(byte[] data)
                      throws java.io.IOException
Send a binary data to the connected client. If client is not connected it will just return.

Specified by:
sendClientBinary in interface ClientHandler
Throws:
java.io.IOException - if Socket IO Error or Socket was closed by the client.
Since:
1.4

sendClientBinary

public void sendClientBinary(byte[] data,
                             int off,
                             int len)
                      throws java.io.IOException
Send a binary data to the connected client. If client is not connected it will just return.

Specified by:
sendClientBinary in interface ClientHandler
Throws:
java.io.IOException - if Socket IO Error or Socket was closed by the client.
Since:
1.4.5

readBinary

public byte[] readBinary()
                  throws java.io.IOException
Read the binary input. This will block till some data is received from the stream. Allowed only when DataType.IN is in DataMode.BINARY mode.

Specified by:
readBinary in interface ClientHandler
Returns:
The data as a String
Throws:
java.io.IOException
Since:
1.4

setClientBinaryHandler

protected void setClientBinaryHandler(ClientBinaryHandler handler)
Sets the ClientBinaryHandler class that interacts with client sockets.

Parameters:
handler - fully qualified name of the class that implements ClientBinaryHandler
Since:
1.4

getAppLogger

public java.util.logging.Logger getAppLogger()
Returns client SelectionKey associated, if any.

Specified by:
getAppLogger in interface ClientHandler
Since:
1.4.5

setTimeout

public void setTimeout(int time)
Sets the client socket's timeout.

Specified by:
setTimeout in interface ClientHandler
Parameters:
time - client socket timeout in milliseconds.
Since:
1.4.5
See Also:
getTimeout()

getTimeout

public int getTimeout()
Returns the Client socket timeout in milliseconds.

Specified by:
getTimeout in interface ClientHandler
Since:
1.4.5
See Also:
setTimeout(int)

hasEvent

public boolean hasEvent(ClientEvent event)
Checks if this client has the event.

Specified by:
hasEvent in interface ClientHandler
Since:
1.4.5

addEvent

public void addEvent(ClientEvent event)
Adds the ClientEvent.

Specified by:
addEvent in interface ClientHandler
Since:
1.4.5

removeEvent

public void removeEvent(ClientEvent event)
Removes the ClientEvent.

Specified by:
removeEvent in interface ClientHandler
Since:
1.4.5

getThreadEvent

protected ClientEvent getThreadEvent()
Returns threads current event for this client.

Since:
1.4.5

setMaxConnectionMsg

public void setMaxConnectionMsg(java.lang.String msg)
Sets message to be displayed when maximum connection reaches.

Specified by:
setMaxConnectionMsg in interface ClientHandler
Since:
1.4.5

getMaxConnectionMsg

public java.lang.String getMaxConnectionMsg()
Returns message to be displayed to the client when maximum connection reaches.

Specified by:
getMaxConnectionMsg in interface ClientHandler
Since:
1.4.5

setSocketChannel

public abstract void setSocketChannel(java.nio.channels.SocketChannel socketChannel)
Sets client socket channel associated, if any.

Specified by:
setSocketChannel in interface ClientHandler
Since:
1.4.5

getSocketChannel

public abstract java.nio.channels.SocketChannel getSocketChannel()
Returns client socket channel associated, if any.

Specified by:
getSocketChannel in interface ClientHandler
Since:
1.4.5

setSelectionKey

public abstract void setSelectionKey(java.nio.channels.SelectionKey selectionKey)
Sets client SelectionKey associated, if any.

Specified by:
setSelectionKey in interface ClientHandler
Since:
1.4.5

getSelectionKey

public abstract java.nio.channels.SelectionKey getSelectionKey()
Returns client SelectionKey associated, if any.

Specified by:
getSelectionKey in interface ClientHandler
Since:
1.4.5

getWillClean

public boolean getWillClean()

registerForRead

public abstract void registerForRead()
                              throws java.io.IOException,
                                     java.nio.channels.ClosedChannelException
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
Throws:
java.io.IOException
java.nio.channels.ClosedChannelException
Since:
1.4.5

registerForWrite

public abstract void registerForWrite()
                               throws java.io.IOException,
                                      java.nio.channels.ClosedChannelException
Register OP_WRITE with the SelectionKey associated with the channel.

Specified by:
registerForWrite in interface ClientHandler
Throws:
java.io.IOException
java.nio.channels.ClosedChannelException
Since:
1.4.5

setClientWriteHandler

protected abstract void setClientWriteHandler(ClientWriteHandler handler)
Sets the ClientWriteHandler class that interacts with client sockets.

Parameters:
handler - fully qualified name of the class that implements ClientWriteHandler
Since:
1.4.5

setCharset

public void setCharset(java.lang.String charset)
Sets the Charset to be used for String decoding and encoding.

Specified by:
setCharset in interface ClientHandler
Parameters:
charset - to be used for String decoding and encoding
Since:
1.4.5
See Also:
getCharset()

getCharset

public java.lang.String getCharset()
Returns Charset to be used for String decoding and encoding..

Specified by:
getCharset in interface ClientHandler
Since:
1.4.5
See Also:
setCharset(java.lang.String)

getHostAddress

public java.lang.String getHostAddress()
Returns cached socket host ip address.

Specified by:
getHostAddress in interface ClientHandler
Since:
1.4.5

assertionSystemExit

protected void assertionSystemExit()

isClientEventNext

public boolean isClientEventNext(ClientEvent clientEvent)
Checks if the passed ClientEvent is the one next for processing if a thread is allowed through this object.

Specified by:
isClientEventNext in interface ClientHandler
Since:
1.4.6

getBufferedInputStream

public java.io.BufferedInputStream getBufferedInputStream()
Returns the BufferedInputStream associated with the Client being handled. Can be null if not available at the time of method call.

Specified by:
getBufferedInputStream in interface ClientHandler
Since:
1.4.6
See Also:
getBufferedOutputStream()

getBufferedOutputStream

public java.io.BufferedOutputStream getBufferedOutputStream()
Returns the BufferedOutputStream associated with the Client being handled. Can be null if not available at the time of method call.

Specified by:
getBufferedOutputStream in interface ClientHandler
Since:
1.4.6
See Also:
getBufferedInputStream()

handleTimeout

protected void handleTimeout(java.net.SocketTimeoutException e)
                      throws java.net.SocketException,
                             java.io.IOException
Throws:
java.net.SocketException
java.io.IOException

QuickServer
v1.4.7

Copyright © 2003-2006 QuickServer.org