|
QuickServer v1.4.6 |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Interface that represents client handle in 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) based on its
implementation.
Method Summary | |
void |
addEvent(ClientEvent event)
Adds the ClientEvent. |
void |
clean()
|
void |
closeConnection()
Closes client socket associated. |
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. |
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 |
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. |
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. |
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. |
java.nio.channels.SocketChannel |
getSocketChannel()
Returns client socket channel associated, if any. |
int |
getTimeout()
Returns the Client socket timeout in milliseconds. |
void |
handleClient(TheClient theClient)
Associates the ClientHanlder with the client encapsulated by theClient . |
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. |
byte[] |
readBinary()
Read the binary input. |
java.lang.String |
readBytes()
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 |
removeEvent(ClientEvent event)
Removes the ClientEvent. |
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() . |
void |
setCharset(java.lang.String charset)
Sets the Charset to be used for String decoding and encoding. |
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 |
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). |
void |
setSelectionKey(java.nio.channels.SelectionKey selectionKey)
Sets client SelectionKey associated, if any. |
void |
setSocket(java.net.Socket socket)
Returns client socket associated. |
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. |
void |
updateInputOutputStreams()
Updates the InputStream and OutputStream for the ClientHandler for the set Socket. |
void |
updateLastCommunicationTime()
Updates the last communication time for this client |
Method Detail |
public void addEvent(ClientEvent event)
public void removeEvent(ClientEvent event)
public void clean()
public void closeConnection()
public void forceClose() throws java.io.IOException
java.io.IOException
public java.util.logging.Logger getAppLogger()
public java.io.BufferedInputStream getBufferedInputStream()
BufferedInputStream
associated with
the Client being handled. Can be null if not available at the time of method call.
getBufferedOutputStream()
public java.io.BufferedOutputStream getBufferedOutputStream()
BufferedOutputStream
associated with
the Client being handled. Can be null if not available at the time of method call.
getBufferedInputStream()
public java.io.BufferedReader getBufferedReader()
BufferedReader
associated with
the Client being handled. Note that this is only available under blocking mode.
getBufferedWriter()
public java.lang.String getCharset()
setCharset(java.lang.String)
public java.util.Date getClientConnectedTime()
null
public ClientData getClientData()
null
ClientData
public boolean getCommunicationLogging()
setCommunicationLogging(boolean)
public DataMode getDataMode(DataType dataType)
DataMode
of the ClientHandler for the
DataType.
public java.lang.String getHostAddress()
public java.io.InputStream getInputStream()
InputStream
associated with
the Client being handled.
public java.util.Date getLastCommunicationTime()
null
public java.lang.String getMaxConnectionMsg()
public java.lang.String getName()
public java.io.ObjectInputStream getObjectInputStream()
ObjectInputStream
associated with
the Client being handled.
It will be null
if no ClientObjectHandler
was set in QuickServer
.
getObjectOutputStream()
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.OutputStream getOutputStream()
OutputStream
associated with
the Client being handled.
setOutputStream(java.io.OutputStream)
public java.nio.channels.SelectionKey getSelectionKey()
public QuickServer getServer()
public java.net.Socket getSocket()
public java.nio.channels.SocketChannel getSocketChannel()
public int getTimeout()
setTimeout(int)
public void handleClient(TheClient theClient)
theClient
.
theClient
- object that encapsulates client socket
and its configuration details.public boolean hasEvent(ClientEvent event)
public java.lang.String info()
public boolean isClientEventNext(ClientEvent clientEvent)
public boolean isClosed()
public boolean isConnected() throws java.net.SocketException
java.net.SocketException
- if Socket is not open.public boolean isOpen()
public boolean isSecure()
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(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 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 byte[] readBinary() throws java.io.IOException
DataType.IN
is in DataMode.BINARY
mode.
java.io.IOException
public java.lang.String readBytes() throws java.io.IOException
DataType.IN
is in DataMode.BYTE
mode.
java.io.IOException
public void registerForRead() throws java.io.IOException, java.nio.channels.ClosedChannelException
java.io.IOException
java.nio.channels.ClosedChannelException
public void registerForWrite() throws java.io.IOException, java.nio.channels.ClosedChannelException
java.io.IOException
java.nio.channels.ClosedChannelException
public void run()
run
in interface java.lang.Runnable
public void sendClientBinary(byte[] data) throws java.io.IOException
java.io.IOException
- if Socket IO Error or Socket was closed by the client.public void sendClientBinary(byte[] data, int off, int len) 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 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 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 setCharset(java.lang.String charset)
charset
- to be used for String decoding and encodinggetCharset()
public void setCommunicationLogging(boolean communicationLogging)
getCommunicationLogging()
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 void setMaxConnectionMsg(java.lang.String msg)
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 void setSecure(boolean secure)
secure
- public void setSelectionKey(java.nio.channels.SelectionKey selectionKey)
public void setSocket(java.net.Socket socket)
updateInputOutputStreams()
public void setSocketChannel(java.nio.channels.SocketChannel socketChannel)
public void setTimeout(int time)
time
- client socket timeout in milliseconds.getTimeout()
public java.lang.String toString()
public void updateInputOutputStreams() throws java.io.IOException
java.io.IOException
setSocket(java.net.Socket)
public void updateLastCommunicationTime()
public java.sql.Connection getConnection(java.lang.String id) throws java.lang.Exception
getServer().getDBPoolUtil().getConnection(id)
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.Exception
public boolean isConected() throws java.net.SocketException
isConnected()
java.net.SocketException
- if Socket is not open.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 java.io.BufferedWriter getBufferedWriter()
BufferedWriter
associated with
the Client being handled.
|
QuickServer v1.4.6 |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |