KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > transport > udp > CommandChannelSupport


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.udp;
19
20 import org.apache.activemq.command.Command;
21 import org.apache.activemq.openwire.OpenWireFormat;
22 import org.apache.activemq.transport.reliable.ReplayBuffer;
23 import org.apache.activemq.util.IntSequenceGenerator;
24
25 import java.io.IOException JavaDoc;
26 import java.net.SocketAddress JavaDoc;
27
28 /**
29  *
30  * @version $Revision: 426366 $
31  */

32 public abstract class CommandChannelSupport implements CommandChannel {
33
34     protected OpenWireFormat wireFormat;
35     protected int datagramSize = 4 * 1024;
36     protected SocketAddress JavaDoc targetAddress;
37     protected SocketAddress JavaDoc replayAddress;
38     protected final String JavaDoc name;
39     protected final IntSequenceGenerator sequenceGenerator;
40     protected DatagramHeaderMarshaller headerMarshaller;
41     private ReplayBuffer replayBuffer;
42
43     public CommandChannelSupport(UdpTransport transport, OpenWireFormat wireFormat, int datagramSize, SocketAddress JavaDoc targetAddress,
44             DatagramHeaderMarshaller headerMarshaller) {
45         this.wireFormat = wireFormat;
46         this.datagramSize = datagramSize;
47         this.targetAddress = targetAddress;
48         this.headerMarshaller = headerMarshaller;
49         this.name = transport.toString();
50         this.sequenceGenerator = transport.getSequenceGenerator();
51         this.replayAddress = targetAddress;
52         if (sequenceGenerator == null) {
53             throw new IllegalArgumentException JavaDoc("No sequenceGenerator on the given transport: " + transport);
54         }
55     }
56     
57     public void write(Command command) throws IOException JavaDoc {
58         write(command, targetAddress);
59     }
60
61
62     // Properties
63
// -------------------------------------------------------------------------
64

65     public int getDatagramSize() {
66         return datagramSize;
67     }
68
69     /**
70      * Sets the default size of a datagram on the network.
71      */

72     public void setDatagramSize(int datagramSize) {
73         this.datagramSize = datagramSize;
74     }
75
76     public SocketAddress JavaDoc getTargetAddress() {
77         return targetAddress;
78     }
79
80     public void setTargetAddress(SocketAddress JavaDoc targetAddress) {
81         this.targetAddress = targetAddress;
82     }
83
84     public SocketAddress JavaDoc getReplayAddress() {
85         return replayAddress;
86     }
87
88     public void setReplayAddress(SocketAddress JavaDoc replayAddress) {
89         this.replayAddress = replayAddress;
90     }
91
92     public String JavaDoc toString() {
93         return "CommandChannel#" + name;
94     }
95
96     public DatagramHeaderMarshaller getHeaderMarshaller() {
97         return headerMarshaller;
98     }
99
100     public void setHeaderMarshaller(DatagramHeaderMarshaller headerMarshaller) {
101         this.headerMarshaller = headerMarshaller;
102     }
103
104     public ReplayBuffer getReplayBuffer() {
105         return replayBuffer;
106     }
107
108     public void setReplayBuffer(ReplayBuffer replayBuffer) {
109         this.replayBuffer = replayBuffer;
110     }
111
112 }
113
Popular Tags