use of java.net.Socket in project XobotOS by xamarin.
the class SingleClientConnManager method releaseConnection.
// non-javadoc, see interface ClientConnectionManager
public void releaseConnection(ManagedClientConnection conn, long validDuration, TimeUnit timeUnit) {
assertStillUp();
if (!(conn instanceof ConnAdapter)) {
throw new IllegalArgumentException("Connection class mismatch, " + "connection not obtained from this manager.");
}
if (log.isDebugEnabled()) {
log.debug("Releasing connection " + conn);
}
ConnAdapter sca = (ConnAdapter) conn;
if (sca.poolEntry == null)
// already released
return;
ClientConnectionManager manager = sca.getManager();
if (manager != null && manager != this) {
throw new IllegalArgumentException("Connection not obtained from this manager.");
}
try {
// BEGIN android-changed
// When recycling a Socket, we un-tag it to avoid collecting
// statistics from future users.
final Socket socket = uniquePoolEntry.connection.getSocket();
if (socket != null) {
SocketTagger.get().untag(socket);
}
// make sure that the response has been read completely
if (sca.isOpen() && (this.alwaysShutDown || !sca.isMarkedReusable())) {
if (log.isDebugEnabled()) {
log.debug("Released connection open but not reusable.");
}
// make sure this connection will not be re-used
// we might have gotten here because of a shutdown trigger
// shutdown of the adapter also clears the tracked route
sca.shutdown();
}
} catch (IOException iox) {
//@@@ log as warning? let pass?
if (log.isDebugEnabled())
log.debug("Exception shutting down released connection.", iox);
} finally {
sca.detach();
managedConn = null;
lastReleaseTime = System.currentTimeMillis();
if (validDuration > 0)
connectionExpiresTime = timeUnit.toMillis(validDuration) + lastReleaseTime;
else
connectionExpiresTime = Long.MAX_VALUE;
}
}
use of java.net.Socket in project XobotOS by xamarin.
the class ThreadSafeClientConnManager method releaseConnection.
// non-javadoc, see interface ClientConnectionManager
public void releaseConnection(ManagedClientConnection conn, long validDuration, TimeUnit timeUnit) {
if (!(conn instanceof BasicPooledConnAdapter)) {
throw new IllegalArgumentException("Connection class mismatch, " + "connection not obtained from this manager.");
}
BasicPooledConnAdapter hca = (BasicPooledConnAdapter) conn;
if ((hca.getPoolEntry() != null) && (hca.getManager() != this)) {
throw new IllegalArgumentException("Connection not obtained from this manager.");
}
try {
// BEGIN android-changed
// When recycling a Socket, we un-tag it to avoid collecting
// statistics from future users.
final BasicPoolEntry entry = (BasicPoolEntry) hca.getPoolEntry();
final Socket socket = entry.getConnection().getSocket();
if (socket != null) {
SocketTagger.get().untag(socket);
}
// make sure that the response has been read completely
if (hca.isOpen() && !hca.isMarkedReusable()) {
if (log.isDebugEnabled()) {
log.debug("Released connection open but not marked reusable.");
}
// In MTHCM, there would be a call to
// SimpleHttpConnectionManager.finishLastResponse(conn);
// Consuming the response is handled outside in 4.0.
// make sure this connection will not be re-used
// Shut down rather than close, we might have gotten here
// because of a shutdown trigger.
// Shutdown of the adapter also clears the tracked route.
hca.shutdown();
}
} catch (IOException iox) {
//@@@ log as warning? let pass?
if (log.isDebugEnabled())
log.debug("Exception shutting down released connection.", iox);
} finally {
BasicPoolEntry entry = (BasicPoolEntry) hca.getPoolEntry();
boolean reusable = hca.isMarkedReusable();
hca.detach();
if (entry != null) {
connectionPool.freeEntry(entry, reusable, validDuration, timeUnit);
}
}
}
use of java.net.Socket in project XobotOS by xamarin.
the class AbstractClientConnAdapter method getSSLSession.
// non-javadoc, see interface ManagedClientConnection
public SSLSession getSSLSession() {
OperatedClientConnection conn = getWrappedConnection();
assertValid(conn);
if (!isOpen())
return null;
SSLSession result = null;
Socket sock = conn.getSocket();
if (sock instanceof SSLSocket) {
result = ((SSLSocket) sock).getSession();
}
return result;
}
use of java.net.Socket in project jedis by xetorthio.
the class Connection method connect.
public void connect() {
if (!isConnected()) {
try {
socket = new Socket();
// ->@wjw_add
socket.setReuseAddress(true);
// Will monitor the TCP connection is
socket.setKeepAlive(true);
// valid
// Socket buffer Whetherclosed, to
socket.setTcpNoDelay(true);
// ensure timely delivery of data
// Control calls close () method,
socket.setSoLinger(true, 0);
// the underlying socket is closed
// immediately
// <-@wjw_add
socket.connect(new InetSocketAddress(host, port), connectionTimeout);
socket.setSoTimeout(soTimeout);
if (ssl) {
if (null == sslSocketFactory) {
sslSocketFactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
}
socket = (SSLSocket) sslSocketFactory.createSocket(socket, host, port, true);
if (null != sslParameters) {
((SSLSocket) socket).setSSLParameters(sslParameters);
}
if ((null != hostnameVerifier) && (!hostnameVerifier.verify(host, ((SSLSocket) socket).getSession()))) {
String message = String.format("The connection to '%s' failed ssl/tls hostname verification.", host);
throw new JedisConnectionException(message);
}
}
outputStream = new RedisOutputStream(socket.getOutputStream());
inputStream = new RedisInputStream(socket.getInputStream());
} catch (IOException ex) {
broken = true;
throw new JedisConnectionException("Failed connecting to host " + host + ":" + port, ex);
}
}
}
use of java.net.Socket in project platformlayer by platformlayer.
the class PlatformLayerTestContext method isPortOpen.
public boolean isPortOpen(InetSocketAddress socketAddress) throws IOException {
Socket socket = new Socket();
try {
int timeout = 5000;
socket.connect(socketAddress, timeout);
return true;
} catch (IOException e) {
String message = e.getMessage();
if (message.equalsIgnoreCase("connect timed out")) {
return false;
}
throw new IllegalStateException("Unexpected IO exception checking port status", e);
} finally {
socket.close();
}
}
Aggregations