|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.zib.scalaris.ConnectionFactory
public class ConnectionFactory
Provides means to create connections to scalaris nodes.
This class uses a singleton-alike pattern providing a global (static)
instance through its getInstance()
method but also allowing for
object construction which might be useful when using multiple threads each
creating its own connections.
The location of the default configuration file used by
ConnectionFactory()
can be overridden by specifying the
scalaris.java.config system property - otherwise the class tries to load
scalaris.properties.
A specific property can also be overridden specifying a (non-empty) system
property with its name.
A user-defined Properties
object can also be used by creating objects
with ConnectionFactory(Properties)
or setting the new values with
setProperties(Properties)
but must provide the following values
(default values as shown)
scalaris.node
can be a whitespace, ',' or ';' separated list of
available nodes. See DefaultConnectionPolicy
about how this list is
used when connections are setup or when existing connections fail.
Since Java and Erlang both need to known the same node name in order to
connect, any "@localhost" in such a name is translated using
fixLocalhostName(String)
to a real node name. The best method of
changing this name is to use the name Erlang uses - it can be provided by
setting the scalaris.erlang.nodename system property. If this is
not set or empty, we will try to look-up the name ourselves (see
getLocalhostName()
.
The connectionPolicy
set will be passed on to created connections.
Changing it via setConnectionPolicy(ConnectionPolicy)
will not
change previously created connections - they keep the old policy. By
default, DefaultConnectionPolicy
is used.
Constructor Summary | |
---|---|
ConnectionFactory()
Constructor, sets the parameters to use for connections according to values given in a scalaris.properties file and falls back to default values if values don't exist. |
|
ConnectionFactory(Properties properties)
Constructor, sets the parameters to use for connections according to values given in the given Properties object and falls back to
default values if values don't exist. |
Method Summary | |
---|---|
void |
addNode(PeerNode node)
Adds a node to the set of nodes available for connections. |
void |
addNode(String node)
Adds a node to the set of nodes available for connections. |
Connection |
createConnection()
Creates a connection to a scalaris erlang node specified by the given parameters. |
Connection |
createConnection(ConnectionPolicy connectionPolicy)
Creates a connection to a scalaris erlang node specified by the given parameters. |
Connection |
createConnection(String clientName)
Creates a connection to a scalaris erlang node specified by the given parameters. |
Connection |
createConnection(String clientName,
boolean clientNameAppendUUID)
Creates a connection to a scalaris erlang node specified by the given parameters. |
Connection |
createConnection(String clientName,
boolean clientNameAppendUUID,
ConnectionPolicy connectionPolicy)
Creates a connection to a scalaris erlang node specified by the given parameters. |
static String |
fixLocalhostName(String node)
Replaces localhost in the node's name to the machine's real host name. |
String |
getClientName()
Returns the name of the (Java) client to use when establishing a connection with erlang. |
ConnectionPolicy |
getConnectionPolicy()
Gets the current connection policy. |
String |
getCookie()
Returns the cookie name to use for connections. |
static ConnectionFactory |
getInstance()
Returns the static instance of a connection factory. |
static String |
getLocalhostName()
Returns the name of the local host as determined by findLocalhostName() . |
String |
getNode()
Deprecated. This method returns the names of all nodes available for connection as a String (as previously when only one node was used), use the new getNodes() method instead. |
List<PeerNode> |
getNodes()
Gets a copy of the list of nodes available for connections. |
boolean |
isClientNameAppendUUID()
Returns whether an UUID is appended to client names or not. |
void |
printProperties()
Prints the object's properties to System.out. |
void |
printProperties(PrintStream out)
Prints the object's properties to the given output stream. |
void |
removeNode(PeerNode node)
Removes a node from the set of nodes available for connections. |
void |
setClientName(String clientName)
Sets the name of the (Java) client to use when establishing a connection with erlang. |
void |
setClientNameAppendUUID(boolean clientNameAppendUUID)
Sets whether to append an UUID to client names or not. |
void |
setConnectionPolicy(ConnectionPolicy connectionPolicy)
Sets the connection policy to use for new connections. |
void |
setCookie(String cookie)
Sets the cookie name to use for connections. |
void |
setNode(PeerNode node)
Sets the name of the node to connect to. |
void |
setNode(String node)
Sets the name of the node to connect to. |
void |
setProperties(Properties properties)
Sets the object's members used for creating connections to erlang to values provided by the given Properties object. |
void |
testAllNodes()
(Re-)evaluates all currently set nodes by trying to establish a connection to each of them. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ConnectionFactory()
public ConnectionFactory(Properties properties)
Properties
object and falls back to
default values if values don't exist.
The Properties
object should provide the following values
(default values as shown):
properties
- Method Detail |
---|
public static ConnectionFactory getInstance()
public void setProperties(Properties properties)
Properties
object.
The Properties
object should provide the following values
(default values as shown):
properties
- the object to get the connection parameters frompublic Connection createConnection(String clientName, boolean clientNameAppendUUID, ConnectionPolicy connectionPolicy) throws ConnectionException
clientName
- the name that identifies the java clientclientNameAppendUUID
- override the object's setting for
clientNameAppendUUID
connectionPolicy
- override the connection policy that will be used for the new
connection
ConnectionException
- if the connection failspublic Connection createConnection(String clientName, boolean clientNameAppendUUID) throws ConnectionException
clientName
- the name that identifies the java clientclientNameAppendUUID
- override the object's setting for
clientNameAppendUUID
ConnectionException
- if the connection failspublic Connection createConnection(String clientName) throws ConnectionException
clientNameAppendUUID
has been set, a pseudo UUID is appended
to the given name. BEWARE that scalaris nodes accept only one connection
per client name!
clientName
- the name that identifies the java client
ConnectionException
- if the connection failspublic Connection createConnection(ConnectionPolicy connectionPolicy) throws ConnectionException
clientNameAppendUUID
has been set, a pseudo UUID is appended
to the given name. BEWARE that scalaris nodes accept only one connection
per client name!
connectionPolicy
- override the connection policy that will be used for the new
connection
ConnectionException
- if the connection failspublic Connection createConnection() throws ConnectionException
ConnectionException
- if the connection failspublic static String fixLocalhostName(String node)
node
- the name of the node to use
InetAddress.getHostName()
public static final String getLocalhostName()
findLocalhostName()
.
public void printProperties()
public void printProperties(PrintStream out)
out
- the output stream to write topublic List<PeerNode> getNodes()
PeerNode
elements of the list will not be copied!
@Deprecated public String getNode()
getNodes()
method instead.
nodes
contains multiple nodes, only the first of
them will be returned. This is not necessarily the one the class will set
up connections with!
public void setNode(String node)
node
- the node to set (will not be mangled by
fixLocalhostName(String)
!)addNode(String)
public void setNode(PeerNode node)
node
- the node to set (will not be mangled by
fixLocalhostName(String)
!)addNode(PeerNode)
public void addNode(String node)
node
- the node to add (will not be mangled by
fixLocalhostName(String)
!)setNode(String)
public void addNode(PeerNode node)
node
- the node to addsetNode(String)
public void removeNode(PeerNode node)
node
- the node to removegetNodes()
public void testAllNodes()
PeerNode
statistics collected before.
public String getCookie()
public void setCookie(String cookie)
cookie
- the cookie to setpublic String getClientName()
public void setClientName(String clientName)
clientName
- the clientName to setpublic boolean isClientNameAppendUUID()
public void setClientNameAppendUUID(boolean clientNameAppendUUID)
clientNameAppendUUID
- true if an UUID is appended, false otherwisepublic void setConnectionPolicy(ConnectionPolicy connectionPolicy)
connectionPolicy
- the connection policy to setpublic ConnectionPolicy getConnectionPolicy()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |