public void testGetConnectorsAsJSON() throws Exception {
    HornetQServerControl serverControl = createManagementControl();

    String jsonString = serverControl.getConnectorsAsJSON();
    Assert.assertNotNull(jsonString);
    JSONArray array = new JSONArray(jsonString);
    Assert.assertEquals(1, array.length());
    JSONObject data = array.getJSONObject(0);
    Assert.assertEquals(connectorConfig.getName(), data.optString("name"));
    Assert.assertEquals(connectorConfig.getFactoryClassName(), data.optString("factoryClassName"));
    Assert.assertEquals(connectorConfig.getParams().size(), data.getJSONObject("params").length());
  }
示例#2
0
  /**
   * Returns an array of RoleInfo corresponding to the JSON serialization returned by {@link
   * QueueControl#listMessageCounterHistory()}.
   */
  public static DayCounterInfo[] fromJSON(final String jsonString) throws JSONException {
    JSONObject json = new JSONObject(jsonString);
    JSONArray dayCounters = json.getJSONArray("dayCounters");
    DayCounterInfo[] infos = new DayCounterInfo[dayCounters.length()];
    for (int i = 0; i < dayCounters.length(); i++) {

      JSONObject counter = (JSONObject) dayCounters.get(i);
      JSONArray hour = (JSONArray) counter.getJSONArray("counters").get(0);
      int[] hourCounters = new int[24];
      for (int j = 0; j < 24; j++) {
        hourCounters[j] = hour.getInt(j);
      }
      DayCounterInfo info = new DayCounterInfo(counter.getString("date"), hourCounters);
      infos[i] = info;
    }
    return infos;
  }
  /* (non-Javadoc)
   * @see org.hornetq.api.core.management.QueueControl#listConsumersAsJSON()
   */
  public String listConsumersAsJSON() throws Exception {
    checkStarted();

    clearIO();
    try {
      Collection<Consumer> consumers = queue.getConsumers();

      JSONArray jsonArray = new JSONArray();

      for (Consumer consumer : consumers) {

        if (consumer instanceof ServerConsumer) {
          ServerConsumer serverConsumer = (ServerConsumer) consumer;

          JSONObject obj = new JSONObject();
          obj.put("consumerID", serverConsumer.getID());
          obj.put("connectionID", serverConsumer.getConnectionID().toString());
          obj.put("sessionID", serverConsumer.getSessionID());
          obj.put("browseOnly", serverConsumer.isBrowseOnly());
          obj.put("creationTime", serverConsumer.getCreationTime());

          jsonArray.put(obj);
        }
      }

      return jsonArray.toString();
    } finally {
      blockOnIO();
    }
  }
示例#4
0
 public static String toJSON(final DayCounterInfo[] infos) throws JSONException {
   JSONObject json = new JSONObject();
   JSONArray counters = new JSONArray();
   for (DayCounterInfo info : infos) {
     JSONObject counter = new JSONObject();
     counter.put("date", info.getDate());
     counter.put("counters", Arrays.asList(info.getCounters()));
     counters.put(counter);
   }
   json.put("dayCounters", counters);
   return json.toString();
 }
示例#5
0
  /* (non-Javadoc)
   * @see org.hornetq.core.server.ServerSession#getProducersInfoJSON()
   */
  public void describeProducersInfo(JSONArray array) throws Exception {
    Map<SimpleString, Pair<UUID, AtomicLong>> targetCopy = cloneTargetAddresses();

    for (Map.Entry<SimpleString, Pair<UUID, AtomicLong>> entry : targetCopy.entrySet()) {
      JSONObject producerInfo = new JSONObject();
      producerInfo.put("connectionID", this.getConnectionID().toString());
      producerInfo.put("sessionID", this.getName());
      producerInfo.put("destination", entry.getKey().toString());
      producerInfo.put("lastUUIDSent", entry.getValue().getA());
      producerInfo.put("msgSent", entry.getValue().getB().longValue());
      array.put(producerInfo);
    }
  }
 public static final AddressSettingsInfo from(final String jsonString) throws Exception {
   JSONObject object = new JSONObject(jsonString);
   return new AddressSettingsInfo(
       object.getString("addressFullMessagePolicy"),
       object.getLong("maxSizeBytes"),
       object.getInt("pageSizeBytes"),
       object.getInt("pageCacheMaxSize"),
       object.getInt("maxDeliveryAttempts"),
       object.getLong("redeliveryDelay"),
       object.getDouble("redeliveryMultiplier"),
       object.getLong("maxRedeliveryDelay"),
       object.getString("DLA"),
       object.getString("expiryAddress"),
       object.getBoolean("lastValueQueue"),
       object.getLong("redistributionDelay"),
       object.getBoolean("sendToDLAOnNoRoute"));
 }