示例#1
0
  protected void openRemoteDatabase() throws IOException {
    minPool = OGlobalConfiguration.CLIENT_CHANNEL_MIN_POOL.getValueAsInteger();
    maxPool = OGlobalConfiguration.CLIENT_CHANNEL_MAX_POOL.getValueAsInteger();

    if (connectionOptions != null && connectionOptions.size() > 0) {
      if (connectionOptions.containsKey(PARAM_MIN_POOL))
        minPool = Integer.parseInt(connectionOptions.get(PARAM_MIN_POOL).toString());
      if (connectionOptions.containsKey(PARAM_MAX_POOL))
        maxPool = Integer.parseInt(connectionOptions.get(PARAM_MAX_POOL).toString());
    }

    setSessionId(-1);
    createConnectionPool();

    OChannelBinaryClient network = null;
    try {
      network = beginRequest(OChannelBinaryProtocol.REQUEST_DB_OPEN);

      network.writeString(name).writeString(connectionUserName).writeString(connectionUserPassword);

    } finally {
      endRequest(network);
    }

    final int sessionId;

    try {
      beginResponse(network);

      sessionId = network.readInt();

      OLogManager.instance().debug(null, "Client connected with session id: " + sessionId);

      readDatabaseInformation(network);

      // READ CLUSTER CONFIGURATION
      clusterConfiguration = new ODocument(network.readBytes());

    } finally {
      endResponse(network);
    }

    setSessionId(sessionId);

    defaultClusterId = clustersIds.get(OStorage.CLUSTER_DEFAULT_NAME);

    status = STATUS.OPEN;
  }
示例#2
0
  public void close(final boolean iForce) {
    lock.acquireExclusiveLock();

    OChannelBinaryClient network = null;
    try {
      if (networkPool.size() > 0) {
        try {
          network = beginRequest(OChannelBinaryProtocol.REQUEST_DB_CLOSE);
        } finally {
          endRequest(network);
        }

        getResponse(network);
      }

      setSessionId(-1);

      if (!checkForClose(iForce)) return;

      // CLOSE THE CHANNEL
      if (serviceThread != null) {
        serviceThread.sendShutdown();
        serviceThread.interrupt();
      }

      synchronized (networkPool) {
        for (OChannelBinaryClient n : networkPool) n.close();
        networkPool.clear();
      }

      level2Cache.shutdown();
      super.close(iForce);
      status = STATUS.CLOSED;

      Orient.instance().unregisterStorage(this);

    } catch (OException e) {
      // PASS THROUGH
      throw e;
    } catch (Exception e) {
      OLogManager.instance().debug(this, "Error on closing remote connection: %s", network);
    } finally {

      lock.releaseExclusiveLock();
    }
  }