KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > transport > reliable > ExceptionIfDroppedReplayStrategy


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.transport.reliable;
19
20 import java.io.IOException JavaDoc;
21
22 /**
23  * Throws an exception if packets are dropped causing the transport to be
24  * closed.
25  *
26  * @version $Revision: 426366 $
27  */

28 public class ExceptionIfDroppedReplayStrategy implements ReplayStrategy {
29
30     private int maximumDifference = 5;
31
32     public ExceptionIfDroppedReplayStrategy() {
33     }
34
35     public ExceptionIfDroppedReplayStrategy(int maximumDifference) {
36         this.maximumDifference = maximumDifference;
37     }
38
39     public boolean onDroppedPackets(ReliableTransport transport, int expectedCounter, int actualCounter, int nextAvailableCounter) throws IOException JavaDoc {
40         int difference = actualCounter - expectedCounter;
41         long count = Math.abs(difference);
42         if (count > maximumDifference) {
43             throw new IOException JavaDoc("Packets dropped on: " + transport + " count: " + count + " expected: " + expectedCounter + " but was: " + actualCounter);
44         }
45
46         // lets discard old commands
47
return difference > 0;
48     }
49
50     public void onReceivedPacket(ReliableTransport transport, long expectedCounter) {
51     }
52
53     public int getMaximumDifference() {
54         return maximumDifference;
55     }
56
57     /**
58      * Sets the maximum allowed difference between an expected packet and an
59      * actual packet before an error occurs
60      */

61     public void setMaximumDifference(int maximumDifference) {
62         this.maximumDifference = maximumDifference;
63     }
64
65 }
66
Popular Tags