public V newInstanceOfDefaultClass() { if (defaultClass != null) { try { return defaultClass.newInstance(); } catch (Exception e) { throw new OException(String.format("Error on creating new instance of default class '%s'", defaultClass), e); } } return null; }
public V newInstance(final K iKey) { if (iKey == null && defaultClass == null) throw new IllegalArgumentException("Cannot create implementation for type null"); final Class<? extends V> cls = registry.get(iKey); if (cls != null) { try { return cls.newInstance(); } catch (Exception e) { throw new OException(String.format("Error on creating new instance of class '%s' registered in factory with key '%s'", cls, iKey), e); } } return newInstanceOfDefaultClass(); }
public synchronized <T> T getResource(final String iName, final Callable<T> iCallback) { T value = (T) sharedResources.get(iName); if (value == null) { // CREATE IT try { value = iCallback.call(); } catch (Exception e) { throw new OException("Error on creation of shared resource", e); } if (value instanceof OSharedResource) ((OSharedResource) value).acquireExclusiveLock(); sharedResources.put(iName, value); } return value; } }
rootException = (RuntimeException) e; else rootException = new OException(e); } catch (InstantiationException ignored) { } catch (IllegalAccessException ignored) {
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 OException("Error during exception deserialization: " + e.toString()); } objectInputStream.close(); if (throwable instanceof OException) throw (OException) throwable; else if (throwable instanceof Throwable) // WRAP IT throw new OResponseProcessingException("Exception during response processing.", (Throwable) throwable); else OLogManager.instance().error(this, "Error during exception serialization, serialized exception is not Throwable, exception type is " + (throwable != null ? throwable.getClass().getName() : "null")); }
@Override public int getClusterIdByName(String clusterName, Class<?> clazz) { OClass oClass = dbf.db().getMetadata().getSchema().getClass(clazz); for(int clusterId : oClass.getClusterIds()){ if(getClusterNameById(clusterId).equals(clusterName)){ return clusterId; } } throw new OException("Cluster " + clusterName + " not found"); }