4 Replies Latest reply on Jul 21, 2005 2:37 PM by mcaughey

    How to create mbeans on runtime.


      The task is to create several Queues from standalone application. i use next code:

      MBeanServer lServer = MBeanServerFactory.createMBeanServer();
      ObjectInstance myQ = lServer.createMBean(
       "org.jboss.mq.server.jmx.Queue", new ObjectName(

      to craete one Queue with name "myQ" ander "jboss.mq.destination" domain. The code runs OK - without exceptions, but i don't see any new created Queues. Whats wrong?

        • 1. Re: How to create mbeans on runtime.

          The right code is:

           private MBeanServerConnection getServer() {
           if (mBeanServer == null) {
           try {
           Properties props = new Properties();
           props.put("java.naming.provider.url", "localhost:1199"); //jnp://
           InitialContext ctx = new InitialContext(props);
           mBeanServer = (MBeanServerConnection) ctx
           } catch (Exception e) {
           mBeanServer = null;
           return mBeanServer;
          public void createQueue(String name) {
           new ObjectName("jboss.mq.destination:service=Queue,name=" + name));

          • 2. Re: How to create mbeans on runtime.

            There is a method on the jboss.mq:service=DestinationManager to programmatically create a queue.

            I think your problem was, though the MBean was created, the attributes (like destination manager, etc.) were not set and "start" was not called.

            • 3. Re: How to create mbeans on runtime.

              Have you been able to get a securityConf Associated with this Queue?

              I'm trying to do the same thing with a Topic. But I haven I cannot authenticate.


              • 4. Re: How to create mbeans on runtime.

                Here's the code I'm using:

                 private void registerTopic(String topicname)
                 throws MalformedObjectNameException, Exception {
                 getTopicObjectName(topicname), "topic/" + topicname);
                 private ObjectName getTopicObjectName(String name)
                 throws MalformedObjectNameException {
                 return new ObjectName("jboss.mq.destination:service=Topic,name=" + name);
                 protected void createDestination(String type, ObjectName name,
                 String jndiName) throws Exception {
                 if (logger.isDebugEnabled()) {
                 logger.debug("Attempting to create destination: " + name
                 + "; type=" + type);
                 MBeanServer server = MBeanServerLocator.locateJBoss();
                 server.createMBean(type, name);
                 server.setAttribute(name, new Attribute("DestinationManager",
                 new ObjectName("jboss.mq:service=DestinationManager")));
                 server.setAttribute(name, new Attribute("SecurityManager",
                 new ObjectName("jboss.mq:service=SecurityManager")));
                 server.setAttribute(name, new Attribute("SecurityConf", getSecurityconf()));
                 server.setAttribute(name, new Attribute("JNDIName", jndiName));
                 TopicMBean tmb = (TopicMBean)MBeanServerInvocationHandler.newProxyInstance(server, name,TopicMBean.class,false);
                 private Element getSecurityconf() throws SAXException, IOException{
                 Element el = null;
                 StringBuffer securityConfStr = new StringBuffer();
                 securityConfStr.append(" <role name=\"publisher\" read=\"true\" write=\"true\" create=\"false\"/>");
                 securityConfStr.append(" <role name=\"durpublisher\" read=\"true\" write=\"true\" create=\"true\"/>");
                 DOMParser parser = new DOMParser();
                 Document doc = parser.getDocument();
                 el = doc.getDocumentElement();
                 return el;