Examples of OJSONWriter


Examples of com.orientechnologies.orient.core.serialization.serializer.OJSONWriter

    iRequest.data.commandInfo = "Server status";

    try {
      StringWriter jsonBuffer = new StringWriter();
      OJSONWriter json = new OJSONWriter(jsonBuffer);

      json.beginObject();

      json.beginCollection(1, true, "connections");

      String lastCommandOn;
      String connectedOn;

      final OClientConnection[] conns = OServerMain.server().getManagedServer().getConnections();
      for (OClientConnection c : conns) {
        synchronized (dateTimeFormat) {
          lastCommandOn = dateTimeFormat.format(new Date(c.protocol.getData().lastCommandReceived));
          connectedOn = dateTimeFormat.format(new Date(c.since));
        }

        json.beginObject(2);
        writeField(json, 2, "id", c.id);
        writeField(json, 2, "id", c.id);
        writeField(json, 2, "remoteAddress", c.protocol.getChannel() != null ? c.protocol.getChannel().toString() : "Disconnected");
        writeField(json, 2, "db", c.database != null ? c.database.getName() : "-");
        writeField(json, 2, "user", c.database != null && c.database.getUser() != null ? c.database.getUser().getName() : "-");
        writeField(json, 2, "protocol", c.protocol.getName());
        writeField(json, 2, "totalRequests", c.protocol.getData().totalRequests);
        writeField(json, 2, "commandInfo", c.protocol.getData().commandInfo);
        writeField(json, 2, "commandDetail", c.protocol.getData().commandDetail);
        writeField(json, 2, "lastCommandOn", lastCommandOn);
        writeField(json, 2, "lastCommandInfo", c.protocol.getData().lastCommandInfo);
        writeField(json, 2, "lastCommandDetail", c.protocol.getData().lastCommandDetail);
        writeField(json, 2, "lastExecutionTime", c.protocol.getData().lastCommandExecutionTime);
        writeField(json, 2, "totalWorkingTime", c.protocol.getData().totalCommandExecutionTime);
        writeField(json, 2, "connectedOn", connectedOn);
        json.endObject(2);
      }
      json.endCollection(1, false);

      json.beginCollection(1, true, "dbs");
      Map<String, OResourcePool<String, ODatabaseDocumentTx>> dbPool = OSharedDocumentDatabase.getDatabasePools();
      for (Entry<String, OResourcePool<String, ODatabaseDocumentTx>> entry : dbPool.entrySet()) {
        for (ODatabaseDocumentTx db : entry.getValue().getResources()) {

          json.beginObject(2);
          writeField(json, 2, "db", db.getName());
          writeField(json, 2, "user", db.getUser() != null ? db.getUser().getName() : "-");
          writeField(json, 2, "open", db.isClosed() ? "closed" : "open");
          writeField(json, 2, "storage", db.getStorage().getClass().getSimpleName());
          json.endObject(2);
        }
      }
      json.endCollection(1, false);

      json.beginCollection(1, true, "storages");
      OStorage[] storages = OServerMain.server().getManagedServer().getOpenedStorages();
      for (OStorage s : storages) {
        json.beginObject(2);
        writeField(json, 2, "name", s.getName());
        writeField(json, 2, "type", s.getClass().getSimpleName());
        writeField(json, 2, "path", s instanceof OStorageLocal ? ((OStorageLocal) s).getStoragePath().replace('\\', '/') : "");
        writeField(json, 2, "activeUsers", s.getUsers());
        json.endObject(2);
      }
      json.endCollection(1, false);

      json.beginCollection(2, true, "properties");
      for (OServerEntryConfiguration entry : OServerMain.server().getConfiguration().properties) {
        json.beginObject(3, true, null);
        json.writeAttribute(4, false, "name", entry.name);
        json.writeAttribute(4, false, "value", entry.value);
        json.endObject(3, true);
      }
      json.endCollection(2, true);

      json.beginObject(1, true, "profiler");
      json.beginCollection(2, true, "counters");
      for (String c : OProfiler.getInstance().getCounters()) {
        json.beginObject(3);
        writeField(json, 3, "name", c);
        writeField(json, 3, "value", OProfiler.getInstance().getCounter(c));
        json.endObject(3);
      }
      json.endCollection(2, false);

      OProfilerEntry pEntry;

      json.beginCollection(2, true, "stats");
      for (String s : OProfiler.getInstance().getStats()) {
        pEntry = OProfiler.getInstance().getStat(s);

        json.beginObject(3);
        writeField(json, 3, "name", s);
        writeField(json, 3, "total", pEntry.items);
        writeField(json, 3, "averageElapsed", pEntry.average);
        writeField(json, 3, "minElapsed", pEntry.min);
        writeField(json, 3, "maxElapsed", pEntry.max);
        writeField(json, 3, "lastElapsed", pEntry.last);
        writeField(json, 3, "totalElapsed", pEntry.total);
        json.endObject(3);
      }
      json.endCollection(2, false);

      json.beginCollection(2, true, "chronos");
      for (String c : OProfiler.getInstance().getChronos()) {
        pEntry = OProfiler.getInstance().getChrono(c);

        json.beginObject(3);
        writeField(json, 3, "name", c);
        writeField(json, 3, "total", pEntry.items);
        writeField(json, 3, "averageElapsed", pEntry.average);
        writeField(json, 3, "minElapsed", pEntry.min);
        writeField(json, 3, "maxElapsed", pEntry.max);
        writeField(json, 3, "lastElapsed", pEntry.last);
        writeField(json, 3, "totalElapsed", pEntry.total);
        json.endObject(3);
      }
      json.endCollection(2, false);
      json.endObject(1);

      json.endObject();

      sendTextContent(iRequest, OHttpUtils.STATUS_OK_CODE, "OK", null, OHttpUtils.CONTENT_JSON, jsonBuffer.toString());

    } finally {
    }
View Full Code Here

Examples of com.orientechnologies.orient.core.serialization.serializer.OJSONWriter

        db = OSharedDocumentDatabase.acquire(urlParts[1], urlParts[2], urlParts[3]);
      } else
        db = getProfiledDatabaseInstance(iRequest);

      final StringWriter buffer = new StringWriter();
      final OJSONWriter json = new OJSONWriter(buffer);

      json.beginObject();
      if (db.getMetadata().getSchema().getClasses() != null) {
        json.beginCollection(1, false, "classes");
        for (OClass cls : db.getMetadata().getSchema().getClasses()) {
          try {
            exportClass(db, json, cls);
          } catch (Exception e) {
            OLogManager.instance().error(this, "Error on exporting class '" + cls + "'", e);
          }
        }
        json.endCollection(1, true);
      }

      if (db.getStorage() instanceof OStorageLocal) {
        json.beginCollection(1, false, "dataSegments");
        for (ODataLocal data : ((OStorageLocal) db.getStorage()).getDataSegments()) {
          json.beginObject(2, true, null);
          json.writeAttribute(3, false, "id", data.getId());
          json.writeAttribute(3, false, "name", data.getName());
          json.writeAttribute(3, false, "size", data.getSize());
          json.writeAttribute(3, false, "filled", data.getFilledUpTo());
          json.writeAttribute(3, false, "maxSize", data.getConfig().maxSize);
          json.writeAttribute(3, false, "files", Arrays.toString(data.getConfig().infoFiles));
          json.endObject(2, false);
        }
        json.endCollection(1, true);
      }

      if (db.getClusterNames() != null) {
        json.beginCollection(1, false, "clusters");
        OCluster cluster;
        for (String clusterName : db.getClusterNames()) {
          cluster = ((OStorageEmbedded) db.getStorage()).getClusterById(db.getClusterIdByName(clusterName));

          try {
            json.beginObject(2, true, null);
            json.writeAttribute(3, false, "id", cluster.getId());
            json.writeAttribute(3, false, "name", clusterName);
            json.writeAttribute(3, false, "type", cluster.getType());
            json.writeAttribute(3, false, "records", cluster.getEntries());
            if (cluster instanceof OClusterLocal) {
              json.writeAttribute(3, false, "size", ((OClusterLocal) cluster).getSize());
              json.writeAttribute(3, false, "filled", ((OClusterLocal) cluster).getFilledUpTo());
              json.writeAttribute(3, false, "maxSize", ((OClusterLocal) cluster).getConfig().maxSize);
              json.writeAttribute(3, false, "files", Arrays.toString(((OClusterLocal) cluster).getConfig().infoFiles));
            } else {
              json.writeAttribute(3, false, "size", "-");
              json.writeAttribute(3, false, "filled", "-");
              json.writeAttribute(3, false, "maxSize", "-");
              json.writeAttribute(3, false, "files", "-");
            }
          } catch (Exception e) {
            json.writeAttribute(3, false, "records", "? (Unauthorized)");
          }
          json.endObject(2, false);
        }
        json.endCollection(1, true);
      }

      if (db.getStorage() instanceof OStorageLocal) {
        json.beginCollection(1, false, "txSegment");
        final OTxSegment txSegment = ((OStorageLocal) db.getStorage()).getTxManager().getTxSegment();
        json.beginObject(2, true, null);
        json.writeAttribute(3, false, "totalLogs", txSegment.getTotalLogCount());
        json.writeAttribute(3, false, "size", txSegment.getSize());
        json.writeAttribute(3, false, "filled", txSegment.getFilledUpTo());
        json.writeAttribute(3, false, "maxSize", txSegment.getConfig().maxSize);
        json.writeAttribute(3, false, "file", txSegment.getConfig().path);
        json.endObject(2, false);
        json.endCollection(1, true);
      }

      json.beginCollection(1, false, "users");
      OUser user;
      for (ODocument doc : db.getMetadata().getSecurity().getUsers()) {
        user = new OUser(doc);
        json.beginObject(2, true, null);
        json.writeAttribute(3, false, "name", user.getName());
        json.writeAttribute(3, false, "roles", user.getRoles() != null ? Arrays.toString(user.getRoles().toArray()) : "null");
        json.endObject(2, false);
      }
      json.endCollection(1, true);

      json.beginCollection(1, true, "roles");
      ORole role;
      for (ODocument doc : db.getMetadata().getSecurity().getRoles()) {
        role = new ORole(doc);
        json.beginObject(2, true, null);
        json.writeAttribute(3, false, "name", role.getName());
        json.writeAttribute(3, false, "mode", role.getMode().toString());

        json.beginCollection(3, true, "rules");
        for (Entry<String, Byte> rule : role.getRules().entrySet()) {
          json.beginObject(4);
          json.writeAttribute(4, true, "name", rule.getKey());
          json.writeAttribute(4, false, "create", role.allow(rule.getKey(), ORole.PERMISSION_CREATE));
          json.writeAttribute(4, false, "read", role.allow(rule.getKey(), ORole.PERMISSION_READ));
          json.writeAttribute(4, false, "update", role.allow(rule.getKey(), ORole.PERMISSION_UPDATE));
          json.writeAttribute(4, false, "delete", role.allow(rule.getKey(), ORole.PERMISSION_DELETE));
          json.endObject(4, true);
        }
        json.endCollection(3, false);

        json.endObject(2, true);
      }
      json.endCollection(1, true);

      json.beginObject(1, true, "config");

      json.beginCollection(2, true, "values");
      json.writeObjects(3, true, null,
          new Object[] { "name", "dateFormat", "value", db.getStorage().getConfiguration().dateFormat }, new Object[] { "name",
              "dateTimeFormat", "value", db.getStorage().getConfiguration().dateTimeFormat }, new Object[] { "name",
              "localeCountry", "value", db.getStorage().getConfiguration().localeCountry }, new Object[] { "name",
              "localeLanguage", "value", db.getStorage().getConfiguration().localeLanguage }, new Object[] { "name",
              "definitionVersion", "value", db.getStorage().getConfiguration().version });
      json.endCollection(2, true);

      json.beginCollection(2, true, "properties");
      if (db.getStorage().getConfiguration().properties != null)
        for (OStorageEntryConfiguration entry : db.getStorage().getConfiguration().properties) {
          if (entry != null) {
            json.beginObject(3, true, null);
            json.writeAttribute(4, false, "name", entry.name);
            json.writeAttribute(4, false, "value", entry.value);
            json.endObject(3, true);
          }
        }
      json.endCollection(2, true);

      json.endObject(1, true);
      json.endObject();
      json.flush();

      sendTextContent(iRequest, OHttpUtils.STATUS_OK_CODE, "OK", null, OHttpUtils.CONTENT_JSON, buffer.toString());
    } finally {
      if (db != null)
        OSharedDocumentDatabase.release(db);
View Full Code Here

Examples of com.orientechnologies.orient.core.serialization.serializer.OJSONWriter

  }

  protected void sendRecordsContent(final OHttpRequest iRequest, final List<ORecord<?>> iRecords, String iFetchPlan)
      throws IOException {
    final StringWriter buffer = new StringWriter();
    final OJSONWriter json = new OJSONWriter(buffer, JSON_FORMAT);
    json.beginObject();

    // WRITE ENTITY SCHEMA IF ANY
    if (iRecords != null && iRecords.size() > 0) {
      ORecord<?> first = iRecords.get(0);
      if (first != null && first instanceof ODocument) {
        ODatabaseRecord db = ((ODocument) first).getDatabase();

        String className = ((ODocument) first).getClassName();
        exportClassSchema(db, json, db.getMetadata().getSchema().getClass(className));
      }
    }

    final String format = iFetchPlan != null ? JSON_FORMAT + ",fetchPlan:" + iFetchPlan : JSON_FORMAT;

    // WRITE RECORDS
    json.beginCollection(1, true, "result");
    if (iRecords != null) {
      int counter = 0;
      String objectJson;
      for (ORecord<?> rec : iRecords) {
        if (rec != null)
          try {
            objectJson = rec.toJSON(format);

            if (counter++ > 0)
              buffer.append(", ");

            buffer.append(objectJson);
          } catch (Exception e) {
            OLogManager.instance().error(this, "Error transforming record " + rec.getIdentity() + " to JSON", e);
          }
      }
    }
    json.endCollection(1, true);

    json.endObject();

    sendTextContent(iRequest, OHttpUtils.STATUS_OK_CODE, "OK", null, OHttpUtils.CONTENT_JSON, buffer.toString());
  }
View Full Code Here

Examples of com.orientechnologies.orient.core.serialization.serializer.OJSONWriter

  @Override
  public StringWriter parse(final OHttpRequest iRequest, final Map<String, String> headers,
      final OHttpMultipartContentInputStream in, ODatabaseRecord database) throws IOException {
    final StringWriter buffer = new StringWriter();
    final OJSONWriter json = new OJSONWriter(buffer);
    json.beginObject();
    String fileName = headers.get(OHttpUtils.MULTIPART_CONTENT_FILENAME);
    int fileSize = 0;
    if (fileName.charAt(0) == '"') {
      fileName = new String(fileName.substring(1));
    }
    if (fileName.charAt(fileName.length() - 1) == '"') {
      fileName = new String(fileName.substring(0, fileName.length() - 1));
    }
    final OutputStream out = new BufferedOutputStream(new FileOutputStream(path + fileName.toString()));
    try {
      while (in.available() > 0) {
        int value = in.read();
        out.write(value);
        fileSize++;
      }
    } finally {
      out.flush();
      out.close();
    }
    json.writeAttribute(1, true, "name", fileName);
    json.writeAttribute(1, true, "type", headers.get(OHttpUtils.MULTIPART_CONTENT_TYPE));
    json.writeAttribute(1, true, "size", fileSize);
    json.endObject();
    return buffer;
  }
View Full Code Here

Examples of com.orientechnologies.orient.core.serialization.serializer.OJSONWriter

  @Override
  public StringBuilder toString(final ORecordInternal<?> iRecord, final StringBuilder iOutput, final String iFormat,
      final OUserObject2RecordHandler iObjHandler, final Set<Integer> iMarshalledRecords, boolean iOnlyDelta) {
    try {
      final StringWriter buffer = new StringWriter();
      final OJSONWriter json = new OJSONWriter(buffer, iFormat);
      final Set<ORID> parsedRecords = new HashSet<ORID>();

      boolean includeVer;
      boolean includeType;
      boolean includeId;
      boolean includeClazz;
      boolean attribSameRow;
      int indentLevel;
      String fetchPlan = null;
      boolean keepTypes;

      if (iFormat == null) {
        includeType = true;
        includeVer = true;
        includeId = true;
        includeClazz = true;
        attribSameRow = true;
        indentLevel = 0;
        fetchPlan = "";
        keepTypes = false;
      } else {
        includeType = false;
        includeVer = false;
        includeId = false;
        includeClazz = false;
        attribSameRow = false;
        indentLevel = 0;
        keepTypes = false;

        final String[] format = iFormat.split(",");
        for (String f : format)
          if (f.equals("type"))
            includeType = true;
          else if (f.equals("rid"))
            includeId = true;
          else if (f.equals("version"))
            includeVer = true;
          else if (f.equals("class"))
            includeClazz = true;
          else if (f.equals("attribSameRow"))
            attribSameRow = true;
          else if (f.startsWith("indent"))
            indentLevel = Integer.parseInt(f.substring(f.indexOf(':') + 1));
          else if (f.startsWith("fetchPlan"))
            fetchPlan = f.substring(f.indexOf(':') + 1);
          else if (f.startsWith("keepTypes"))
            keepTypes = true;
      }

      json.beginObject(indentLevel);

      writeSignature(json, indentLevel, includeType, includeId, includeVer, includeClazz, attribSameRow, iRecord);

      if (iRecord instanceof ORecordSchemaAware<?>) {
        // SCHEMA AWARE
        final ORecordSchemaAware<?> record = (ORecordSchemaAware<?>) iRecord;
        parsedRecords.add(iRecord.getIdentity());

        Map<String, Integer> fetchPlanMap = null;
        if (fetchPlan != null && fetchPlan.length() > 0)
          fetchPlanMap = OFetchHelper.buildFetchPlan(fetchPlan);

        processRecord(json, indentLevel, includeType, includeId, includeVer, includeClazz, attribSameRow, record, fetchPlanMap,
            keepTypes, 0, -1, parsedRecords);
      } else if (iRecord instanceof ORecordStringable) {

        // STRINGABLE
        final ORecordStringable record = (ORecordStringable) iRecord;
        json.writeAttribute(indentLevel + 1, true, "value", record.value());

      } else if (iRecord instanceof ORecordBytes) {
        // BYTES
        final ORecordBytes record = (ORecordBytes) iRecord;
        json.writeAttribute(indentLevel + 1, true, "value", OBase64Utils.encodeBytes(record.toStream()));
      } else

        throw new OSerializationException("Error on marshalling record of type '" + iRecord.getClass()
            + "' to JSON. The record type can't be exported to JSON");

      json.endObject(indentLevel);
      parsedRecords.clear();

      iOutput.append(buffer);
      return iOutput;
    } catch (IOException e) {
View Full Code Here

Examples of com.orientechnologies.orient.core.serialization.serializer.OJSONWriter

    final File f = new File(fileName);
    f.mkdirs();
    if (f.exists())
      f.delete();

    writer = new OJSONWriter(new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(fileName))));
    writer.beginObject();
    iDatabase.getLevel1Cache().setEnable(false);
    iDatabase.getLevel2Cache().setEnable(false);
  }
View Full Code Here

Examples of com.orientechnologies.orient.core.serialization.serializer.OJSONWriter

  public ODatabaseExport(final ODatabaseRecord iDatabase, final OutputStream iOutputStream, final OCommandOutputListener iListener)
      throws IOException {
    super(iDatabase, "streaming", iListener);

    writer = new OJSONWriter(new OutputStreamWriter(iOutputStream));
    writer.beginObject();
    iDatabase.getLevel1Cache().setEnable(false);
    iDatabase.getLevel2Cache().setEnable(false);
  }
View Full Code Here

Examples of com.orientechnologies.orient.core.serialization.serializer.OJSONWriter

  @Override
  public StringBuilder toString(final ORecordInternal<?> iRecord, final StringBuilder iOutput, final String iFormat,
      final OUserObject2RecordHandler iObjHandler, final Set<Integer> iMarshalledRecords, boolean iOnlyDelta) {
    try {
      final StringWriter buffer = new StringWriter();
      final OJSONWriter json = new OJSONWriter(buffer, iFormat);
      final Set<ORID> parsedRecords = new HashSet<ORID>();

      boolean includeVer;
      boolean includeType;
      boolean includeId;
      boolean includeClazz;
      boolean attribSameRow;
      int indentLevel;
      String fetchPlan = null;
      boolean keepTypes;

      if (iFormat == null) {
        includeType = true;
        includeVer = true;
        includeId = true;
        includeClazz = true;
        attribSameRow = true;
        indentLevel = 0;
        fetchPlan = "";
        keepTypes = false;
      } else {
        includeType = false;
        includeVer = false;
        includeId = false;
        includeClazz = false;
        attribSameRow = false;
        indentLevel = 0;
        keepTypes = false;

        final String[] format = iFormat.split(",");
        for (String f : format)
          if (f.equals("type"))
            includeType = true;
          else if (f.equals("rid"))
            includeId = true;
          else if (f.equals("version"))
            includeVer = true;
          else if (f.equals("class"))
            includeClazz = true;
          else if (f.equals("attribSameRow"))
            attribSameRow = true;
          else if (f.startsWith("indent"))
            indentLevel = Integer.parseInt(f.substring(f.indexOf(':') + 1));
          else if (f.startsWith("fetchPlan"))
            fetchPlan = f.substring(f.indexOf(':') + 1);
          else if (f.startsWith("keepTypes"))
            keepTypes = true;
      }

      json.beginObject(indentLevel);

      writeSignature(json, indentLevel, includeType, includeId, includeVer, includeClazz, attribSameRow, iRecord);

      if (iRecord instanceof ORecordSchemaAware<?>) {
        // SCHEMA AWARE
        final ORecordSchemaAware<?> record = (ORecordSchemaAware<?>) iRecord;
        parsedRecords.add(iRecord.getIdentity());

        Map<String, Integer> fetchPlanMap = null;
        if (fetchPlan != null && fetchPlan.length() > 0)
          fetchPlanMap = OFetchHelper.buildFetchPlan(fetchPlan);

        processRecord(json, indentLevel, includeType, includeId, includeVer, includeClazz, attribSameRow, record, fetchPlanMap,
            keepTypes, 0, -1, parsedRecords);
      } else if (iRecord instanceof ORecordStringable) {

        // STRINGABLE
        final ORecordStringable record = (ORecordStringable) iRecord;
        json.writeAttribute(indentLevel + 1, true, "value", record.value());

      } else if (iRecord instanceof ORecordBytes) {
        // BYTES
        final ORecordBytes record = (ORecordBytes) iRecord;
        json.writeAttribute(indentLevel + 1, true, "value", OBase64Utils.encodeBytes(record.toStream()));
      } else

        throw new OSerializationException("Error on marshalling record of type '" + iRecord.getClass()
            + "' to JSON. The record type can't be exported to JSON");

      json.endObject(indentLevel);
      parsedRecords.clear();

      iOutput.append(buffer);
      return iOutput;
    } catch (IOException e) {
View Full Code Here

Examples of com.orientechnologies.orient.core.serialization.serializer.OJSONWriter

    iRequest.data.commandInfo = "Server status";

    try {
      StringWriter jsonBuffer = new StringWriter();
      OJSONWriter json = new OJSONWriter(jsonBuffer);

      json.beginObject();

      json.beginCollection(1, true, "connections");

      String lastCommandOn;
      String connectedOn;

      final OClientConnection[] conns = OServerMain.server().getManagedServer().getConnections();
      for (OClientConnection c : conns) {
        synchronized (dateTimeFormat) {
          lastCommandOn = dateTimeFormat.format(new Date(c.protocol.getData().lastCommandReceived));
          connectedOn = dateTimeFormat.format(new Date(c.since));
        }

        json.beginObject(2);
        writeField(json, 2, "id", c.id);
        writeField(json, 2, "id", c.id);
        writeField(json, 2, "remoteAddress", c.protocol.getChannel() != null ? c.protocol.getChannel().toString() : "Disconnected");
        writeField(json, 2, "db", c.database != null ? c.database.getName() : "-");
        writeField(json, 2, "user", c.database != null && c.database.getUser() != null ? c.database.getUser().getName() : "-");
        writeField(json, 2, "protocol", c.protocol.getName());
        writeField(json, 2, "totalRequests", c.protocol.getData().totalRequests);
        writeField(json, 2, "commandInfo", c.protocol.getData().commandInfo);
        writeField(json, 2, "commandDetail", c.protocol.getData().commandDetail);
        writeField(json, 2, "lastCommandOn", lastCommandOn);
        writeField(json, 2, "lastCommandInfo", c.protocol.getData().lastCommandInfo);
        writeField(json, 2, "lastCommandDetail", c.protocol.getData().lastCommandDetail);
        writeField(json, 2, "lastExecutionTime", c.protocol.getData().lastCommandExecutionTime);
        writeField(json, 2, "totalWorkingTime", c.protocol.getData().totalCommandExecutionTime);
        writeField(json, 2, "connectedOn", connectedOn);
        json.endObject(2);
      }
      json.endCollection(1, false);

      json.beginCollection(1, true, "dbs");
      Map<String, OResourcePool<String, ODatabaseDocumentTx>> dbPool = OSharedDocumentDatabase.getDatabasePools();
      for (Entry<String, OResourcePool<String, ODatabaseDocumentTx>> entry : dbPool.entrySet()) {
        for (ODatabaseDocumentTx db : entry.getValue().getResources()) {

          json.beginObject(2);
          writeField(json, 2, "db", db.getName());
          writeField(json, 2, "user", db.getUser() != null ? db.getUser().getName() : "-");
          writeField(json, 2, "open", db.isClosed() ? "closed" : "open");
          writeField(json, 2, "storage", db.getStorage().getClass().getSimpleName());
          json.endObject(2);
        }
      }
      json.endCollection(1, false);

      json.beginCollection(1, true, "storages");
      OStorage[] storages = OServerMain.server().getManagedServer().getOpenedStorages();
      for (OStorage s : storages) {
        json.beginObject(2);
        writeField(json, 2, "name", s.getName());
        writeField(json, 2, "type", s.getClass().getSimpleName());
        writeField(json, 2, "path", s instanceof OStorageLocal ? ((OStorageLocal) s).getStoragePath().replace('\\', '/') : "");
        writeField(json, 2, "activeUsers", s.getUsers());
        json.endObject(2);
      }
      json.endCollection(1, false);

      json.beginCollection(2, true, "properties");
      for (OServerEntryConfiguration entry : OServerMain.server().getConfiguration().properties) {
        json.beginObject(3, true, null);
        json.writeAttribute(4, false, "name", entry.name);
        json.writeAttribute(4, false, "value", entry.value);
        json.endObject(3, true);
      }
      json.endCollection(2, true);

      json.beginObject(1, true, "profiler");
      json.beginCollection(2, true, "hookValues");
      for (String h : OProfiler.getInstance().getHooks()) {
        json.beginObject(3);
        writeField(json, 3, "name", h);
        writeField(json, 3, "value", OProfiler.getInstance().getHookValue(h));
        json.endObject(3);
      }
      json.endCollection(2, false);
     
      json.beginCollection(2, true, "counters");
      for (String c : OProfiler.getInstance().getCounters()) {
        json.beginObject(3);
        writeField(json, 3, "name", c);
        writeField(json, 3, "value", OProfiler.getInstance().getCounter(c));
        json.endObject(3);
      }
      json.endCollection(2, false);

      OProfilerEntry pEntry;

      json.beginCollection(2, true, "stats");
      for (String s : OProfiler.getInstance().getStats()) {
        pEntry = OProfiler.getInstance().getStat(s);

        json.beginObject(3);
        writeField(json, 3, "name", s);
        writeField(json, 3, "total", pEntry.items);
        writeField(json, 3, "averageElapsed", pEntry.average);
        writeField(json, 3, "minElapsed", pEntry.min);
        writeField(json, 3, "maxElapsed", pEntry.max);
        writeField(json, 3, "lastElapsed", pEntry.last);
        writeField(json, 3, "totalElapsed", pEntry.total);
        json.endObject(3);
      }
      json.endCollection(2, false);

      json.beginCollection(2, true, "chronos");
      for (String c : OProfiler.getInstance().getChronos()) {
        pEntry = OProfiler.getInstance().getChrono(c);

        json.beginObject(3);
        writeField(json, 3, "name", c);
        writeField(json, 3, "total", pEntry.items);
        writeField(json, 3, "averageElapsed", pEntry.average);
        writeField(json, 3, "minElapsed", pEntry.min);
        writeField(json, 3, "maxElapsed", pEntry.max);
        writeField(json, 3, "lastElapsed", pEntry.last);
        writeField(json, 3, "totalElapsed", pEntry.total);
        json.endObject(3);
      }
      json.endCollection(2, false);
      json.endObject(1);

      json.endObject();

      sendTextContent(iRequest, OHttpUtils.STATUS_OK_CODE, "OK", null, OHttpUtils.CONTENT_JSON, jsonBuffer.toString());

    } finally {
    }
View Full Code Here

Examples of com.orientechnologies.orient.core.serialization.serializer.OJSONWriter

  }

  protected void sendRecordsContent(final OHttpRequest iRequest, final List<ORecord<?>> iRecords, final String iFetchPlan)
      throws IOException {
    final StringWriter buffer = new StringWriter();
    final OJSONWriter json = new OJSONWriter(buffer, JSON_FORMAT);
    json.beginObject();

    // WRITE ENTITY SCHEMA IF ANY
    if (iRecords != null && iRecords.size() > 0) {
      ORecord<?> first = iRecords.get(0);
      if (first != null && first instanceof ODocument) {
        ODatabaseRecord db = ((ODocument) first).getDatabase();

        final String className = ((ODocument) first).getClassName();
        exportClassSchema(db, json, db.getMetadata().getSchema().getClass(className));
      }
    }

    final String format = iFetchPlan != null ? JSON_FORMAT + ",fetchPlan:" + iFetchPlan : JSON_FORMAT;

    // WRITE RECORDS
    json.beginCollection(1, true, "result");
    if (iRecords != null) {
      int counter = 0;
      String objectJson;
      for (ORecord<?> rec : iRecords) {
        if (rec != null)
          try {
            objectJson = rec.toJSON(format);

            if (counter++ > 0)
              buffer.append(", ");

            buffer.append(objectJson);
          } catch (Exception e) {
            OLogManager.instance().error(this, "Error transforming record " + rec.getIdentity() + " to JSON", e);
          }
      }
    }
    json.endCollection(1, true);

    json.endObject();

    sendTextContent(iRequest, OHttpUtils.STATUS_OK_CODE, "OK", null, OHttpUtils.CONTENT_JSON, buffer.toString());
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.