anon.infoservice
Class ListenerInterface

java.lang.Object
  extended by anon.infoservice.ListenerInterface
All Implemented Interfaces:
ImmutableListenerInterface, IXMLEncodable
Direct Known Subclasses:
ProxyInterface

public class ListenerInterface
extends java.lang.Object
implements ImmutableListenerInterface, IXMLEncodable

Saves the information about a network server.


Field Summary
private  boolean m_bHidden
           
private  boolean m_bUseInterface
          This describes, whether we can reach this interface or not.
private  boolean m_bVirtual
           
private  long m_endOfBlocking
           
private  int m_iInetPort
          This is the representation of the port of the ListenerInterface.
private  int m_iProtocolType
          This describes the protocol type.
private  java.lang.String m_strHostname
          This is the host of this interface (hostname or IP).
static int PORT_MAX_VALUE
           
static int PORT_MIN_VALUE
           
static java.lang.String XML_ATTR_HIDDEN
           
static java.lang.String XML_ATTR_VIRTUAL
           
static java.lang.String XML_ELEM_FILE
           
static java.lang.String XML_ELEM_HOST
           
static java.lang.String XML_ELEM_PORT
           
static java.lang.String XML_ELEMENT_CONTAINER_NAME
           
static java.lang.String XML_ELEMENT_NAME
           
 
Fields inherited from interface anon.infoservice.ImmutableListenerInterface
PROTOCOL_STR_TYPE_HTTP, PROTOCOL_STR_TYPE_HTTPS, PROTOCOL_STR_TYPE_RAW_TCP, PROTOCOL_STR_TYPE_RAW_UNIX, PROTOCOL_STR_TYPE_SOCKS, PROTOCOL_STR_TYPE_UNKNOWN, PROTOCOL_TYPE_HTTP, PROTOCOL_TYPE_HTTPS, PROTOCOL_TYPE_RAW_TCP, PROTOCOL_TYPE_RAW_UNIX, PROTOCOL_TYPE_SOCKS, PROTOCOL_TYPE_UNKNOWN
 
Fields inherited from interface anon.util.IXMLEncodable
FIELD_XML_ELEMENT_CONTAINER_NAME, FIELD_XML_ELEMENT_NAME, XML_ATTR_ID, XML_ATTR_LANGUAGE, XML_ATTR_VERSION
 
Constructor Summary
ListenerInterface(org.w3c.dom.Element listenerInterfaceNode)
          Creates a new ListenerInterface from XML description (ListenerInterface node).
ListenerInterface(java.lang.String a_strValue)
          Creates a new ListenerInterface from a String which is of the form hostname:port.
ListenerInterface(java.lang.String a_hostname, int a_port)
          Creates a new ListenerInterface from a hostname / IP address and a port.
ListenerInterface(java.lang.String a_hostname, int a_port, int a_protocol)
          Creates a new ListenerInterface from a hostname / IP address, a port and a protocol information.
 
Method Summary
 void blockInterface(long a_blockingTime)
          Blocks this interface for a specified time.
 boolean equals(ListenerInterface a_listenerInterface)
          Tests if two ListenerInterface instances are equal.
 java.lang.String getHost()
          Get the host (hostname or IP) of this interface as a String.
 int getPort()
          Get the port of this interface.
 int getProtocol()
          Gets the protocol of this ListenerInterface.
 java.lang.String getProtocolAsString()
          Gets the protocol of this ListenerInterface as String.
 boolean isHidden()
           
 boolean isValid()
          Get the validity of this interface.
static boolean isValidHostname(java.lang.String a_hostname)
          Returns if the given host name is valid.
static boolean isValidIP(java.lang.String a_ipAddress)
          Returns if the given IP address is valid.
static boolean isValidPort(int a_port)
          Returns if the given port is valid.
static boolean isValidProtocol(int a_protocol)
          Returns if the given protocol is valid web protocol and can be recognized by recognizeProtocol().
static boolean isValidProtocol(java.lang.String a_protocol)
          Returns if the given protocol is valid web protocol and can be recognized by recognizeProtocol().
 boolean isVirtual()
           
protected static int recognizeProtocol(int a_protocol)
          Transforms a given protocol into a valid protocol if recognized.
protected static int recognizeProtocol(java.lang.String a_protocol)
          Transforms a given protocol into a valid protocol if recognized.
 void setHostname(java.lang.String a_strHostname)
          Sets the host name.
 void setPort(int a_port)
          Sets the port number.
 void setProtocol(int a_protocol)
          Sets the protocol.
 void setProtocol(java.lang.String a_protocol)
          Sets the protocol.
 void setUseInterface(boolean a_bUseInterface)
          Sets if this interface is used or not.
 java.lang.String toString()
           
 java.util.Vector toVector()
          Creates a Vector of listeners with only the current listener.
 org.w3c.dom.Element toXmlElement(org.w3c.dom.Document a_doc)
          Creates an XML node without signature for this ListenerInterface..
protected  org.w3c.dom.Element toXmlElementInternal(org.w3c.dom.Document doc, java.lang.String a_strXmlElementName)
          Creates an XML node without signature for this ListenerInterface.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PORT_MIN_VALUE

public static final int PORT_MIN_VALUE
See Also:
Constant Field Values

PORT_MAX_VALUE

public static final int PORT_MAX_VALUE
See Also:
Constant Field Values

XML_ELEMENT_NAME

public static final java.lang.String XML_ELEMENT_NAME
See Also:
Constant Field Values

XML_ELEMENT_CONTAINER_NAME

public static final java.lang.String XML_ELEMENT_CONTAINER_NAME
See Also:
Constant Field Values

XML_ATTR_HIDDEN

public static final java.lang.String XML_ATTR_HIDDEN
See Also:
Constant Field Values

XML_ATTR_VIRTUAL

public static final java.lang.String XML_ATTR_VIRTUAL
See Also:
Constant Field Values

XML_ELEM_HOST

public static final java.lang.String XML_ELEM_HOST
See Also:
Constant Field Values

XML_ELEM_PORT

public static final java.lang.String XML_ELEM_PORT
See Also:
Constant Field Values

XML_ELEM_FILE

public static final java.lang.String XML_ELEM_FILE
See Also:
Constant Field Values

m_endOfBlocking

private long m_endOfBlocking

m_strHostname

private java.lang.String m_strHostname
This is the host of this interface (hostname or IP). It can be NULL indicating, that the hostname is unspecified. The user has to decide how to handle this (e.g. if this means 'any' IP of any interface or if whis means 'only localhost' etc.


m_iInetPort

private int m_iInetPort
This is the representation of the port of the ListenerInterface. Might be -1 to indicate that the port is unspecified.


m_iProtocolType

private int m_iProtocolType
This describes the protocol type.


m_bUseInterface

private boolean m_bUseInterface
This describes, whether we can reach this interface or not. If we can't get a connection to this interface, we set it to false and so there are no more connection trys. The interface still remains in the database because others may get a connection to this interface (causes can be firewalls, another network, ...). This is only meaningful for non-local (remote) interfaces.


m_bVirtual

private boolean m_bVirtual

m_bHidden

private boolean m_bHidden
Constructor Detail

ListenerInterface

public ListenerInterface(org.w3c.dom.Element listenerInterfaceNode)
                  throws XMLParseException
Creates a new ListenerInterface from XML description (ListenerInterface node).

Parameters:
listenerInterfaceNode - The ListenerInterface node from an XML document.
Throws:
XMLParseException - if an error in the xml structure occurs

ListenerInterface

public ListenerInterface(java.lang.String a_hostname,
                         int a_port)
                  throws java.lang.IllegalArgumentException
Creates a new ListenerInterface from a hostname / IP address and a port. The protocol is set to HTTP/TCP.

Parameters:
a_hostname - The hostname or the IP address of this interface.
a_port - The port of this interface (1 <= port <= 65535).
Throws:
java.lang.IllegalArgumentException - if an illegal host name or port was given

ListenerInterface

public ListenerInterface(java.lang.String a_strValue)
                  throws java.lang.IllegalArgumentException
Creates a new ListenerInterface from a String which is of the form hostname:port. (The hostname can also be omitted) The protocol is set to HTTP/TCP.

Parameters:
a_strValue - The string containing hostname and port.
Throws:
java.lang.IllegalArgumentException - if an illegal host name or port was given

ListenerInterface

public ListenerInterface(java.lang.String a_hostname,
                         int a_port,
                         int a_protocol)
                  throws java.lang.IllegalArgumentException
Creates a new ListenerInterface from a hostname / IP address, a port and a protocol information.

Parameters:
a_hostname - The hostname or the IP address of this interface.
a_port - The port of this interface (1 <= port <= 65535).
a_protocol - The protocol information. Invalid protocols are replaced by http.
Throws:
java.lang.IllegalArgumentException - if an illegal host name, port or protocol was given
Method Detail

isValidPort

public static boolean isValidPort(int a_port)
Returns if the given port is valid.

Parameters:
a_port - a port number
Returns:
true if the given port is valid; false otherwise

isValidProtocol

public static boolean isValidProtocol(java.lang.String a_protocol)
Returns if the given protocol is valid web protocol and can be recognized by recognizeProtocol().

Parameters:
a_protocol - a web protocol
Returns:
true if the given protocol is valid web protocol; false otherwise
See Also:
recognizeProtocol(String)

isValidProtocol

public static boolean isValidProtocol(int a_protocol)
Returns if the given protocol is valid web protocol and can be recognized by recognizeProtocol().

Parameters:
a_protocol - a web protocol
Returns:
true if the given protocol is valid web protocol; false otherwise
See Also:
recognizeProtocol(String)

isValidHostname

public static boolean isValidHostname(java.lang.String a_hostname)
Returns if the given host name is valid.

Parameters:
a_hostname - a host name
Returns:
true if the given host name is valid; false otherwise

isValidIP

public static boolean isValidIP(java.lang.String a_ipAddress)
Returns if the given IP address is valid.

Parameters:
a_ipAddress - an IP address
Returns:
true if the given IP address is valid; false otherwise

getProtocol

public int getProtocol()
Gets the protocol of this ListenerInterface.

Specified by:
getProtocol in interface ImmutableListenerInterface
Returns:
the protocol of this ListenerInterface

getProtocolAsString

public java.lang.String getProtocolAsString()
Gets the protocol of this ListenerInterface as String.

Returns:
the protocol of this ListenerInterface

getHost

public java.lang.String getHost()
Get the host (hostname or IP) of this interface as a String.

Specified by:
getHost in interface ImmutableListenerInterface
Returns:
The host of this interface.

getPort

public int getPort()
Get the port of this interface.

Specified by:
getPort in interface ImmutableListenerInterface
Returns:
The port of this interface.

equals

public boolean equals(ListenerInterface a_listenerInterface)
Tests if two ListenerInterface instances are equal.

Parameters:
a_listenerInterface - a ListenerInterface
Returns:
true if the two ListenerInterface instances are equal; false otherwise

toXmlElement

public org.w3c.dom.Element toXmlElement(org.w3c.dom.Document a_doc)
Creates an XML node without signature for this ListenerInterface..

Specified by:
toXmlElement in interface IXMLEncodable
Parameters:
a_doc - The XML document, which is the environment for the created XML node.
Returns:
The ListenerInterface XML node.

setUseInterface

public void setUseInterface(boolean a_bUseInterface)
Sets if this interface is used or not. If it is not used, further connection retries are prevented for a predefined amount of time

Parameters:
a_bUseInterface - true if this interface is used; false otherwise

blockInterface

public void blockInterface(long a_blockingTime)
Blocks this interface for a specified time. This is useful if the service is temporarily not reachable.

Parameters:
a_blockingTime - long

isValid

public boolean isValid()
Get the validity of this interface. If it is not valid, further connection retries are prevented.

Specified by:
isValid in interface ImmutableListenerInterface
Returns:
Whether this interface is valid or not.

isVirtual

public boolean isVirtual()

isHidden

public boolean isHidden()

recognizeProtocol

protected static int recognizeProtocol(java.lang.String a_protocol)
Transforms a given protocol into a valid protocol if recognized.

Parameters:
a_protocol - a protocol
Returns:
the protocol (my be transformed in some way) or PROTOCOL_TYPE_UNKNOWN if not recognized

recognizeProtocol

protected static int recognizeProtocol(int a_protocol)
Transforms a given protocol into a valid protocol if recognized.

Parameters:
a_protocol - a protocol
Returns:
the protocol (my be transformed in some way) or PROTOCOL_TYPE_UNKNOWN if not recognized

setProtocol

public void setProtocol(java.lang.String a_protocol)
Sets the protocol. If it is invalid, it is set to PROTOCOL_TYPE_RAW_TCP.

Parameters:
a_protocol - a protocol

setProtocol

public void setProtocol(int a_protocol)
Sets the protocol. If it is invalid, it is set to PROTOCOL_TYPE_RAW_TCP.

Parameters:
a_protocol - a protocol

setPort

public void setPort(int a_port)
Sets the port number.

Parameters:
a_port - a port number

setHostname

public void setHostname(java.lang.String a_strHostname)
Sets the host name.

Parameters:
a_strHostname - a host name

toVector

public java.util.Vector toVector()
Creates a Vector of listeners with only the current listener.

Returns:
a Vector of listeners with only the current listener

toXmlElementInternal

protected org.w3c.dom.Element toXmlElementInternal(org.w3c.dom.Document doc,
                                                   java.lang.String a_strXmlElementName)
Creates an XML node without signature for this ListenerInterface.

Parameters:
doc - The XML document, which is the environment for the created XML node.
a_strXmlElementName - the name of the xml element to create
Returns:
The ListenerInterface XML node.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object