Java Doc for QuickServer.java in » Net » QuickServer » org » quickserver » net » server » Java Source Code / Java DocumentationJava Source Code and Java Documentation
Main class of QuickServer library. This class is used to create
multi client servers quickly.
Ones a client is connected, it creates
ClientHandler object,
which is run using any thread available from the pool of threads
maintained by
org.quickserver.util.pool.thread.ClientPool , which
handles the client.
QuickServer divides the application logic of its developer over eight
class,
[#] = Any one of these have to be set based on default DataMode for input.
The default DataMode for input is String so if not changes you will
have to set ClientCommandHandler.
Eg:
package echoserver;
import org.quickserver.net.*;
import org.quickserver.net.server.*;
import java.io.*;
public class EchoServer {
public static void main(String args[]) {
String cmdHandle = "echoserver.EchoCommandHandler";
QuickServer myServer = new QuickServer();
myServer.setClientCommandHandler(cmdHandle);
myServer.setPort(4123);
myServer.setName(Echo Server v1.0");
try {
myServer.startServer();
} catch(AppException e) {
System.err.println("Error in server : "+e);
e.printStackTrace();
}
}
}
getQSAdminServerAuthenticator() Returns the Authenticator or ClientAuthenticationHandler class of
QSAdminServer that handles the authentication of a client.
getSSLContext(String protocol) Returns the SSLContext object that implements the specified
secure socket protocol from Secure configuring.
See Also:QuickServer.loadSSLContext Parameters: protocol - the standard name of the requested protocol.
setClientObjectHandler(String handler) Sets the ClientObjectHandler class that interacts with
client sockets to handle java objects.
public void
setClientWriteHandler(String handler) Sets the ClientWriteHandler class that interacts with
client sockets to handle data write (only used in non-blocking mode).
setQSAdminServerAuthenticator(String authenticator) Set the ClientAuthenticationHandler class of
QSAdminServer that handles the authentication of a client.
setServiceState(int state) Sets the state of the process
As any constant of
Service interface.
public void
setStoreObjects(Object[] storeObjects) Sets the store of objects to QuickServer, it is an array of objects
that main program or the class that created QuickServer passes to
the QuickServer.
public void
setTimeout(int time) Sets the client socket's timeout.
Returns an iterator containing all the
org.quickserver.net.server.ClientHandler that
are currently handling clients.
It is recommended not to change the collection under an iterator.
It is imperative that the user manually synchronize on the returned collection
when iterating over it:
Tries to find the Client by the matching pattern passed to the Id.
Note: This command is an expensive so do use it limitedly and
cache the returned object. But before you start sending message to the
cached object do validate that ClientHandler with you is currently
connected and is pointing to the same clinet has it was before.
This can be done as follows.
foundClientHandler.isConnected(); //this method will through SocketException if not connected
Date newTime = foundClientHandler.getClientConnectedTime();
if(oldCachedTime!=newTime) {
//Client had disconnected and ClientHandler was reused for
//someother client, so write code to again find ur client
foundClientHandler = handler.getServer().findFirstClientById("friendsid");
...
}
See Also:ClientIdentifiable ClientHandler object if client was found else null since: 1.3.2
Tries to find the Client by the matching pattern passed to the key.
Note: This command is an expensive so do use it limitedly and
cache the returned object. But before you start sending message to the
cached object do validate that ClientHandler with you is currently
connected and is pointing to the same clinet has it was before.
This can be done as follows.
foundClientHandler.isConnected(); //this method will through SocketException if not connected
Date newTime = foundClientHandler.getClientConnectedTime();
if(oldCachedTime!=newTime) {
//Client had disconnected and ClientHandler was reused for
//some other client, so write code to again find ur client
foundClientHandler = handler.getServer().findFirstClientByKey("friendsid");
...
}
See Also:ClientIdentifiable ClientHandler object if client was found else null since: 1.4
Note: This command is an expensive so do use it limitedly and
cache the returned object. But before you start sending message to the
cached object do validate that ClientHandler with you is currently
connected and is pointing to the same clinet has it was before.
This can be done as follows.
foundClientHandler.isConnected(); //this method will through SocketException if not connected
Date newTime = foundClientHandler.getClientConnectedTime();
if(oldCachedTime!=newTime) {
//Client had disconnected and ClientHandler was reused for
//someother client, so write code to again find ur client
foundClientHandler = handler.getServer().findClientByKey("friendskey");
...
}
See Also:ClientIdentifiable ClientHandler object if client was found else null since: 1.3.1
Note: This command is an expensive so do use it limitedly and
cache the returned object. But before you start sending message to the
cached object do validate that ClientHandler with you is currently
connected and is pointing to the same clinet has it was before.
This can be done as follows.
foundClientHandler.isConnected(); //this method will through SocketException if not connected
Date newTime = foundClientHandler.getClientConnectedTime();
if(oldCachedTime!=newTime) {
//Client had disconnected and ClientHandler was reused for
//someother client, so write code to again find ur client
foundClientHandler = handler.getServer().findFirstClientById("friendsid");
...
}
See Also:ClientIdentifiable ClientHandler object if client was found else null since: 1.3.1
Returns the applications jar/s path. This can be either absolute or
relative(to config file) path to the jar file or the directory containing the
jars needed by the application.
See Also:QuickServer.setApplicationJarPath since: 1.3.3
Returns the ClientData class string that carries client data
the fully qualified name of the class that implements ClientData. See Also:QuickServer.setClientData
Returns the ClientWriteHandler class that interacts with
client sockets (only used in non-blocking mode).
See Also:QuickServer.setClientWriteHandler since: 1.4.5
Returns the message to be sent to any new client connected
after maximum client connection has reached.
since: 1.1 See Also:QuickServer.setMaxConnectionMsg
Returns the SSLContext object that implements the specified
secure socket protocol from Secure configuring.
See Also:QuickServer.loadSSLContext Parameters: protocol - the standard name of the requested protocol. If null will use the protocol set in secure configuration of the server. throws: IOException - throws: NoSuchAlgorithmException - throws: KeyManagementException - since: 1.4.0
Returns a SSLSocketFactory object to be used for creating SSLSockets.
See Also:QuickServer.setSecure Parameters: protocol - the standard name of the requested protocol. If null will use the protocol set in secure configuration of the server. throws: IOException - throws: NoSuchAlgorithmException - throws: KeyManagementException - since: 1.4.0
Initialise and create the server.
Parameters: param - of the xml configuration file. exception: AppException - if QuickServerConfig creation failed from the xml config file. since: 1.4.7
Usage: QuickServer [-options]
Where options include:
-about Opens About Dialogbox
-load [options] Loads the server from xml file.
where options include:
-fullXML2File
Register the given channel for the given operations. This adds the request
to a list and will be processed after selector select wakes up.
boolean flag to indicate if new entry was added to the list to register. since: 1.4.5
Sets the applications jar/s path. This can be either absolute or
relative(to config file) path to the jar file or the directory containing
the jars needed by the application.
See Also:QuickServer.getApplicationJarPath since: 1.3.3
setAuthenticator
public void setAuthenticator(String authenticator)(Code)
Sets the Ip address to bind to.
Parameters: bindAddr - argument can be used on a multi-homed host for a QuickServer that will only accept connect requests to one of its addresses. If not set, it will default accepting connections on any/all local addresses. exception: java.net.UnknownHostException - if no IP address for the host could be found since: 1.1 See Also:QuickServer.getBindAddr
public void setClientBinaryHandler(String handler)(Code)
Sets the ClientBinaryHandler class that interacts with
client sockets to handle binary data.
Parameters: handler - object the fully qualified name of the class that implements ClientBinaryHandler See Also:QuickServer.getClientBinaryHandler since: 1.4
setClientCommandHandler
public void setClientCommandHandler(String handler)(Code)
Sets the ClientData class that carries client data.
Parameters: data - the fully qualified name of the class that extends ClientData. See Also:QuickServer.getClientData
setClientEventHandler
public void setClientEventHandler(String handler)(Code)
Sets the ClientEventHandler class that gets notified of
client events.
Parameters: handler - the fully qualified name of the class that implements ClientEventHandler See Also:QuickServer.getClientEventHandler since: 1.4.6
setClientExtendedEventHandler
public void setClientExtendedEventHandler(String handler)(Code)
public void setClientObjectHandler(String handler)(Code)
Sets the ClientObjectHandler class that interacts with
client sockets to handle java objects.
Parameters: handler - object the fully qualified name of the class that implements ClientObjectHandler See Also:QuickServer.getClientObjectHandler since: 1.2
setClientWriteHandler
public void setClientWriteHandler(String handler)(Code)
Sets the ClientWriteHandler class that interacts with
client sockets to handle data write (only used in non-blocking mode).
Parameters: handler - object the fully qualified name of the class that implements ClientWriteHandler See Also:QuickServer.getClientWriteHandler since: 1.4.5
setCommunicationLogging
public void setCommunicationLogging(boolean communicationLogging)(Code)
Sets the console log handler formatter.
Parameters: formatter - fully qualified name of the class that implements java.util.logging.Formatter since: 1.2
setConsoleLoggingLevel
public void setConsoleLoggingLevel(Level level)(Code)
Sets message to be displayed when maximum allowed login
attempts has reached.
Default is : -ERR Max Auth Try Reached
See Also:QuickServer.getMaxAuthTryMsg
setMaxConnection
public void setMaxConnection(long maxConnection)(Code)
public void setMaxConnectionMsg(String maxConnectionMsg)(Code)
Sets the message to be sent to any new client connected after
maximum client connection has reached.
Default is : -ERR Server Busy. Max Connection Reached since: 1.1 See Also:QuickServer.getMaxConnectionMsg
Sets the state of the process
As any constant of
Service interface.
since: 1.2
setStoreObjects
public void setStoreObjects(Object[] storeObjects)(Code)
Sets the store of objects to QuickServer, it is an array of objects
that main program or the class that created QuickServer passes to
the QuickServer.
Parameters: storeObjects - array of objects See Also:QuickServer.getStoreObjects since: 1.1
Starts QSAdminServer for this QuickServer.
See Also:org.quickserver.net.qsadmin.QSAdminServer Parameters: authenticator - sets the ClientAuthenticationHandler class that handles the authentication of a client, if null uses org.quickserver.net.qsadmin.Authenticator. Parameters: port - to run QSAdminServer on exception: org.quickserver.net.AppException - if Server already running or if it could not load the classes[ClientCommandHandler, ClientAuthenticationHandler, ClientData]. since: 1.1
Starts the QuickServer.
exception: org.quickserver.net.AppException - if Server already running or if it could not load the classes[ClientCommandHandler, ClientAuthenticationHandler, ClientData]. See Also:QuickServer.startService