This content has been marked as final.
Show 4 replies
-
1. Re: How to create mbeans on runtime.
denisius Jul 19, 2005 6:35 AM (in response to denisius)The right code is:
private MBeanServerConnection getServer() { if (mBeanServer == null) { try { Properties props = new Properties(); props.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory"); props.put("ava.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces"); props.put("java.naming.provider.url", "localhost:1199"); //jnp:// InitialContext ctx = new InitialContext(props); mBeanServer = (MBeanServerConnection) ctx .lookup(jmx/invoker/RMIAdaptor); } catch (Exception e) { e.printStackTrace(); mBeanServer = null; } } return mBeanServer; } public void createQueue(String name) { getServer().createMBean( "org.jboss.mq.server.jmx.Queue", new ObjectName("jboss.mq.destination:service=Queue,name=" + name)); }
-
2. Re: How to create mbeans on runtime.
genman Jul 20, 2005 12:53 AM (in response to denisius)
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.
mcaughey Jul 21, 2005 2:35 PM (in response to denisius)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.
-Michael -
4. Re: How to create mbeans on runtime.
mcaughey Jul 21, 2005 2:37 PM (in response to denisius)Here's the code I'm using:
private void registerTopic(String topicname) throws MalformedObjectNameException, Exception { createDestination("org.jboss.mq.server.jmx.Topic", 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); tmb.start(); } private Element getSecurityconf() throws SAXException, IOException{ Element el = null; StringBuffer securityConfStr = new StringBuffer(); securityConfStr.append("<security>"); securityConfStr.append(" <role name=\"publisher\" read=\"true\" write=\"true\" create=\"false\"/>"); securityConfStr.append(" <role name=\"durpublisher\" read=\"true\" write=\"true\" create=\"true\"/>"); securityConfStr.append("</security>"); DOMParser parser = new DOMParser(); parser.parse(securityConfStr.toString()); Document doc = parser.getDocument(); el = doc.getDocumentElement(); return el; }