use of com.orientechnologies.common.exception.OException in project orientdb by orientechnologies.
the class OStorageRemote method openRemoteDatabase.
protected String openRemoteDatabase(String currentURL) {
do {
do {
OChannelBinaryAsynchClient network = null;
try {
network = getNetwork(currentURL);
openRemoteDatabase(network);
connectionManager.release(network);
return currentURL;
} 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.exception.OException 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.exception.OException in project orientdb by orientechnologies.
the class OChannelBinaryAsynchClient method throwSerializedException.
private void throwSerializedException(final byte[] serializedException) throws IOException {
final OMemoryInputStream inputStream = new OMemoryInputStream(serializedException);
final ObjectInputStream objectInputStream = new ObjectInputStream(inputStream);
Object throwable = null;
try {
throwable = objectInputStream.readObject();
} catch (ClassNotFoundException e) {
OLogManager.instance().error(this, "Error during exception deserialization", e);
throw new IOException("Error during exception deserialization: " + e.toString());
}
objectInputStream.close();
if (throwable instanceof OException) {
try {
final Class<? extends OException> cls = (Class<? extends OException>) throwable.getClass();
final Constructor<? extends OException> constructor;
constructor = cls.getConstructor(cls);
final OException proxyInstance = constructor.newInstance(throwable);
throw proxyInstance;
} catch (NoSuchMethodException e) {
OLogManager.instance().error(this, "Error during exception deserialization", e);
} catch (InvocationTargetException e) {
OLogManager.instance().error(this, "Error during exception deserialization", e);
} catch (InstantiationException e) {
OLogManager.instance().error(this, "Error during exception deserialization", e);
} catch (IllegalAccessException e) {
OLogManager.instance().error(this, "Error during exception deserialization", e);
}
}
if (throwable instanceof Throwable) {
throw new OResponseProcessingException("Exception during response processing", (Throwable) throwable);
} else
// WRAP IT
OLogManager.instance().error(this, "Error during exception serialization, serialized exception is not Throwable, exception type is " + (throwable != null ? throwable.getClass().getName() : "null"));
}
use of com.orientechnologies.common.exception.OException in project orientdb by orientechnologies.
the class OChannelBinaryClientAbstract method throwSerializedException.
protected void throwSerializedException(final byte[] serializedException) throws IOException {
final OMemoryInputStream inputStream = new OMemoryInputStream(serializedException);
final ObjectInputStream objectInputStream = new ObjectInputStream(inputStream);
Object throwable = null;
try {
throwable = objectInputStream.readObject();
} catch (ClassNotFoundException e) {
OLogManager.instance().error(this, "Error during exception deserialization", e);
throw new IOException("Error during exception deserialization: " + e.toString());
}
objectInputStream.close();
if (throwable instanceof OException) {
try {
final Class<? extends OException> cls = (Class<? extends OException>) throwable.getClass();
final Constructor<? extends OException> constructor;
constructor = cls.getConstructor(cls);
final OException proxyInstance = constructor.newInstance(throwable);
throw proxyInstance;
} catch (NoSuchMethodException e) {
OLogManager.instance().error(this, "Error during exception deserialization", e);
} catch (InvocationTargetException e) {
OLogManager.instance().error(this, "Error during exception deserialization", e);
} catch (InstantiationException e) {
OLogManager.instance().error(this, "Error during exception deserialization", e);
} catch (IllegalAccessException e) {
OLogManager.instance().error(this, "Error during exception deserialization", e);
}
}
if (throwable instanceof Throwable) {
throw new OResponseProcessingException("Exception during response processing", (Throwable) throwable);
} else
// WRAP IT
OLogManager.instance().error(this, "Error during exception serialization, serialized exception is not Throwable, exception type is " + (throwable != null ? throwable.getClass().getName() : "null"));
}
use of com.orientechnologies.common.exception.OException in project orientdb by orientechnologies.
the class OServerAdmin method networkAdminOperation.
protected <T> T networkAdminOperation(final OStorageRemoteOperation<T> operation, final String errorMessage) {
OChannelBinaryAsynchClient network = null;
try {
//TODO:replace this api with one that get connection for only the specified url.
String serverUrl = storage.getNextAvailableServerURL(false, session);
do {
try {
network = storage.getNetwork(serverUrl);
} catch (OException e) {
serverUrl = storage.useNewServerURL(serverUrl);
if (serverUrl == null)
throw e;
}
} while (network == null);
T res = operation.execute(network, storage.getCurrentSession());
storage.connectionManager.release(network);
return res;
} catch (Exception e) {
if (network != null)
storage.connectionManager.release(network);
storage.close(true, false);
throw OException.wrapException(new OStorageException(errorMessage), e);
}
}
Aggregations