List of usage examples for java.net Socket setReceiveBufferSize
public synchronized void setReceiveBufferSize(int size) throws SocketException
From source file:com.mirth.connect.connectors.tcp.TcpDispatcher.java
@Override public Response send(ConnectorProperties connectorProperties, ConnectorMessage message) { TcpDispatcherProperties tcpDispatcherProperties = (TcpDispatcherProperties) connectorProperties; Status responseStatus = Status.QUEUED; String responseData = null;// w ww. ja v a2s. com String responseStatusMessage = null; String responseError = null; boolean validateResponse = false; long dispatcherId = getDispatcherId(); String socketKey = dispatcherId + tcpDispatcherProperties.getRemoteAddress() + tcpDispatcherProperties.getRemotePort(); if (tcpDispatcherProperties.isOverrideLocalBinding()) { socketKey += tcpDispatcherProperties.getLocalAddress() + tcpDispatcherProperties.getLocalPort(); } Socket socket = null; Thread timeoutThread = null; try { // Do some validation first to avoid unnecessarily creating sockets if (StringUtils.isBlank(tcpDispatcherProperties.getRemoteAddress())) { throw new Exception("Remote address is blank."); } else if (NumberUtils.toInt(tcpDispatcherProperties.getRemotePort()) <= 0) { throw new Exception("Remote port is invalid."); } socket = connectedSockets.get(socketKey); timeoutThread = timeoutThreads.get(socketKey); // If keep connection open is true, then interrupt the thread so it won't close the socket if (tcpDispatcherProperties.isKeepConnectionOpen() && timeoutThread != null) { disposeThreadQuietly(socketKey); } // Initialize a new socket if our current one is invalid, the remote side has closed, or keep connection open is false if (!tcpDispatcherProperties.isKeepConnectionOpen() || socket == null || socket.isClosed() || (tcpDispatcherProperties.isCheckRemoteHost() && socket instanceof StateAwareSocketInterface && ((StateAwareSocketInterface) socket).remoteSideHasClosed())) { closeSocketQuietly(socketKey); logger.debug("Creating new socket (" + connectorProperties.getName() + " \"" + getDestinationName() + "\" on channel " + getChannelId() + ")."); String info = "Trying to connect on " + tcpDispatcherProperties.getRemoteAddress() + ":" + tcpDispatcherProperties.getRemotePort() + "..."; eventController.dispatchEvent(new ConnectionStatusEvent(getChannelId(), getMetaDataId(), getDestinationName(), ConnectionStatusEventType.CONNECTING, info)); if (tcpDispatcherProperties.isOverrideLocalBinding()) { socket = SocketUtil.createSocket(configuration, tcpDispatcherProperties.getLocalAddress(), NumberUtils.toInt(tcpDispatcherProperties.getLocalPort())); } else { socket = SocketUtil.createSocket(configuration); } ThreadUtils.checkInterruptedStatus(); connectedSockets.put(socketKey, socket); SocketUtil.connectSocket(socket, tcpDispatcherProperties.getRemoteAddress(), NumberUtils.toInt(tcpDispatcherProperties.getRemotePort()), responseTimeout); socket.setReuseAddress(true); socket.setReceiveBufferSize(bufferSize); socket.setSendBufferSize(bufferSize); socket.setSoTimeout(responseTimeout); socket.setKeepAlive(tcpDispatcherProperties.isKeepConnectionOpen()); eventController.dispatchEvent(new ConnectorCountEvent(getChannelId(), getMetaDataId(), getDestinationName(), ConnectionStatusEventType.CONNECTED, SocketUtil.getLocalAddress(socket) + " -> " + SocketUtil.getInetAddress(socket), true)); } ThreadUtils.checkInterruptedStatus(); // Send the message eventController.dispatchEvent(new ConnectionStatusEvent(getChannelId(), getMetaDataId(), getDestinationName(), ConnectionStatusEventType.SENDING, SocketUtil.getLocalAddress(socket) + " -> " + SocketUtil.getInetAddress(socket))); BufferedOutputStream bos = new BufferedOutputStream(socket.getOutputStream(), bufferSize); BatchStreamReader batchStreamReader = new DefaultBatchStreamReader(socket.getInputStream()); StreamHandler streamHandler = transmissionModeProvider.getStreamHandler(socket.getInputStream(), bos, batchStreamReader, tcpDispatcherProperties.getTransmissionModeProperties()); streamHandler.write(getTemplateBytes(tcpDispatcherProperties, message)); bos.flush(); if (!tcpDispatcherProperties.isIgnoreResponse()) { ThreadUtils.checkInterruptedStatus(); // Attempt to get the response from the remote endpoint try { String info = "Waiting for response from " + SocketUtil.getInetAddress(socket) + " (Timeout: " + tcpDispatcherProperties.getResponseTimeout() + " ms)... "; eventController.dispatchEvent(new ConnectionStatusEvent(getChannelId(), getMetaDataId(), getDestinationName(), ConnectionStatusEventType.WAITING_FOR_RESPONSE, info)); byte[] responseBytes = streamHandler.read(); if (responseBytes != null) { responseData = new String(responseBytes, CharsetUtils.getEncoding(tcpDispatcherProperties.getCharsetEncoding())); responseStatusMessage = "Message successfully sent."; } else { responseStatusMessage = "Message successfully sent, but no response received."; } streamHandler.commit(true); responseStatus = Status.SENT; // We only want to validate the response if we were able to retrieve it successfully validateResponse = tcpDispatcherProperties.getDestinationConnectorProperties() .isValidateResponse(); } catch (IOException e) { // An exception occurred while retrieving the response if (e instanceof SocketTimeoutException || e.getCause() != null && e.getCause() instanceof SocketTimeoutException) { responseStatusMessage = "Timeout waiting for response"; if (!tcpDispatcherProperties.isQueueOnResponseTimeout()) { responseStatus = Status.ERROR; } } else { responseStatusMessage = "Error receiving response"; } responseError = ErrorMessageBuilder.buildErrorMessage(connectorProperties.getName(), responseStatusMessage + ": " + e.getMessage(), e); logger.warn(responseStatusMessage + " (" + connectorProperties.getName() + " \"" + getDestinationName() + "\" on channel " + getChannelId() + ").", e); eventController.dispatchEvent(new ErrorEvent(getChannelId(), getMetaDataId(), message.getMessageId(), ErrorEventType.DESTINATION_CONNECTOR, getDestinationName(), connectorProperties.getName(), responseStatusMessage + ".", e)); eventController.dispatchEvent(new ConnectionStatusEvent(getChannelId(), getMetaDataId(), getDestinationName(), ConnectionStatusEventType.FAILURE, responseStatusMessage + " from " + SocketUtil.getInetAddress(socket))); closeSocketQuietly(socketKey); } } else { try { // MIRTH-2980: Since we're ignoring responses, flush out the socket's input stream so it doesn't continually grow socket.getInputStream().skip(socket.getInputStream().available()); } catch (IOException e) { logger.warn("Error flushing socket input stream.", e); } // We're ignoring the response, so always return a successful response responseStatus = Status.SENT; responseStatusMessage = "Message successfully sent."; } if (tcpDispatcherProperties.isKeepConnectionOpen() && (getCurrentState() == DeployedState.STARTED || getCurrentState() == DeployedState.STARTING)) { if (sendTimeout > 0) { // Close the connection after the send timeout has been reached startThread(socketKey); } } else { // If keep connection open is false, then close the socket right now closeSocketQuietly(socketKey); } } catch (Throwable t) { disposeThreadQuietly(socketKey); closeSocketQuietly(socketKey); String monitorMessage = "Error sending message (" + SocketUtil.getLocalAddress(socket) + " -> " + SocketUtil.getInetAddress(socket) + "): " + t.getMessage(); eventController.dispatchEvent(new ConnectionStatusEvent(getChannelId(), getMetaDataId(), getDestinationName(), ConnectionStatusEventType.FAILURE, monitorMessage)); // If an exception occurred then close the socket, even if keep connection open is true responseStatusMessage = t.getClass().getSimpleName() + ": " + t.getMessage(); responseError = ErrorMessageBuilder.buildErrorMessage(connectorProperties.getName(), t.getMessage(), t); String logMessage = "Error sending message via TCP (" + connectorProperties.getName() + " \"" + getDestinationName() + "\" on channel " + getChannelId() + ")."; if (t instanceof InterruptedException) { Thread.currentThread().interrupt(); } else if (t instanceof ConnectException || t.getCause() != null && t.getCause() instanceof ConnectException) { if (isQueueEnabled()) { logger.warn(logMessage, t); } else { logger.error(logMessage, t); } } else { logger.debug(logMessage, t); } eventController.dispatchEvent(new ErrorEvent(getChannelId(), getMetaDataId(), message.getMessageId(), ErrorEventType.DESTINATION_CONNECTOR, getDestinationName(), connectorProperties.getName(), "Error sending message via TCP.", t)); } finally { eventController.dispatchEvent(new ConnectorCountEvent(getChannelId(), getMetaDataId(), getDestinationName(), ConnectionStatusEventType.IDLE, SocketUtil.getLocalAddress(socket) + " -> " + SocketUtil.getInetAddress(socket), (Boolean) null)); } return new Response(responseStatus, responseData, responseStatusMessage, responseError, validateResponse); }
From source file:com.atomicleopard.thundr.ftp.commons.FTPClient.java
/** * Establishes a data connection with the FTP server, returning * a Socket for the connection if successful. If a restart * offset has been set with {@link #setRestartOffset(long)}, * a REST command is issued to the server with the offset as * an argument before establishing the data connection. Active * mode connections also cause a local PORT command to be issued. * <p>//w w w . ja v a 2 s . c o m * @param command The text representation of the FTP command to send. * @param arg The arguments to the FTP command. If this parameter is * set to null, then the command is sent with no argument. * @return A Socket corresponding to the established data connection. * Null is returned if an FTP protocol error is reported at * any point during the establishment and initialization of * the connection. * @exception IOException If an I/O error occurs while either sending a * command to the server or receiving a reply from the server. * @since 3.1 */ protected Socket _openDataConnection_(String command, String arg) throws IOException { if (__dataConnectionMode != ACTIVE_LOCAL_DATA_CONNECTION_MODE && __dataConnectionMode != PASSIVE_LOCAL_DATA_CONNECTION_MODE) { return null; } final boolean isInet6Address = getRemoteAddress() instanceof Inet6Address; Socket socket; if (__dataConnectionMode == ACTIVE_LOCAL_DATA_CONNECTION_MODE) { // if no activePortRange was set (correctly) -> getActivePort() = 0 // -> new ServerSocket(0) -> bind to any free local port ServerSocket server = _serverSocketFactory_.createServerSocket(getActivePort(), 1, getHostAddress()); try { // Try EPRT only if remote server is over IPv6, if not use PORT, // because EPRT has no advantage over PORT on IPv4. // It could even have the disadvantage, // that EPRT will make the data connection fail, because // today's intelligent NAT Firewalls are able to // substitute IP addresses in the PORT command, // but might not be able to recognize the EPRT command. if (isInet6Address) { if (!FTPReply.isPositiveCompletion(eprt(getReportHostAddress(), server.getLocalPort()))) { return null; } } else { if (!FTPReply.isPositiveCompletion(port(getReportHostAddress(), server.getLocalPort()))) { return null; } } if ((__restartOffset > 0) && !restart(__restartOffset)) { return null; } if (!FTPReply.isPositivePreliminary(sendCommand(command, arg))) { return null; } // For now, let's just use the data timeout value for waiting for // the data connection. It may be desirable to let this be a // separately configurable value. In any case, we really want // to allow preventing the accept from blocking indefinitely. if (__dataTimeout >= 0) { server.setSoTimeout(__dataTimeout); } socket = server.accept(); // Ensure the timeout is set before any commands are issued on the new socket if (__dataTimeout >= 0) { socket.setSoTimeout(__dataTimeout); } if (__receiveDataSocketBufferSize > 0) { socket.setReceiveBufferSize(__receiveDataSocketBufferSize); } if (__sendDataSocketBufferSize > 0) { socket.setSendBufferSize(__sendDataSocketBufferSize); } } finally { server.close(); } } else { // We must be in PASSIVE_LOCAL_DATA_CONNECTION_MODE // Try EPSV command first on IPv6 - and IPv4 if enabled. // When using IPv4 with NAT it has the advantage // to work with more rare configurations. // E.g. if FTP server has a static PASV address (external network) // and the client is coming from another internal network. // In that case the data connection after PASV command would fail, // while EPSV would make the client succeed by taking just the port. boolean attemptEPSV = isUseEPSVwithIPv4() || isInet6Address; if (attemptEPSV && epsv() == FTPReply.ENTERING_EPSV_MODE) { _parseExtendedPassiveModeReply(_replyLines.get(0)); } else { if (isInet6Address) { return null; // Must use EPSV for IPV6 } // If EPSV failed on IPV4, revert to PASV if (pasv() != FTPReply.ENTERING_PASSIVE_MODE) { return null; } _parsePassiveModeReply(_replyLines.get(0)); } socket = _socketFactory_.createSocket(); if (__receiveDataSocketBufferSize > 0) { socket.setReceiveBufferSize(__receiveDataSocketBufferSize); } if (__sendDataSocketBufferSize > 0) { socket.setSendBufferSize(__sendDataSocketBufferSize); } if (__passiveLocalHost != null) { socket.bind(new InetSocketAddress(__passiveLocalHost, 0)); } // For now, let's just use the data timeout value for waiting for // the data connection. It may be desirable to let this be a // separately configurable value. In any case, we really want // to allow preventing the accept from blocking indefinitely. if (__dataTimeout >= 0) { socket.setSoTimeout(__dataTimeout); } socket.connect(new InetSocketAddress(__passiveHost, __passivePort), connectTimeout); if ((__restartOffset > 0) && !restart(__restartOffset)) { socket.close(); return null; } if (!FTPReply.isPositivePreliminary(sendCommand(command, arg))) { socket.close(); return null; } } if (__remoteVerificationEnabled && !verifyRemote(socket)) { socket.close(); throw new IOException("Host attempting data connection " + socket.getInetAddress().getHostAddress() + " is not same as server " + getRemoteAddress().getHostAddress()); } return socket; }
From source file:org.apache.geode.internal.net.SocketCreator.java
/** * Return a client socket, timing out if unable to connect and timeout > 0 (millis). The parameter * <i>timeout</i> is ignored if SSL is being used, as there is no timeout argument in the ssl * socket factory/*ww w.j a va 2 s .c o m*/ */ public Socket connect(InetAddress inetadd, int port, int timeout, ConnectionWatcher optionalWatcher, boolean clientSide, int socketBufferSize, boolean sslConnection) throws IOException { Socket socket = null; SocketAddress sockaddr = new InetSocketAddress(inetadd, port); printConfig(); try { if (sslConnection) { if (this.sslContext == null) { throw new GemFireConfigException("SSL not configured correctly, Please look at previous error"); } SocketFactory sf = this.sslContext.getSocketFactory(); socket = sf.createSocket(); // Optionally enable SO_KEEPALIVE in the OS network protocol. socket.setKeepAlive(ENABLE_TCP_KEEP_ALIVE); // If necessary, set the receive buffer size before connecting the // socket so that large buffers will be allocated on accepted sockets // (see java.net.Socket.setReceiverBufferSize javadocs for details) if (socketBufferSize != -1) { socket.setReceiveBufferSize(socketBufferSize); } if (optionalWatcher != null) { optionalWatcher.beforeConnect(socket); } socket.connect(sockaddr, Math.max(timeout, 0)); configureClientSSLSocket(socket, timeout); return socket; } else { if (clientSide && this.clientSocketFactory != null) { socket = this.clientSocketFactory.createSocket(inetadd, port); } else { socket = new Socket(); // Optionally enable SO_KEEPALIVE in the OS network protocol. socket.setKeepAlive(ENABLE_TCP_KEEP_ALIVE); // If necessary, set the receive buffer size before connecting the // socket so that large buffers will be allocated on accepted sockets // (see java.net.Socket.setReceiverBufferSize javadocs for details) if (socketBufferSize != -1) { socket.setReceiveBufferSize(socketBufferSize); } if (optionalWatcher != null) { optionalWatcher.beforeConnect(socket); } socket.connect(sockaddr, Math.max(timeout, 0)); } return socket; } } finally { if (optionalWatcher != null) { optionalWatcher.afterConnect(socket); } } }
From source file:org.archive.wayback.resourcestore.locationdb.FileProxyServlet.java
private DataSource locationToDataSource(String location, long offset) throws IOException { DataSource ds = null;/*from ww w. j a v a2 s .c om*/ if (location.startsWith("http://")) { URL url = new URL(location); String hostname = url.getHost(); int port = url.getPort(); if (port == -1) { port = 80; } byte GET[] = "GET".getBytes(); byte HTTP11[] = "HTTP/1.1".getBytes(); InetAddress addr = InetAddress.getByName(hostname); HttpRequestMessage requestMessage = new HttpRequestMessage(GET, url.getFile().getBytes(), HTTP11); ANVLRecord headers = new ANVLRecord(); headers.addLabelValue("Host", hostname); if (offset != 0) { headers.addLabelValue(RANGE_HTTP_HEADER, HEADER_BYTES_PREFIX + String.valueOf(offset) + HEADER_BYTES_SUFFIX); } InetSocketAddress sockAddr = new InetSocketAddress(addr, port); Socket socket = new Socket(); socket.setSoTimeout(socketTimeoutMs); socket.setReceiveBufferSize(BUF_SIZE); socket.connect(sockAddr, connectTimeoutMs); OutputStream socketOut = socket.getOutputStream(); InputStream socketIn = socket.getInputStream(); socketOut.write(requestMessage.getBytes(true)); socketOut.write(headers.getUTF8Bytes()); socketOut.flush(); HttpResponse response = HttpResponse.load(socketIn); String contentType = response.getHeaders().asMap().get("Content-Type"); if (contentType == null) { contentType = "application/unknown"; } String xferEncoding = response.getHeaders().asMap().get("Transfer-Encoding"); if (xferEncoding != null) { if (xferEncoding.equals("chunked")) { socketIn = new ChunkedInputStream(socketIn); } } ds = new URLDataSource(socketIn, contentType); } else { // assume a local file path: File f = new File(location); if (f.isFile() && f.canRead()) { long size = f.length(); if (size < offset) { throw new IOException("short file " + location + " cannot" + " seek to offset " + offset); } RandomAccessFile raf = new RandomAccessFile(f, "r"); raf.seek(offset); // BUGBUG: is it compressed? ds = new FileDataSource(raf, DEFAULT_CONTENT_TYPE); } else { throw new IOException("No readable file at " + location); } } return ds; }
From source file:org.darkphoenixs.pool.socket.SocketConnectionFactory.java
@Override public Socket createConnection() throws Exception { Socket socket = new Socket(); try {/* w w w .jav a 2 s . co m*/ if (sendBufferSize > 0) socket.setSendBufferSize(sendBufferSize); if (receiveBufferSize > 0) socket.setReceiveBufferSize(receiveBufferSize); if (soTimeout > 0) socket.setSoTimeout(soTimeout); if (linger > 0) socket.setSoLinger(true, linger); if (keepAlive) socket.setKeepAlive(keepAlive); if (tcpNoDelay) socket.setTcpNoDelay(tcpNoDelay); if (performance != null) socket.setPerformancePreferences(Integer.parseInt(performance[0]), Integer.parseInt(performance[1]), Integer.parseInt(performance[2])); socket.connect(socketAddress, connectionTimeout); } catch (Exception se) { socket.close(); throw se; } return socket; }
From source file:org.globus.ftp.dc.GridFTPActiveConnectTask.java
public void execute() { Socket mySocket = null; if (logger.isDebugEnabled()) { logger.debug("connecting new socket to: " + hostPort.getHost() + " " + hostPort.getPort()); }/* w w w . j a va 2 s .com*/ SocketFactory factory = SocketFactory.getDefault(); try { mySocket = factory.createSocket(hostPort.getHost(), hostPort.getPort()); // set TCP buffer size if (gSession.TCPBufferSize != Session.SERVER_DEFAULT) { logger.debug("setting socket's TCP buffer size to " + gSession.TCPBufferSize); mySocket.setReceiveBufferSize(gSession.TCPBufferSize); mySocket.setSendBufferSize(gSession.TCPBufferSize); } if (!gSession.dataChannelAuthentication.equals(DataChannelAuthentication.NONE)) { logger.debug("authenticating"); mySocket = GridFTPServerFacade.authenticate(mySocket, true, // this IS client socket gSession.credential, gSession.dataChannelProtection, gSession.dataChannelAuthentication); } else { logger.debug("not authenticating"); } // setting the Facade's socket list // synchronize to prevent race condidion against // the section in GridFTPServerFacade.setTCPBufferSize synchronized (box) { box.setSocket(mySocket); } } catch (Exception e) { FTPServerFacade.exceptionToControlChannel(e, "active connection to server failed", control); try { if (mySocket != null) { mySocket.close(); } } catch (Exception second) { } } }
From source file:org.globus.ftp.dc.GridFTPPassiveConnectTask.java
protected SocketBox openSocket() throws Exception { logger.debug("server.accept()"); Socket newSocket = myServer.accept(); // set TCP buffer size if (gSession.TCPBufferSize != Session.SERVER_DEFAULT) { logger.debug("setting socket's TCP buffer size to " + gSession.TCPBufferSize); newSocket.setReceiveBufferSize(gSession.TCPBufferSize); newSocket.setSendBufferSize(gSession.TCPBufferSize); }/* ww w.ja v a2 s . co m*/ logger.debug("server.accept() returned"); if (!gSession.dataChannelAuthentication.equals(DataChannelAuthentication.NONE)) { logger.debug("authenticating"); newSocket = GridFTPServerFacade.authenticate(newSocket, false, // this is NOT client socket gSession.credential, gSession.dataChannelProtection, gSession.dataChannelAuthentication); } else { // do not authenticate logger.debug("not authenticating"); } // mark the socket as busy and store in the global socket pool ManagedSocketBox sBox = new ManagedSocketBox(); sBox.setSocket(newSocket); sBox.setStatus(ManagedSocketBox.BUSY); if (session.transferMode != GridFTPSession.MODE_EBLOCK) { // synchronize to prevent race condidion against // the section in GridFTPServerFacade.setTCPBufferSize synchronized (sBox) { sBox.setReusable(false); } } SocketPool socketPool = ((EBlockParallelTransferContext) context).getSocketPool(); logger.debug("adding new socket to the pool"); socketPool.add(sBox); logger.debug("available cached sockets: " + socketPool.countFree() + "; busy: " + socketPool.countBusy()); return sBox; }
From source file:org.globus.ftp.extended.GridFTPServerFacade.java
/** This method needs to be called BEFORE the local socket(s) get created. In other words, before setActive(), setPassive(), get(), put(), etc. **///from w w w. ja v a 2 s.co m public void setTCPBufferSize(final int size) throws ClientException { logger.debug("Changing local TCP buffer setting to " + size); gSession.TCPBufferSize = size; SocketOperator op = new SocketOperator() { public void operate(SocketBox s) throws Exception { // synchronize to prevent race condition against // the socket initialization code that also sets // TCP buffer (GridFTPActiveConnectTask) synchronized (s) { logger.debug("Changing local socket's TCP buffer to " + size); Socket mySocket = s.getSocket(); if (mySocket != null) { mySocket.setReceiveBufferSize(size); mySocket.setSendBufferSize(size); } else { logger.debug("the socket is null. probably being initialized"); } } } }; try { socketPool.applyToAll(op); } catch (Exception e) { ClientException ce = new ClientException(ClientException.SOCKET_OP_FAILED); ce.setRootCause(e); throw ce; } }
From source file:org.mule.transport.http.HttpServerConnection.java
public HttpServerConnection(final Socket socket, String encoding, HttpConnector connector) throws IOException { super();//from w w w . j a v a 2s. c o m if (socket == null) { throw new IllegalArgumentException("Socket may not be null"); } this.socket = socket; if (this.socket instanceof SSLSocket) { ((SSLSocket) socket).addHandshakeCompletedListener(this); } setSocketTcpNoDelay(); this.socket.setKeepAlive(connector.isKeepAlive()); if (connector.getReceiveBufferSize() != Connector.INT_VALUE_NOT_SET && socket.getReceiveBufferSize() != connector.getReceiveBufferSize()) { socket.setReceiveBufferSize(connector.getReceiveBufferSize()); } if (connector.getServerSoTimeout() != Connector.INT_VALUE_NOT_SET && socket.getSoTimeout() != connector.getServerSoTimeout()) { socket.setSoTimeout(connector.getServerSoTimeout()); } this.in = socket.getInputStream(); this.out = new DataOutputStream(socket.getOutputStream()); this.encoding = encoding; }
From source file:org.mule.transport.tcp.TcpConnector.java
public void configureSocket(boolean client, Socket socket) throws SocketException { // There is some overhead in setting socket timeout and buffer size, so we're // careful here only to set if needed if (newValue(getReceiveBufferSize(), socket.getReceiveBufferSize())) { socket.setReceiveBufferSize(getReceiveBufferSize()); }/* w w w . j a v a2 s . c o m*/ if (newValue(getSendBufferSize(), socket.getSendBufferSize())) { socket.setSendBufferSize(getSendBufferSize()); } if (client) { if (newValue(getClientSoTimeout(), socket.getSoTimeout())) { socket.setSoTimeout(getClientSoTimeout()); } } else { if (newValue(getServerSoTimeout(), socket.getSoTimeout())) { socket.setSoTimeout(getServerSoTimeout()); } } if (newValue(getSocketSoLinger(), socket.getSoLinger())) { socket.setSoLinger(true, getSocketSoLinger()); } try { socket.setTcpNoDelay(isSendTcpNoDelay()); } catch (SocketException e) { // MULE-2800 - Bug in Solaris } socket.setKeepAlive(isKeepAlive()); }