2
* Copyright 1999,2006 The Apache Software Foundation.
4
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5
* use this file except in compliance with the License. You may obtain a copy of
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
* License for the specific language governing permissions and limitations under
17
package org.apache.catalina.tribes.transport;
19
import java.io.IOException;
20
import java.net.InetAddress;
21
import java.net.UnknownHostException;
23
import org.apache.catalina.tribes.Member;
28
* <p>Description: </p>
30
* <p>Copyright: Copyright (c) 2005</p>
34
* @author not attributable
37
public abstract class AbstractSender implements DataSender {
39
private boolean connected = false;
40
private int rxBufSize = 25188;
41
private int txBufSize = 43800;
42
private boolean directBuffer = false;
43
private int keepAliveCount = -1;
44
private int requestCount = 0;
45
private long connectTime;
46
private long keepAliveTime = -1;
47
private long timeout = 15000;
48
private Member destination;
49
private InetAddress address;
51
private int maxRetryAttempts = 2;//zero resends
53
private boolean tcpNoDelay = true;
54
private boolean soKeepAlive = false;
55
private boolean ooBInline = true;
56
private boolean soReuseAddress = true;
57
private boolean soLingerOn = true;
58
private int soLingerTime = 3;
59
private int soTrafficClass = 0x04 | 0x08 | 0x010;
60
public AbstractSender() {
64
public AbstractSender(Member destination) throws UnknownHostException {
65
this.destination = destination;
66
this.address = InetAddress.getByAddress(destination.getHost());
67
this.port = destination.getPort();
70
public AbstractSender(Member destination, int rxBufSize, int txBufSize) throws UnknownHostException {
72
this.rxBufSize = rxBufSize;
73
this.txBufSize = txBufSize;
80
* @todo Implement this org.apache.catalina.tribes.transport.DataSender method
82
public abstract void connect() throws IOException;
87
* @todo Implement this org.apache.catalina.tribes.transport.DataSender method
89
public abstract void disconnect();
95
* @todo Implement this org.apache.catalina.tribes.transport.DataSender method
97
public boolean keepalive() {
98
boolean disconnect = false;
99
if ( keepAliveCount >= 0 && requestCount>keepAliveCount ) disconnect = true;
100
else if ( keepAliveTime >= 0 && keepAliveTime> (System.currentTimeMillis()-connectTime) ) disconnect = true;
101
if ( disconnect ) disconnect();
106
protected void setConnected(boolean connected){
107
this.connected = connected;
110
public boolean isConnected() {
114
public long getConnectTime() {
118
public Member getDestination() {
123
public int getKeepAliveCount() {
124
return keepAliveCount;
127
public long getKeepAliveTime() {
128
return keepAliveTime;
131
public int getRequestCount() {
135
public int getRxBufSize() {
139
public long getTimeout() {
143
public int getTxBufSize() {
147
public InetAddress getAddress() {
151
public int getPort() {
155
public int getMaxRetryAttempts() {
156
return maxRetryAttempts;
159
public void setDirectBuffer(boolean directBuffer) {
160
this.directBuffer = directBuffer;
163
public boolean getDirectBuffer() {
164
return this.directBuffer;
167
public int getAttempt() {
171
public boolean getTcpNoDelay() {
175
public boolean getSoKeepAlive() {
179
public boolean getOoBInline() {
183
public boolean getSoReuseAddress() {
184
return soReuseAddress;
187
public boolean getSoLingerOn() {
191
public int getSoLingerTime() {
195
public int getSoTrafficClass() {
196
return soTrafficClass;
199
public void setKeepAliveCount(int keepAliveCount) {
200
this.keepAliveCount = keepAliveCount;
203
public void setKeepAliveTime(long keepAliveTime) {
204
this.keepAliveTime = keepAliveTime;
207
public void setRequestCount(int requestCount) {
208
this.requestCount = requestCount;
211
public void setRxBufSize(int rxBufSize) {
212
this.rxBufSize = rxBufSize;
215
public void setTimeout(long timeout) {
216
this.timeout = timeout;
219
public void setTxBufSize(int txBufSize) {
220
this.txBufSize = txBufSize;
223
public void setConnectTime(long connectTime) {
224
this.connectTime = connectTime;
227
public void setMaxRetryAttempts(int maxRetryAttempts) {
228
this.maxRetryAttempts = maxRetryAttempts;
231
public void setAttempt(int attempt) {
232
this.attempt = attempt;
235
public void setTcpNoDelay(boolean tcpNoDelay) {
236
this.tcpNoDelay = tcpNoDelay;
239
public void setSoKeepAlive(boolean soKeepAlive) {
240
this.soKeepAlive = soKeepAlive;
243
public void setOoBInline(boolean ooBInline) {
244
this.ooBInline = ooBInline;
247
public void setSoReuseAddress(boolean soReuseAddress) {
248
this.soReuseAddress = soReuseAddress;
251
public void setSoLingerOn(boolean soLingerOn) {
252
this.soLingerOn = soLingerOn;
255
public void setSoLingerTime(int soLingerTime) {
256
this.soLingerTime = soLingerTime;
259
public void setSoTrafficClass(int soTrafficClass) {
260
this.soTrafficClass = soTrafficClass;