KickJava   Java API By Example, From Geeks To Geeks.

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


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

17 package org.apache.activemq.transport.reliable;
18
19 import org.apache.activemq.openwire.OpenWireFormat;
20 import org.apache.activemq.transport.CommandJoiner;
21 import org.apache.activemq.transport.Transport;
22 import org.apache.activemq.transport.udp.ResponseRedirectInterceptor;
23 import org.apache.activemq.transport.udp.UdpTransport;
24 import org.apache.activemq.transport.udp.UdpTransportTest;
25
26 import java.net.SocketAddress JavaDoc;
27 import java.net.URI JavaDoc;
28 import java.util.HashSet JavaDoc;
29 import java.util.Set JavaDoc;
30
31 /**
32  *
33  * @version $Revision: $
34  */

35 public class UnreliableUdpTransportTest extends UdpTransportTest {
36
37     protected DropCommandStrategy dropStrategy = new DropCommandStrategy() {
38         
39         public boolean shouldDropCommand(int commandId, SocketAddress JavaDoc address, boolean redelivery) {
40             if (redelivery) {
41                 return false;
42             }
43             return commandId % 3 == 2;
44         }
45     };
46
47     protected Transport createProducer() throws Exception JavaDoc {
48         log.info("Producer using URI: " + producerURI);
49
50         OpenWireFormat wireFormat = createWireFormat();
51         UnreliableUdpTransport transport = new UnreliableUdpTransport(wireFormat, new URI JavaDoc(producerURI));
52         transport.setDropCommandStrategy(dropStrategy);
53
54         ReliableTransport reliableTransport = new ReliableTransport(transport, transport);
55         Replayer replayer = reliableTransport.getReplayer();
56         reliableTransport.setReplayStrategy(createReplayStrategy(replayer));
57
58         return new CommandJoiner(reliableTransport, wireFormat);
59     }
60
61     protected Transport createConsumer() throws Exception JavaDoc {
62         log.info("Consumer on port: " + consumerPort);
63         OpenWireFormat wireFormat = createWireFormat();
64         UdpTransport transport = new UdpTransport(wireFormat, consumerPort);
65
66         ReliableTransport reliableTransport = new ReliableTransport(transport, transport);
67         Replayer replayer = reliableTransport.getReplayer();
68         reliableTransport.setReplayStrategy(createReplayStrategy(replayer));
69
70         ResponseRedirectInterceptor redirectInterceptor = new ResponseRedirectInterceptor(reliableTransport, transport);
71         return new CommandJoiner(redirectInterceptor, wireFormat);
72     }
73
74     protected ReplayStrategy createReplayStrategy(Replayer replayer) {
75         assertNotNull("Should have a replayer!", replayer);
76         return new DefaultReplayStrategy(1);
77     }
78 }
79
Popular Tags