|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object SK.gnome.dwarf.GenericService SK.gnome.dwarf.GenericServer SK.gnome.dwarf.thread.ThreadServer SK.gnome.dwarf.thread.MultiThreadServer SK.gnome.dwarf.tcpip.TCPIPServer
Provides generic TCP/IP server.
This is just a convenience class. It extends the MultiThreadServer
by setting some default initial values for the queue size, number of active handlers
and the handler timeout. The real servers may directly use an instance of this class,
or they may extend it to implement the additional protocol-related functionality.
This class also provides a means to configure a SSL/TLS context, from which a client
or server sockets may be created without an effort. Use the setKeyStoreURL(URL)
,
setKeyStorePwd(String)
, setKeyPwd(String)
and setSSLProtocol(String)
methods to initialize the SSL/TLS context.
Field Summary | |
protected javax.net.ssl.SSLContext |
sslContext
SSL context associated with this server. |
Fields inherited from class SK.gnome.dwarf.thread.MultiThreadServer |
counter |
Fields inherited from class SK.gnome.dwarf.thread.ThreadServer |
daemon, thread |
Fields inherited from class SK.gnome.dwarf.GenericService |
initParameters, parent |
Fields inherited from interface SK.gnome.dwarf.Service |
INITIALIZED, LOG_DEBUG, LOG_ERROR, LOG_FATAL, LOG_INFO, LOG_TRACE, LOG_WARN, LOG_XFER, SHUTDOWN, STARTED, STOPPED |
Constructor Summary | |
TCPIPServer(java.lang.String name)
Creates a new TCPIPServer. |
Method Summary | |
java.net.ServerSocket |
createSSLServerSocket(int port,
int backlog)
Creates a SSL server socket. |
java.net.ServerSocket |
createSSLServerSocket(int port,
int backlog,
java.net.InetAddress address)
Creates a SSL server socket. |
java.net.Socket |
createSSLSocket(java.net.Socket socket,
boolean autoClose)
Creates a SSL socket. |
boolean |
enqueue(java.lang.Object obj)
Puts the client request to the queue. |
void |
finish(java.lang.Object obj)
Returns the processed request to the server. |
protected int |
getRequestReadTimeout()
Returns the request read timeout. |
protected TCPRequest |
getTCPRequest()
Returns a TCPRequest implementation.
|
void |
init(Server parent)
Initializes the service. |
protected boolean |
isBlocking()
Returns whether this server is configured as blocking. |
boolean |
isSSLConfigured()
Whether the SSL sockets may be created. |
protected void |
loop()
Main server thread loop. |
java.lang.String |
report()
Returns the service report. |
void |
setKeyPwd(java.lang.String pwd)
Sets the key password. |
void |
setKeyStorePwd(java.lang.String pwd)
Sets the keystore password. |
void |
setKeyStoreURL(java.net.URL url)
Sets the keystore URL. |
void |
setRegistrationQueueSize(int size)
Sets the max size of channel registration queue. |
void |
setRequestClass(java.lang.Class cl)
Sets the class of non-blocking request implementation. |
void |
setSSLProtocol(java.lang.String name)
Sets the requested SSL/TLS protocol name. |
void |
shutdown()
Shuts down the service. |
void |
start()
Starts the service. |
Methods inherited from class SK.gnome.dwarf.thread.MultiThreadServer |
addService, dequeue, enableThread, getHandlerTimeout, setHandlerClass, setHandlerTimeout, setMaxHandlers, setMinHandlers, setQueueSize, setSingleRequest, wakeUpHandlers |
Methods inherited from class SK.gnome.dwarf.thread.ThreadServer |
finish, run, setDaemon, stop |
Methods inherited from class SK.gnome.dwarf.GenericServer |
addService, getAuthenticator, getLogger, getParameters, getService, getServices, getServices, removeService |
Methods inherited from class SK.gnome.dwarf.GenericService |
getAuthFacility, getFullName, getInitParameter, getInitParameterNames, getLogFacility, getName, getPrincipal, getShutdownTimeout, getState, log, log, login, logout, setAuthFacility, setInitParameters, setLogFacility, toString |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface SK.gnome.dwarf.Service |
getFullName, getName, getState, log, log, login, logout |
Field Detail |
protected javax.net.ssl.SSLContext sslContext
Constructor Detail |
public TCPIPServer(java.lang.String name)
The inherited attributes are initialized to some default values as follows, so an instance of this class may be created and used without any further effort:
setQueueSize(TCPIPConstants.TCPIP_DEFAULT_QUEUE_SIZE); setReqistrationQueueSize(TCPIPConstants.TCPIP_DEFAULT_REGISTRATION_QUEUE_SIZE); setHandlerTimeout(TCPIPConstants.TCPIP_DEFAULT_HANDLER_TIMEOUT); setMinHandlers(TCPIPConstants.TCPIP_DEFAULT_MIN_HANDLERS); setMaxHandlers(TCPIPConstants.TCPIP_DEFAULT_MAX_HANDLERS);
Method Detail |
public void setRegistrationQueueSize(int size)
size
- the queue size limitpublic void setRequestClass(java.lang.Class cl)
cl
- the request classpublic void setKeyStoreURL(java.net.URL url)
The keystore must be in the "JKS" format.
url
- URL of the keystorepublic void setKeyStorePwd(java.lang.String pwd)
pwd
- keystore passwordpublic void setKeyPwd(java.lang.String pwd)
pwd
- key passwordpublic void setSSLProtocol(java.lang.String name)
The default protocol used is "TLSv1".
name
- the protocol namepublic void init(Server parent) throws ServiceException
If the key store URL has been specified, the corresponding key store is loaded and
a key manager is created and configured from it. Then a sslContext
is initialized
with the given key manager.
init
in interface Service
init
in class MultiThreadServer
ServiceException
public void start() throws ServiceException
It calls super.start() and then logs an information about the current package's implementation title and version.
start
in interface Service
start
in class ThreadServer
ServiceException
public void shutdown()
ThreadServer
It interrupts the ThreadServer.thread
via its interrupt() method and waits for
it to finish by calling the ThreadServer.finish()
method.
shutdown
in interface Service
shutdown
in class ThreadServer
public boolean enqueue(java.lang.Object obj)
MultiThreadServer
The request is represented by an instance of the java.lang.Object, which is
added to the server's internal queue. The idle handlers (which are blocked on the queue)
are then notified that a client request is waiting for the processing. After that, if the
current queue size is still greater than zero, the server also tries to start some of the
temporarily stopped handlers - this process is actually preformed in the protected
MultiThreadServer.loop()
method. The method returns true if the client request was accepted
by the server, otherwise returns false - it probably means either that the overall
server's processing capacity has been reached, or an object equal to obj is
already processed by a handler.
enqueue
in class MultiThreadServer
obj
- the client request
public void finish(java.lang.Object obj)
MultiThreadServer
This method just adjusts the MultiThreadServer.counter
value.
finish
in class MultiThreadServer
obj
- the request objectpublic java.net.ServerSocket createSSLServerSocket(int port, int backlog) throws java.io.IOException
Uses the Sun JSSE implementation to create a SSL server socket by using the
system default socket factory. The socket is created according to the current
sslContext
value.
The created socket will be bound to all available addresses.
port
- the port to listen onbacklog
- the size of server backlog
java.io.IOException
- if socket could not be createdpublic java.net.ServerSocket createSSLServerSocket(int port, int backlog, java.net.InetAddress address) throws java.io.IOException
Uses the Sun JSSE implementation to create a SSL server socket by using the
system default socket factory. The socket is created according to the current
sslContext
value.
The created socket will be bound to the given address.
port
- the port to listen onbacklog
- the size of server backlogaddress
- the address to listen on
java.io.IOException
- if socket could not be createdpublic java.net.Socket createSSLSocket(java.net.Socket socket, boolean autoClose) throws java.io.IOException
Uses the Sun JSSE implementation to create a SSL socket by tunneling the existing
normal (insecure) socket. The socket is created according to the current
sslContext
value.
socket
- the normal socketautoClose
- whether to close the underlying socket if closing the SSL socket
ServiceException
- if the socket could not be created
java.io.IOException
public boolean isSSLConfigured()
It returns true is the sslContext
has been initialized properly
and the SSL client and server sockets may be created by this server. Application code
may consult the result of this method to advertise some SSL-based capabilities to remote
clients.
public java.lang.String report()
MultiThreadServer
Returns report from the superclass plus the statistics of the handlers' activity and the internal client request queue.
report
in interface Reportable
report
in class MultiThreadServer
protected boolean isBlocking()
protected int getRequestReadTimeout()
This timeout is used by the non-blocking servers only.
protected void loop()
MultiThreadServer
This method calls the MultiThreadServer.wakeUpHandlers()
method and then waits blocked until notified.
loop
in class MultiThreadServer
protected TCPRequest getTCPRequest()
TCPRequest
implementation.
The default implementation just creates and returns a new request object.
setRequestClass(Class)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |