本文整理了Java中org.codehaus.jettison.json.JSONObject.<init>()
方法的一些代码示例,展示了JSONObject.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONObject.<init>()
方法的具体详情如下:
包路径:org.codehaus.jettison.json.JSONObject
类名称:JSONObject
方法名:<init>
[英]Construct an empty JSONObject.
[中]构造一个空的JSONObject。
代码示例来源:origin: Netflix/Priam
private JSONObject createJson(
String primaryEndpoint,
String dataCenter,
String rack,
String status,
String state,
String load,
String owns,
String token)
throws JSONException {
JSONObject object = new JSONObject();
object.put("endpoint", primaryEndpoint);
object.put("dc", dataCenter);
object.put("rack", rack);
object.put("status", status);
object.put("state", state);
object.put("load", load);
object.put("owns", owns);
object.put("token", token);
return object;
}
代码示例来源:origin: Netflix/Priam
@GET
@Path("/decompress")
public Response decompress(@QueryParam("in") String in, @QueryParam("out") String out)
throws Exception {
SnappyCompression compress = new SnappyCompression();
compress.decompressAndClose(new FileInputStream(in), new FileOutputStream(out));
JSONObject object = new JSONObject();
object.put("Input compressed file", in);
object.put("Output decompress file", out);
return Response.ok(object.toString(), MediaType.APPLICATION_JSON).build();
}
}
代码示例来源:origin: Netflix/Priam
@GET
@Path("/compact")
public Response cassCompact() throws IOException, ExecutionException, InterruptedException {
JSONObject rootObj = new JSONObject();
try {
compaction.execute();
rootObj.put("Compcated", true);
return Response.ok().entity(rootObj).build();
} catch (Exception e) {
try {
rootObj.put("status", "ERRROR");
rootObj.put("desc", e.getLocalizedMessage());
} catch (Exception e1) {
return Response.status(503).entity("CompactionError").build();
}
return Response.status(503).entity(rootObj).build();
}
}
代码示例来源:origin: Netflix/Priam
private static JSONObject parseGossipInfo(String gossipinfo) throws JSONException {
String[] ginfo = gossipinfo.split("\n");
JSONObject rootObj = new JSONObject();
JSONObject obj = new JSONObject();
String key = "";
for (String line : ginfo) {
if (line.matches("^.*/.*$")) {
String[] data = line.split("/");
if (StringUtils.isNotBlank(key)) {
rootObj.put(key, obj);
obj = new JSONObject();
}
key = data[1];
} else if (line.matches("^ .*:.*$")) {
String[] kv = line.split(":");
kv[0] = kv[0].trim();
if (kv[0].equals("STATUS")) {
obj.put(kv[0], kv[1]);
String[] vv = kv[1].split(",");
obj.put("Token", vv[1]);
} else {
obj.put(kv[0], kv[1]);
}
}
}
if (StringUtils.isNotBlank(key)) rootObj.put(key, obj);
return rootObj;
}
代码示例来源:origin: Netflix/Priam
@GET
@Path("/flush")
public Response cassFlush() throws IOException, InterruptedException, ExecutionException {
JSONObject rootObj = new JSONObject();
try {
flush.execute();
rootObj.put("Flushed", true);
return Response.ok().entity(rootObj).build();
} catch (Exception e) {
try {
rootObj.put("status", "ERRROR");
rootObj.put("desc", e.getLocalizedMessage());
} catch (Exception e1) {
return Response.status(503).entity("FlushError").build();
}
return Response.status(503).entity(rootObj).build();
}
}
代码示例来源:origin: Netflix/Priam
@GET
@Path("/status")
@Produces(MediaType.APPLICATION_JSON)
public Response status() throws Exception {
JSONObject object = new JSONObject();
object.put("SnapshotStatus", snapshotBackup.state().toString());
return Response.ok(object.toString(), MediaType.APPLICATION_JSON).build();
}
代码示例来源:origin: Netflix/Priam
/**
* You must do the compaction before running this to remove the duplicate tokens out of the
* server. TODO code it.
*/
@SuppressWarnings("unchecked")
public JSONObject estimateKeys() throws JSONException {
Iterator<Entry<String, ColumnFamilyStoreMBean>> it =
super.getColumnFamilyStoreMBeanProxies();
JSONObject object = new JSONObject();
while (it.hasNext()) {
Entry<String, ColumnFamilyStoreMBean> entry = it.next();
object.put("keyspace", entry.getKey());
object.put("column_family", entry.getValue().getColumnFamilyName());
object.put("estimated_size", entry.getValue().estimateKeys());
}
return object;
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
protected JSONObject addPotentialActions(final HttpServletRequest request) throws JSONException {
final JSONObject potentialAction = new JSONObject();
potentialAction.put("@type", "SearchAction");
potentialAction.put("target", getSiteBaseUrl() + getSiteSearchUri());
potentialAction.put("query-input", "required name=query");
extensionManager.getProxy().addPotentialActionsData(request, potentialAction);
return potentialAction;
}
代码示例来源:origin: Netflix/Priam
@GET
@Path("/statusthrift")
public Response statusthrift()
throws IOException, ExecutionException, InterruptedException, JSONException {
JMXNodeTool nodeTool;
try {
nodeTool = JMXNodeTool.instance(config);
} catch (JMXConnectionException e) {
logger.error(
"Exception in fetching c* jmx tool . Msgl: {}", e.getLocalizedMessage(), e);
return Response.status(503).entity("JMXConnectionException").build();
}
return Response.ok(
new JSONObject()
.put(
"status",
(nodeTool.isThriftServerRunning()
? "running"
: "not running")),
MediaType.APPLICATION_JSON)
.build();
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
protected void addCategoryProductData(final HttpServletRequest request, final JSONObject categoryData) throws JSONException {
final List<Product> products = getProducts(request);
final JSONArray itemList = new JSONArray();
for (int i = 0; i < products.size(); i++) {
JSONObject item = new JSONObject();
item.put("@type", "ListItem");
item.put("position", i + 1);
item.put("url", products.get(i).getUrl());
itemList.put(item);
extensionManager.getProxy().addCategoryProductData(request, categoryData);
}
categoryData.put("itemListElement", itemList);
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
/**
* Generates an object representing the Schema.org WebSite
*
* @return JSON representation of WebSite from Schema.org
*/
protected JSONObject addWebSiteData(final HttpServletRequest request) throws JSONException {
JSONObject webSite = new JSONObject();
webSite.put("@context", DEFAULT_STRUCTURED_CONTENT_CONTEXT);
webSite.put("@type", "WebSite");
webSite.put("name", getSiteName());
webSite.put("url", getSiteBaseUrl());
webSite.put("potentialAction", addPotentialActions(request));
extensionManager.getProxy().addWebSiteData(request, webSite);
return webSite;
}
代码示例来源:origin: Netflix/Priam
@GET
@Path("/status/{date}/snapshots")
@Produces(MediaType.APPLICATION_JSON)
public Response snapshotsByDate(@PathParam("date") String date) throws Exception {
List<BackupMetadata> metadata = this.completedBkups.locate(date);
JSONObject object = new JSONObject();
List<String> snapshots = new ArrayList<>();
if (metadata != null && !metadata.isEmpty())
snapshots.addAll(
metadata.stream()
.filter(
backupMetadata ->
backupMetadata
.getBackupVersion()
.equals(BackupVersion.SNAPSHOT_BACKUP))
.map(
backupMetadata ->
DateUtil.formatyyyyMMddHHmm(backupMetadata.getStart()))
.collect(Collectors.toList()));
object.put("Snapshots", snapshots);
return Response.ok(object.toString(), MediaType.APPLICATION_JSON).build();
}
代码示例来源:origin: Netflix/Priam
@GET
@Path("/status/{date}")
@Produces(MediaType.APPLICATION_JSON)
public Response statusByDate(@PathParam("date") String date) throws Exception {
JSONObject object = new JSONObject();
Optional<BackupMetadata> backupMetadataOptional =
this.completedBkups
.locate(date)
.stream()
.filter(Objects::nonNull)
.filter(backupMetadata -> backupMetadata.getStatus() == Status.FINISHED)
.filter(
backupMetadata ->
backupMetadata
.getBackupVersion()
.equals(BackupVersion.SNAPSHOT_BACKUP))
.findFirst();
if (!backupMetadataOptional.isPresent()) {
object.put("Snapshotstatus", false);
} else {
object.put("Snapshotstatus", true);
object.put("Details", backupMetadataOptional.get().toString());
}
return Response.ok(object.toString(), MediaType.APPLICATION_JSON).build();
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
protected JSONArray addContactData(final HttpServletRequest request) throws JSONException {
final JSONArray contactList = new JSONArray();
final JSONObject contact = new JSONObject();
contact.put("@type", "ContactPoint");
contact.put("telephone", getSiteCustomerServiceNumber());
contact.put("contactType", "customerService");
extensionManager.getProxy().addContactData(request, contact);
contactList.put(contact);
return contactList;
}
代码示例来源:origin: Netflix/Priam
return Response.status(503).entity("JMXConnectionException").build();
JSONObject rootObj = new JSONObject();
CompactionManagerMBean cm = nodeTool.getCompactionManagerProxy();
rootObj.put("pending tasks", cm.getPendingTasks());
JSONArray compStats = new JSONArray();
for (Map<String, String> c : cm.getCompactions()) {
JSONObject cObj = new JSONObject();
cObj.put("id", c.get("id"));
cObj.put("keyspace", c.get("keyspace"));
cObj.put("columnfamily", c.get("columnfamily"));
cObj.put("bytesComplete", c.get("bytesComplete"));
代码示例来源:origin: Netflix/Priam
@SuppressWarnings("unchecked")
public JSONObject info() throws JSONException {
JSONObject object = new JSONObject();
object.put("gossip_active", isInitialized());
object.put("thrift_active", isThriftServerRunning());
object.put("token", getTokens().toString());
object.put("load", getLoadString());
object.put("generation_no", getCurrentGenerationNumber());
object.put("uptime", getUptime() / 1000);
MemoryUsage heapUsage = getHeapMemoryUsage();
double memUsed = (double) heapUsage.getUsed() / (1024 * 1024);
double memMax = (double) heapUsage.getMax() / (1024 * 1024);
object.put("heap_memory_mb", memUsed + "/" + memMax);
object.put("data_center", getDataCenter());
object.put("rack", getRack());
return object;
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
protected JSONArray getLinkedDataJsonInternal(final String url, final HttpServletRequest request,
final JSONArray schemaObjects) throws JSONException {
final JSONObject categoryData = new JSONObject();
categoryData.put("@context", getStructuredDataContext());
categoryData.put("@type", "ItemList");
addCategoryProductData(request, categoryData);
extensionManager.getProxy().addCategoryData(request, categoryData);
schemaObjects.put(categoryData);
return schemaObjects;
}
代码示例来源:origin: Netflix/Priam
Entry<String, JMXEnabledThreadPoolExecutorMBean> thread = threads.next();
JMXEnabledThreadPoolExecutorMBean threadPoolProxy = thread.getValue();
JSONObject tpObj = new JSONObject(); // "Pool Name", "Active",
tpObj.put("pool name", thread.getKey());
tpObj.put("active", threadPoolProxy.getActiveCount());
tpObj.put("pending", threadPoolProxy.getPendingTasks());
tpObj.put("completed", threadPoolProxy.getCompletedTasks());
tpObj.put("blocked", threadPoolProxy.getCurrentlyBlockedTasks());
threadPoolArray.put(tpObj);
JSONObject droppedMsgs = new JSONObject();
for (Entry<String, Integer> entry : nodeTool.getDroppedMessages().entrySet())
droppedMsgs.put(entry.getKey(), entry.getValue());
JSONObject rootObj = new JSONObject();
rootObj.put("thread pool", threadPoolArray);
rootObj.put("dropped messages", droppedMsgs);
代码示例来源:origin: apache/hive
private JSONObject createConfigJson(long containerSize, long cache, long xmx,
String java_home) throws JSONException {
JSONObject configs = new JSONObject();
configs.put("java.home", java_home);
configs.put(ConfVars.LLAP_DAEMON_YARN_CONTAINER_MB.varname,
HiveConf.getIntVar(conf, ConfVars.LLAP_DAEMON_YARN_CONTAINER_MB));
configs.put(ConfVars.LLAP_DAEMON_YARN_CONTAINER_MB.varname, containerSize);
configs.put(HiveConf.ConfVars.LLAP_IO_MEMORY_MAX_SIZE.varname,
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
protected JSONObject addProductData(final HttpServletRequest request, final Product product, final String url)
throws JSONException {
final JSONObject productData = new JSONObject();
productData.put("@context", DEFAULT_STRUCTURED_CONTENT_CONTEXT);
productData.put("@type", "Product");
productData.put("name", product.getName());
addImageUrl(product, productData);
productData.put("description", product.getLongDescription());
productData.put("brand", product.getManufacturer());
productData.put("url", url);
productData.put("sku", product.getDefaultSku().getId());
productData.put("category", product.getCategory().getName());
addSkus(request, product, productData, url);
extensionManager.getProxy().addProductData(request, product, productData);
return productData;
}
内容来源于网络,如有侵权,请联系作者删除!