|
QuickServer v1.4.1 |
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Object | +--org.quickserver.net.server.ClientHandler
Class that handles clients for QuickServer.
This class is used by QuickServer to create a new thread for
each new client connected. This class is responsible to handle client
sockets.
| Field Summary | |
protected boolean |
authorised
Client authorisation status |
protected int |
counAuthTry
Count of client login atempts |
protected int |
maxAuthTry
max alloed login atempts |
protected java.lang.String |
maxAuthTryMsg
Message to be displayed when max login attempt reaches. |
protected java.net.Socket |
socket
Client socket |
protected java.lang.String |
timeoutMsg
timeout message |
| Constructor Summary | |
ClientHandler()
|
|
ClientHandler(TheClient theClient,
int timeOut)
Created new ClientHandler thread that handles that client encapsulated by theClient. |
|
| Method Summary | |
void |
clean()
|
void |
closeConnection()
Closes client socket associated. |
protected void |
finalize()
|
void |
forceClose()
Force the closing of the client by closing the associated socket. |
java.io.BufferedReader |
getBufferedReader()
Returns the BufferedReader associated with
the Client being handled. |
java.io.BufferedWriter |
getBufferedWriter()
Returns the BufferedWriter associated with
the Client being handled. |
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 |
boolean |
getCommunicationLogging()
Returns the communication logging flag. |
java.sql.Connection |
getConnection(java.lang.String id)
Returns the Connection object for the
DatabaseConnection that is identified by id passed. |
DataMode |
getDataMode(DataType dataType)
Returns the DataMode of the ClientHandler for the
DataType. |
java.io.InputStream |
getInputStream()
Returns the InputStream associated with
the Client being handled. |
java.util.Date |
getLastCommunicationTime()
Returns the date/time when the client socket last sent a data to this ClientHanlder. |
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. |
QuickServer |
getServer()
Returns the QuickServer object that created it. |
java.net.Socket |
getSocket()
Returns client socket associated. |
long |
getSocketTimeout()
Return socket timeout |
void |
handleClient(TheClient theClient,
int timeOut)
Start handling of client handles that client encapsulated by theClient. |
boolean |
isClosed()
Checks if the client is closed. |
boolean |
isConected()
Checks if the client is still conected. |
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. |
byte[] |
readBinary()
Read the binary input. |
java.lang.String |
readBytes()
Read the byte input. |
void |
run()
|
void |
sendClientBinary(byte[] data)
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. |
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 |
setClientObjectHandler(ClientObjectHandler handler)
Sets the ClientObjectHandler class that interacts with client sockets. |
void |
setCommunicationLogging(boolean communicationLogging)
Sets the communication logging flag. |
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. |
void |
setInputStream(java.io.InputStream in)
Sets the InputStream associated with
the Client being handled. |
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). |
protected void |
setServer(QuickServer server)
Sets the QuickServer object associated with this ClientHandler. |
protected void |
setServerAuthenticator(Authenticator authenticator)
Deprecated. As of v1.3 use setAuthenticator(org.quickserver.net.server.Authenticator) |
void |
setSocket(java.net.Socket socket)
Returns client socket associated. |
java.lang.String |
toString()
Returns the Clients InetAddress |
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 |
protected java.net.Socket socket
protected boolean authorised
protected int counAuthTry
protected int maxAuthTry
protected java.lang.String timeoutMsg
protected java.lang.String maxAuthTryMsg
| Constructor Detail |
public ClientHandler()
public ClientHandler(TheClient theClient,
int timeOut)
theClient.
theClient - object that encapsulates client socket
and its configuration details.timeOut - Socket timeout in milliseconds| Method Detail |
public void clean()
protected void finalize()
throws java.lang.Throwable
finalize in class java.lang.Objectjava.lang.Throwable
public void handleClient(TheClient theClient,
int timeOut)
theClient.
theClient - object that encapsulates client socket
and its configuration details.timeOut - Socket timeout in millisecondspublic QuickServer getServer()
setServer(org.quickserver.net.server.QuickServer)protected void setServer(QuickServer server)
getServer()protected void setClientData(ClientData data)
ClientData,
getClientData()public ClientData getClientData()
null
ClientData,
setClientData(org.quickserver.net.server.ClientData)protected void setServerAuthenticator(Authenticator authenticator)
setAuthenticator(org.quickserver.net.server.Authenticator)
authenticator - fully qualified name of the class that
implements Authenticator.protected void setAuthenticator(Authenticator authenticator)
authenticator - fully qualified name of the class that
implements Authenticator.public java.io.InputStream getInputStream()
InputStream associated with
the Client being handled.
setInputStream(java.io.InputStream)
public void setInputStream(java.io.InputStream in)
throws java.io.IOException
InputStream associated with
the Client being handled.
java.io.IOExceptiongetInputStream()public java.io.OutputStream getOutputStream()
OutputStream associated with
the Client being handled.
setOutputStream(java.io.OutputStream)
public void setOutputStream(java.io.OutputStream out)
throws java.io.IOException
OutputStream associated with
the Client being handled.
java.io.IOException - if ObjectOutputStream could not be created.getOutputStream()public java.io.BufferedReader getBufferedReader()
BufferedReader associated with
the Client being handled.
getBufferedWriter()public java.io.BufferedWriter getBufferedWriter()
BufferedWriter associated with
the Client being handled.
public java.io.ObjectOutputStream getObjectOutputStream()
ObjectOutputStream associated with
the Client being handled.
It will be null if no ClientObjectHandler
was set in QuickServer.
getObjectInputStream()public java.io.ObjectInputStream getObjectInputStream()
ObjectInputStream associated with
the Client being handled.
It will be null if no ClientObjectHandler
was set in QuickServer.
getObjectOutputStream()protected void setClientCommandHandler(ClientCommandHandler handler)
handler - fully qualified name of the class that
implements ClientCommandHandlerprotected void setClientObjectHandler(ClientObjectHandler handler)
handler - fully qualified name of the class that
implements ClientObjectHandlerpublic void closeConnection()
public java.net.Socket getSocket()
public void setSocket(java.net.Socket socket)
updateInputOutputStreams()
public boolean isConected()
throws java.net.SocketException
java.net.SocketException - if Socket is not open.public boolean isClosed()
public void sendClientMsg(java.lang.String msg)
throws java.io.IOException
java.io.IOException - if Socket IO Error or Socket was closed by the client.
public void sendClientBytes(java.lang.String msg)
throws java.io.IOException
java.io.IOException - if Socket IO Error or Socket was closed by the client.
public void sendClientObject(java.lang.Object msg)
throws java.io.IOException
java.io.IOException - if Socket IO Error or Socket was closed
by the client.
java.lang.IllegalStateException - if DataType.OUT is not in
DataMode.OBJECTsetDataMode(org.quickserver.net.server.DataMode, org.quickserver.net.server.DataType)public void sendSystemMsg(java.lang.String msg)
QuickServer.getAppLogger() with Level.INFO as its level.
public void sendSystemMsg(java.lang.String msg,
java.util.logging.Level level)
QuickServer.getAppLogger().
public void sendSystemMsg(java.lang.String msg,
boolean newline)
sendSystemMsg(java.lang.String),
since it uses Logging.
newline - indicates if new line required at the end.public void run()
run in interface java.lang.Runnablepublic java.lang.String toString()
toString in class java.lang.Object
public void setDataMode(DataMode dataMode,
DataType dataType)
throws java.io.IOException
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.
dataMode - mode of data exchange - String or Object.dataType - type of data for which mode has to be set.
java.io.IOException - if mode could not be changed.public DataMode getDataMode(DataType dataType)
DataMode of the ClientHandler for the
DataType.
public java.sql.Connection getConnection(java.lang.String id)
throws java.lang.Exception
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)
java.lang.Exceptionpublic java.util.Date getClientConnectedTime()
null
public java.lang.String readBytes()
throws java.io.IOException
DataType.IN is in DataMode.BYTE mode.
java.io.IOExceptionpublic void setCommunicationLogging(boolean communicationLogging)
getCommunicationLogging()public boolean getCommunicationLogging()
setCommunicationLogging(boolean)public java.util.Date getLastCommunicationTime()
null
public void updateLastCommunicationTime()
public long getSocketTimeout()
public void forceClose()
throws java.io.IOException
java.io.IOExceptionpublic boolean isSecure()
public void setSecure(boolean secure)
secure -
public void updateInputOutputStreams()
throws java.io.IOException
java.io.IOExceptionsetSocket(java.net.Socket)
public void makeSecure()
throws java.io.IOException,
java.security.NoSuchAlgorithmException,
java.security.KeyManagementException
makeSecure(false, false, true, null).
java.io.IOException
java.security.NoSuchAlgorithmException
java.security.KeyManagementException
public void makeSecure(java.lang.String protocol)
throws java.io.IOException,
java.security.NoSuchAlgorithmException,
java.security.KeyManagementException
makeSecure(false, false, true, protocol).
java.io.IOException
java.security.NoSuchAlgorithmException
java.security.KeyManagementException
public void makeSecure(boolean useClientMode,
boolean needClientAuth,
boolean autoClose,
java.lang.String protocol)
throws java.io.IOException,
java.security.NoSuchAlgorithmException,
java.security.KeyManagementException
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 closedprotocol - the standard name of the requested protocol. If null will use the protocol set in secure configuration of the server.
java.io.IOException
java.security.NoSuchAlgorithmException
java.security.KeyManagementException
public void sendClientBinary(byte[] data)
throws java.io.IOException
java.io.IOException - if Socket IO Error or Socket was closed by the client.
public byte[] readBinary()
throws java.io.IOException
DataType.IN is in DataMode.BINARY mode.
java.io.IOExceptionprotected void setClientBinaryHandler(ClientBinaryHandler handler)
handler - fully qualified name of the class that
implements ClientBinaryHandler
|
QuickServer v1.4.1 |
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||