SK.gnome.dwarf.tcpip
Class Listener

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

public abstract class Listener
extends ThreadService

Abstract service for receiving client requests.

This service just defines a set of common methods for a network listener. Subclasses must further add the required network listening functionality.

The setAddress(InetAddress) and setPort(int) methods can be used to setup an internet address and port on which the listener will receive the client requests. The setAllowedHosts(InetHostSet) and setDeniedHosts(InetHostSet) may be used to specify which clients will be accepted or rejected by the listener.

The protected method acceptHost(InetAddress) tests the given address against the internal sets of allowed and denied hosts, and returns true if a request from the given address may be accepted by the listener and forwarded to the server for further processing. This method may be overriden to implement a custom behaviour.


Field Summary
protected  java.net.InetAddress address
          The internet address to listen on.
protected  InetHostSet allowedHosts
          The set of allowed host ranges.
protected  InetHostSet deniedHosts
          The set of denied host ranges.
protected  int port
          The network port to listen on.
 
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
Listener(java.lang.String name)
          Creates a new Listener.
 
Method Summary
protected  boolean acceptHost(java.net.InetAddress address)
          Decides whether to accept a request from the given address.
 void setAddress(java.net.InetAddress address)
          Sets the internet address to listen on.
 void setAllowedHosts(InetHostSet hosts)
          Sets the allowed host ranges.
 void setDeniedHosts(InetHostSet hosts)
          Sets the denied host ranges.
 void setPort(int port)
          Sets the port to listen on.
 
Methods inherited from class SK.gnome.dwarf.thread.ThreadService
enableThread, finish, loop, 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, init, 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

address

protected java.net.InetAddress address
The internet address to listen on.


port

protected int port
The network port to listen on.


allowedHosts

protected InetHostSet allowedHosts
The set of allowed host ranges.

See Also:
setAllowedHosts(InetHostSet)

deniedHosts

protected InetHostSet deniedHosts
The set of denied host ranges.

See Also:
setDeniedHosts(InetHostSet)
Constructor Detail

Listener

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

Method Detail

setAddress

public void setAddress(java.net.InetAddress address)
Sets the internet address to listen on.

Parameters:
address - the internet address
See Also:
address

setPort

public void setPort(int port)
Sets the port to listen on.

Parameters:
port - the port
See Also:
port

setAllowedHosts

public void setAllowedHosts(InetHostSet hosts)
Sets the allowed host ranges.

Parameters:
hosts - the host range list
See Also:
acceptHost(InetAddress), InetHostSet

setDeniedHosts

public void setDeniedHosts(InetHostSet hosts)
Sets the denied host ranges.

Parameters:
hosts - the host range list
See Also:
acceptHost(InetAddress), InetHostSet

acceptHost

protected boolean acceptHost(java.net.InetAddress address)
Decides whether to accept a request from the given address.

The decision is based on the sets of allowed/denied host ranges. The current alghoritm works as follows: if the allowedHosts is not null and does not imply the given address, the method return false, otherwise the deniedHosts is consulted. If it is not null and implies the given address, false is returned, otherwise true is returned.

This method can be overriden to customize the listener's way of accepting client request.



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