Example usage for javax.management.j2ee Management invoke

List of usage examples for javax.management.j2ee Management invoke

Introduction

In this page you can find the example usage for javax.management.j2ee Management invoke.

Prototype

Object invoke(ObjectName name, String operationName, Object[] params, String[] signature)
        throws InstanceNotFoundException, MBeanException, ReflectionException, RemoteException;

Source Link

Document

Invokes an operation on a managed object.

Usage

From source file:org.firstopen.singularity.util.JMSUtil.java

public static Queue createTopic(String topicName) throws InfrastructureException {

    Queue queue = null;/*  w  w w.  j a va 2 s . c o  m*/
    InitialContext jndiContext = null;
    try {
        queue = (Queue) jndiContext.lookup("topic/" + topicName);
    } catch (Exception e) {
        /*
         * try to create the queue
         */
        try {
            jndiContext = JNDIUtil.getInitialContext();

            ManagementHome mejbHome = (ManagementHome) jndiContext.lookup("ejb/mgmt/MEJB");
            Management mejb = mejbHome.create();
            ObjectName objectName = new ObjectName("jboss.mq:service=DestinationManager");
            mejb.invoke(objectName, "createTopic", new Object[] { topicName, "topic/" + topicName },
                    new String[] { String.class.getName(), String.class.getName() });

            queue = queueExists(topicName);
        } catch (Exception e1) {
            log.error("unable to create queue/" + topicName, e1);
            throw new InfrastructureException();
        }
    }
    return queue;
}

From source file:org.firstopen.singularity.util.JMSUtil.java

public static Queue createQueue(String queueName) throws InfrastructureException {

    Queue queue = null;// w  ww.  j  av a 2  s.  c  o m
    InitialContext jndiContext = null;
    try {
        queue = queueExists(queueName);
    } catch (Exception e) {
        /*
         * try to create the queue
         */
        try {
            jndiContext = JNDIUtil.getInitialContext();

            ManagementHome mejbHome = (ManagementHome) jndiContext.lookup("ejb/mgmt/MEJB");
            Management mejb = mejbHome.create();
            ObjectName objectName = new ObjectName("jboss.mq:service=DestinationManager");
            mejb.invoke(objectName, "createQueue", new Object[] { queueName, "queue/" + queueName },
                    new String[] { String.class.getName(), String.class.getName() });

            queue = queueExists(queueName);
        } catch (Exception e1) {
            log.error("unable to create queue/" + queueName, e1);
            throw new InfrastructureException();
        }
    }
    return queue;
}

From source file:org.firstopen.singularity.util.JMSUtil.java

public static String listMessageCounter(String queueName) throws Exception {
    InitialContext jndiContext = JNDIUtil.getInitialContext();
    ManagementHome mejbHome = (ManagementHome) jndiContext.lookup("ejb/mgmt/MEJB");
    Management mejb = mejbHome.create();
    ObjectName objectName = new ObjectName("jboss.mq.destination:service=Queue,id=" + queueName);
    return (String) mejb.invoke(objectName, "listMessageCounter", new Object[] {}, new String[] {});
}

From source file:org.firstopen.singularity.util.JMSUtil.java

public static void terminateQueue(String queueName) throws InfrastructureException {
    InitialContext jndiContext;//from w  w w.  j a  va 2  s.co  m
    try {
        jndiContext = JNDIUtil.getInitialContext();
        ManagementHome mejbHome = (ManagementHome) jndiContext.lookup("ejb/mgmt/MEJB");
        Management mejb = mejbHome.create();
        ObjectName objectName = new ObjectName("jboss.mq.destination:service=Queue,id=" + queueName);

        objectName = new ObjectName("jboss.mq:service=DestinationManager");
        mejb.invoke(objectName, "destroyQueue", new Object[] { queueName },
                new String[] { String.class.getName() });
    } catch (Exception e) {

        log.error("Unable Terminate Queue: " + queueName, e);
        throw new InfrastructureException("Unable Terminate Queue: " + queueName);
    }

}

From source file:org.firstopen.singularity.util.JMSUtil.java

public static void terminateTopic(String topicName) throws InfrastructureException {
    InitialContext jndiContext;/* ww w  .  j a va  2s  .  c om*/
    try {
        jndiContext = JNDIUtil.getInitialContext();
        ManagementHome mejbHome = (ManagementHome) jndiContext.lookup("ejb/mgmt/MEJB");
        Management mejb = mejbHome.create();
        ObjectName objectName = new ObjectName("jboss.mq.destination:service=Queue,id=" + topicName);
        // mejb.invoke(objectName, "stop", new Object[]{}, new String[]{});
        objectName = new ObjectName("jboss.mq:service=DestinationManager");
        mejb.invoke(objectName, "destroyTopic", new Object[] { topicName },
                new String[] { String.class.getName() });
    } catch (Exception e) {

        log.error("Unable Terminate Topic: " + topicName, e);
        throw new InfrastructureException("Unable Terminate Topic: " + topicName);
    }

}