1 10 11 package org.mule.providers.tcp; 12 13 import org.mule.config.i18n.Message; 14 import org.mule.providers.AbstractServiceEnabledConnector; 15 import org.mule.providers.tcp.protocols.DefaultProtocol; 16 import org.mule.umo.lifecycle.InitialisationException; 17 import org.mule.util.ClassUtils; 18 19 26 public class TcpConnector extends AbstractServiceEnabledConnector 27 { 28 public static final int DEFAULT_SOCKET_TIMEOUT = INT_VALUE_NOT_SET; 29 30 public static final int DEFAULT_BUFFER_SIZE = INT_VALUE_NOT_SET; 31 32 public static final int DEFAULT_BACKLOG = INT_VALUE_NOT_SET; 33 34 protected int sendTimeout = DEFAULT_SOCKET_TIMEOUT; 35 36 protected int receiveTimeout = DEFAULT_SOCKET_TIMEOUT; 37 38 protected int bufferSize = DEFAULT_BUFFER_SIZE; 39 40 protected int backlog = DEFAULT_BACKLOG; 41 42 protected String tcpProtocolClassName = DefaultProtocol.class.getName(); 43 44 protected TcpProtocol tcpProtocol; 45 46 protected boolean keepSendSocketOpen = false; 47 48 protected boolean keepAlive = false; 49 50 public boolean isKeepSendSocketOpen() 51 { 52 return keepSendSocketOpen; 53 } 54 55 public void doInitialise() throws InitialisationException 56 { 57 super.doInitialise(); 58 if (tcpProtocol == null) 59 { 60 try 61 { 62 tcpProtocol = (TcpProtocol)ClassUtils.instanciateClass(tcpProtocolClassName, null); 63 } 64 catch (Exception e) 65 { 66 throw new InitialisationException(new Message("tcp", 3), e); 67 } 68 } 69 } 70 71 public String getProtocol() 72 { 73 return "TCP"; 74 } 75 76 79 public void setTimeout(int timeout) 80 { 81 setSendTimeout(timeout); 82 setReceiveTimeout(timeout); 83 } 84 85 public int getSendTimeout() 86 { 87 return this.sendTimeout; 88 } 89 90 public void setSendTimeout(int timeout) 91 { 92 if (timeout < 0) 93 { 94 timeout = DEFAULT_SOCKET_TIMEOUT; 95 } 96 this.sendTimeout = timeout; 97 } 98 99 public int getReceiveTimeout() 103 { 104 return receiveTimeout; 105 } 106 107 public void setReceiveTimeout(int timeout) 108 { 109 if (timeout < 0) 110 { 111 timeout = DEFAULT_SOCKET_TIMEOUT; 112 } 113 this.receiveTimeout = timeout; 114 } 115 116 public int getBufferSize() 117 { 118 return bufferSize; 119 } 120 121 public void setBufferSize(int bufferSize) 122 { 123 if (bufferSize < 1) 124 { 125 bufferSize = DEFAULT_BUFFER_SIZE; 126 } 127 this.bufferSize = bufferSize; 128 } 129 130 public int getBacklog() 131 { 132 return backlog; 133 } 134 135 public void setBacklog(int backlog) 136 { 137 this.backlog = backlog; 138 } 139 140 public TcpProtocol getTcpProtocol() 141 { 142 return tcpProtocol; 143 } 144 145 public void setTcpProtocol(TcpProtocol tcpProtocol) 146 { 147 this.tcpProtocol = tcpProtocol; 148 } 149 150 public String getTcpProtocolClassName() 151 { 152 return tcpProtocolClassName; 153 } 154 155 public void setTcpProtocolClassName(String protocolClassName) 156 { 157 this.tcpProtocolClassName = protocolClassName; 158 } 159 160 public boolean isRemoteSyncEnabled() 161 { 162 return true; 163 } 164 165 public boolean isKeepAlive() 166 { 167 return keepAlive; 168 } 169 170 public void setKeepAlive(boolean keepAlive) 171 { 172 this.keepAlive = keepAlive; 173 } 174 } 175 | Popular Tags |