Spring AMQP

org.springframework.erlang.connection
Class SingleConnectionFactory

java.lang.Object
  extended by org.springframework.erlang.connection.SingleConnectionFactory
All Implemented Interfaces:
DisposableBean, InitializingBean, ConnectionFactory

public class SingleConnectionFactory
extends Object
implements ConnectionFactory, InitializingBean, DisposableBean

A ConnectionFactory implementation that returns the same Connections from all createConnection() calls, and ignores calls to Connection.close(). Provides a more traditional API to creating a connection to a remote erlang node than the JInterface API.

The following is taken from the JInterface javadocs that describe the valid node names that can be used. These naming constraints apply to the string values you pass into the node names in SimpleConnectionFactory's constructor.

About nodenames: Erlang nodenames consist of two components, an alivename and a hostname separated by '@'. Additionally, there are two nodename formats: short and long. Short names are of the form "alive@hostname", while long names are of the form "alive@host.fully.qualified.domainname". Erlang has special requirements regarding the use of the short and long formats, in particular they cannot be mixed freely in a network of communicating nodes, however Jinterface makes no distinction. See the Erlang documentation for more information about nodenames.

The constructors for the AbstractNode classes will create names exactly as you provide them as long as the name contains '@'. If the string you provide contains no '@', it will be treated as an alivename and the name of the local host will be appended, resulting in a shortname. Nodenames longer than 255 characters will be truncated without warning.

Upon initialization, this class attempts to read the file .erlang.cookie in the user's home directory, and uses the trimmed first line of the file as the default cookie by those constructors lacking a cookie argument. If for any reason the file cannot be found or read, the default cookie will be set to the empty string (""). The location of a user's home directory is determined using the system property "user.home", which may not be automatically set on all platforms.

Author:
Mark Pollack

Field Summary
protected  org.apache.commons.logging.Log logger
           
 
Constructor Summary
SingleConnectionFactory(String selfNodeName, String peerNodeName)
           
SingleConnectionFactory(String selfNodeName, String cookie, String peerNodeName)
           
 
Method Summary
 void afterPropertiesSet()
           
protected  void closeConnection(Connection connection)
          Close the given Connection.
 Connection createConnection()
           
 void destroy()
          Close the underlying shared connection.
protected  Connection doCreateConnection()
          Create a JInterface Connection via this class's ConnectionFactory.
protected  Connection getSharedConnectionProxy(Connection target)
          Wrap the given OtpConnection with a proxy that delegates every method call to it but suppresses close calls.
 void initConnection()
           
 boolean isUniqueSelfNodeName()
           
protected  void prepareConnection(Connection con)
           
 void resetConnection()
          Reset the underlying shared Connection, to be reinitialized on next access.
 void setUniqueSelfNodeName(boolean uniqueSelfNodeName)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final org.apache.commons.logging.Log logger
Constructor Detail

SingleConnectionFactory

public SingleConnectionFactory(String selfNodeName,
                               String cookie,
                               String peerNodeName)

SingleConnectionFactory

public SingleConnectionFactory(String selfNodeName,
                               String peerNodeName)
Method Detail

isUniqueSelfNodeName

public boolean isUniqueSelfNodeName()

setUniqueSelfNodeName

public void setUniqueSelfNodeName(boolean uniqueSelfNodeName)

createConnection

public Connection createConnection()
                            throws UnknownHostException,
                                   com.ericsson.otp.erlang.OtpAuthException
Specified by:
createConnection in interface ConnectionFactory
Throws:
UnknownHostException
com.ericsson.otp.erlang.OtpAuthException

initConnection

public void initConnection()
                    throws IOException,
                           com.ericsson.otp.erlang.OtpAuthException
Throws:
IOException
com.ericsson.otp.erlang.OtpAuthException

destroy

public void destroy()
Close the underlying shared connection. The provider of this ConnectionFactory needs to care for proper shutdown.

As this bean implements DisposableBean, a bean factory will automatically invoke this on destruction of its cached singletons.

Specified by:
destroy in interface DisposableBean

resetConnection

public void resetConnection()
Reset the underlying shared Connection, to be reinitialized on next access.


closeConnection

protected void closeConnection(Connection connection)
Close the given Connection.

Parameters:
connection - the Connection to close

doCreateConnection

protected Connection doCreateConnection()
                                 throws IOException,
                                        com.ericsson.otp.erlang.OtpAuthException
Create a JInterface Connection via this class's ConnectionFactory.

Returns:
the new Otp Connection
Throws:
com.ericsson.otp.erlang.OtpAuthException
IOException

prepareConnection

protected void prepareConnection(Connection con)
                          throws IOException
Throws:
IOException

getSharedConnectionProxy

protected Connection getSharedConnectionProxy(Connection target)
Wrap the given OtpConnection with a proxy that delegates every method call to it but suppresses close calls. This is useful for allowing application code to handle a special framework Connection just like an ordinary Connection from a Rabbit ConnectionFactory.

Parameters:
target - the original Connection to wrap
Returns:
the wrapped Connection

afterPropertiesSet

public void afterPropertiesSet()
Specified by:
afterPropertiesSet in interface InitializingBean

Spring AMQP

Copyright © 2011. All Rights Reserved.