JXTA

net.jxta.impl.protocol
Class TCPAdv

java.lang.Object
  extended by net.jxta.document.Advertisement
      extended by net.jxta.document.ExtendableAdvertisement
          extended by net.jxta.protocol.TransportAdvertisement
              extended by net.jxta.impl.protocol.TCPAdv

public class TCPAdv
extends TransportAdvertisement

Provides configuration parameters for the JXTA TCP Message Transport.


Nested Class Summary
static class TCPAdv.Instantiator
          Our instantiator
 
Field Summary
 
Fields inherited from class net.jxta.protocol.TransportAdvertisement
protocol
 
Method Summary
static String getAdvertisementType()
          Returns the identifying type of this Advertisement.
 String getAdvType()
          Returns the identifying type of this Advertisement.
 String getConfigMode()
          returns the config mode.
 Document getDocument(MimeMediaType encodeAs)
          Write this advertisement into a document of the requested type.
 int getEndPort()
          Return the highest port on which the TCP Transport will listen if configured to do so.
 String[] getIndexFields()
          Returns the element names on which this advertisement should be indexed.
 String getInterfaceAddress()
          Returns the interface which the TCP transport will use.
 String getMulticastAddr()
          returns the multicastaddr
 int getMulticastPort()
          returns the multicastport
 int getMulticastSize()
          returns the multicastsize
 boolean getMulticastState()
          Determine whether multicast if off or not
 int getPort()
          Returns the port on which the TCP Transport will listen if configured to do so.
 boolean getPublicAddressOnly()
          Returns the state of whether to only use public address
 String getServer()
          Returns the public address
 int getStartPort()
          Return the lowest port on which the TCP Transport will listen if configured to do so.
protected  boolean handleElement(Element raw)
          Process an individual element from the document during parse.
 boolean isClientEnabled()
          Returns the configuration for outbound connections.
 boolean isServerEnabled()
          Returns the configuration for inbound connections.
 void setClientEnabled(boolean enabled)
          Sets the configuration for outbound connections.
 void setConfigMode(String mode)
          set the config mode.
 void setEndPort(int end)
          Sets the highest port on which the TCP Transport will listen if configured to do so.
 void setInterfaceAddress(String ia)
          Sets the interface which the TCP transport will use.
 void setMulticastAddr(String multicastaddr)
          set the multicastaddr
 void setMulticastPort(int multicastport)
          set the multicastport
 void setMulticastSize(int multicastsize)
          set the multicastsize
 void setMulticastState(boolean newState)
          Enable or disable multicast.
 void setPort(int port)
          Sets the port on which the TCP Transport will listen if configured to do so.
 void setPublicAddressOnly(boolean only)
          Sets the state of whether to only use public address
 void setServer(String address)
          Set the public address.
 void setServerEnabled(boolean enabled)
          Sets the configuration for inbound connections.
 void setStartPort(int start)
          Sets the lowest port on which the TCP Transport will listen if configured to do so.
 
Methods inherited from class net.jxta.protocol.TransportAdvertisement
getBaseAdvType, getID, getProtocol, setProtocol
 
Methods inherited from class net.jxta.document.ExtendableAdvertisement
handleAttribute
 
Methods inherited from class net.jxta.document.Advertisement
clone, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getAdvertisementType

public static String getAdvertisementType()
Returns the identifying type of this Advertisement.

Note: This is a static method. It cannot be used to determine the runtime type of an advertisement. ie.

      Advertisement adv = module.getSomeAdv();
      String advType = adv.getAdvertisementType();
  

This is wrong and does not work the way you might expect. This call is not polymorphic and calls Advertisement.getAdvertisementType() no matter what the real type of the advertisement.

Returns:
String the type of advertisement

getAdvType

public String getAdvType()
Returns the identifying type of this Advertisement. Unlike Advertisement.getAdvertisementType() this method will return the correct runtime type of an Advertisement object.

This implementation is provided for existing advertisements which do not provide their own implementation. In most cases you should provide your own implementation for efficiency reasons.

Overrides:
getAdvType in class Advertisement
Returns:
The identifying type of this Advertisement.

getInterfaceAddress

public String getInterfaceAddress()
Returns the interface which the TCP transport will use.

Returns:
The interface to use. May be a DNS name or an IP Address.

setInterfaceAddress

public void setInterfaceAddress(String ia)
Sets the interface which the TCP transport will use.

Parameters:
ia - The interface to use. May be a DNS name or an IP Address.

getPort

public int getPort()
Returns the port on which the TCP Transport will listen if configured to do so. If a port range is specified then this the preference. Valid values are -1, 0 and 1-65535. The -1 value is used to signify that there is no port preference and any port in range will be used. The 0 specifies that the Socket API dynamic port allocation should be used. For values 1-65535 the value specifies the required port on which the TCP transport will listen.

Returns:
the port

setPort

public void setPort(int port)
Sets the port on which the TCP Transport will listen if configured to do so. If a port range is specified then this the preference. Valid values are -1, 0 and 1-65535. The -1 value is used to signify that there is no port preference and any port in range will be used. The 0 specifies that the Socket API dynamic port allocation should be used. For values 1-65535 the value specifies the required port on which the TCP transport will listen.

Parameters:
port - the port on which to listen.

getStartPort

public int getStartPort()
Return the lowest port on which the TCP Transport will listen if configured to do so. Valid values are -1, 0 and 1-65535. The -1 value is used to signify that the port range feature should be disabled. The 0 specifies that the Socket API dynamic port allocation should be used. For values 1-65535 the value must be equal to or less than the value used for end port.

Returns:
the lowest port on which to listen.

setStartPort

public void setStartPort(int start)
Sets the lowest port on which the TCP Transport will listen if configured to do so. Valid values are -1, 0 and 1-65535. The -1 value is used to signify that the port range feature should be disabled. The 0 specifies that the Socket API dynamic port allocation should be used. For values 1-65535 the value must be equal to or less than the value used for end port.

Parameters:
start - the lowest port on which to listen.

getEndPort

public int getEndPort()
Return the highest port on which the TCP Transport will listen if configured to do so. Valid values are -1, 0 and 1-65535. The -1 value is used to signify that the port range feature should be disabled. The 0 specifies that the Socket API dynamic port allocation should be used. For values 1-65535 the value must be equal to or greater than the value used for start port.

Returns:
the highest port on which to listen.

setEndPort

public void setEndPort(int end)
Sets the highest port on which the TCP Transport will listen if configured to do so. Valid values are -1, 0 and 1-65535. The -1 value is used to signify that the port range feature should be disabled. The 0 specifies that the Socket API dynamic port allocation should be used. For values 1-65535 the value must be equal to or greater than the value used for start port.

Parameters:
end - the highest port on which to listen.

getMulticastState

public boolean getMulticastState()
Determine whether multicast if off or not

Returns:
boolean current multicast state

setMulticastState

public void setMulticastState(boolean newState)
Enable or disable multicast.

Parameters:
newState - the desired state.

getMulticastAddr

public String getMulticastAddr()
returns the multicastaddr

Returns:
string multicastaddr

setMulticastAddr

public void setMulticastAddr(String multicastaddr)
set the multicastaddr

Parameters:
multicastaddr - set multicastaddr

getMulticastPort

public int getMulticastPort()
returns the multicastport

Returns:
string multicastport

setMulticastPort

public void setMulticastPort(int multicastport)
set the multicastport

Parameters:
multicastport - set multicastport

getMulticastSize

public int getMulticastSize()
returns the multicastsize

Returns:
integer containting the multicast size

setMulticastSize

public void setMulticastSize(int multicastsize)
set the multicastsize

Parameters:
multicastsize - set multicast size

getServer

public String getServer()
Returns the public address

Returns:
string public address

setServer

public void setServer(String address)
Set the public address. That is, a the address of a server socket to connect to from the outside. Argument is in the form host:port

Parameters:
address - address

isClientEnabled

public boolean isClientEnabled()
Returns the configuration for outbound connections.

Returns:
true if outbound connections are allowed otherwise false

setClientEnabled

public void setClientEnabled(boolean enabled)
Sets the configuration for outbound connections.

Parameters:
enabled - true if outbound connections are allowed otherwise false

isServerEnabled

public boolean isServerEnabled()
Returns the configuration for inbound connections.

Returns:
true if inbound connections are allowed otherwise false

setServerEnabled

public void setServerEnabled(boolean enabled)
Sets the configuration for inbound connections.

Parameters:
enabled - true if inbound connections are allowed otherwise false

getConfigMode

public String getConfigMode()
returns the config mode. That is, how the user prefers to configure the interface address: "auto", "manual"

Returns:
string config mode

setConfigMode

public void setConfigMode(String mode)
set the config mode. That is, how the user prefers to configure the interface address: "auto", "manual" This is just a pure config item. It is never in published advs. The TCP transport strips it when it initializes.

Parameters:
mode - Can be "auto", "manual" other settings will act as the default which is "auto".

getPublicAddressOnly

public boolean getPublicAddressOnly()
Returns the state of whether to only use public address

Returns:
boolean true if set to use "Public Address Only"

setPublicAddressOnly

public void setPublicAddressOnly(boolean only)
Sets the state of whether to only use public address

Parameters:
only - true to use "Public Address Only"

handleElement

protected boolean handleElement(Element raw)
Process an individual element from the document during parse. Normally, implementations will allow the base advertisements a chance to handle the element before attempting to handle the element themselves. ie.


  protected boolean handleElement(Element elem) {

      if (super.handleElement()) {
           // it's been handled.
           return true;
           }
      ... handle elements here ...

      // we don't know how to handle the element
      return false;
      }
  

Overrides:
handleElement in class ExtendableAdvertisement
Parameters:
raw - The element to be processed.
Returns:
true if the element was recognized, otherwise false.

getDocument

public Document getDocument(MimeMediaType encodeAs)
Write this advertisement into a document of the requested type. Two standard document forms are defined. "text/plain" encodes the document in a "pretty-print" format for human viewing and "text/xml" which provides an XML format.

We don't have any content to add, just build the document instance and return it to implementations that actually do something with it.

Overrides:
getDocument in class ExtendableAdvertisement
Parameters:
encodeAs - MimeMediaType format representation requested.
Returns:
The Advertisement represented as a Document of the requested MIME Media Type.

getIndexFields

public String[] getIndexFields()
Returns the element names on which this advertisement should be indexed.

Specified by:
getIndexFields in class Advertisement
Returns:
The element names on which this advertisement should be indexed.

JXSE