QuickServer
v1.4.7

org.quickserver.net.server
Class QuickServer

java.lang.Object
  extended byorg.quickserver.net.server.QuickServer
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Runnable, java.io.Serializable, Service

public class QuickServer
extends java.lang.Object
implements java.lang.Runnable, Service, java.lang.Cloneable, java.io.Serializable

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 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();
                }
        }
}

Author:
Akshathkumar Shetty
See Also:
Serialized Form

Field Summary
protected  java.lang.Class clientDataClass
           
 
Fields inherited from interface org.quickserver.net.Service
INIT, RUNNING, STOPPED, SUSPENDED, UNKNOWN
 
Constructor Summary
QuickServer()
          Creates a new server without any configuration.
QuickServer(java.lang.String commandHandler)
          Creates a new server with the specified commandHandler has it ClientCommandHandler.
QuickServer(java.lang.String commandHandler, int port)
          Creates a new server at port with the specified commandHandler has it ClientCommandHandler.
 
Method Summary
 void clearAllPools()
          Cleans all Object and Thread pools
 java.lang.Object clone()
          Creates and returns a copy of this object.
 void closeAllPools()
          Closes all Object and Thread pools
 void configQuickServer()
          Configures QSAdminServer and QuickServer based on the internal QuickServerConfig object.
 void configQuickServer(QSAdminServerConfig config)
          Configures QSAdminServer based on the passed QuickServerConfig object.
 void configQuickServer(QuickServerConfig config)
          Configures QuickServer based on the passed QuickServerConfig object.
 java.util.Iterator findAllClient()
          Returns an iterator containing all the ClientHandler that are currently handling clients.
 java.util.Iterator findAllClientById(java.lang.String pattern)
          Tries to find the Client by the matching pattern passed to the Id.
 java.util.Iterator findAllClientByKey(java.lang.String pattern)
          Tries to find the Client by the matching pattern passed to the key.
 ClientHandler findClientByKey(java.lang.String key)
          Tries to find the Client by the Key passed.
 ClientHandler findFirstClientById(java.lang.String id)
          Tries to find the Client by the Id passed.
 AccessConstraintConfig getAccessConstraintConfig()
          Returns Access constraints if present else null.
 java.lang.String getApplicationJarPath()
          Returns the applications jar/s path.
 java.util.logging.Logger getAppLogger()
          Returns the application logger associated with QuickServer.
 java.lang.String getAuthenticator()
          Deprecated. since 1.4.6 use getClientAuthenticationHandler
 BasicServerConfig getBasicConfig()
          Returns the basic confiuration of the QuickServer.
 java.net.InetAddress getBindAddr()
          Returns the IP address binding to.
 boolean getBlockingMode()
          Returns the current blocking mode of the server.
 org.apache.commons.pool.ObjectPool getByteBufferPool()
          Returns ObjectPool of java.nio.ByteBuffer class.
 java.lang.Class getClass(java.lang.String name, boolean reload)
          Utility method to load a class
 java.lang.ClassLoader getClassLoader()
          Gets the classloader used to load the dynamicaly resolved classes.
 java.lang.String getClientAuthenticationHandler()
          Returns the ClientAuthenticationHandler class that handles the authentication of a client.
 java.lang.String getClientBinaryHandler()
          Returns the ClientBinaryHandler class that interacts with client sockets.
 java.lang.String getClientCommandHandler()
          Returns the ClientCommandHandler class that interacts with client sockets.
 long getClientCount()
          Returns number of clients connected.
 java.lang.String getClientData()
          Returns the ClientData class string that carries client data
 org.apache.commons.pool.ObjectPool getClientDataPool()
          Returns ObjectPool of ClientData class.
 java.lang.String getClientEventHandler()
          Returns the ClientEventHandler class that gets notified of client events.
 java.lang.String getClientExtendedEventHandler()
          Returns the ClientExtendedEventHandler class that gets notified of extended client events.
 org.apache.commons.pool.ObjectPool getClientHandlerPool()
          Returns ObjectPool of ClientHandler class.
 ClientIdentifier getClientIdentifier()
          Returns the implementation that is used to do Client Identification.
 java.lang.String getClientObjectHandler()
          Returns the ClientObjectHandler class that interacts with client sockets.
 ClientPool getClientPool()
          Returns ClientPool class that managing the pool of threads for handling clients.
 java.lang.String getClientWriteHandler()
          Returns the ClientWriteHandler class that interacts with client sockets (only used in non-blocking mode).
 boolean getCommunicationLogging()
          Returns the communication logging flag.
 QuickServerConfig getConfig()
          Returns the confiuration of the QuickServer.
 java.lang.String getConsoleLoggingFormatter()
          Gets the console log handler formatter.
 java.lang.String getConsoleLoggingLevel()
          Gets the console log handler level.
 DBPoolUtil getDBPoolUtil()
          Returns DBPoolUtil object if DBObjectPoolConfig was set.
 DataMode getDefaultDataMode(DataType dataType)
          Returns the default DataMode for the ClientHandler
 java.util.Date getLastStartTime()
          Returns the date/time when the server was last started.
 int getMaxAuthTry()
          Returns max allowed login attempts.
 java.lang.String getMaxAuthTryMsg()
          Returns message to be displayed when maximum allowed login attempts has reached.
 long getMaxConnection()
          Returns the maximum number of client connection allowed.
 java.lang.String getMaxConnectionMsg()
          Returns the message to be sent to any new client connected after maximum client connection has reached.
 java.lang.String getName()
          Returns the name of the QuickServer.
static java.lang.String getNewLine()
          Returns the new line string used by QuickServer.
 int getPort()
          Returns the port for the QuickServer.
 QSAdminServer getQSAdminServer()
          Returns QSAdminServer associated with this QuickServer
 java.lang.String getQSAdminServerAuthenticator()
          Returns the Authenticator or ClientAuthenticationHandler class of QSAdminServer that handles the authentication of a client.
 int getQSAdminServerPort()
          Returns the port to run QSAdminServer on.
 Secure getSecure()
          Returns Secure setting for QuickServer
 java.lang.SecurityManager getSecurityManager()
           
 java.lang.String getSecurityManagerClass()
          Returns the SecurityManager class
 java.nio.channels.Selector getSelector()
          Returns the Selector (NIO),if any.
 java.lang.String getServerBanner()
          Returns the Server Banner of the QuickServer
 ServerHooks getServerHooks()
          Returns ServerHooks if present else null.
 java.lang.Throwable getServiceError()
          Returns service error if any.
 int getServiceState()
          Returns the state of the process As any constant of Service interface.
 javax.net.ssl.SSLContext getSSLContext()
          Returns the SSLContext from Secure configuring.
 javax.net.ssl.SSLContext getSSLContext(java.lang.String protocol)
          Returns the SSLContext object that implements the specified secure socket protocol from Secure configuring.
 javax.net.ssl.SSLSocketFactory getSSLSocketFactory()
          Returns a SSLSocketFactory object to be used for creating SSLSockets.
 javax.net.ssl.SSLSocketFactory getSSLSocketFactory(java.lang.String protocol)
          Returns a SSLSocketFactory object to be used for creating SSLSockets.
 java.lang.Object[] getStoreObjects()
          Returns store of objects from QuickServer, if nothing was set will return null.
 int getTimeout()
          Returns the Client socket timeout in milliseconds.
 java.lang.String getTimeoutMsg()
          Returns timeout message.
static java.lang.String getVersion()
          Returns the version of the library.
static float getVersionNo()
          Returns the numerical version of the library.
static float getVersionNo(java.lang.String ver)
          Returns the numerical version of the library.
 java.lang.String info()
          Information about the service.
 void initAllPools()
          Initialise all Object and Thread pools.
 void initServer(java.lang.Object[] param)
          Initialise and create the server.
 void initServer(QuickServerConfig qsConfig)
          Initialise and create the service.
 boolean initService(java.lang.Object[] param)
          Initialise and create the service.
 boolean initService(QuickServerConfig qsConfig)
          Initialise and create the service.
 boolean isClosed()
          Returns the closed state of the QuickServer Socket.
 boolean isRunningSecure()
          Returns if the server is running in Secure mode [SSL or TLS].
static QuickServer load(java.lang.String xml)
          Loads the server from the xml file name passed.
protected  void loadBusinessLogic()
          Loads all the Business Logic class
 void loadSSLContext()
          Loads the SSLContext from Secure configuring if set.
static void main(java.lang.String[] args)
          Usage: QuickServer [-options]
Where options include:
-about Opens About Dialogbox
-load [options] Loads the server from xml file.
protected  void makeServerSocket()
          Returns a ServerSocket object to be used for listening.
 void nextClientIsTrusted()
          Sets next client has a trusted client.
 boolean registerChannel(java.nio.channels.SocketChannel channel, int ops, java.lang.Object att)
          Register the given channel for the given operations.
 void restartServer()
          Restarts the QuickServer.
 boolean resumeService()
          Resume the service.
 void run()
           
 void setAccessConstraintConfig(AccessConstraintConfig accessConstraintConfig)
          Sets the Access constraints
protected  void setApplicationJarPath(java.lang.String applicationJarPath)
          Sets the applications jar/s path.
 void setAppLogger(java.util.logging.Logger appLogger)
          Sets the application logger associated with QuickServer
 void setAuthenticator(java.lang.String authenticator)
          Deprecated. since 1.4.6 use setClientAuthenticationHandler
 void setBasicConfig(BasicServerConfig basicConfig)
          Sets the basic confiuration of the QuickServer.
 void setBindAddr(java.lang.String bindAddr)
          Sets the Ip address to bind to.
 void setClassLoader(java.lang.ClassLoader classLoader)
          Sets the classloader to be used to load the dynamicaly resolved classes
 void setClientAuthenticationHandler(java.lang.String authenticator)
          Sets the ClientAuthenticationHandler class that handles the authentication of a client.
 void setClientBinaryHandler(java.lang.String handler)
          Sets the ClientBinaryHandler class that interacts with client sockets to handle binary data.
 void setClientCommandHandler(java.lang.String handler)
          Sets the ClientCommandHandler class that interacts with client sockets.
 void setClientData(java.lang.String data)
          Sets the ClientData class that carries client data.
 void setClientEventHandler(java.lang.String handler)
          Sets the ClientEventHandler class that gets notified of client events.
 void setClientExtendedEventHandler(java.lang.String handler)
          Sets the ClientExtendedEventHandler class that gets notified of extended client events.
 void setClientObjectHandler(java.lang.String handler)
          Sets the ClientObjectHandler class that interacts with client sockets to handle java objects.
 void setClientWriteHandler(java.lang.String handler)
          Sets the ClientWriteHandler class that interacts with client sockets to handle data write (only used in non-blocking mode).
 void setCommunicationLogging(boolean communicationLogging)
          Sets the communication logging flag.
 void setConfig(QuickServerConfig config)
          Sets the confiuration of the QuickServer.
 void setConsoleLoggingFormatter(java.lang.String formatter)
          Sets the console log handler formatter.
 void setConsoleLoggingLevel(java.util.logging.Level level)
          Sets the console log handler level.
 void setConsoleLoggingToMicro()
          Sets the console log handler formater to MicroFormatter
 void setConsoleLoggingToMini()
          Sets the console log handler formater to MiniFormatter
 void setDBObjectPoolConfig(DBObjectPoolConfig dBObjectPoolConfig)
          Sets DBObjectPoolConfig
static void setDebugNonBlockingMode(boolean flag)
          Sets the debug flag to ByteBufferOutputStream and ByteBufferInputStream class that are used in non-blcking mode
 void setDefaultDataMode(DataMode dataMode, DataType dataType)
          Sets the default DataMode for the ClientHandler
 void setDefaultDataMode(DefaultDataMode defaultDataMode)
          Sets the default DataMode for the ClientHandler
 void setLoggingLevel(java.util.logging.Level level)
          Sets the level for all log handlers.
 void setMaxAuthTry(int authTry)
          Sets max allowed login attempts.
 void setMaxAuthTryMsg(java.lang.String msg)
          Sets message to be displayed when maximum allowed login attempts has reached.
 void setMaxConnection(long maxConnection)
          Sets the maximum number of client connection allowed.
 void setMaxConnectionMsg(java.lang.String maxConnectionMsg)
          Sets the message to be sent to any new client connected after maximum client connection has reached.
 void setName(java.lang.String name)
          Sets the name for the QuickServer
 void setPort(int port)
          Sets the port for the QuickServer to listen on.
 void setQSAdminServer(QSAdminServer adminServer)
          Sets QSAdminServer associated with this QuickServer
 void setQSAdminServerAuthenticator(java.lang.String authenticator)
          Set the ClientAuthenticationHandler class of QSAdminServer that handles the authentication of a client.
 void setQSAdminServerPort(int port)
          Set the port to run QSAdminServer on.
 void setRunningSecure(boolean runningSecure)
          Sets the server mode if its running in Secure mode [SSL or TLS].
 void setSecure(Secure secure)
          Sets the Secure setting for QuickServer
 void setSecurityManagerClass(java.lang.String securityManagerClass)
          Sets the SecurityManager class
 void setSelector(java.nio.channels.Selector selector)
          Sets the Selector (NIO).
 void setServerBanner(java.lang.String banner)
          Sets the serverBanner for the QuickServer that will be displayed on the standard output [console] when server starts.
 void setServerHooks(ServerHooks serverHooks)
          Sets the ServerHooks
 void setServiceState(int state)
          Sets the state of the process As any constant of Service interface.
 void setStoreObjects(java.lang.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.
 void setTimeout(int time)
          Sets the client socket's timeout.
 void setTimeoutMsg(java.lang.String msg)
          Sets timeout message.
 void startQSAdminServer()
          Starts QSAdminServer for this QuickServer.
 void startQSAdminServer(int port, java.lang.String authenticator)
          Starts QSAdminServer for this QuickServer.
 void startServer()
          Starts the QuickServer.
 boolean startService()
          Start the service.
 void stopServer()
          Stops the QuickServer.
 boolean stopService()
          Stop the service.
 boolean suspendService()
          Suspends the service.
 java.lang.String toString()
          Returns the Server name : port of the QuickServer.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

clientDataClass

protected java.lang.Class clientDataClass
Constructor Detail

QuickServer

public QuickServer()
Creates a new server without any configuration. Make sure you configure the QuickServer, before calling startServer()

Since:
1.2
See Also:
ClientEventHandler, ClientCommandHandler, ClientObjectHandler, ClientBinaryHandler, ClientWriteHandler, ClientAuthenticationHandler, ClientHandler, configQuickServer(org.quickserver.util.xmlreader.QuickServerConfig), initService(java.lang.Object[]), setPort(int), setClientCommandHandler(java.lang.String)

QuickServer

public QuickServer(java.lang.String commandHandler)
Creates a new server with the specified commandHandler has it ClientCommandHandler.

Parameters:
commandHandler - the fully qualified name of the desired class that implements ClientCommandHandler
See Also:
ClientCommandHandler, ClientAuthenticationHandler, ClientHandler, setPort(int)

QuickServer

public QuickServer(java.lang.String commandHandler,
                   int port)
Creates a new server at port with the specified commandHandler has it ClientCommandHandler.

Parameters:
commandHandler - fully qualified name of the class that implements ClientCommandHandler
port - to listen on.
See Also:
ClientCommandHandler, ClientAuthenticationHandler, ClientHandler
Method Detail

getVersion

public static final java.lang.String getVersion()
Returns the version of the library.


getVersionNo

public static final float getVersionNo()
Returns the numerical version of the library.

Since:
1.2

getVersionNo

public static final float getVersionNo(java.lang.String ver)
Returns the numerical version of the library.

Since:
1.4.5

getNewLine

public static java.lang.String getNewLine()
Returns the new line string used by QuickServer.

Since:
1.2

toString

public java.lang.String toString()
Returns the Server name : port of the QuickServer.


startServer

public void startServer()
                 throws AppException
Starts the QuickServer.

Throws:
AppException - if Server already running or if it could not load the classes [ClientCommandHandler, ClientAuthenticationHandler, ClientData].
See Also:
startService()

stopServer

public void stopServer()
                throws AppException
Stops the QuickServer.

Throws:
AppException - if could not stop server
Since:
1.1
See Also:
stopService()

restartServer

public void restartServer()
                   throws AppException
Restarts the QuickServer.

Throws:
AppException - if could not stop server or if it could not start the server.
Since:
1.2

getName

public java.lang.String getName()
Returns the name of the QuickServer. Default is 'QuickServer'.

See Also:
setName(java.lang.String)

setName

public void setName(java.lang.String name)
Sets the name for the QuickServer

Parameters:
name - for the QuickServer
See Also:
getName()

getServerBanner

public java.lang.String getServerBanner()
Returns the Server Banner of the QuickServer

See Also:
setServerBanner(java.lang.String)

setServerBanner

public void setServerBanner(java.lang.String banner)
Sets the serverBanner for the QuickServer that will be displayed on the standard output [console] when server starts.
 
To set welcome message to your client ClientEventHandler.gotConnected(org.quickserver.net.server.ClientHandler)

Parameters:
banner - for the QuickServer
See Also:
getServerBanner()

setPort

public void setPort(int port)
Sets the port for the QuickServer to listen on. If not set, it will run on Port 9876

Parameters:
port - to listen on.
See Also:
getPort()

getPort

public int getPort()
Returns the port for the QuickServer.

See Also:
setPort(int)

setClientCommandHandler

public void setClientCommandHandler(java.lang.String handler)
Sets the ClientCommandHandler class that interacts with client sockets.

Parameters:
handler - the fully qualified name of the class that implements ClientCommandHandler
See Also:
getClientCommandHandler()

getClientCommandHandler

public java.lang.String getClientCommandHandler()
Returns the ClientCommandHandler class that interacts with client sockets.

Since:
1.1
See Also:
setClientCommandHandler(java.lang.String)

setClientAuthenticationHandler

public void setClientAuthenticationHandler(java.lang.String authenticator)
Sets the ClientAuthenticationHandler class that handles the authentication of a client.

Parameters:
authenticator - the fully qualified name of the class that implements ClientAuthenticationHandler.
Since:
1.4.6
See Also:
getClientAuthenticationHandler()

getClientAuthenticationHandler

public java.lang.String getClientAuthenticationHandler()
Returns the ClientAuthenticationHandler class that handles the authentication of a client.

Since:
1.4.6
See Also:
setClientAuthenticationHandler(java.lang.String)

setAuthenticator

public void setAuthenticator(java.lang.String authenticator)
Deprecated. since 1.4.6 use setClientAuthenticationHandler

Sets the Authenticator class that handles the authentication of a client.

Parameters:
authenticator - the fully qualified name of the class that implements Authenticator or ClientAuthenticationHandler.
Since:
1.3
See Also:
getAuthenticator()

getAuthenticator

public java.lang.String getAuthenticator()
Deprecated. since 1.4.6 use getClientAuthenticationHandler

Returns the Authenticator class that handles the authentication of a client.

Since:
1.3
See Also:
setAuthenticator(java.lang.String)

setClientData

public void setClientData(java.lang.String data)
Sets the ClientData class that carries client data.

Parameters:
data - the fully qualified name of the class that extends ClientData.
See Also:
getClientData()

getClientData

public java.lang.String getClientData()
Returns the ClientData class string that carries client data

Returns:
the fully qualified name of the class that implements ClientData.
See Also:
setClientData(java.lang.String)

setTimeout

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

Parameters:
time - client socket timeout in milliseconds.
See Also:
getTimeout()

getTimeout

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

See Also:
setTimeout(int)

setMaxAuthTry

public void setMaxAuthTry(int authTry)
Sets max allowed login attempts.

Since:
1.2
See Also:
getMaxAuthTry()

getMaxAuthTry

public int getMaxAuthTry()
Returns max allowed login attempts. Default is 5.

Since:
1.2
See Also:
setMaxAuthTry(int)

setMaxAuthTryMsg

public void setMaxAuthTryMsg(java.lang.String msg)
Sets message to be displayed when maximum allowed login attempts has reached. Default is : -ERR Max Auth Try Reached

See Also:
getMaxAuthTryMsg()

getMaxAuthTryMsg

public java.lang.String getMaxAuthTryMsg()
Returns message to be displayed when maximum allowed login attempts has reached.

See Also:
getMaxAuthTryMsg()

setTimeoutMsg

public void setTimeoutMsg(java.lang.String msg)
Sets timeout message. Default is : -ERR Timeout

See Also:
getTimeoutMsg()

getTimeoutMsg

public java.lang.String getTimeoutMsg()
Returns timeout message.

See Also:
setTimeoutMsg(java.lang.String)

run

public void run()
Specified by:
run in interface java.lang.Runnable

setMaxConnection

public void setMaxConnection(long maxConnection)
Sets the maximum number of client connection allowed.

Since:
1.1
See Also:
getMaxConnection()

getMaxConnection

public long getMaxConnection()
Returns the maximum number of client connection allowed.

Since:
1.1
See Also:
setMaxConnection(long)

getClientCount

public long getClientCount()
Returns number of clients connected.

Since:
1.1

setMaxConnectionMsg

public void setMaxConnectionMsg(java.lang.String maxConnectionMsg)
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:
getMaxConnectionMsg()

getMaxConnectionMsg

public java.lang.String getMaxConnectionMsg()
Returns the message to be sent to any new client connected after maximum client connection has reached.

Since:
1.1
See Also:
setMaxConnectionMsg(java.lang.String)

setBindAddr

public void setBindAddr(java.lang.String bindAddr)
                 throws java.net.UnknownHostException
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.
Throws:
java.net.UnknownHostException - if no IP address for the host could be found
Since:
1.1
See Also:
getBindAddr()

getBindAddr

public java.net.InetAddress getBindAddr()
Returns the IP address binding to.

Since:
1.1
See Also:
setBindAddr(java.lang.String)

setStoreObjects

public void setStoreObjects(java.lang.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.

Parameters:
storeObjects - array of objects
Since:
1.1
See Also:
getStoreObjects()

getStoreObjects

public java.lang.Object[] getStoreObjects()
Returns store of objects from QuickServer, if nothing was set will return null.

Since:
1.1
See Also:
setStoreObjects(java.lang.Object[])

setQSAdminServerPort

public void setQSAdminServerPort(int port)
Set the port to run QSAdminServer on.

Since:
1.2

getQSAdminServerPort

public int getQSAdminServerPort()
Returns the port to run QSAdminServer on.

Since:
1.2

setQSAdminServerAuthenticator

public void setQSAdminServerAuthenticator(java.lang.String authenticator)
Set the ClientAuthenticationHandler class of QSAdminServer that handles the authentication of a client.

Since:
1.2

getQSAdminServerAuthenticator

public java.lang.String getQSAdminServerAuthenticator()
Returns the Authenticator or ClientAuthenticationHandler class of QSAdminServer that handles the authentication of a client.

Since:
1.2

startQSAdminServer

public void startQSAdminServer(int port,
                               java.lang.String authenticator)
                        throws AppException
Starts QSAdminServer for this QuickServer.

Parameters:
authenticator - sets the ClientAuthenticationHandler class that handles the authentication of a client, if null uses Authenticator.
port - to run QSAdminServer on
Throws:
AppException - if Server already running or if it could not load the classes [ClientCommandHandler, ClientAuthenticationHandler, ClientData].
Since:
1.1
See Also:
QSAdminServer

startQSAdminServer

public void startQSAdminServer()
                        throws AppException
Starts QSAdminServer for this QuickServer.

Throws:
AppException
Since:
1.2
See Also:
QSAdminServer

getQSAdminServer

public QSAdminServer getQSAdminServer()
Returns QSAdminServer associated with this QuickServer

Since:
1.1

setQSAdminServer

public void setQSAdminServer(QSAdminServer adminServer)
Sets QSAdminServer associated with this QuickServer

Since:
1.3.3

isClosed

public boolean isClosed()
Returns the closed state of the QuickServer Socket.

Since:
1.1

getAppLogger

public java.util.logging.Logger getAppLogger()
Returns the application logger associated with QuickServer. If it was not set will return QuickServer's own logger.

Since:
1.2

setAppLogger

public void setAppLogger(java.util.logging.Logger appLogger)
Sets the application logger associated with QuickServer

Since:
1.2

setClientObjectHandler

public void setClientObjectHandler(java.lang.String handler)
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
Since:
1.2
See Also:
getClientObjectHandler()

getClientObjectHandler

public java.lang.String getClientObjectHandler()
Returns the ClientObjectHandler class that interacts with client sockets.

Since:
1.2
See Also:
setClientObjectHandler(java.lang.String)

setConsoleLoggingFormatter

public void setConsoleLoggingFormatter(java.lang.String formatter)
                                throws java.lang.ClassNotFoundException,
                                       java.lang.InstantiationException,
                                       java.lang.IllegalAccessException
Sets the console log handler formatter.

Parameters:
formatter - fully qualified name of the class that implements Formatter
Throws:
java.lang.ClassNotFoundException
java.lang.InstantiationException
java.lang.IllegalAccessException
Since:
1.2

getConsoleLoggingFormatter

public java.lang.String getConsoleLoggingFormatter()
Gets the console log handler formatter.

Since:
1.3

setConsoleLoggingToMini

public void setConsoleLoggingToMini()
Sets the console log handler formater to MiniFormatter

Since:
1.2

setConsoleLoggingToMicro

public void setConsoleLoggingToMicro()
Sets the console log handler formater to MicroFormatter

Since:
1.2

setConsoleLoggingLevel

public void setConsoleLoggingLevel(java.util.logging.Level level)
Sets the console log handler level.

Since:
1.2

getConsoleLoggingLevel

public java.lang.String getConsoleLoggingLevel()
Gets the console log handler level.

Since:
1.3

setLoggingLevel

public void setLoggingLevel(java.util.logging.Level level)
Sets the level for all log handlers.

Since:
1.3.1

getServiceError

public java.lang.Throwable getServiceError()
Returns service error if any.

Specified by:
getServiceError in interface Service
Since:
1.4.7

initService

public boolean initService(java.lang.Object[] param)
Initialise and create the service.

Specified by:
initService in interface Service
Parameters:
param - of the xml configuration file.
Since:
1.2

initService

public boolean initService(QuickServerConfig qsConfig)
Initialise and create the service.

Parameters:
qsConfig - QuickServerConfig object.
Since:
1.4.6

startService

public boolean startService()
Start the service.

Specified by:
startService in interface Service
Returns:
true if serivce was stopped from Running state.
Since:
1.2

stopService

public boolean stopService()
Stop the service.

Specified by:
stopService in interface Service
Returns:
true if serivce was stopped from Running state.
Since:
1.2

suspendService

public boolean suspendService()
Suspends the service.

Specified by:
suspendService in interface Service
Returns:
true if service was suspended from resumed state.
Since:
1.2

resumeService

public boolean resumeService()
Resume the service.

Specified by:
resumeService in interface Service
Returns:
true if service was resumed from suspended state.
Since:
1.2

info

public java.lang.String info()
Information about the service.

Specified by:
info in interface Service
Since:
1.2

initServer

public void initServer(java.lang.Object[] param)
                throws AppException
Initialise and create the server.

Parameters:
param - of the xml configuration file.
Throws:
AppException - if QuickServerConfig creation failed from the xml config file.
Since:
1.4.7

initServer

public void initServer(QuickServerConfig qsConfig)
                throws AppException
Initialise and create the service.

Parameters:
qsConfig - QuickServerConfig object.
Throws:
AppException
Since:
1.4.7

getServiceState

public int getServiceState()
Returns the state of the process As any constant of Service interface.

Specified by:
getServiceState in interface Service
Since:
1.2

setServiceState

public void setServiceState(int state)
Sets the state of the process As any constant of Service interface.

Since:
1.2

configQuickServer

public void configQuickServer(QuickServerConfig config)
                       throws java.lang.Exception
Configures QuickServer based on the passed QuickServerConfig object.

Throws:
java.lang.Exception
Since:
1.2

configQuickServer

public void configQuickServer(QSAdminServerConfig config)
                       throws java.lang.Exception
Configures QSAdminServer based on the passed QuickServerConfig object.

Throws:
java.lang.Exception
Since:
1.2

configQuickServer

public void configQuickServer()
                       throws java.lang.Exception
Configures QSAdminServer and QuickServer based on the internal QuickServerConfig object.

Throws:
java.lang.Exception
Since:
1.3

main

public static void main(java.lang.String[] args)
Usage: QuickServer [-options]
Where options include:
-about Opens About Dialogbox
-load [options] Loads the server from xml file. where options include: -fullXML2File


load

public static QuickServer load(java.lang.String xml)
                        throws AppException
Loads the server from the xml file name passed.

Throws:
AppException
Since:
1.4.7

clearAllPools

public void clearAllPools()
                   throws java.lang.Exception
Cleans all Object and Thread pools

Throws:
java.lang.Exception
Since:
1.3

closeAllPools

public void closeAllPools()
                   throws java.lang.Exception
Closes all Object and Thread pools

Throws:
java.lang.Exception
Since:
1.3

initAllPools

public void initAllPools()
                  throws java.lang.Exception
Initialise all Object and Thread pools.

Throws:
java.lang.Exception
Since:
1.3

getClientPool

public ClientPool getClientPool()
Returns ClientPool class that managing the pool of threads for handling clients.

Throws:
java.lang.IllegalStateException - if pool is not created yet.
Since:
1.3

getClientHandlerPool

public org.apache.commons.pool.ObjectPool getClientHandlerPool()
Returns ObjectPool of ClientHandler class.

Throws:
java.lang.IllegalStateException - if pool is not created yet.
Since:
1.3

setConfig

public void setConfig(QuickServerConfig config)
Sets the confiuration of the QuickServer.

Since:
1.3

getConfig

public QuickServerConfig getConfig()
Returns the confiuration of the QuickServer.

Since:
1.3

getClientDataPool

public org.apache.commons.pool.ObjectPool getClientDataPool()
Returns ObjectPool of ClientData class. If ClientData was not poolable will return null.

Since:
1.3

getDBPoolUtil

public DBPoolUtil getDBPoolUtil()
Returns DBPoolUtil object if DBObjectPoolConfig was set.

Returns:
DBPoolUtil object if object could be loaded, else will return null
Since:
1.3

setDBObjectPoolConfig

public void setDBObjectPoolConfig(DBObjectPoolConfig dBObjectPoolConfig)
Sets DBObjectPoolConfig

Since:
1.3

findFirstClientById

public ClientHandler findFirstClientById(java.lang.String id)
Tries to find the Client by the Id passed.

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");
                ...
        }

Returns:
ClientHandler object if client was found else null
Since:
1.3.1
See Also:
ClientIdentifiable

findAllClient

public java.util.Iterator findAllClient()
Returns an iterator containing all the 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:
   Eg:

        ClientData foundClientData = null;
        Object syncObj = quickserver.getClientIdentifier().getObjectToSynchronize();
        synchronized(syncObj) {	
                Iterator iterator = quickserver.findAllClient();
                while(iterator.hasNext()) {
                        foundClientHandler = (ClientHandler) iterator.next();
                        ....
                }
        }

        //OR

        ClientData foundClientData = null;
        ClientIdentifier clientIdentifier = quickserver.getClientIdentifier();
        synchronized(clientIdentifier.getObjectToSynchronize()) {	
                Iterator iterator = clientIdentifier.findAllClient();
                while(iterator.hasNext()) {
                        foundClientHandler = (ClientHandler) iterator.next();
                        ....
                }
        }
   

Since:
1.3.1

findAllClientById

public java.util.Iterator findAllClientById(java.lang.String pattern)
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");
                ...
        }

Returns:
ClientHandler object if client was found else null
Since:
1.3.2
See Also:
ClientIdentifiable

findClientByKey

public ClientHandler findClientByKey(java.lang.String key)
Tries to find the Client by the Key passed.

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");
                ...
        }

Returns:
ClientHandler object if client was found else null
Since:
1.3.1
See Also:
ClientIdentifiable

findAllClientByKey

public java.util.Iterator findAllClientByKey(java.lang.String pattern)
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");
                ...
        }

Returns:
ClientHandler object if client was found else null
Since:
1.4
See Also:
ClientIdentifiable

nextClientIsTrusted

public void nextClientIsTrusted()
Sets next client has a trusted client.

This will skip any authentication and will not set any timout.

Since:
1.3.2

setCommunicationLogging

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

Since:
1.3.2
See Also:
getCommunicationLogging()

getCommunicationLogging

public boolean getCommunicationLogging()
Returns the communication logging flag.

Since:
1.3.2
See Also:
setCommunicationLogging(boolean)

setSecurityManagerClass

public void setSecurityManagerClass(java.lang.String securityManagerClass)
Sets the SecurityManager class

Parameters:
securityManagerClass - the fully qualified name of the class that extends SecurityManager.
Since:
1.3.3
See Also:
getSecurityManagerClass()

getSecurityManagerClass

public java.lang.String getSecurityManagerClass()
Returns the SecurityManager class

Since:
1.3.3
See Also:
setSecurityManagerClass(java.lang.String)

getSecurityManager

public java.lang.SecurityManager getSecurityManager()
                                             throws AppException
Throws:
AppException

setAccessConstraintConfig

public void setAccessConstraintConfig(AccessConstraintConfig accessConstraintConfig)
Sets the Access constraints

Since:
1.3.3

getAccessConstraintConfig

public AccessConstraintConfig getAccessConstraintConfig()
Returns Access constraints if present else null.

Since:
1.3.3

setClassLoader

public void setClassLoader(java.lang.ClassLoader classLoader)
Sets the classloader to be used to load the dynamicaly resolved classes

Since:
1.3.3

getClassLoader

public java.lang.ClassLoader getClassLoader()
Gets the classloader used to load the dynamicaly resolved classes.

Since:
1.4.6

getClass

public java.lang.Class getClass(java.lang.String name,
                                boolean reload)
                         throws java.lang.ClassNotFoundException
Utility method to load a class

Throws:
java.lang.ClassNotFoundException
Since:
1.3.3

setApplicationJarPath

protected void setApplicationJarPath(java.lang.String applicationJarPath)
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.

Since:
1.3.3
See Also:
getApplicationJarPath()

getApplicationJarPath

public java.lang.String getApplicationJarPath()
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.

Since:
1.3.3
See Also:
setApplicationJarPath(java.lang.String)

setServerHooks

public void setServerHooks(ServerHooks serverHooks)
Sets the ServerHooks

Since:
1.3.3

getServerHooks

public ServerHooks getServerHooks()
Returns ServerHooks if present else null.

Since:
1.3.3

clone

public java.lang.Object clone()
Creates and returns a copy of this object.

Since:
1.3.3

setSecure

public void setSecure(Secure secure)
Sets the Secure setting for QuickServer

Since:
1.4.0

getSecure

public Secure getSecure()
Returns Secure setting for QuickServer

Since:
1.4.0

isRunningSecure

public boolean isRunningSecure()

Returns if the server is running in Secure mode [SSL or TLS].

Since:
1.4.0

setRunningSecure

public void setRunningSecure(boolean runningSecure)

Sets the server mode if its running in Secure mode [SSL or TLS].

Since:
1.4.0

makeServerSocket

protected void makeServerSocket()
                         throws java.net.BindException,
                                java.io.IOException
Returns a ServerSocket object to be used for listening.

Throws:
java.net.BindException
java.io.IOException
Since:
1.4.0

setBasicConfig

public void setBasicConfig(BasicServerConfig basicConfig)
                    throws java.lang.Exception
Sets the basic confiuration of the QuickServer.

Throws:
java.lang.Exception
Since:
1.4.0

getBasicConfig

public BasicServerConfig getBasicConfig()
Returns the basic confiuration of the QuickServer.

Since:
1.4.0

loadSSLContext

public void loadSSLContext()
                    throws java.io.IOException
Loads the SSLContext from Secure configuring if set.

Throws:
java.io.IOException
Since:
1.4.0
See Also:
setSecure(org.quickserver.util.xmlreader.Secure)

getSSLContext

public javax.net.ssl.SSLContext getSSLContext()
                                       throws java.io.IOException,
                                              java.security.NoSuchAlgorithmException,
                                              java.security.KeyManagementException
Returns the SSLContext from Secure configuring.

Throws:
java.io.IOException
java.security.NoSuchAlgorithmException
java.security.KeyManagementException
Since:
1.4.0
See Also:
loadSSLContext()

getSSLContext

public javax.net.ssl.SSLContext getSSLContext(java.lang.String protocol)
                                       throws java.io.IOException,
                                              java.security.NoSuchAlgorithmException,
                                              java.security.KeyManagementException
Returns the SSLContext object that implements the specified secure socket protocol from Secure configuring.

Parameters:
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
See Also:
loadSSLContext()

getSSLSocketFactory

public javax.net.ssl.SSLSocketFactory getSSLSocketFactory()
                                                   throws java.io.IOException,
                                                          java.security.NoSuchAlgorithmException,
                                                          java.security.KeyManagementException
Returns a SSLSocketFactory object to be used for creating SSLSockets. Secure socket protocol will be picked from the Secure configuring.

Throws:
java.io.IOException
java.security.NoSuchAlgorithmException
java.security.KeyManagementException
Since:
1.4.0
See Also:
setSecure(org.quickserver.util.xmlreader.Secure)

getSSLSocketFactory

public javax.net.ssl.SSLSocketFactory getSSLSocketFactory(java.lang.String protocol)
                                                   throws java.io.IOException,
                                                          java.security.NoSuchAlgorithmException,
                                                          java.security.KeyManagementException
Returns a SSLSocketFactory object to be used for creating SSLSockets.

Parameters:
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
See Also:
setSecure(org.quickserver.util.xmlreader.Secure)

setClientBinaryHandler

public void setClientBinaryHandler(java.lang.String handler)
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
Since:
1.4
See Also:
getClientBinaryHandler()

getClientBinaryHandler

public java.lang.String getClientBinaryHandler()
Returns the ClientBinaryHandler class that interacts with client sockets.

Since:
1.4
See Also:
setClientBinaryHandler(java.lang.String)

setSelector

public void setSelector(java.nio.channels.Selector selector)
Sets the Selector (NIO).

Since:
1.4.5

getSelector

public java.nio.channels.Selector getSelector()
Returns the Selector (NIO),if any.

Since:
1.4.5

registerChannel

public boolean registerChannel(java.nio.channels.SocketChannel channel,
                               int ops,
                               java.lang.Object att)
                        throws java.io.IOException,
                               java.nio.channels.ClosedChannelException
Register the given channel for the given operations. This adds the request to a list and will be processed after selector select wakes up.

Returns:
boolean flag to indicate if new entry was added to the list to register.
Throws:
java.io.IOException
java.nio.channels.ClosedChannelException
Since:
1.4.5

getByteBufferPool

public org.apache.commons.pool.ObjectPool getByteBufferPool()
Returns ObjectPool of java.nio.ByteBuffer class.

Since:
1.4.5

setClientWriteHandler

public void setClientWriteHandler(java.lang.String handler)
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
Since:
1.4.5
See Also:
getClientWriteHandler()

getClientWriteHandler

public java.lang.String getClientWriteHandler()
Returns the ClientWriteHandler class that interacts with client sockets (only used in non-blocking mode).

Since:
1.4.5
See Also:
setClientWriteHandler(java.lang.String)

getLastStartTime

public java.util.Date getLastStartTime()
Returns the date/time when the server was last started.

Returns:
last started time. Will be null if never started.
Since:
1.4.5

setDebugNonBlockingMode

public static void setDebugNonBlockingMode(boolean flag)
Sets the debug flag to ByteBufferOutputStream and ByteBufferInputStream class that are used in non-blcking mode

Since:
1.4.5

getClientIdentifier

public ClientIdentifier getClientIdentifier()
Returns the implementation that is used to do Client Identification.

Since:
1.4.5

getBlockingMode

public boolean getBlockingMode()
Returns the current blocking mode of the server.

Since:
1.4.6

loadBusinessLogic

protected void loadBusinessLogic()
                          throws java.lang.Exception
Loads all the Business Logic class

Throws:
java.lang.Exception
Since:
1.4.6

setClientEventHandler

public void setClientEventHandler(java.lang.String handler)
Sets the ClientEventHandler class that gets notified of client events.

Parameters:
handler - the fully qualified name of the class that implements ClientEventHandler
Since:
1.4.6
See Also:
getClientEventHandler()

getClientEventHandler

public java.lang.String getClientEventHandler()
Returns the ClientEventHandler class that gets notified of client events.

Since:
1.4.6
See Also:
setClientEventHandler(java.lang.String)

setDefaultDataMode

public void setDefaultDataMode(DataMode dataMode,
                               DataType dataType)
                        throws java.io.IOException
Sets the default DataMode for the ClientHandler

Throws:
java.io.IOException
Since:
1.4.6

setDefaultDataMode

public void setDefaultDataMode(DefaultDataMode defaultDataMode)
                        throws java.io.IOException
Sets the default DataMode for the ClientHandler

Throws:
java.io.IOException
Since:
1.4.6

getDefaultDataMode

public DataMode getDefaultDataMode(DataType dataType)
Returns the default DataMode for the ClientHandler

Since:
1.4.6

setClientExtendedEventHandler

public void setClientExtendedEventHandler(java.lang.String handler)
Sets the ClientExtendedEventHandler class that gets notified of extended client events.

Parameters:
handler - the fully qualified name of the class that implements ClientExtendedEventHandler
Since:
1.4.6
See Also:
getClientExtendedEventHandler()

getClientExtendedEventHandler

public java.lang.String getClientExtendedEventHandler()
Returns the ClientExtendedEventHandler class that gets notified of extended client events.

Since:
1.4.6
See Also:
setClientExtendedEventHandler(java.lang.String)

QuickServer
v1.4.7

Copyright © 2003-2006 QuickServer.org