de.zib.scalaris
Class Connection

java.lang.Object
  extended by de.zib.scalaris.Connection

public class Connection
extends Object

Wraps an OtpConnection and allows automatic re-connects using a ConnectionPolicy object.

Since:
2.3
Version:
3.14
Author:
Nico Kruber, kruber@zib.de

Constructor Summary
Connection(OtpSelf self, ConnectionPolicy connectionPolicy)
          Creates a new connection between the a self node and one of the remoteNodes, selected by the connectionPolicy.
Connection(OtpSelf self, PeerNode remote)
          Creates a new connection using the given nodes and a default connection policy.
 
Method Summary
 void close()
          Closes the connection to the remote node.
 OtpErlangObject doRPC(String mod, String fun, OtpErlangList args)
          Sends the given RPC and waits for a result.
 OtpErlangObject doRPC(String mod, String fun, OtpErlangObject[] args)
          Sends the given RPC and waits for a result.
 OtpConnection getConnection()
          Gets the encapsulated OTP connection object.
 PeerNode getRemote()
          Gets the remote node connected to.
 OtpSelf getSelf()
          Gets the local node used for the connection.
 void sendRPC(String mod, String fun, OtpErlangList args)
          Sends the given RPC and returns immediately.
 void sendRPC(String mod, String fun, OtpErlangObject[] args)
          Sends the given RPC and returns immediately.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Connection

public Connection(OtpSelf self,
                  PeerNode remote)
           throws UnknownHostException,
                  IOException,
                  OtpAuthException
Creates a new connection using the given nodes and a default connection policy. Provided for convenience.

Parameters:
self - the local node
remote - the remote node to connect to
Throws:
UnknownHostException - if the remote host could not be found
IOException - if it was not possible to connect to the remote node
OtpAuthException - if the connection was refused by the remote node

Connection

public Connection(OtpSelf self,
                  ConnectionPolicy connectionPolicy)
           throws UnknownHostException,
                  IOException,
                  OtpAuthException
Creates a new connection between the a self node and one of the remoteNodes, selected by the connectionPolicy.

Parameters:
self - the local node
connectionPolicy - the connection policy to use
Throws:
UnknownHostException - if the remote host could not be found
IOException - if it was not possible to connect to the remote node
OtpAuthException - if the connection was refused by the remote node
Method Detail

doRPC

public OtpErlangObject doRPC(String mod,
                             String fun,
                             OtpErlangList args)
                      throws ConnectionException
Sends the given RPC and waits for a result.

Parameters:
mod - the module of the function to call
fun - the function to call
args - the function's arguments
Returns:
the result of the call
Throws:
ConnectionException - if the connection is not active, a communication error occurs, an exit signal is received from a process on the peer node or the remote node sends a message containing an invalid cookie

doRPC

public OtpErlangObject doRPC(String mod,
                             String fun,
                             OtpErlangObject[] args)
                      throws ConnectionException
Sends the given RPC and waits for a result. Provided for convenience.

Parameters:
mod - the module of the function to call
fun - the function to call
args - the function's arguments
Returns:
the result of the call
Throws:
ConnectionException - if the connection is not active, a communication error occurs, an exit signal is received from a process on the peer node or the remote node sends a message containing an invalid cookie

sendRPC

public void sendRPC(String mod,
                    String fun,
                    OtpErlangList args)
             throws ConnectionException
Sends the given RPC and returns immediately.

Parameters:
mod - the module of the function to call
fun - the function to call
args - the function's arguments
Throws:
ConnectionException - if the connection is not active, a communication error occurs, an exit signal is received from a process on the peer node or the remote node sends a message containing an invalid cookie

sendRPC

public void sendRPC(String mod,
                    String fun,
                    OtpErlangObject[] args)
             throws ConnectionException
Sends the given RPC and returns immediately. Provided for convenience.

Parameters:
mod - the module of the function to call
fun - the function to call
args - the function's arguments
Throws:
ConnectionException - if the connection is not active, a communication error occurs, an exit signal is received from a process on the peer node or the remote node sends a message containing an invalid cookie

close

public void close()
Closes the connection to the remote node.


getSelf

public OtpSelf getSelf()
Gets the local node used for the connection.

Returns:
the local node (self)

getRemote

public PeerNode getRemote()
Gets the remote node connected to.

Returns:
the remote node

getConnection

public OtpConnection getConnection()
Gets the encapsulated OTP connection object.

Returns:
the connection object