diff --git a/client/src/main/java/com/orientechnologies/orient/client/remote/ORemoteConnectionManager.java b/client/src/main/java/com/orientechnologies/orient/client/remote/ORemoteConnectionManager.java index b7b67b7cc06..cbf09287acf 100755 --- a/client/src/main/java/com/orientechnologies/orient/client/remote/ORemoteConnectionManager.java +++ b/client/src/main/java/com/orientechnologies/orient/client/remote/ORemoteConnectionManager.java @@ -84,7 +84,7 @@ public OChannelBinaryAsynchClient createNewResource(final String iKey, final Obj @Override public boolean reuseResource(final String iKey, final Object[] iAdditionalArgs, final OChannelBinaryAsynchClient iValue) { - return true; + return iValue.isConnected(); } }); diff --git a/enterprise/src/main/java/com/orientechnologies/orient/enterprise/channel/binary/OChannelBinaryAsynchClient.java b/enterprise/src/main/java/com/orientechnologies/orient/enterprise/channel/binary/OChannelBinaryAsynchClient.java index 14027319fe8..9e03bd02846 100755 --- a/enterprise/src/main/java/com/orientechnologies/orient/enterprise/channel/binary/OChannelBinaryAsynchClient.java +++ b/enterprise/src/main/java/com/orientechnologies/orient/enterprise/channel/binary/OChannelBinaryAsynchClient.java @@ -29,7 +29,6 @@ import com.orientechnologies.orient.core.config.OGlobalConfiguration; import com.orientechnologies.orient.core.exception.OStorageException; import com.orientechnologies.orient.core.serialization.OMemoryInputStream; -import com.orientechnologies.orient.core.sql.parser.OMatchStatement; import com.orientechnologies.orient.enterprise.channel.OSocketFactory; import java.io.BufferedInputStream; @@ -67,7 +66,7 @@ public OChannelBinaryAsynchClient(final String remoteHost, final int remotePort, public OChannelBinaryAsynchClient(final String remoteHost, final int remotePort, final String iDatabaseName, final OContextConfiguration iConfig, final int protocolVersion, final ORemoteServerEventListener asynchEventListener) - throws IOException { + throws IOException { super(OSocketFactory.instance(iConfig).createSocket(), iConfig); try { @@ -98,13 +97,12 @@ public OChannelBinaryAsynchClient(final String remoteHost, final int remotePort, srvProtocolVersion = readShort(); } catch (IOException e) { - throw new ONetworkProtocolException("Cannot read protocol version from remote server " + socket.getRemoteSocketAddress() - + ": " + e); + throw new ONetworkProtocolException( + "Cannot read protocol version from remote server " + socket.getRemoteSocketAddress() + ": " + e); } if (srvProtocolVersion != protocolVersion) { - OLogManager.instance().warn( - this, + OLogManager.instance().warn(this, "The Client driver version is different than Server version: client=" + protocolVersion + ", server=" + srvProtocolVersion + ". You could not use the full features of the newer version. Assure to have the same versions on both"); @@ -167,11 +165,11 @@ public void endRequest() throws IOException { releaseWriteLock(); } - public byte[] beginResponse(final int iRequesterId, boolean token) throws IOException { + public byte[] beginResponse(final int iRequesterId, final boolean token) throws IOException { return beginResponse(iRequesterId, timeout, token); } - public byte[] beginResponse(final int iRequesterId, final long iTimeout, boolean token) throws IOException { + public byte[] beginResponse(final int iRequesterId, final long iTimeout, final boolean token) throws IOException { try { int unreadResponse = 0; final long startClock = iTimeout > 0 ? System.currentTimeMillis() : 0; @@ -187,8 +185,6 @@ else if (!getLockRead().tryAcquireLock(iTimeout, TimeUnit.MILLISECONDS)) if (!isConnected()) { releaseReadLock(); - readLock = false; - throw new IOException("Channel is closed"); } @@ -417,13 +413,15 @@ protected int handleStatus(final byte iResult, final int iClientTxId) throws IOE } private void setReadResponseTimeout() throws SocketException { - if (socket != null && socket.isConnected() && !socket.isClosed()) - socket.setSoTimeout(socketTimeout); + final Socket s = socket; + if (s != null && s.isConnected() && !s.isClosed()) + s.setSoTimeout(socketTimeout); } private void setWaitResponseTimeout() throws SocketException { - if (socket != null) - socket.setSoTimeout(OGlobalConfiguration.NETWORK_REQUEST_TIMEOUT.getValueAsInteger()); + final Socket s = socket; + if (s != null) + s.setSoTimeout(OGlobalConfiguration.NETWORK_REQUEST_TIMEOUT.getValueAsInteger()); } private void throwSerializedException(final byte[] serializedException) throws IOException { @@ -465,8 +463,7 @@ private void throwSerializedException(final byte[] serializedException) throws I // WRAP IT else - OLogManager.instance().error( - this, + OLogManager.instance().error(this, "Error during exception serialization, serialized exception is not Throwable, exception type is " + (throwable != null ? throwable.getClass().getName() : "null")); } diff --git a/server/src/main/java/com/orientechnologies/orient/server/network/protocol/binary/ONetworkProtocolBinary.java b/server/src/main/java/com/orientechnologies/orient/server/network/protocol/binary/ONetworkProtocolBinary.java index 03e90f05a7a..fa36e1a83f7 100755 --- a/server/src/main/java/com/orientechnologies/orient/server/network/protocol/binary/ONetworkProtocolBinary.java +++ b/server/src/main/java/com/orientechnologies/orient/server/network/protocol/binary/ONetworkProtocolBinary.java @@ -675,8 +675,8 @@ protected void removeCluster() throws IOException { final String clusterName = connection.database.getClusterNameById(id); if (clusterName == null) - throw new IllegalArgumentException("Cluster " + id - + " does not exist anymore. Refresh the db structure or just reconnect to the database"); + throw new IllegalArgumentException( + "Cluster " + id + " does not exist anymore. Refresh the db structure or just reconnect to the database"); boolean result = connection.database.dropCluster(clusterName, true); @@ -923,8 +923,9 @@ protected void sendError(final int iClientTxId, final Throwable t) throws IOExce channel.writeByte(OChannelBinaryProtocol.RESPONSE_STATUS_ERROR); channel.writeInt(iClientTxId); - if (!Boolean.FALSE.equals(tokenBased) && requestType != OChannelBinaryProtocol.REQUEST_CONNECT && requestType != OChannelBinaryProtocol.REQUEST_DB_OPEN && (connection != null && connection.data != null - || connection.data.protocolVersion <= OChannelBinaryProtocol.PROTOCOL_VERSION_32)){ + if (tokenBased != null && Boolean.TRUE.equals(tokenBased) && requestType != OChannelBinaryProtocol.REQUEST_CONNECT + && (requestType != OChannelBinaryProtocol.REQUEST_DB_OPEN || (connection != null && connection.data != null + && connection.data.protocolVersion <= OChannelBinaryProtocol.PROTOCOL_VERSION_32))) { // TODO: Check if the token is expiring and if it is send a new token if (token != null) { @@ -1041,8 +1042,8 @@ protected void replicationDatabase() throws IOException { } else if (operation.equals("config")) { checkServerAccess("server.replication.config"); - response = new ODocument().fromJSON(dManager.getDatabaseConfiguration((String) request.field("db")).serialize() - .toJSON("prettyPrint")); + response = new ODocument() + .fromJSON(dManager.getDatabaseConfiguration((String) request.field("db")).serialize().toJSON("prettyPrint")); } @@ -1919,7 +1920,8 @@ protected void beginResponse() { protected void endResponse() throws IOException { // resetting transaction state. Commands are stateless and connection should be cleared // otherwise reused connection (connections pool) may lead to unpredicted errors - if (connection != null && connection.database != null && connection.database.activateOnCurrentThread().getTransaction() != null) { + if (connection != null && connection.database != null + && connection.database.activateOnCurrentThread().getTransaction() != null) { connection.database.activateOnCurrentThread(); connection.database.getTransaction().rollback(); } @@ -2119,8 +2121,8 @@ private void ridBagSize() throws IOException { final OSBTreeCollectionManager sbTreeCollectionManager = connection.database.getSbTreeCollectionManager(); final OSBTreeBonsai tree = sbTreeCollectionManager.loadSBTree(collectionPointer); try { - final Map changes = OSBTreeRidBag.ChangeSerializationHelper.INSTANCE.deserializeChanges( - changeStream, 0); + final Map changes = OSBTreeRidBag.ChangeSerializationHelper.INSTANCE + .deserializeChanges(changeStream, 0); int realSize = tree.getRealBagSize(changes); @@ -2175,8 +2177,8 @@ private void sbTreeBonsaiGetEntriesMajor() throws IOException { private byte[] serializeSBTreeEntryCollection(List> collection, OBinarySerializer keySerializer, OBinarySerializer valueSerializer) { - byte[] stream = new byte[OIntegerSerializer.INT_SIZE + collection.size() - * (keySerializer.getFixedLength() + valueSerializer.getFixedLength())]; + byte[] stream = new byte[OIntegerSerializer.INT_SIZE + + collection.size() * (keySerializer.getFixedLength() + valueSerializer.getFixedLength())]; int offset = 0; OIntegerSerializer.INSTANCE.serializeLiteral(collection.size(), stream, offset);