use of com.orientechnologies.common.io.OIOException in project orientdb by orientechnologies.
the class OStorageRemote method openRemoteDatabase.
protected void openRemoteDatabase(String currentURL) {
do {
do {
OChannelBinaryAsynchClient network = null;
try {
network = getNetwork(currentURL);
openRemoteDatabase(network);
final int serverVersion = network.getSrvProtocolVersion();
connectionManager.release(network);
return;
} catch (OIOException e) {
if (network != null) {
// REMOVE THE NETWORK CONNECTION IF ANY
connectionManager.remove(network);
}
OLogManager.instance().debug(this, "Cannot open database with url " + currentURL, e);
} catch (OException e) {
connectionManager.release(network);
// PROPAGATE ANY OTHER ORIENTDB EXCEPTION
throw e;
} catch (Exception e) {
if (network != null) {
// REMOVE THE NETWORK CONNECTION IF ANY
try {
connectionManager.remove(network);
} catch (Exception ex) {
// IGNORE ANY EXCEPTION
OLogManager.instance().debug(this, "Cannot remove connection or database url=" + currentURL, e);
}
}
OLogManager.instance().error(this, "Cannot open database url=" + currentURL, e);
}
} while (connectionManager.getReusableConnections(currentURL) > 0);
currentURL = useNewServerURL(currentURL);
} while (currentURL != null);
// REFILL ORIGINAL SERVER LIST
parseServerURLs();
synchronized (serverURLs) {
throw new OStorageException("Cannot create a connection to remote server address(es): " + serverURLs);
}
}
use of com.orientechnologies.common.io.OIOException in project orientdb by orientechnologies.
the class OStorageRemote method reopenRemoteDatabase.
protected String reopenRemoteDatabase() throws IOException {
String currentURL = getCurrentServerURL();
do {
do {
final OChannelBinaryAsynchClient network = getNetwork(currentURL);
try {
OStorageRemoteSession session = getCurrentSession();
OStorageRemoteNodeSession nodeSession = session.getOrCreateServerSession(network.getServerURL());
if (nodeSession == null || !nodeSession.isValid()) {
openRemoteDatabase(network);
connectionManager.release(network);
return network.getServerURL();
} else {
try {
network.writeByte(OChannelBinaryProtocol.REQUEST_DB_REOPEN);
network.writeInt(nodeSession.getSessionId());
network.writeBytes(nodeSession.getToken());
} finally {
endRequest(network);
}
final int sessionId;
try {
byte[] newToken = network.beginResponse(nodeSession.getSessionId(), true);
sessionId = network.readInt();
if (newToken != null && newToken.length > 0) {
nodeSession.setSession(sessionId, newToken);
} else {
nodeSession.setSession(sessionId, nodeSession.getToken());
}
OLogManager.instance().debug(this, "Client connected to %s with session id=%d", network.getServerURL(), sessionId);
return currentURL;
} finally {
endResponse(network);
connectionManager.release(network);
}
}
} catch (OIOException e) {
if (network != null) {
// REMOVE THE NETWORK CONNECTION IF ANY
connectionManager.remove(network);
}
OLogManager.instance().error(this, "Cannot open database with url " + currentURL, e);
} catch (OOfflineNodeException e) {
if (network != null) {
// REMOVE THE NETWORK CONNECTION IF ANY
connectionManager.remove(network);
}
OLogManager.instance().debug(this, "Cannot open database with url " + currentURL, e);
} catch (OSecurityException ex) {
OLogManager.instance().debug(this, "Invalidate token for url=%s", ex, currentURL);
OStorageRemoteSession session = getCurrentSession();
session.removeServerSession(currentURL);
if (network != null) {
// REMOVE THE NETWORK CONNECTION IF ANY
try {
connectionManager.remove(network);
} catch (Exception e) {
// IGNORE ANY EXCEPTION
OLogManager.instance().debug(this, "Cannot remove connection or database url=" + currentURL, e);
}
}
} catch (OException e) {
connectionManager.release(network);
// PROPAGATE ANY OTHER ORIENTDB EXCEPTION
throw e;
} catch (Exception e) {
OLogManager.instance().debug(this, "Cannot open database with url " + currentURL, e);
if (network != null) {
// REMOVE THE NETWORK CONNECTION IF ANY
try {
connectionManager.remove(network);
} catch (Exception ex) {
// IGNORE ANY EXCEPTION
OLogManager.instance().debug(this, "Cannot remove connection or database url=" + currentURL, e);
}
}
}
} while (connectionManager.getAvailableConnections(currentURL) > 0);
currentURL = useNewServerURL(currentURL);
} while (currentURL != null);
// REFILL ORIGINAL SERVER LIST
parseServerURLs();
synchronized (serverURLs) {
throw new OStorageException("Cannot create a connection to remote server address(es): " + serverURLs);
}
}
use of com.orientechnologies.common.io.OIOException in project orientdb by orientechnologies.
the class OStorageRemote method getNetwork.
public OChannelBinaryAsynchClient getNetwork(final String iCurrentURL) {
OChannelBinaryAsynchClient network;
do {
try {
network = connectionManager.acquire(iCurrentURL, clientConfiguration, connectionOptions, asynchEventListener);
} catch (OIOException cause) {
throw cause;
} catch (Exception cause) {
throw OException.wrapException(new OStorageException("Cannot open a connection to remote server: " + iCurrentURL), cause);
}
if (!network.tryLock()) {
// CANNOT LOCK IT, MAYBE HASN'T BE CORRECTLY UNLOCKED BY PREVIOUS USER?
OLogManager.instance().error(this, "Removing locked network channel '%s' (connected=%s)...", iCurrentURL, network.isConnected());
connectionManager.remove(network);
network = null;
}
} while (network == null);
return network;
}
use of com.orientechnologies.common.io.OIOException in project orientdb by orientechnologies.
the class OStorageRemote method close.
public void close(final boolean iForce, boolean onDelete) {
if (status == STATUS.CLOSED)
return;
stateLock.acquireWriteLock();
try {
if (status == STATUS.CLOSED)
return;
final OStorageRemoteSession session = getCurrentSession();
if (session != null) {
final Collection<OStorageRemoteNodeSession> nodes = session.getAllServerSessions();
if (!nodes.isEmpty()) {
for (OStorageRemoteNodeSession nodeSession : nodes) {
OChannelBinaryAsynchClient network = null;
try {
network = getNetwork(nodeSession.getServerURL());
network.beginRequest(OChannelBinaryProtocol.REQUEST_DB_CLOSE, session);
endRequest(network);
connectionManager.release(network);
} catch (OIOException ex) {
// IGNORING IF THE SERVER IS DOWN OR NOT REACHABLE THE SESSION IS AUTOMATICALLY CLOSED.
OLogManager.instance().debug(this, "Impossible to comunicate to the server for close: %s", ex);
connectionManager.remove(network);
} catch (IOException ex) {
// IGNORING IF THE SERVER IS DOWN OR NOT REACHABLE THE SESSION IS AUTOMATICALLY CLOSED.
OLogManager.instance().debug(this, "Impossible to comunicate to the server for close: %s", ex);
connectionManager.remove(network);
}
}
session.close();
sessions.remove(session);
if (!checkForClose(iForce))
return;
} else {
if (!iForce)
return;
}
}
status = STATUS.CLOSING;
// CLOSE ALL THE CONNECTIONS
for (String url : serverURLs) {
connectionManager.closePool(url);
}
sbTreeCollectionManager.close();
super.close(iForce, onDelete);
status = STATUS.CLOSED;
Orient.instance().unregisterStorage(this);
} finally {
stateLock.releaseWriteLock();
}
}
use of com.orientechnologies.common.io.OIOException in project orientdb by orientechnologies.
the class OChannelBinaryAsynchClient method beginRequest.
public void beginRequest(final byte iCommand, final OStorageRemoteSession session) throws IOException {
final OStorageRemoteNodeSession nodeSession = session.getServerSession(getServerURL());
if (nodeSession == null)
throw new OIOException("Invalid session for URL '" + getServerURL() + "'");
writeByte(iCommand);
writeInt(nodeSession.getSessionId());
if (nodeSession.getToken() != null) {
// if (!session.hasConnection(this) || true) {
writeBytes(nodeSession.getToken());
// session.addConnection(this);
// } else
// writeBytes(new byte[] {});
}
}
Aggregations