use of com.orientechnologies.orient.core.engine.OEngine in project orientdb by orientechnologies.
the class PostponedEngineStartTest method testStoppedEngineShouldStartAndCreateStorage.
// @Test
public void testStoppedEngineShouldStartAndCreateStorage() {
OEngine engine = ORIENT.getEngineIfRunning(ENGINE2.getName());
Assert.assertNull(engine);
final OStorage storage = ORIENT.loadStorage(ENGINE2.getName() + ":storage");
Assert.assertNotNull(storage);
engine = ORIENT.getRunningEngine(ENGINE2.getName());
Assert.assertTrue(engine.isRunning());
}
use of com.orientechnologies.orient.core.engine.OEngine in project orientdb by orientechnologies.
the class PostponedEngineStartTest method testGetRunningEngineShouldStartEngine.
// @Test(dependsOnMethods = "testGetEngineIfRunningShouldReturnNullEngineIfNotRunning")
public void testGetRunningEngineShouldStartEngine() {
final OEngine engine = ORIENT.getRunningEngine(ENGINE1.getName());
Assert.assertNotNull(engine);
Assert.assertTrue(engine.isRunning());
}
use of com.orientechnologies.orient.core.engine.OEngine in project orientdb by orientechnologies.
the class Orient method registerEngines.
/**
* Shutdown whole OrientDB ecosystem. Usually is called during JVM shutdown by JVM shutdown handler. During shutdown all handlers
* which were registered by the call of {@link #addShutdownHandler(OShutdownHandler)} are called together with pre-registered
* system shoutdown handlers according to their priority.
*
* @see OShutdownWorkersHandler
* @see
*/
private void registerEngines() {
ClassLoader classLoader = Orient.class.getClassLoader();
Iterator<OEngine> engines = OClassLoaderHelper.lookupProviderWithOrientClassLoader(OEngine.class, classLoader);
OEngine engine = null;
while (engines.hasNext()) {
try {
engine = engines.next();
registerEngine(engine);
} catch (IllegalArgumentException e) {
if (engine != null)
OLogManager.instance().debug(this, "Failed to replace engine " + engine.getName());
}
}
}
use of com.orientechnologies.orient.core.engine.OEngine in project orientdb by orientechnologies.
the class Orient method loadStorage.
public OStorage loadStorage(String iURL) {
if (iURL == null || iURL.length() == 0)
throw new IllegalArgumentException("URL missed");
if (iURL.endsWith("/"))
iURL = iURL.substring(0, iURL.length() - 1);
// SEARCH FOR ENGINE
int pos = iURL.indexOf(':');
if (pos <= 0)
throw new OConfigurationException("Error in database URL: the engine was not specified. Syntax is: " + URL_SYNTAX + ". URL was: " + iURL);
final String engineName = iURL.substring(0, pos);
engineLock.readLock().lock();
try {
final OEngine engine = engines.get(engineName.toLowerCase());
if (engine == null)
throw new OConfigurationException("Error on opening database: the engine '" + engineName + "' was not found. URL was: " + iURL + ". Registered engines are: " + engines.keySet());
if (!engine.isRunning()) {
final List<String> knownEngines = new ArrayList<String>(engines.keySet());
if (!startEngine(engine))
throw new OConfigurationException("Error on opening database: the engine '" + engineName + "' was unable to start. URL was: " + iURL + ". Registered engines was: " + knownEngines);
}
// SEARCH FOR DB-NAME
iURL = iURL.substring(pos + 1);
if (isWindowsOS()) {
// WINDOWS ONLY: REMOVE DOUBLE SLASHES NOT AS PREFIX (WINDOWS PATH COULD NEED STARTING FOR "\\". EXAMPLE: "\\mydrive\db").
// AT
// THIS LEVEL BACKSLASHES ARRIVES AS SLASHES
iURL = iURL.charAt(0) + iURL.substring(1).replace("//", "/");
} else
// REMOVE ANY //
iURL = iURL.replace("//", "/");
pos = iURL.indexOf('?');
Map<String, String> parameters = null;
String dbPath;
if (pos > 0) {
dbPath = iURL.substring(0, pos);
iURL = iURL.substring(pos + 1);
// PARSE PARAMETERS
parameters = new HashMap<String, String>();
String[] pairs = iURL.split("&");
String[] kv;
for (String pair : pairs) {
kv = pair.split("=");
if (kv.length < 2)
throw new OConfigurationException("Error on opening database: parameter has no value. Syntax is: " + URL_SYNTAX + ". URL was: " + iURL);
parameters.put(kv[0], kv[1]);
}
} else
dbPath = iURL;
if (registerDatabaseByPath) {
try {
dbPath = new File(dbPath).getCanonicalPath();
} catch (IOException e) {
// IGNORE IT
}
}
final String dbName = registerDatabaseByPath ? dbPath : engine.getNameFromPath(dbPath);
OStorage storage;
// SEARCH IF ALREADY USED
storage = storages.get(dbName);
if (storage == null) {
do {
storage = engine.createStorage(dbPath, parameters);
} while ((storage instanceof OIdentifiableStorage) && storageIds.putIfAbsent(((OIdentifiableStorage) storage).getId(), Boolean.TRUE) != null);
final OStorage oldStorage = storages.putIfAbsent(dbName, storage);
if (oldStorage != null)
storage = oldStorage;
for (OOrientListener l : browseListeners()) l.onStorageRegistered(storage);
}
return storage;
} finally {
engineLock.readLock().unlock();
}
}
use of com.orientechnologies.orient.core.engine.OEngine in project orientdb by orientechnologies.
the class Orient method unregisterStorage.
public void unregisterStorage(final OStorage storage) {
if (!active)
// SHUTDOWNING OR NOT ACTIVE: RETURN
return;
if (storage == null)
return;
engineLock.writeLock().lock();
try {
// UNREGISTER ALL THE LISTENER ONE BY ONE AVOIDING SELF-RECURSION BY REMOVING FROM THE LIST
final Iterable<OOrientListener> listenerCopy = getListenersCopy();
for (final OOrientListener l : listenerCopy) {
unregisterListener(l);
l.onStorageUnregistered(storage);
}
final List<String> storagesToRemove = new ArrayList<String>();
for (Entry<String, OStorage> s : storages.entrySet()) {
if (s.getValue().equals(storage))
storagesToRemove.add(s.getKey());
}
for (String dbName : storagesToRemove) storages.remove(dbName);
// UNREGISTER STORAGE FROM ENGINES IN CASE IS CACHED
for (OEngine engine : engines.values()) {
engine.removeStorage(storage);
}
} finally {
engineLock.writeLock().unlock();
}
}
Aggregations