📄 clienthandler.java
字号:
/*
* This file is part of the QuickServer library
* Copyright (C) 2003-2005 QuickServer.org
*
* Use, modification, copying and distribution of this software is subject to
* the terms and conditions of the GNU Lesser General Public License.
* You should have received a copy of the GNU LGP License along with this
* library; if not, you can download a copy from <http://www.quickserver.org/>.
*
* For questions, suggestions, bug-reports, enhancement-requests etc.
* visit http://www.quickserver.org
*
*/
package org.quickserver.net.server;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.InetAddress;
import java.net.Socket;
import java.net.SocketException;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.SelectionKey;
import java.nio.channels.SocketChannel;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.sql.Connection;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.net.ssl.SSLSocket;
import org.quickserver.util.MyString;
/**
* Interface that represents client handle in QuickServer.
* <p> This class is used by {@link 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.</p>
* @author Akshathkumar Shetty
*/
public interface ClientHandler extends Runnable {
/**
* Adds the ClientEvent.
* @since 1.4.5
*/
void addEvent(ClientEvent event);
/**
* Removes the ClientEvent.
* @since 1.4.5
*/
void removeEvent(ClientEvent event);
void clean();
/** Closes client socket associated. */
void closeConnection();
/**
* Force the closing of the client by closing the associated socket.
* @since 1.3.3
*/
void forceClose() throws IOException;
/**
* Returns client SelectionKey associated, if any.
* @since 1.4.5
*/
Logger getAppLogger();
/**
*Returns the {@link java.io.BufferedInputStream} associated with
* the Client being handled. Can be null if not available at the time of method call.
* @see #getBufferedOutputStream
* @since 1.4.6
*/
BufferedInputStream getBufferedInputStream();
/**
* Returns the {@link java.io.BufferedOutputStream} associated with
* the Client being handled. Can be null if not available at the time of method call.
* @see #getBufferedInputStream
* @since 1.4.6
*/
BufferedOutputStream getBufferedOutputStream();
/**
* Returns the {@link java.io.BufferedReader} associated with
* the Client being handled. Note that this is only available under blocking mode.
* @see #getBufferedWriter
*/
BufferedReader getBufferedReader();
/**
* Returns Charset to be used for String decoding and encoding..
* @see #setCharset
* @since 1.4.5
*/
String getCharset();
/**
* Returns the date/time when the client socket was assigned to this
* ClientHanlder. If no client is currently connected it will return
* <code>null</code>
* @since 1.3.1
*/
Date getClientConnectedTime();
/**
* Returns the ClientData object associated with this ClientHandler,
* if not set will return <code>null</code>
* @see ClientData
*/
ClientData getClientData();
/**
* Returns the communication logging flag.
* @see #setCommunicationLogging
* @since 1.3.2
*/
boolean getCommunicationLogging();
/**
* Returns the {@link DataMode} of the ClientHandler for the
* DataType.
* @since 1.2
*/
DataMode getDataMode(DataType dataType);
/**
* Returns cached socket host ip address.
* @since 1.4.5
*/
String getHostAddress();
/**
* Returns the {@link java.io.InputStream} associated with
* the Client being handled.
*/
InputStream getInputStream();
/**
* Returns the date/time when the client socket last sent a data to this
* ClientHanlder. If no client is currently connected it will return
* <code>null</code>
* @since 1.3.3
*/
Date getLastCommunicationTime();
/**
* Returns message to be displayed to the client when maximum
* connection reaches.
* @since 1.4.5
*/
String getMaxConnectionMsg();
/**
* Returns the ClientHandler name
* @since 1.4.6
*/
String getName();
/**
* Returns the {@link java.io.ObjectInputStream} associated with
* the Client being handled.
* It will be <code>null</code> if no {@link ClientObjectHandler}
* was set in {@link QuickServer}.
* @see #getObjectOutputStream
* @since 1.2
*/
ObjectInputStream getObjectInputStream();
/**
* Returns the {@link java.io.ObjectOutputStream} associated with
* the Client being handled.
* It will be <code>null</code> if no {@link ClientObjectHandler}
* was set in {@link QuickServer}.
* @see #getObjectInputStream
* @since 1.2
*/
ObjectOutputStream getObjectOutputStream();
/**
* Returns the {@link java.io.OutputStream} associated with
* the Client being handled.
* @see #setOutputStream
*/
OutputStream getOutputStream();
/**
* Returns client SelectionKey associated, if any.
* @since 1.4.5
*/
SelectionKey getSelectionKey();
/**
* Returns the QuickServer object that created it.
*/
QuickServer getServer();
/** Returns client socket associated. */
Socket getSocket();
/**
* Returns client socket channel associated, if any.
* @since 1.4.5
*/
SocketChannel getSocketChannel();
/**
* Returns the Client socket timeout in milliseconds.
* @see #setTimeout
* @since 1.4.5
*/
int getTimeout();
/**
* Associates the ClientHanlder with the client encapsulated by
* <code>theClient</code>.
* @param theClient object that encapsulates client socket
* and its configuration details.
*/
void handleClient(TheClient theClient);
/**
* Checks if this client has the event.
* @since 1.4.5
*/
boolean hasEvent(ClientEvent event);
/**
* Returns the ClientHandler detailed information.
* If ClientData is present and is ClientIdentifiable will return ClientInfo else
* it will return Clients InetAddress and port information.
*/
String info();
/**
* Checks if the passed ClientEvent is the one next for
* processing if a thread is allowed through this object.
* @since 1.4.6
*/
boolean isClientEventNext(ClientEvent clientEvent);
/**
* Checks if the client is closed.
* @since 1.4.1
*/
boolean isClosed();
/**
* Checks if the client is still connected.
* @exception SocketException if Socket is not open.
* @since 1.4.5
*/
boolean isConnected() throws SocketException;
/**
* Checks if the client is still connected and if socket is open. This is same as isConnected()
* but does not throw SocketException.
* @since 1.4.6
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -