Skip to content

Commit

Permalink
Issue #2029, second part of new exceptions design is introduced.
Browse files Browse the repository at this point in the history
  • Loading branch information
laa committed Oct 1, 2015
1 parent a866936 commit 85ea92f
Show file tree
Hide file tree
Showing 111 changed files with 1,124 additions and 1,035 deletions.
Expand Up @@ -21,6 +21,7 @@


import com.orientechnologies.common.concur.resource.OResourcePool; import com.orientechnologies.common.concur.resource.OResourcePool;
import com.orientechnologies.common.concur.resource.OResourcePoolListener; import com.orientechnologies.common.concur.resource.OResourcePoolListener;
import com.orientechnologies.common.exception.OException;
import com.orientechnologies.common.io.OIOException; import com.orientechnologies.common.io.OIOException;
import com.orientechnologies.common.log.OLogManager; import com.orientechnologies.common.log.OLogManager;
import com.orientechnologies.orient.core.config.OContextConfiguration; import com.orientechnologies.orient.core.config.OContextConfiguration;
Expand Down Expand Up @@ -176,15 +177,14 @@ public int getAvailableConnections(final String url) {
return pool.getAvailableResources(); return pool.getAvailableResources();
} }


public int getReusableConnections(final String url){ public int getReusableConnections(final String url) {
final OResourcePool<String, OChannelBinaryAsynchClient> pool = connections.get(url); final OResourcePool<String, OChannelBinaryAsynchClient> pool = connections.get(url);
if (pool == null) if (pool == null)
return 0; return 0;


return pool.getInPoolResources(); return pool.getInPoolResources();
} }



public int getCreatedInstancesInPool(final String url) { public int getCreatedInstancesInPool(final String url) {
final OResourcePool<String, OChannelBinaryAsynchClient> pool = connections.get(url); final OResourcePool<String, OChannelBinaryAsynchClient> pool = connections.get(url);
if (pool == null) if (pool == null)
Expand All @@ -205,7 +205,7 @@ protected void closePool(final OResourcePool<String, OChannelBinaryAsynchClient>
final List<OChannelBinaryAsynchClient> conns = new ArrayList<OChannelBinaryAsynchClient>(pool.getAllResources()); final List<OChannelBinaryAsynchClient> conns = new ArrayList<OChannelBinaryAsynchClient>(pool.getAllResources());
for (OChannelBinaryAsynchClient c : conns) for (OChannelBinaryAsynchClient c : conns)
try { try {
//Unregister the listener that make the connection return to the closing pool. // Unregister the listener that make the connection return to the closing pool.
c.unregisterListener(this); c.unregisterListener(this);
c.close(); c.close();
} catch (Exception e) { } catch (Exception e) {
Expand Down Expand Up @@ -252,7 +252,7 @@ protected OChannelBinaryAsynchClient createNetworkConnection(String iServerURL,
throw e; throw e;
} catch (Exception e) { } catch (Exception e) {
OLogManager.instance().debug(this, "Error on connecting to %s", e, iServerURL); OLogManager.instance().debug(this, "Error on connecting to %s", e, iServerURL);
throw new OIOException("Error on connecting to " + iServerURL, e); throw OException.wrapException(new OIOException("Error on connecting to " + iServerURL), e);
} }
} }
} }
Expand Up @@ -26,6 +26,7 @@
import java.util.Set; import java.util.Set;


import com.orientechnologies.common.concur.lock.OModificationOperationProhibitedException; import com.orientechnologies.common.concur.lock.OModificationOperationProhibitedException;
import com.orientechnologies.common.exception.OException;
import com.orientechnologies.common.log.OLogManager; import com.orientechnologies.common.log.OLogManager;
import com.orientechnologies.orient.core.Orient; import com.orientechnologies.orient.core.Orient;
import com.orientechnologies.orient.core.config.OGlobalConfiguration; import com.orientechnologies.orient.core.config.OGlobalConfiguration;
Expand Down Expand Up @@ -142,7 +143,7 @@ public synchronized Map<String, String> listDatabases() throws IOException {


} catch (Exception e) { } catch (Exception e) {
storage.close(true, false); storage.close(true, false);
throw new OStorageException("Cannot retrieve the configuration list", e); throw OException.wrapException(new OStorageException("Cannot retrieve the configuration list"), e);
} }
return (Map<String, String>) result.field("databases"); return (Map<String, String>) result.field("databases");
} }
Expand Down Expand Up @@ -255,7 +256,8 @@ public synchronized boolean existsDatabase(final String iDatabaseName, final Str


} catch (Exception e) { } catch (Exception e) {
storage.close(true, false); storage.close(true, false);
throw new OStorageException("Error on checking existence of the remote storage: " + storage.getName(), e); throw OException.wrapException(
new OStorageException("Error on checking existence of the remote storage: " + storage.getName()), e);
} }
} }


Expand Down Expand Up @@ -315,7 +317,7 @@ public synchronized OServerAdmin dropDatabase(final String iDatabaseName, final
} catch (OModificationOperationProhibitedException oope) { } catch (OModificationOperationProhibitedException oope) {
retry = handleDBFreeze(); retry = handleDBFreeze();
} catch (Exception e) { } catch (Exception e) {
throw new OStorageException("Cannot delete the remote storage: " + storage.getName(), e); throw OException.wrapException(new OStorageException("Cannot delete the remote storage: " + storage.getName()), e);
} }


final Set<OStorage> underlyingStorages = new HashSet<OStorage>(); final Set<OStorage> underlyingStorages = new HashSet<OStorage>();
Expand Down Expand Up @@ -371,7 +373,7 @@ public synchronized OServerAdmin freezeDatabase(final String storageType) throws


storage.getResponse(network); storage.getResponse(network);
} catch (Exception e) { } catch (Exception e) {
throw new OStorageException("Cannot freeze the remote storage: " + storage.getName(), e); throw OException.wrapException(new OStorageException("Cannot freeze the remote storage: " + storage.getName()), e);
} }


return this; return this;
Expand Down Expand Up @@ -400,7 +402,7 @@ public synchronized OServerAdmin releaseDatabase(final String storageType) throw


storage.getResponse(network); storage.getResponse(network);
} catch (Exception e) { } catch (Exception e) {
throw new OStorageException("Cannot release the remote storage: " + storage.getName(), e); throw OException.wrapException(new OStorageException("Cannot release the remote storage: " + storage.getName()), e);
} }


return this; return this;
Expand Down Expand Up @@ -435,7 +437,8 @@ public synchronized OServerAdmin freezeCluster(final int clusterId, final String
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
throw e; throw e;
} catch (Exception e) { } catch (Exception e) {
throw new OStorageException("Cannot freeze the remote cluster " + clusterId + " on storage: " + storage.getName(), e); throw OException.wrapException(new OStorageException("Cannot freeze the remote cluster " + clusterId + " on storage: "
+ storage.getName()), e);
} }


return this; return this;
Expand Down Expand Up @@ -469,7 +472,8 @@ public synchronized OServerAdmin releaseCluster(final int clusterId, final Strin
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
throw e; throw e;
} catch (Exception e) { } catch (Exception e) {
throw new OStorageException("Cannot release the remote cluster " + clusterId + " on storage: " + storage.getName(), e); throw OException.wrapException(new OStorageException("Cannot release the remote cluster " + clusterId + " on storage: "
+ storage.getName()), e);
} }


return this; return this;
Expand Down Expand Up @@ -520,7 +524,7 @@ public synchronized OServerAdmin copyDatabase(final String databaseName, final S
OLogManager.instance().debug(this, "Database '%s' has been copied to the server '%s'", databaseName, iRemoteName); OLogManager.instance().debug(this, "Database '%s' has been copied to the server '%s'", databaseName, iRemoteName);


} catch (Exception e) { } catch (Exception e) {
throw new OStorageException("Cannot copy the database: " + databaseName, e); throw OException.wrapException(new OStorageException("Cannot copy the database: " + databaseName), e);
} }


return this; return this;
Expand All @@ -545,7 +549,7 @@ public synchronized Map<String, String> getGlobalConfigurations() throws IOExcep


} catch (Exception e) { } catch (Exception e) {
storage.close(true, false); storage.close(true, false);
throw new OStorageException("Cannot retrieve the configuration list", e); throw OException.wrapException(new OStorageException("Cannot retrieve the configuration list"), e);
} }
return config; return config;
} }
Expand All @@ -566,7 +570,7 @@ public synchronized String getGlobalConfiguration(final OGlobalConfiguration con


} catch (Exception e) { } catch (Exception e) {
storage.close(true, false); storage.close(true, false);
throw new OStorageException("Cannot retrieve the configuration value: " + config.getKey(), e); throw OException.wrapException(new OStorageException("Cannot retrieve the configuration value: " + config.getKey()), e);
} }
} }


Expand All @@ -582,7 +586,7 @@ public synchronized OServerAdmin setGlobalConfiguration(final OGlobalConfigurati


} catch (Exception e) { } catch (Exception e) {
storage.close(true, false); storage.close(true, false);
throw new OStorageException("Cannot set the configuration value: " + config.getKey(), e); throw OException.wrapException(new OStorageException("Cannot set the configuration value: " + config.getKey()), e);
} }
return this; return this;
} }
Expand Down Expand Up @@ -631,11 +635,11 @@ protected ODocument sendRequest(final byte iRequest, final ODocument iPayLoad, f
} catch (IOException e) { } catch (IOException e) {
if (network != null) if (network != null)
storage.getEngine().getConnectionManager().remove(network); storage.getEngine().getConnectionManager().remove(network);
throw new OStorageException("Error on executing '" + iActivity + "'", e); throw OException.wrapException(new OStorageException("Error on executing '" + iActivity + "'"), e);
} catch (Exception e2) { } catch (Exception e2) {
if (network != null) if (network != null)
storage.getEngine().getConnectionManager().release(network); storage.getEngine().getConnectionManager().release(network);
throw new OStorageException("Error on executing '" + iActivity + "'", e2); throw OException.wrapException(new OStorageException("Error on executing '" + iActivity + "'"), e2);
} }
} }
return null; return null;
Expand Down
Expand Up @@ -259,7 +259,7 @@ public void open(final String iUserName, final String iUserPassword, final Map<S
// PASS THROUGH // PASS THROUGH
throw (RuntimeException) e; throw (RuntimeException) e;
else else
throw new OStorageException("Cannot open the remote storage: " + name, e); throw OException.wrapException(new OStorageException("Cannot open the remote storage: " + name), e);


} finally { } finally {
stateLock.releaseWriteLock(); stateLock.releaseWriteLock();
Expand Down Expand Up @@ -1744,7 +1744,7 @@ protected void handleException(final OChannelBinaryAsynchClient iNetwork, final
} else if (!(exception instanceof IOException)) { } else if (!(exception instanceof IOException)) {
if (iNetwork != null) if (iNetwork != null)
engine.getConnectionManager().release(iNetwork); engine.getConnectionManager().release(iNetwork);
throw new OStorageException(message, exception); throw OException.wrapException(new OStorageException(message), exception);
} }


if (status != STATUS.OPEN) if (status != STATUS.OPEN)
Expand Down Expand Up @@ -1824,7 +1824,7 @@ protected void handleException(final OChannelBinaryAsynchClient iNetwork, final
} }


// RECONNECTION FAILED: THROW+LOG THE ORIGINAL EXCEPTION // RECONNECTION FAILED: THROW+LOG THE ORIGINAL EXCEPTION
throw new OStorageException(message, exception); throw OException.wrapException(new OStorageException(message), exception);
} }


protected String reopenRemoteDatabase() { protected String reopenRemoteDatabase() {
Expand Down Expand Up @@ -2180,7 +2180,7 @@ protected OChannelBinaryAsynchClient getAvailableNetwork(final String iCurrentUR
parseServerURLs(); parseServerURLs();
if (cause instanceof IOException) if (cause instanceof IOException)
throw (IOException) cause; throw (IOException) cause;
throw new OIOException("Cannot open a connection to remote server: " + iCurrentURL, cause); throw OException.wrapException(new OIOException("Cannot open a connection to remote server: " + iCurrentURL), cause);
} }
} else if (!network.isConnected()) { } else if (!network.isConnected()) {
// DISCONNECTED NETWORK, GET ANOTHER ONE // DISCONNECTED NETWORK, GET ANOTHER ONE
Expand Down Expand Up @@ -2315,7 +2315,7 @@ private void commitEntry(final OChannelBinaryAsynchClient iNetwork, final ORecor
} catch (Exception e) { } catch (Exception e) {
// ABORT TX COMMIT // ABORT TX COMMIT
iNetwork.writeByte((byte) -1); iNetwork.writeByte((byte) -1);
throw new OTransactionException("Error on transaction commit", e); throw OException.wrapException(new OTransactionException("Error on transaction commit"), e);
} }


iNetwork.writeByte((byte) 1); iNetwork.writeByte((byte) 1);
Expand Down
Expand Up @@ -20,6 +20,7 @@
package com.orientechnologies.common.concur.lock; package com.orientechnologies.common.concur.lock;


import com.orientechnologies.common.concur.OTimeoutException; import com.orientechnologies.common.concur.OTimeoutException;
import com.orientechnologies.common.exception.OException;
import com.orientechnologies.common.log.OLogManager; import com.orientechnologies.common.log.OLogManager;


import java.io.PrintWriter; import java.io.PrintWriter;
Expand Down Expand Up @@ -89,8 +90,8 @@ public void lock() {
} }
} }


throw new OLockException("Thread interrupted while waiting for resource of class '" + getClass() + "' with timeout=" throw OException.wrapException(new OLockException("Thread interrupted while waiting for resource of class '" + getClass()
+ timeout, e); + "' with timeout=" + timeout), e);
} }


throwTimeoutException(lock); throwTimeoutException(lock);
Expand All @@ -109,8 +110,8 @@ public boolean tryAcquireLock(final long iTimeout, final TimeUnit iUnit) {
try { try {
return lock.tryLock(iTimeout, iUnit); return lock.tryLock(iTimeout, iUnit);
} catch (InterruptedException e) { } catch (InterruptedException e) {
throw new OLockException("Thread interrupted while waiting for resource of class '" + getClass() + "' with timeout=" throw OException.wrapException(new OLockException("Thread interrupted while waiting for resource of class '" + getClass()
+ timeout, e); + "' with timeout=" + timeout), e);
} }
else else
return lock.tryLock(); return lock.tryLock();
Expand Down
Expand Up @@ -31,6 +31,7 @@


import com.orientechnologies.common.concur.lock.OInterruptedException; import com.orientechnologies.common.concur.lock.OInterruptedException;
import com.orientechnologies.common.concur.lock.OLockException; import com.orientechnologies.common.concur.lock.OLockException;
import com.orientechnologies.common.exception.OException;
import com.orientechnologies.common.log.OLogManager; import com.orientechnologies.common.log.OLogManager;


/** /**
Expand Down Expand Up @@ -110,7 +111,7 @@ public V getResource(K key, final long maxWaitMillis, Object... additionalArgs)
} catch (Exception e) { } catch (Exception e) {
sem.release(); sem.release();


throw new OLockException("Error on creation of the new resource in the pool", e); throw OException.wrapException(new OLockException("Error on creation of the new resource in the pool"), e);
} }
} }


Expand Down
Expand Up @@ -35,18 +35,4 @@ public static OException wrapException(OException exception, Exception cause) {
public OException(final String message) { public OException(final String message) {
super(message); super(message);
} }

@Override
public boolean equals(final Object obj) {
if (obj == null || !obj.getClass().equals(getClass()))
return false;

final String myMsg = getMessage();
final String otherMsg = ((OException) obj).getMessage();
if (myMsg == null || otherMsg == null)
// UNKNOWN
return false;

return myMsg.equals(otherMsg);
}
} }
5 changes: 3 additions & 2 deletions core/src/main/java/com/orientechnologies/common/parser/OStringForwardReader.java 100644 → 100755
Expand Up @@ -19,6 +19,7 @@
*/ */
package com.orientechnologies.common.parser; package com.orientechnologies.common.parser;


import com.orientechnologies.common.exception.OException;
import com.orientechnologies.common.io.OIOException; import com.orientechnologies.common.io.OIOException;


import java.io.BufferedReader; import java.io.BufferedReader;
Expand Down Expand Up @@ -83,7 +84,7 @@ private void read(final int iIndex) {
end = start + byteRead; end = start + byteRead;
current = start; current = start;
} catch (IOException e) { } catch (IOException e) {
throw new OIOException("Error in read", e); throw OException.wrapException(new OIOException("Error in read"), e);
} }
} }


Expand All @@ -99,7 +100,7 @@ public boolean ready() {
try { try {
return current < end || input.ready(); return current < end || input.ready();
} catch (IOException e) { } catch (IOException e) {
throw new OIOException("Error in ready", e); throw OException.wrapException(new OIOException("Error in ready"), e);
} }
} }


Expand Down
Expand Up @@ -230,7 +230,7 @@ public Object clone() {
f.mag01 = (int[]) (mag01.clone()); f.mag01 = (int[]) (mag01.clone());
return f; return f;
} catch (CloneNotSupportedException e) { } catch (CloneNotSupportedException e) {
throw new OSystemException("Can not clone instance of " + MersenneTwister.class.getSimpleName(), e); throw OException.wrapException(new OSystemException("Can not clone instance of " + MersenneTwister.class.getSimpleName()), e);
} // should never happen } // should never happen
} }


Expand Down
Expand Up @@ -222,7 +222,8 @@ public Object clone() {
f.mag01 = (int[]) (mag01.clone()); f.mag01 = (int[]) (mag01.clone());
return f; return f;
} catch (CloneNotSupportedException e) { } catch (CloneNotSupportedException e) {
throw new OSystemException("Can not clone " + MersenneTwisterFast.class.getSimpleName() + " instance", e); throw OException.wrapException(new OSystemException("Can not clone " + MersenneTwisterFast.class.getSimpleName()
+ " instance"), e);
} // should never happen } // should never happen
} }


Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/com/orientechnologies/common/util/OClassLoaderHelper.java 100644 → 100755
Expand Up @@ -23,6 +23,7 @@
import java.util.Iterator; import java.util.Iterator;
import java.util.ServiceLoader; import java.util.ServiceLoader;


import com.orientechnologies.common.exception.OException;
import com.orientechnologies.common.log.OLogManager; import com.orientechnologies.common.log.OLogManager;
import com.orientechnologies.orient.core.exception.OConfigurationException; import com.orientechnologies.orient.core.exception.OConfigurationException;


Expand Down Expand Up @@ -50,7 +51,7 @@ public static synchronized <T extends Object> Iterator<T> lookupProviderWithOrie
return ServiceLoader.load(clazz).iterator(); return ServiceLoader.load(clazz).iterator();
} catch (Exception e) { } catch (Exception e) {
OLogManager.instance().warn(null, "Cannot lookup in service registry", e); OLogManager.instance().warn(null, "Cannot lookup in service registry", e);
throw new OConfigurationException("Cannot lookup in service registry", e); throw OException.wrapException(new OConfigurationException("Cannot lookup in service registry"), e);
} finally { } finally {
Thread.currentThread().setContextClassLoader(origClassLoader); Thread.currentThread().setContextClassLoader(origClassLoader);
} }
Expand Down
5 changes: 3 additions & 2 deletions core/src/main/java/com/orientechnologies/orient/core/command/OCommandManager.java 100644 → 100755
Expand Up @@ -19,6 +19,7 @@
*/ */
package com.orientechnologies.orient.core.command; package com.orientechnologies.orient.core.command;


import com.orientechnologies.common.exception.OException;
import com.orientechnologies.common.util.OCallable; import com.orientechnologies.common.util.OCallable;
import com.orientechnologies.orient.core.command.script.OCommandExecutorScript; import com.orientechnologies.orient.core.command.script.OCommandExecutorScript;
import com.orientechnologies.orient.core.command.script.OCommandScript; import com.orientechnologies.orient.core.command.script.OCommandScript;
Expand Down Expand Up @@ -112,8 +113,8 @@ public OCommandExecutor getExecutor(OCommandRequestInternal iCommand) {
return exec; return exec;


} catch (Exception e) { } catch (Exception e) {
throw new OCommandExecutionException("Cannot create the command executor of class " + executorClass throw OException.wrapException(new OCommandExecutionException("Cannot create the command executor of class " + executorClass
+ " for the command request: " + iCommand, e); + " for the command request: " + iCommand), e);
} }
} }
} }
Expand Up @@ -20,6 +20,7 @@
package com.orientechnologies.orient.core.command.script; package com.orientechnologies.orient.core.command.script;


import com.orientechnologies.common.concur.resource.OPartitionedObjectPool; import com.orientechnologies.common.concur.resource.OPartitionedObjectPool;
import com.orientechnologies.common.exception.OException;
import com.orientechnologies.common.util.OCommonConst; import com.orientechnologies.common.util.OCommonConst;
import com.orientechnologies.orient.core.Orient; import com.orientechnologies.orient.core.Orient;
import com.orientechnologies.orient.core.command.OCommandContext; import com.orientechnologies.orient.core.command.OCommandContext;
Expand Down Expand Up @@ -89,7 +90,7 @@ public Object executeInContext(final OCommandContext iContext, final Map<Object,
for (Entry<Object, Object> arg : iArgs.entrySet()) for (Entry<Object, Object> arg : iArgs.entrySet())
args[i++] = arg.getValue(); args[i++] = arg.getValue();
} else { } else {
args = OCommonConst.EMPTY_OBJECT_ARRAY; args = OCommonConst.EMPTY_OBJECT_ARRAY;
} }
result = invocableEngine.invokeFunction(parserText, args); result = invocableEngine.invokeFunction(parserText, args);


Expand All @@ -102,9 +103,10 @@ public Object executeInContext(final OCommandContext iContext, final Map<Object,
return OCommandExecutorUtility.transformResult(result); return OCommandExecutorUtility.transformResult(result);


} catch (ScriptException e) { } catch (ScriptException e) {
throw new OCommandScriptException("Error on execution of the script", request.getText(), e.getColumnNumber(), e); throw OException.wrapException(
new OCommandScriptException("Error on execution of the script", request.getText(), e.getColumnNumber()), e);
} catch (NoSuchMethodException e) { } catch (NoSuchMethodException e) {
throw new OCommandScriptException("Error on execution of the script", request.getText(), 0, e); throw OException.wrapException(new OCommandScriptException("Error on execution of the script", request.getText(), 0), e);
} catch (OCommandScriptException e) { } catch (OCommandScriptException e) {
// PASS THROUGH // PASS THROUGH
throw e; throw e;
Expand Down

0 comments on commit 85ea92f

Please sign in to comment.