SK.gnome.dwarf.tcpip
Class TCPListener

java.lang.Object
  extended bySK.gnome.dwarf.GenericService
      extended bySK.gnome.dwarf.thread.ThreadService
          extended bySK.gnome.dwarf.tcpip.Listener
              extended bySK.gnome.dwarf.tcpip.TCPListener
All Implemented Interfaces:
java.lang.Runnable, Service
Direct Known Subclasses:
SSLListener

public class TCPListener
extends Listener

Service for receiving client connections.

It listenes on a specified port and address and passes the received connections to the TCPIPServer for further processing.


Field Summary
protected  int backlog
          The server socket queue size.
protected  java.net.ServerSocket socket
          The server socket.
 
Fields inherited from class SK.gnome.dwarf.tcpip.Listener
address, allowedHosts, deniedHosts, port
 
Fields inherited from class SK.gnome.dwarf.thread.ThreadService
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
TCPListener(java.lang.String name)
          Creates a new TCPListener.
 
Method Summary
protected  boolean enableThread()
          Enables or disables the service thread.
protected  void finish()
          Waits for the thread to complete.
protected  java.net.ServerSocket getServerSocket()
          Returns the server socket.
 void init(Server parent)
          Initializes the service.
protected  void loop()
          Performs the listening operation.
 void setBacklog(int backlog)
          Sets the server socket queue size.
 void setDumpDir(java.io.File dir)
          Sets the directory where to dump the socket streams.
 
Methods inherited from class SK.gnome.dwarf.tcpip.Listener
acceptHost, setAddress, setAllowedHosts, setDeniedHosts, setPort
 
Methods inherited from class SK.gnome.dwarf.thread.ThreadService
run, setDaemon, shutdown, start, stop
 
Methods inherited from class SK.gnome.dwarf.GenericService
getAuthenticator, getAuthFacility, getFullName, getInitParameter, getInitParameterNames, getLogFacility, getLogger, getName, getParameters, 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
 

Field Detail

backlog

protected int backlog
The server socket queue size.

Default value: TCPIPConstants.TCPIP_DEFAULT_BACKLOG_SIZE


socket

protected java.net.ServerSocket socket
The server socket.

See Also:
getServerSocket()
Constructor Detail

TCPListener

public TCPListener(java.lang.String name)
Creates a new TCPListener.

Method Detail

setBacklog

public void setBacklog(int backlog)
Sets the server socket queue size.

Parameters:
backlog - the backlog size
See Also:
backlog

setDumpDir

public void setDumpDir(java.io.File dir)
Sets the directory where to dump the socket streams.

If it is set to an existing directory, all client sockets created by this listener will dump their input and output streams to separate files in the specified directory.

Parameters:
dir - the directory

init

public void init(Server parent)
          throws ServiceException
Initializes the service.

Sets the socket field to value returned by the getServerSocket() method.

This method requires that the parent server is an instance of TCPIPServer class.

Specified by:
init in interface Service
Overrides:
init in class GenericService
Throws:
ServiceException

finish

protected void finish()
Waits for the thread to complete.

It closes the socket, which causes an interruption of the blocked listening thread, so it can finish gracefully.

Overrides:
finish in class ThreadService

enableThread

protected boolean enableThread()
Enables or disables the service thread.

This method always returns true, so the new listening thread is always started.

Overrides:
enableThread in class ThreadService
Returns:
true if the thread is enabled

loop

protected void loop()
Performs the listening operation.

Listenes on a specified port and address via the socket. If a new client connection is detected, first checks whether the connection should be accepted by invoking the inherited Listener.acceptHost(InetAddress) method and if the result is true, it passes the socket to the parent server by calling its TCPIPServer.enqueue(Object) method. In the case that the listener will not accept the connection, the socket is silently closed and a warning message is written to the log.

Overrides:
loop in class ThreadService

getServerSocket

protected java.net.ServerSocket getServerSocket()
                                         throws ServiceException
Returns the server socket.

Returns a socket for the listening. The returned socket will be bound to the Listener.port. If the Listener.address field is null, the socket will listen on all available addresses, otherwise it will listen of the specified address only. The socket is created using the system-default ServerSocketFactory.

Throws:
ServiceException


Copyright (c) 1999-2005, Gnome Ltd. All rights reserved.