001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.catalina.tribes.transport;
019:
020: import java.io.IOException;
021: import java.net.InetAddress;
022: import java.net.UnknownHostException;
023:
024: import org.apache.catalina.tribes.Member;
025:
026: /**
027: * <p>Title: </p>
028: *
029: * <p>Description: </p>
030: *
031: * <p>Company: </p>
032: *
033: * @author not attributable
034: * @version 1.0
035: */
036: public abstract class AbstractSender implements DataSender {
037:
038: private boolean connected = false;
039: private int rxBufSize = 25188;
040: private int txBufSize = 43800;
041: private boolean directBuffer = false;
042: private int keepAliveCount = -1;
043: private int requestCount = 0;
044: private long connectTime;
045: private long keepAliveTime = -1;
046: private long timeout = 3000;
047: private Member destination;
048: private InetAddress address;
049: private int port;
050: private int maxRetryAttempts = 1;//1 resends
051: private int attempt;
052: private boolean tcpNoDelay = true;
053: private boolean soKeepAlive = false;
054: private boolean ooBInline = true;
055: private boolean soReuseAddress = true;
056: private boolean soLingerOn = false;
057: private int soLingerTime = 3;
058: private int soTrafficClass = 0x04 | 0x08 | 0x010;
059: private boolean throwOnFailedAck = true;
060:
061: /**
062: * transfers sender properties from one sender to another
063: * @param from AbstractSender
064: * @param to AbstractSender
065: */
066: public static void transferProperties(AbstractSender from,
067: AbstractSender to) {
068: to.rxBufSize = from.rxBufSize;
069: to.txBufSize = from.txBufSize;
070: to.directBuffer = from.directBuffer;
071: to.keepAliveCount = from.keepAliveCount;
072: to.keepAliveTime = from.keepAliveTime;
073: to.timeout = from.timeout;
074: to.destination = from.destination;
075: to.address = from.address;
076: to.port = from.port;
077: to.maxRetryAttempts = from.maxRetryAttempts;
078: to.tcpNoDelay = from.tcpNoDelay;
079: to.soKeepAlive = from.soKeepAlive;
080: to.ooBInline = from.ooBInline;
081: to.soReuseAddress = from.soReuseAddress;
082: to.soLingerOn = from.soLingerOn;
083: to.soLingerTime = from.soLingerTime;
084: to.soTrafficClass = from.soTrafficClass;
085: to.throwOnFailedAck = from.throwOnFailedAck;
086: }
087:
088: public AbstractSender() {
089:
090: }
091:
092: /**
093: * connect
094: *
095: * @throws IOException
096: * @todo Implement this org.apache.catalina.tribes.transport.DataSender method
097: */
098: public abstract void connect() throws IOException;
099:
100: /**
101: * disconnect
102: *
103: * @todo Implement this org.apache.catalina.tribes.transport.DataSender method
104: */
105: public abstract void disconnect();
106:
107: /**
108: * keepalive
109: *
110: * @return boolean
111: * @todo Implement this org.apache.catalina.tribes.transport.DataSender method
112: */
113: public boolean keepalive() {
114: boolean disconnect = false;
115: if (keepAliveCount >= 0 && requestCount > keepAliveCount)
116: disconnect = true;
117: else if (keepAliveTime >= 0
118: && (System.currentTimeMillis() - connectTime) > keepAliveTime)
119: disconnect = true;
120: if (disconnect)
121: disconnect();
122: return disconnect;
123: }
124:
125: protected void setConnected(boolean connected) {
126: this .connected = connected;
127: }
128:
129: public boolean isConnected() {
130: return connected;
131: }
132:
133: public long getConnectTime() {
134: return connectTime;
135: }
136:
137: public Member getDestination() {
138: return destination;
139: }
140:
141: public int getKeepAliveCount() {
142: return keepAliveCount;
143: }
144:
145: public long getKeepAliveTime() {
146: return keepAliveTime;
147: }
148:
149: public int getRequestCount() {
150: return requestCount;
151: }
152:
153: public int getRxBufSize() {
154: return rxBufSize;
155: }
156:
157: public long getTimeout() {
158: return timeout;
159: }
160:
161: public int getTxBufSize() {
162: return txBufSize;
163: }
164:
165: public InetAddress getAddress() {
166: return address;
167: }
168:
169: public int getPort() {
170: return port;
171: }
172:
173: public int getMaxRetryAttempts() {
174: return maxRetryAttempts;
175: }
176:
177: public void setDirect(boolean direct) {
178: setDirectBuffer(direct);
179: }
180:
181: public void setDirectBuffer(boolean directBuffer) {
182: this .directBuffer = directBuffer;
183: }
184:
185: public boolean getDirect() {
186: return getDirectBuffer();
187: }
188:
189: public boolean getDirectBuffer() {
190: return this .directBuffer;
191: }
192:
193: public int getAttempt() {
194: return attempt;
195: }
196:
197: public boolean getTcpNoDelay() {
198: return tcpNoDelay;
199: }
200:
201: public boolean getSoKeepAlive() {
202: return soKeepAlive;
203: }
204:
205: public boolean getOoBInline() {
206: return ooBInline;
207: }
208:
209: public boolean getSoReuseAddress() {
210: return soReuseAddress;
211: }
212:
213: public boolean getSoLingerOn() {
214: return soLingerOn;
215: }
216:
217: public int getSoLingerTime() {
218: return soLingerTime;
219: }
220:
221: public int getSoTrafficClass() {
222: return soTrafficClass;
223: }
224:
225: public boolean getThrowOnFailedAck() {
226: return throwOnFailedAck;
227: }
228:
229: public void setKeepAliveCount(int keepAliveCount) {
230: this .keepAliveCount = keepAliveCount;
231: }
232:
233: public void setKeepAliveTime(long keepAliveTime) {
234: this .keepAliveTime = keepAliveTime;
235: }
236:
237: public void setRequestCount(int requestCount) {
238: this .requestCount = requestCount;
239: }
240:
241: public void setRxBufSize(int rxBufSize) {
242: this .rxBufSize = rxBufSize;
243: }
244:
245: public void setTimeout(long timeout) {
246: this .timeout = timeout;
247: }
248:
249: public void setTxBufSize(int txBufSize) {
250: this .txBufSize = txBufSize;
251: }
252:
253: public void setConnectTime(long connectTime) {
254: this .connectTime = connectTime;
255: }
256:
257: public void setMaxRetryAttempts(int maxRetryAttempts) {
258: this .maxRetryAttempts = maxRetryAttempts;
259: }
260:
261: public void setAttempt(int attempt) {
262: this .attempt = attempt;
263: }
264:
265: public void setTcpNoDelay(boolean tcpNoDelay) {
266: this .tcpNoDelay = tcpNoDelay;
267: }
268:
269: public void setSoKeepAlive(boolean soKeepAlive) {
270: this .soKeepAlive = soKeepAlive;
271: }
272:
273: public void setOoBInline(boolean ooBInline) {
274: this .ooBInline = ooBInline;
275: }
276:
277: public void setSoReuseAddress(boolean soReuseAddress) {
278: this .soReuseAddress = soReuseAddress;
279: }
280:
281: public void setSoLingerOn(boolean soLingerOn) {
282: this .soLingerOn = soLingerOn;
283: }
284:
285: public void setSoLingerTime(int soLingerTime) {
286: this .soLingerTime = soLingerTime;
287: }
288:
289: public void setSoTrafficClass(int soTrafficClass) {
290: this .soTrafficClass = soTrafficClass;
291: }
292:
293: public void setThrowOnFailedAck(boolean throwOnFailedAck) {
294: this .throwOnFailedAck = throwOnFailedAck;
295: }
296:
297: public void setDestination(Member destination)
298: throws UnknownHostException {
299: this .destination = destination;
300: this .address = InetAddress.getByAddress(destination.getHost());
301: this .port = destination.getPort();
302:
303: }
304:
305: public void setPort(int port) {
306: this .port = port;
307: }
308:
309: public void setAddress(InetAddress address) {
310: this.address = address;
311: }
312:
313: }
|