Author: ritchiem Date: Fri Mar 27 10:38:41 2009 New Revision: 759097 URL: http://svn.apache.org/viewvc?rev=759097&view=rev Log: QPID-1778 : Add NoFailover FailoverMethod that blocks that still allows connection retry but only on the initial connection. Failover will not be attempted after an established connection is lost. Updated FailoverMethodTest to test this behaviour.
Added: qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jms/failover/NoFailover.java Modified: qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jms/FailoverPolicy.java qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jms/failover/FailoverMethod.java qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jms/failover/FailoverSingleServer.java qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/failover/FailoverMethodTest.java Modified: qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jms/FailoverPolicy.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jms/FailoverPolicy.java?rev=759097&r1=759096&r2=759097&view=diff ============================================================================== --- qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jms/FailoverPolicy.java (original) +++ qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jms/FailoverPolicy.java Fri Mar 27 10:38:41 2009 @@ -25,6 +25,7 @@ import org.apache.qpid.jms.failover.FailoverMethod; import org.apache.qpid.jms.failover.FailoverRoundRobinServers; import org.apache.qpid.jms.failover.FailoverSingleServer; +import org.apache.qpid.jms.failover.NoFailover; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -94,6 +95,10 @@ { method = new FailoverExchangeMethod(connectionDetails, conn); } + else if (failoverMethod.equals(FailoverMethod.NO_FAILOVER)) + { + method = new NoFailover(connectionDetails); + } else { try Modified: qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jms/failover/FailoverMethod.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jms/failover/FailoverMethod.java?rev=759097&r1=759096&r2=759097&view=diff ============================================================================== --- qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jms/failover/FailoverMethod.java (original) +++ qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jms/failover/FailoverMethod.java Fri Mar 27 10:38:41 2009 @@ -29,6 +29,8 @@ public static final String ROUND_ROBIN = "roundrobin"; public static final String FAILOVER_EXCHANGE= "failover_exchange"; public static final String RANDOM = "random"; + public static final String NO_FAILOVER = "nofailover"; + /** * Reset the Failover to initial conditions */ Modified: qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jms/failover/FailoverSingleServer.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jms/failover/FailoverSingleServer.java?rev=759097&r1=759096&r2=759097&view=diff ============================================================================== --- qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jms/failover/FailoverSingleServer.java (original) +++ qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jms/failover/FailoverSingleServer.java Fri Mar 27 10:38:41 2009 @@ -36,10 +36,10 @@ private BrokerDetails _brokerDetail; /** The number of times to retry connecting to the sever */ - private int _retries; + protected int _retries; /** The current number of attempts made to the server */ - private int _currentRetries; + protected int _currentRetries; public FailoverSingleServer(ConnectionURL connectionDetails) @@ -157,7 +157,7 @@ public String toString() { - return "SingleServer:\n" + + return methodName()+":\n" + "Max Retries:" + _retries + "\nCurrent Retry:" + _currentRetries + "\n" + _brokerDetail + "\n"; Added: qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jms/failover/NoFailover.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jms/failover/NoFailover.java?rev=759097&view=auto ============================================================================== --- qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jms/failover/NoFailover.java (added) +++ qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/jms/failover/NoFailover.java Fri Mar 27 10:38:41 2009 @@ -0,0 +1,62 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.jms.failover; + +import org.apache.qpid.jms.BrokerDetails; +import org.apache.qpid.jms.ConnectionURL; + +/** + * Extend the Single Server Model to gain retry functionality but once connected do not attempt to failover. + */ +public class NoFailover extends FailoverSingleServer +{ + private boolean _connected = false; + + public NoFailover(BrokerDetails brokerDetail) + { + super(brokerDetail); + } + + public NoFailover(ConnectionURL connectionDetails) + { + super(connectionDetails); + } + + @Override + public void attainedConnection() + { + _connected=true; + _currentRetries = _retries; + } + + @Override + public String methodName() + { + return "NoFailover"; + } + + @Override + public String toString() + { + return super.toString() + (_connected ? "Connection attained." : "Never connected.") + "\n"; + } + +} Modified: qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/failover/FailoverMethodTest.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/failover/FailoverMethodTest.java?rev=759097&r1=759096&r2=759097&view=diff ============================================================================== --- qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/failover/FailoverMethodTest.java (original) +++ qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/failover/FailoverMethodTest.java Fri Mar 27 10:38:41 2009 @@ -28,8 +28,6 @@ import org.apache.qpid.client.transport.TransportConnection; import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException; import org.apache.qpid.url.URLSyntaxException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import javax.jms.ExceptionListener; import javax.jms.JMSException; @@ -151,4 +149,78 @@ _failoverComplete.countDown(); } } + + public void testNoFailover() throws URLSyntaxException, AMQVMBrokerCreationException, + InterruptedException, JMSException + { + String connectionString = "amqp://guest:guest@/test?brokerlist='vm://:1?connectdelay='500',retries='3'',failover='nofailover'"; + + AMQConnectionURL url = new AMQConnectionURL(connectionString); + + try + { + //Kill initial broker + TransportConnection.killAllVMBrokers(); + + //Create a thread to start the broker asynchronously + Thread brokerStart = new Thread(new Runnable() + { + public void run() + { + try + { + //Wait before starting broker + // The wait should allow atleast 1 retries to fail before broker is ready + Thread.sleep(750); + TransportConnection.createVMBroker(1); + } + catch (Exception e) + { + System.err.println(e.getMessage()); + e.printStackTrace(); + } + } + }); + + + brokerStart.start(); + long start = System.currentTimeMillis(); + + + //Start the connection so it will use the retries + AMQConnection connection = new AMQConnection(url, null); + + long end = System.currentTimeMillis(); + + long duration = (end - start); + + // Check that we actually had a delay had a delay in connection + assertTrue("Initial connection should be longer than 1 delay : 500 <:(" + duration + ")", duration > 500); + + + connection.setExceptionListener(this); + + //Ensure we collect the brokerStart thread + brokerStart.join(); + + start = System.currentTimeMillis(); + + //Kill connection + TransportConnection.killAllVMBrokers(); + + _failoverComplete.await(); + + end = System.currentTimeMillis(); + + duration = (end - start); + + // Notification of the connection failure should be very quick as we are denying the ability to failover. + assertTrue("Notification of the connection failure took was : 100 >:(" + duration + ")", duration < 100); + } + catch (AMQException e) + { + fail(e.getMessage()); + } + } + } --------------------------------------------------------------------- Apache Qpid - AMQP Messaging Implementation Project: http://qpid.apache.org Use/Interact: mailto:commits-subscr...@qpid.apache.org