Spring AMQP

org.springframework.amqp.rabbit.connection
Class SingleConnectionFactory

java.lang.Object
  extended by org.springframework.amqp.rabbit.connection.AbstractConnectionFactory
      extended by org.springframework.amqp.rabbit.connection.SingleConnectionFactory
All Implemented Interfaces:
ConnectionFactory, DisposableBean

public class SingleConnectionFactory
extends AbstractConnectionFactory

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

Author:
Mark Fisher, Mark Pollack, Dave Syer

Field Summary
 
Fields inherited from class org.springframework.amqp.rabbit.connection.AbstractConnectionFactory
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(int port)
          Create a new SingleConnectionFactory given a host name.
SingleConnectionFactory(String hostname)
          Create a new SingleConnectionFactory given a host name.
SingleConnectionFactory(String hostname, int port)
          Create a new SingleConnectionFactory given a host name.
 
Method Summary
 void addConnectionListener(ConnectionListener listener)
           
 Connection createConnection()
           
 void destroy()
          Close the underlying shared connection.
protected  Connection doCreateConnection()
          Create a Connection.
 void setConnectionListeners(List<? extends ConnectionListener> listeners)
           
 String toString()
           
 
Methods inherited from class org.springframework.amqp.rabbit.connection.AbstractConnectionFactory
addChannelListener, createBareConnection, getChannelListener, getConnectionListener, getDefaultHostName, getHost, getPort, getVirtualHost, setChannelListeners, setHost, setPassword, setPort, setUsername, setVirtualHost
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

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(int port)
Create a new SingleConnectionFactory given a host name.

Parameters:
port - the port to connect to

SingleConnectionFactory

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

Parameters:
hostname - the host name to connect to

SingleConnectionFactory

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

Parameters:
hostname - the host name to connect to
port - the port number 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

setConnectionListeners

public void setConnectionListeners(List<? extends ConnectionListener> listeners)
Overrides:
setConnectionListeners in class AbstractConnectionFactory

addConnectionListener

public void addConnectionListener(ConnectionListener listener)
Specified by:
addConnectionListener in interface ConnectionFactory
Overrides:
addConnectionListener in class AbstractConnectionFactory

createConnection

public final Connection createConnection()
                                  throws AmqpException
Throws:
AmqpException

destroy

public final 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
Overrides:
destroy in class AbstractConnectionFactory

doCreateConnection

protected Connection doCreateConnection()
Create a Connection. This implementation just delegates to the underlying Rabbit ConnectionFactory. Subclasses typically will decorate the result to provide additional features.

Returns:
the new Connection

toString

public String toString()
Overrides:
toString in class Object

Spring AMQP

Copyright © 2011. All Rights Reserved.