Esempio n. 1
0
  public void unregisterStorage(final OStorage iStorage) {
    if (!active)
      // SHUTDOWNING OR NOT ACTIVE: RETURN
      return;

    acquireExclusiveLock();
    try {
      // UNREGISTER ALL THE LISTENER ONE BY ONE AVOIDING SELF-RECURSION BY REMOVING FROM THE LIST
      final ArrayList<OOrientListener> listenerCopy = new ArrayList<OOrientListener>(listeners);
      for (Iterator<OOrientListener> it = listenerCopy.iterator(); it.hasNext(); ) {
        final OOrientListener l = it.next();
        listeners.remove(l);
        l.onStorageUnregistered(iStorage);
      }

      for (Entry<String, OStorage> s : storages.entrySet()) {
        if (s.getValue() == iStorage) {
          storages.remove(s.getKey());
          break;
        }
      }
    } finally {
      releaseExclusiveLock();
    }
  }
Esempio n. 2
0
  public OStorage registerStorage(final OStorage iStorage) throws IOException {
    acquireExclusiveLock();
    try {
      for (OOrientListener l : listeners) l.onStorageRegistered(iStorage);

      if (!storages.containsKey(iStorage.getName())) storages.put(iStorage.getName(), iStorage);

    } finally {
      releaseExclusiveLock();
    }
    return iStorage;
  }
Esempio n. 3
0
  public void shutdown() {
    acquireExclusiveLock();
    try {
      if (!active) return;

      active = false;

      if (shutdownHook != null) shutdownHook.cancel();
      if (profiler != null) profiler.shutdown();

      OLogManager.instance().debug(this, "Orient Engine is shutting down...");

      if (listeners != null)
        // CALL THE SHUTDOWN ON ALL THE LISTENERS
        for (OOrientListener l : listeners) {
          if (l != null) l.onShutdown();
        }

      // SHUTDOWN ENGINES
      for (OEngine engine : engines.values()) {
        engine.shutdown();
      }

      if (databaseFactory != null)
        // CLOSE ALL DATABASES
        databaseFactory.shutdown();

      if (storages != null) {
        // CLOSE ALL THE STORAGES
        final List<OStorage> storagesCopy = new ArrayList<OStorage>(storages.values());
        for (OStorage stg : storagesCopy) {
          OLogManager.instance().info(this, "Shutting down storage: " + stg.getName() + "...");
          stg.close(true);
        }
      }

      if (OMMapManagerLocator.getInstance() != null) OMMapManagerLocator.getInstance().shutdown();

      if (threadGroup != null)
        // STOP ALL THE PENDING THREADS
        threadGroup.interrupt();

      if (listeners != null) listeners.clear();

      OLogManager.instance().info(this, "Orient Engine shutdown complete\n");

    } finally {
      releaseExclusiveLock();
    }
  }
Esempio n. 4
0
  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);

    acquireExclusiveLock();
    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());

      // SEARCH FOR DB-NAME
      iURL = iURL.substring(pos + 1);
      pos = iURL.indexOf('?');

      Map<String, String> parameters = null;
      String dbPath = null;
      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;

      final String dbName;
      pos = dbPath.lastIndexOf('/');
      if (pos > -1) dbName = dbPath.substring(pos + 1);
      else dbName = dbPath;

      OStorage storage;
      if (engine.isShared()) {
        // SEARCH IF ALREADY USED
        storage = storages.get(dbName);
        if (storage == null) {
          // NOT FOUND: CREATE IT
          storage = engine.createStorage(dbPath, parameters);
          storages.put(dbName, storage);
        }
      } else {
        // REGISTER IT WITH A SERIAL NAME TO AVOID BEING REUSED
        storage = engine.createStorage(dbPath, parameters);
        storages.put(dbName + "__" + serialId.incrementAndGet(), storage);
      }

      for (OOrientListener l : listeners) l.onStorageRegistered(storage);

      return storage;

    } finally {
      releaseExclusiveLock();
    }
  }