use of javax.json.JsonArrayBuilder in project activemq-artemis by apache.
the class DayCounterInfo method toJSON.
// Static --------------------------------------------------------
public static String toJSON(final DayCounterInfo[] infos) {
JsonObjectBuilder json = JsonLoader.createObjectBuilder();
JsonArrayBuilder counters = JsonLoader.createArrayBuilder();
for (DayCounterInfo info : infos) {
JsonArrayBuilder counter = JsonLoader.createArrayBuilder();
for (long c : info.getCounters()) {
counter.add(c);
}
JsonObjectBuilder dci = JsonLoader.createObjectBuilder().add("date", info.getDate()).add("counters", counter);
counters.add(dci);
}
json.add("dayCounters", counters);
return json.build().toString();
}
use of javax.json.JsonArrayBuilder in project activemq-artemis by apache.
the class JsonUtilTest method testAddByteArrayToJsonArray.
@Test
public void testAddByteArrayToJsonArray() {
JsonArrayBuilder jsonArrayBuilder = JsonLoader.createArrayBuilder();
byte[] bytes = { 0x0a, 0x1b, 0x2c, 0x3d, 0x4e, 0x5f };
JsonUtil.addToArray(bytes, jsonArrayBuilder);
JsonArray jsonArray = jsonArrayBuilder.build();
Assert.assertEquals(1, jsonArray.size());
}
use of javax.json.JsonArrayBuilder in project activemq-artemis by apache.
the class ActiveMQServerControlImpl method listConnectionsAsJSON.
@Override
public String listConnectionsAsJSON() throws Exception {
checkStarted();
clearIO();
try {
JsonArrayBuilder array = JsonLoader.createArrayBuilder();
Set<RemotingConnection> connections = server.getRemotingService().getConnections();
for (RemotingConnection connection : connections) {
JsonObjectBuilder obj = JsonLoader.createObjectBuilder().add("connectionID", connection.getID().toString()).add("clientAddress", connection.getRemoteAddress()).add("creationTime", connection.getCreationTime()).add("implementation", connection.getClass().getSimpleName()).add("sessionCount", server.getSessions(connection.getID().toString()).size());
array.add(obj);
}
return array.build().toString();
} finally {
blockOnIO();
}
}
use of javax.json.JsonArrayBuilder in project activemq-artemis by apache.
the class ActiveMQServerControlImpl method listNetworkTopology.
@Override
public String listNetworkTopology() throws Exception {
checkStarted();
clearIO();
try {
JsonArrayBuilder brokers = JsonLoader.createArrayBuilder();
ClusterManager clusterManager = server.getClusterManager();
if (clusterManager != null) {
Set<ClusterConnection> clusterConnections = clusterManager.getClusterConnections();
for (ClusterConnection clusterConnection : clusterConnections) {
Topology topology = clusterConnection.getTopology();
Collection<TopologyMemberImpl> members = topology.getMembers();
for (TopologyMemberImpl member : members) {
JsonObjectBuilder obj = JsonLoader.createObjectBuilder();
TransportConfiguration live = member.getLive();
if (live != null) {
obj.add("nodeID", member.getNodeId()).add("live", live.getParams().get("host") + ":" + live.getParams().get("port"));
TransportConfiguration backup = member.getBackup();
if (backup != null) {
obj.add("backup", backup.getParams().get("host") + ":" + backup.getParams().get("port"));
}
}
brokers.add(obj);
}
}
}
return brokers.build().toString();
} finally {
blockOnIO();
}
}
use of javax.json.JsonArrayBuilder in project activemq-artemis by apache.
the class ActiveMQServerControlImpl method getConnectorsAsJSON.
@Override
public String getConnectorsAsJSON() throws Exception {
checkStarted();
clearIO();
try {
JsonArrayBuilder array = JsonLoader.createArrayBuilder();
for (TransportConfiguration config : configuration.getConnectorConfigurations().values()) {
array.add(config.toJson());
}
return array.build().toString();
} finally {
blockOnIO();
}
}
Aggregations