Package org.jcsp.net.tcpip
Class TCPIPNodeFactory
- java.lang.Object
-
- org.jcsp.net.tcpip.TCPIPNodeFactory
-
- All Implemented Interfaces:
java.io.Serializable
,NodeFactory
public class TCPIPNodeFactory extends java.lang.Object implements NodeFactory
Default factory for simple initialisations using the TCPIPv4 protocol package.
Other constructors can be used to specify a particular CNS server. The default behaviour will extract a CNS server from the system property "org.jcsp.tcpip.DefaultCNSServer" with the server specified as a name or IP address with optional port number.
If built with 1.4 or higher the user preferences will also be checked but only if a runtime supporting the preferences is available. If not present the system preferences will then be checked.
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private NodeAddressID
cnsServer
Address of the CNS server.private int
localPort
Port number to use for the local link server.private SecurityService
security
Optional security service to install.
-
Constructor Summary
Constructors Constructor Description TCPIPNodeFactory()
Default constructor, connecting to the local host on the default CNS port or to a host name in the system properties.TCPIPNodeFactory(java.lang.String cnsServer)
Connect to the named host on the default CNS port.TCPIPNodeFactory(java.lang.String cnsServerAddress, int cnsServerPort)
Connect to a named host on a specific port.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private NodeAddressID
construct(java.lang.String cnsServer)
Split the server string into a server and port component on the : character.private NodeAddressID
construct(java.lang.String cnsServerAddress, int cnsServerPort)
Construct the server address, assuming the local host if none is specified.private java.lang.String
getServerFromPrefs()
This code was moved into this method from the constructor below in the hope that code would compile on 1.4 and still run on 1.3 and 1.2,NodeKey
initNode(Node node, Node.Attributes attribs)
Initialise the node to listen on all local addresses, and start a CNS service.static NodeFactory
instantiate()
Constructs an instance of this class.void
setLocalPort(int port)
Sets the port number that should be used.void
setSecurityAuthority(SecurityService security)
Sets the security service to be used.
-
-
-
Field Detail
-
cnsServer
private final NodeAddressID cnsServer
Address of the CNS server.
-
localPort
private int localPort
Port number to use for the local link server. By default will be system assigned. Call setLocalPort prior to calling Node.init () to set a specific value.
-
security
private SecurityService security
Optional security service to install.
-
-
Constructor Detail
-
TCPIPNodeFactory
public TCPIPNodeFactory()
Default constructor, connecting to the local host on the default CNS port or to a host name in the system properties. The host name should be specified as name:port or just the host name to use the default CNS port.
-
TCPIPNodeFactory
public TCPIPNodeFactory(java.lang.String cnsServer)
Connect to the named host on the default CNS port. If the server name is given asnull
then the CNS service will not be loaded.- Parameters:
cnsServer
- name of server
-
TCPIPNodeFactory
public TCPIPNodeFactory(java.lang.String cnsServerAddress, int cnsServerPort)
Connect to a named host on a specific port.- Parameters:
cnsServerAddress
- name of the servercnsServerPort
- port to connect to
-
-
Method Detail
-
instantiate
public static NodeFactory instantiate()
Constructs an instance of this class. This method is provided so that a later implementation can opt to pass construction to an alternative under certain conditions. This is for use by the infrastructure only. Users should call the public constructors.
-
construct
private NodeAddressID construct(java.lang.String cnsServerAddress, int cnsServerPort)
Construct the server address, assuming the local host if none is specified.- Parameters:
cnsServerAddress
- address of CNS server or null to use the local host.cnsServerPort
- port number
-
construct
private NodeAddressID construct(java.lang.String cnsServer)
Split the server string into a server and port component on the : character. If none is present the default port is assumed and the request passed to the otherconstruct
method.- Parameters:
cnsServer
- server with optional port number
-
getServerFromPrefs
private java.lang.String getServerFromPrefs()
This code was moved into this method from the constructor below in the hope that code would compile on 1.4 and still run on 1.3 and 1.2,
-
initNode
public NodeKey initNode(Node node, Node.Attributes attribs) throws NodeInitFailedException
Initialise the node to listen on all local addresses, and start a CNS service.- Specified by:
initNode
in interfaceNodeFactory
- Parameters:
node
- the node to be initializedattribs
- access to the restricted node attributes- Throws:
NodeInitFailedException
- if a problem occurs
-
setLocalPort
public void setLocalPort(int port)
Sets the port number that should be used. If this is not called then the system will allocate an arbitrary port.- Parameters:
port
- the port number, 0 <= port < 65536.
-
setSecurityAuthority
public void setSecurityAuthority(SecurityService security)
Sets the security service to be used.- Parameters:
security
- the new security authority.
-
-