List of usage examples for org.json.simple JSONArray clear
public void clear()
From source file:sce.Main.java
public String getSchedulerMetadata() { String result;//from w w w. jav a2s.co m try { SchedulerMetaData schedulerMetadata = sched.getMetaData(); JSONObject results_obj = new JSONObject(); JSONArray jsonList1 = new JSONArray(); jsonList1.add(schedulerMetadata.getNumberOfJobsExecuted()); jsonList1.add("Reports the number of jobs executed since the scheduler started"); results_obj.put("Number of jobs executed", jsonList1); JSONArray jsonList2 = new JSONArray(); jsonList2.add(schedulerMetadata.getRunningSince().toString()); jsonList2.add("Reports the date at which the scheduler started running"); results_obj.put("Running since", jsonList2); JSONArray jsonList3 = new JSONArray(); jsonList3.add(schedulerMetadata.getSchedulerInstanceId()); jsonList3.add("Reports the instance id of the scheduler"); results_obj.put("Scheduler instance id", jsonList3); JSONArray jsonList4 = new JSONArray(); jsonList4.add(schedulerMetadata.getSchedulerName()); jsonList4.add("Reports the name of the scheduler"); results_obj.put("Scheduler name", jsonList4); JSONArray jsonList5 = new JSONArray(); jsonList5.add(schedulerMetadata.isInStandbyMode() ? "yes" : "no"); jsonList5.add("Reports whether the scheduler is in standby mode"); results_obj.put("Standby mode", jsonList5); JSONArray jsonList6 = new JSONArray(); jsonList6.add(schedulerMetadata.isJobStoreClustered() ? "yes" : "no"); jsonList6.add("Reports whether or not the scheduler's JobStore is clustered"); results_obj.put("JobStore Clustered", jsonList6); JSONArray jsonList7 = new JSONArray(); jsonList7.add(schedulerMetadata.isJobStoreSupportsPersistence() ? "yes" : "no"); jsonList7.add("Reports whether or not the scheduler's JobStore instance supports persistence"); results_obj.put("JobStore supports persistence", jsonList7); JSONArray jsonList8 = new JSONArray(); jsonList8.add(schedulerMetadata.isSchedulerRemote() ? "yes" : "no"); jsonList8.add("Reports whether the scheduler is being used remotely (via RMI)"); results_obj.put("Remote Scheduler", jsonList8); JSONArray jsonList9 = new JSONArray(); jsonList9.add(schedulerMetadata.isShutdown() ? "yes" : "no"); jsonList9.add("Reports whether the scheduler has been shutdown"); results_obj.put("Scheduler shutdown", jsonList9); JSONArray jsonList10 = new JSONArray(); jsonList10.add(schedulerMetadata.isStarted() ? "yes" : "no"); jsonList10.add("Reports whether the scheduler has been started"); results_obj.put("Scheduler started", jsonList10); result = results_obj.toJSONString(); jsonList1.clear(); jsonList2.clear(); jsonList3.clear(); jsonList4.clear(); jsonList5.clear(); jsonList6.clear(); jsonList7.clear(); jsonList8.clear(); jsonList9.clear(); jsonList10.clear(); } catch (SchedulerException e) { result = ""; } return result; }
From source file:sce.Main.java
public String getSystemStatus() { String result;/*w w w.j ava 2 s . c o m*/ OperatingSystemMXBean omx = ManagementFactory.getOperatingSystemMXBean(); com.sun.management.OperatingSystemMXBean osMxBean = null; if (omx instanceof com.sun.management.OperatingSystemMXBean) { osMxBean = (com.sun.management.OperatingSystemMXBean) omx; } JSONObject results_obj = new JSONObject(); JSONArray jsonList1 = new JSONArray(); String arch = ""; if (osMxBean != null) { arch = osMxBean.getArch(); } jsonList1.add(arch != null ? arch : ""); jsonList1.add("Returns the operating system architecture"); results_obj.put("Operating System architecture", jsonList1); JSONArray jsonList2 = new JSONArray(); int availableProcessors = -1; if (osMxBean != null) { availableProcessors = osMxBean.getAvailableProcessors(); } jsonList2.add(Integer.toString(availableProcessors)); jsonList2.add("Reports the number of processors available to the Java virtual machine"); results_obj.put("Number of processors", jsonList2); JSONArray jsonList3 = new JSONArray(); String name = ""; if (osMxBean != null) { name = osMxBean.getName(); } jsonList3.add(name != null ? name : ""); jsonList3.add("Reports the operating system name"); results_obj.put("Operating System name", jsonList3); JSONArray jsonList4 = new JSONArray(); double systemLoadAverage = -1; if (osMxBean != null) { systemLoadAverage = osMxBean.getSystemLoadAverage(); } jsonList4.add(Double.toString(systemLoadAverage)); jsonList4.add( "Reports the system load average for the last minute. The system load average is the sum of the number of runnable entities queued to the available processors and the number of runnable entities running on the available processors averaged over a period of time. The way in which the load average is calculated is operating system specific but is typically a damped time-dependent average.\n" + "\n" + "If the load average is not available, a negative value is returned." + "\n" + "This value is designed to provide a hint about the system load and may be queried frequently. The load average may be unavailable on some platform where it is expensive to implement this method"); results_obj.put("System Load average", jsonList4); JSONArray jsonList5 = new JSONArray(); String version = ""; if (osMxBean != null) { version = osMxBean.getVersion(); } jsonList5.add(version != null ? version : ""); jsonList5.add("Reports the operating system version"); results_obj.put("Operating System version", jsonList5); JSONArray jsonList6 = new JSONArray(); long committedVirtualMemorySize = -1; if (osMxBean != null) { committedVirtualMemorySize = osMxBean.getCommittedVirtualMemorySize(); } jsonList6.add(Long.toString(committedVirtualMemorySize)); jsonList6.add( "Reports the amount of virtual memory that is guaranteed to be available to the running process in bytes, or -1 if this operation is not supported"); results_obj.put("Committed virtual memory", jsonList6); JSONArray jsonList7 = new JSONArray(); long freePhysicalMemorySize = -1; if (osMxBean != null) { freePhysicalMemorySize = osMxBean.getFreePhysicalMemorySize(); } jsonList7.add(Long.toString(freePhysicalMemorySize)); jsonList7.add("Reports the amount of free physical memory in bytes"); results_obj.put("Free physical memory", jsonList7); JSONArray jsonList8 = new JSONArray(); long freeSwapSpaceSize = -1; if (osMxBean != null) { freeSwapSpaceSize = osMxBean.getFreeSwapSpaceSize(); } jsonList8.add(Long.toString(freeSwapSpaceSize)); jsonList8.add("Reports the amount of free swap space in bytes"); results_obj.put("Free swap space", jsonList8); JSONArray jsonList9 = new JSONArray(); double processCpuLoad = -1; if (osMxBean != null) { processCpuLoad = osMxBean.getProcessCpuLoad(); } jsonList9.add(Double.toString(processCpuLoad)); jsonList9.add( "Returns the recent cpu usage for the Java Virtual Machine process. This value is a double in the [0.0, 1.0] interval. A value of 0.0 means that none of the CPUs were running threads from the JVM process during the recent period of time observed, while a value of 1.0 means that all CPUs were actively running threads from the JVM 100% of the time during the recent period being observed. Threads from the JVM include the application threads as well as the JVM internal threads. All values between 0.0 and 1.0 are possible depending of the activities going on in the JVM process and the whole system. If the Java Virtual Machine recent CPU usage is not available, the value reports a negative value"); results_obj.put("CPU load (JVM)", jsonList9); JSONArray jsonList10 = new JSONArray(); long processCpuTime = -1; if (osMxBean != null) { processCpuTime = osMxBean.getProcessCpuTime(); } jsonList10.add(Long.toString(processCpuTime)); jsonList10.add( "Returns the cpu time used by the process on which the Java virtual machine is running in nanoseconds. The returned value is of nanoseconds precision but not necessarily nanoseconds accuracy. This value reports -1 if the platform does not support this operation"); results_obj.put("Process CPU time", jsonList10); JSONArray jsonList11 = new JSONArray(); double systemCpuLoad = -1; if (osMxBean != null) { systemCpuLoad = osMxBean.getSystemCpuLoad(); } jsonList11.add(Double.toString(systemCpuLoad)); jsonList11.add( "Returns the recent cpu usage for the whole system. This value is a double in the [0.0, 1.0] interval. A value of 0.0 means that all CPUs were idle during the recent period of time observed, while a value of 1.0 means that all CPUs were actively running 100% of the time during the recent period being observed. All values between 0.0 and 1.0 are possible depending of the activities going on in the system. If the system recent cpu usage is not available, the value reports a negative value"); results_obj.put("CPU load", jsonList11); JSONArray jsonList12 = new JSONArray(); double totalPhysicalMemorySize = -1; if (osMxBean != null) { totalPhysicalMemorySize = osMxBean.getTotalPhysicalMemorySize(); } jsonList12.add(Double.toString(totalPhysicalMemorySize)); jsonList12.add("Returns the total amount of physical memory in bytes"); results_obj.put("Total physical memory", jsonList12); JSONArray jsonList13 = new JSONArray(); double totalSwapSpaceSize = -1; if (osMxBean != null) { totalSwapSpaceSize = osMxBean.getTotalSwapSpaceSize(); } jsonList13.add(Double.toString(totalSwapSpaceSize)); jsonList13.add("Returns the total amount of swap space in bytes"); results_obj.put("Total swap space", jsonList13); result = results_obj.toJSONString(); jsonList1.clear(); jsonList2.clear(); jsonList3.clear(); jsonList4.clear(); jsonList5.clear(); jsonList6.clear(); jsonList7.clear(); jsonList8.clear(); jsonList9.clear(); jsonList10.clear(); jsonList11.clear(); jsonList12.clear(); jsonList13.clear(); return result; }
From source file:scheduler.ServerThread.java
@SuppressWarnings("unchecked") public void localReceive(PrintWriter out) throws InterruptedException, ParseException { JSONArray responseList = new JSONArray(); JSONParser parser = new JSONParser(); int batchSize = 10; while (msg_cnt > 0) { while (!localRespQ.isEmpty()) { //waiting up to 100ms for an element to become available. String messageBody = localRespQ.poll(100, TimeUnit.MILLISECONDS); JSONObject resp = (JSONObject) parser.parse(messageBody); responseList.add(resp);//ww w . j av a 2 s . c o m msg_cnt--; if (responseList.size() == batchSize) { out.println(responseList.toString()); responseList.clear(); } } if (!responseList.isEmpty()) { out.println(responseList.toString()); responseList.clear(); } } }
From source file:scheduler.ServerThread.java
@SuppressWarnings("unchecked") public void remoteBatchReceive(PrintWriter out) throws ParseException { JSONArray responseList = new JSONArray(); JSONParser parser = new JSONParser(); while (msg_cnt > 0) { while (resQ.getQueueSize() > 0) { //Get up to 10 messages List<Message> messages = resQ.batchReceive(); for (Message message : messages) { // System.out.println(" Message"); // System.out.println(" MessageId: " + message.getMessageId()); // System.out.println(" ReceiptHandle: " + message.getReceiptHandle()); // System.out.println(" MD5OfBody: " + message.getMD5OfBody()); // System.out.println(" Body: " + message.getBody()); //Get task String messageBody = message.getBody(); JSONObject resp = (JSONObject) parser.parse(messageBody); responseList.add(resp);/*from w w w .ja va2 s.c om*/ msg_cnt--; // Delete the message String messageRecieptHandle = message.getReceiptHandle(); resQ.deleteMessage(messageRecieptHandle); } if (!responseList.isEmpty()) { out.println(responseList.toString()); responseList.clear(); } } } }