Note: Import the required broker jars.
import COM.activesw.api.client.*;
public class DeleteClient {
static String client_group = "admin";
public static void main(String[] args) {
String broker_host = args[0];
String broker_name = args[1];
BrokerAdminClient client;
BrokerClientInfo[] info;
BrokerEvent event;
BrokerEvent client_stat_event;
String[] str;
String conn;
long queue_length;
BrokerClientSession session[];
try {
client= new BrokerAdminClient(broker_host, broker_name, null, client_group ,"Broker Manager" ,null);
str= client.getClientIds();
System.out.println("Number of Clients attached to Broker: ["+str.length+"]");
info= client.getClientInfosById(str);
for (int i=0;i<str.length;i++){
session= info[i].sessions;
/* If session length is 0 means client is not connected */
// check the client's queue. If it's 0, clear the queue.
queue_length = 0;
if (session.length == 0)
{
conn = "Disconnected";
client_stat_event = client.getClientStatsById(str[i]);
System.out.println (client_stat_event.toString());
try {
queue_length = client_stat_event.getLongField("queueLength");
System.out.println(" clientId = " + str[i] + "--- queue_length = " + queue_length);
if (queue_length == 0)
{
System.out.println("Deleting Disconnected Client: "+str[i]+"...");
client.destroyClientById(str[i]);
}
else
System.out.println (" not delete client");
} catch (BrokerException ex) {
System.out.println("error on getting client queueLength");
}
}
else
{
}
}
}catch(Exception e){
System.out.println(e);
}
}
}