public ORecordInternal<?> fromStream(
      final byte[] iSource, final ORecordInternal<?> iRecord, final String[] iFields) {
    final long timer = PROFILER.startChrono();

    try {
      return fromString(OBinaryProtocol.bytes2string(iSource), iRecord, iFields);
    } finally {

      PROFILER.stopChrono(
          PROFILER.getProcessMetric("serializer.record.string.fromStream"),
          "Deserialize record from stream",
          timer);
    }
  }
  public byte[] toStream(final ORecordInternal<?> iRecord, boolean iOnlyDelta) {
    final long timer = PROFILER.startChrono();

    try {
      return OBinaryProtocol.string2bytes(
          toString(
                  iRecord,
                  new StringBuilder(),
                  null,
                  null,
                  OSerializationLongIdThreadLocal.INSTANCE.get(),
                  iOnlyDelta,
                  true)
              .toString());
    } finally {

      PROFILER.stopChrono(
          PROFILER.getProcessMetric("serializer.record.string.toStream"),
          "Serialize record to stream",
          timer);
    }
  }
예제 #3
0
파일: Orient.java 프로젝트: xamidi/orientdb
  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();
    }
  }
예제 #4
0
파일: Orient.java 프로젝트: xamidi/orientdb
  protected Orient() {
    // REGISTER THE EMBEDDED ENGINE
    registerEngine(new OEngineLocal());
    registerEngine(new OEngineLocalPaginated());
    registerEngine(new OEngineMemory());
    registerEngine("com.orientechnologies.orient.client.remote.OEngineRemote");

    profiler = new OJVMProfiler();
    if (OGlobalConfiguration.PROFILER_ENABLED.getValueAsBoolean())
      // ACTIVATE RECORDING OF THE PROFILER
      profiler.startRecording();

    if (OGlobalConfiguration.ENVIRONMENT_DUMP_CFG_AT_STARTUP.getValueAsBoolean())
      OGlobalConfiguration.dumpConfiguration(System.out);

    memoryWatchDog = new OMemoryWatchDog();

    active = true;
  }
  public static void fieldTypeToString(
      final StringBuilder iBuffer, OType iType, final Object iValue) {
    if (iValue == null) return;

    final long timer = PROFILER.startChrono();

    if (iType == null) {
      if (iValue instanceof ORID) iType = OType.LINK;
      else iType = OType.EMBEDDED;
    }

    switch (iType) {
      case STRING:
        simpleValueToStream(iBuffer, iType, iValue);
        PROFILER.stopChrono(
            PROFILER.getProcessMetric("serializer.record.string.string2string"),
            "Serialize string to string",
            timer);
        break;

      case BOOLEAN:
        simpleValueToStream(iBuffer, iType, iValue);
        PROFILER.stopChrono(
            PROFILER.getProcessMetric("serializer.record.string.bool2string"),
            "Serialize boolean to string",
            timer);
        break;

      case INTEGER:
        simpleValueToStream(iBuffer, iType, iValue);
        PROFILER.stopChrono(
            PROFILER.getProcessMetric("serializer.record.string.int2string"),
            "Serialize integer to string",
            timer);
        break;

      case FLOAT:
        simpleValueToStream(iBuffer, iType, iValue);
        PROFILER.stopChrono(
            PROFILER.getProcessMetric("serializer.record.string.float2string"),
            "Serialize float to string",
            timer);
        break;

      case DECIMAL:
        simpleValueToStream(iBuffer, iType, iValue);
        PROFILER.stopChrono(
            PROFILER.getProcessMetric("serializer.record.string.decimal2string"),
            "Serialize decimal to string",
            timer);
        break;

      case LONG:
        simpleValueToStream(iBuffer, iType, iValue);
        PROFILER.stopChrono(
            PROFILER.getProcessMetric("serializer.record.string.long2string"),
            "Serialize long to string",
            timer);
        break;

      case DOUBLE:
        simpleValueToStream(iBuffer, iType, iValue);
        PROFILER.stopChrono(
            PROFILER.getProcessMetric("serializer.record.string.double2string"),
            "Serialize double to string",
            timer);
        break;

      case SHORT:
        simpleValueToStream(iBuffer, iType, iValue);
        PROFILER.stopChrono(
            PROFILER.getProcessMetric("serializer.record.string.short2string"),
            "Serialize short to string",
            timer);
        break;

      case BYTE:
        simpleValueToStream(iBuffer, iType, iValue);
        PROFILER.stopChrono(
            PROFILER.getProcessMetric("serializer.record.string.byte2string"),
            "Serialize byte to string",
            timer);
        break;

      case BINARY:
        simpleValueToStream(iBuffer, iType, iValue);
        PROFILER.stopChrono(
            PROFILER.getProcessMetric("serializer.record.string.binary2string"),
            "Serialize binary to string",
            timer);
        break;

      case DATE:
        simpleValueToStream(iBuffer, iType, iValue);
        PROFILER.stopChrono(
            PROFILER.getProcessMetric("serializer.record.string.date2string"),
            "Serialize date to string",
            timer);
        break;

      case DATETIME:
        simpleValueToStream(iBuffer, iType, iValue);
        PROFILER.stopChrono(
            PROFILER.getProcessMetric("serializer.record.string.datetime2string"),
            "Serialize datetime to string",
            timer);
        break;

      case LINK:
        if (iValue instanceof ORecordId) ((ORecordId) iValue).toString(iBuffer);
        else ((ORecord<?>) iValue).getIdentity().toString(iBuffer);
        PROFILER.stopChrono(
            PROFILER.getProcessMetric("serializer.record.string.link2string"),
            "Serialize link to string",
            timer);
        break;

      case EMBEDDEDSET:
        ORecordSerializerSchemaAware2CSV.INSTANCE.embeddedCollectionToStream(
            ODatabaseRecordThreadLocal.INSTANCE.getIfDefined(),
            null,
            iBuffer,
            null,
            null,
            iValue,
            null,
            true);
        PROFILER.stopChrono(
            PROFILER.getProcessMetric("serializer.record.string.embedSet2string"),
            "Serialize embeddedset to string",
            timer);
        break;

      case EMBEDDEDLIST:
        ORecordSerializerSchemaAware2CSV.INSTANCE.embeddedCollectionToStream(
            ODatabaseRecordThreadLocal.INSTANCE.getIfDefined(),
            null,
            iBuffer,
            null,
            null,
            iValue,
            null,
            true);
        PROFILER.stopChrono(
            PROFILER.getProcessMetric("serializer.record.string.embedList2string"),
            "Serialize embeddedlist to string",
            timer);
        break;

      case EMBEDDEDMAP:
        ORecordSerializerSchemaAware2CSV.INSTANCE.embeddedMapToStream(
            ODatabaseRecordThreadLocal.INSTANCE.getIfDefined(),
            null,
            iBuffer,
            null,
            null,
            iValue,
            null,
            true);
        PROFILER.stopChrono(
            PROFILER.getProcessMetric("serializer.record.string.embedMap2string"),
            "Serialize embeddedmap to string",
            timer);
        break;

      case EMBEDDED:
        OStringSerializerEmbedded.INSTANCE.toStream(iBuffer, iValue);
        PROFILER.stopChrono(
            PROFILER.getProcessMetric("serializer.record.string.embed2string"),
            "Serialize embedded to string",
            timer);
        break;

      case CUSTOM:
        OStringSerializerAnyStreamable.INSTANCE.toStream(iBuffer, iValue);
        PROFILER.stopChrono(
            PROFILER.getProcessMetric("serializer.record.string.custom2string"),
            "Serialize custom to string",
            timer);
        break;

      default:
        throw new IllegalArgumentException(
            "Type " + iType + " not supported to convert value: " + iValue);
    }
  }