FailoverNoopSupport.java
01 /*
02  *  Licensed to the Apache Software Foundation (ASF) under one
03  *  or more contributor license agreements.  See the NOTICE file
04  *  distributed with this work for additional information
05  *  regarding copyright ownership.  The ASF licenses this file
06  *  to you under the Apache License, Version 2.0 (the
07  *  "License"); you may not use this file except in compliance
08  *  with the License.  You may obtain a copy of the License at
09  *
10  *    http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing,
13  *  software distributed under the License is distributed on an
14  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  *  KIND, either express or implied.  See the License for the
16  *  specific language governing permissions and limitations
17  *  under the License.
18  *
19  *
20  */
21 
22 package org.apache.qpid.client.failover;
23 
24 import org.apache.qpid.client.AMQConnection;
25 
26 /**
27  * FailoverNoopSupport is a {@link FailoverSupport} implementation that does not really provide any failover support
28  * at all. It wraps a {@link FailoverProtectedOperation} but should that operation throw {@link FailoverException} this
29  * support class simply re-raises that exception as an IllegalStateException. This support wrapper should only be
30  * used where the caller can be certain that the failover protected operation cannot acutally throw a failover exception,
31  * for example, because the caller already holds a lock preventing that condition from arising.
32  *
33  <p><table id="crc"><caption>CRC Card</caption>
34  <tr><th> Responsibilities <th> Collaborations
35  <tr><td> Perform a fail-over protected operation raising providing no handling of fail-over conditions.
36  </table>
37  */
38 public class FailoverNoopSupport<T, E extends Exception> implements FailoverSupport<T, E>
39 {
40     /** The protected operation that is to be retried in the event of fail-over. */
41     FailoverProtectedOperation<T, E> operation;
42 
43     /** The connection on which the fail-over protected operation is to be performed. */
44     AMQConnection connection;
45 
46     /**
47      * Creates an automatic retrying fail-over handler for the specified operation.
48      *
49      @param operation The fail-over protected operation to wrap in this handler.
50      */
51     public FailoverNoopSupport(FailoverProtectedOperation<T, E> operation, AMQConnection con)
52     {
53         this.operation = operation;
54         this.connection = con;
55     }
56 
57     /**
58      * Delegates to another continuation which is to be provided with fail-over handling.
59      *
60      @return The return value from the delegated to continuation.
61      @throws E Any exception that the delegated to continuation may raise.
62      */
63     public T execute() throws E
64     {
65         try
66         {
67             return operation.execute();
68         }
69         catch (FailoverException e)
70         {
71             throw new IllegalStateException("Fail-over interupted no-op failover support. "
72                 "No-op support should only be used where the caller is certain fail-over cannot occur.", e);
73         }
74     }
75 }