org.apache.qpid.client.failover
Class FailoverHandler

java.lang.Object
  extended by org.apache.qpid.client.failover.FailoverHandler
All Implemented Interfaces:
Runnable

public class FailoverHandler
extends Object
implements Runnable

FailoverHandler is a continuation that performs the failover procedure on a protocol session. As described in the class level comment for AMQProtocolHandler, a protocol connection can span many physical transport connections, failing over to a new connection if the transport connection fails. The procedure to establish a new connection is expressed as a continuation, in order that it may be run in a seperate thread to the i/o thread that detected the failure and is used to handle the communication to establish a new connection.

The reason this needs to be a separate thread is because this work cannot be done inside the i/o processor thread. The significant task is the connection setup which involves a protocol exchange until a particular state is achieved. This procedure waits until the state is achieved which would prevent the i/o thread doing the work it needs to do to achieve the new state.

The failover procedure does the following:

  1. Sets the failing over condition to true.
  2. Creates a FailoverException and gets the protocol connection handler to propagate this event to all interested parties.
  3. Takes the failover mutex on the protocol connection handler.
  4. Abandons the fail over if any of the interested parties vetoes it. The mutex is released and the condition reset.
  5. Creates a new AMQStateManager and re-established the connection through it.
  6. Informs the AMQConnection if the connection cannot be re-established.
  7. Recreates all sessions from the old connection to the new.
  8. Resets the failing over condition and releases the mutex.

CRC Card
Responsibilities Collaborations
Update fail-over state AMQProtocolHandler

Todo:
The failover latch and mutex are used like a lock and condition. If the retrotranlator supports lock/condition then could change over to using them. 1.4 support still needed., If the condition is set to null on a vetoes fail-over and there are already other threads waiting on the condition, they will never be released. It might be an idea to reset the condition in a finally block., Creates a AMQDisconnectedException and passes it to the AMQConnection. No need to use an exception-as-argument here, could just as easily call a specific method for this purpose on AMQConnection., Creates a FailoverException and propagates it to the MethodHandlers. No need to use an exception-as-argument here, could just as easily call a specific method for this purpose on AMQMethodListener.

Constructor Summary
FailoverHandler(AMQProtocolHandler amqProtocolHandler)
          Creates a failover handler on a protocol session, for a particular MINA session (network connection).
 
Method Summary
 void run()
          Performs the failover procedure.
 void setHost(String host)
          Sets the host name to fail over to.
 void setPort(int port)
          Sets the port to fail over to.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FailoverHandler

public FailoverHandler(AMQProtocolHandler amqProtocolHandler)
Creates a failover handler on a protocol session, for a particular MINA session (network connection).

Parameters:
amqProtocolHandler - The protocol handler that spans the failover.
Method Detail

run

public void run()
Performs the failover procedure. See the class level comment, FailoverHandler, for a description of the failover procedure.

Specified by:
run in interface Runnable

setHost

public void setHost(String host)
Sets the host name to fail over to. This is optional and if not set a reconnect to the previous host is tried.

Parameters:
host - The host name to fail over to.

setPort

public void setPort(int port)
Sets the port to fail over to.

Parameters:
port - The port to fail over to.


Licensed to the Apache Software Foundation