Spring AMQP

org.springframework.amqp.rabbit.connection
Class SingleConnectionFactory

java.lang.Object
  extended by org.springframework.amqp.rabbit.connection.SingleConnectionFactory
All Implemented Interfaces:
ConnectionFactory, DisposableBean
Direct Known Subclasses:
CachingConnectionFactory

public class SingleConnectionFactory
extends Object
implements ConnectionFactory, DisposableBean

A ConnectionFactory implementation that returns the same Connections from all createConnection() calls, and ignores calls to Connection.close().

Author:
Mark Fisher, Mark Pollack

Field Summary
protected  org.apache.commons.logging.Log logger
           
 
Constructor Summary
SingleConnectionFactory()
          Create a new SingleConnectionFactory initializing the hostname to be the value returned from InetAddress.getLocalHost(), or "localhost" if getLocalHost() throws an exception.
SingleConnectionFactory(com.rabbitmq.client.ConnectionFactory rabbitConnectionFactory)
          Create a new SingleConnectionFactory for the given target ConnectionFactory.
SingleConnectionFactory(String hostname)
          Create a new SingleConnectionFactory given a host name.
 
Method Summary
protected  void closeConnection(Connection connection)
          Close the given Connection.
 Connection createConnection()
           
 void destroy()
          Close the underlying shared connection.
protected  Connection doCreateConnection()
          Create a Rabbit Connection via this class's ConnectionFactory.
protected  com.rabbitmq.client.Channel getChannel(Connection connection, boolean transactional)
           
 String getHost()
           
protected  int getPort()
           
protected  Connection getSharedConnectionProxy(Connection target)
          Wrap the given Connection with a proxy that delegates every method call to it but suppresses close calls.
 String getVirtualHost()
           
 void initConnection()
           
protected  void prepareConnection(Connection con)
           
 void resetConnection()
          Reset the underlying shared Connection, to be reinitialized on next access.
 void setPassword(String password)
           
 void setPort(int port)
           
 void setUsername(String username)
           
 void setVirtualHost(String virtualHost)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

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

SingleConnectionFactory

public SingleConnectionFactory()
Create a new SingleConnectionFactory initializing the hostname to be the value returned from InetAddress.getLocalHost(), or "localhost" if getLocalHost() throws an exception.


SingleConnectionFactory

public SingleConnectionFactory(String hostname)
Create a new SingleConnectionFactory given a host name.

Parameters:
hostname - the host name to connect to

SingleConnectionFactory

public SingleConnectionFactory(com.rabbitmq.client.ConnectionFactory rabbitConnectionFactory)
Create a new SingleConnectionFactory for the given target ConnectionFactory.

Parameters:
rabbitConnectionFactory - the target ConnectionFactory
Method Detail

setUsername

public void setUsername(String username)

setPassword

public void setPassword(String password)

getHost

public String getHost()
Specified by:
getHost in interface ConnectionFactory

setVirtualHost

public void setVirtualHost(String virtualHost)

getVirtualHost

public String getVirtualHost()
Specified by:
getVirtualHost in interface ConnectionFactory

setPort

public void setPort(int port)

getPort

protected int getPort()

getChannel

protected com.rabbitmq.client.Channel getChannel(Connection connection,
                                                 boolean transactional)
                                          throws IOException
Throws:
IOException

createConnection

public Connection createConnection()
                            throws IOException
Specified by:
createConnection in interface ConnectionFactory
Throws:
IOException

initConnection

public void initConnection()
                    throws IOException
Throws:
IOException

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
Create a Rabbit Connection via this class's ConnectionFactory.

Returns:
the new Rabbit Connection
Throws:
IOException

prepareConnection

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

getSharedConnectionProxy

protected Connection getSharedConnectionProxy(Connection target)
Wrap the given Connection 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

toString

public String toString()
Overrides:
toString in class Object

Spring AMQP

Copyright © 2010. All Rights Reserved.