Here's a standard way to invoke your MBean method:
import javax.management.*;
// Get the target MBean server (assumed here to be first server)
java.util.ArrayList servers = MBeanServerFactory.findMBeanServer(null);
if (servers.size() != 1) {
// ...deal with it
}
MBeanServer server = servers.get(0);
// Invoke the method
try {
String name = ":name=MyService"; // or whatever you call your MBean; note leading
colon
ObjectName objNm = new ObjectName(name);
Object[] args = { new CommandObject(arg1, arg2) };
String[] sigs = { CommandObject.class.getName(); }
server.invoke(name, "myMethod", args, sigs);
} catch (Exception e) {
// ...handle it
}
Cf. Sun jmx docs, although it is far from clear how to use JMX from any documentation
I've read. You may experience classloader or other deployment problems, in which case
you can make your own MBeanServer. That approach has worked well for me on a
substantial service-based application, but takes a bit of effort.
JNDI is probably not an option in this case, since presumably you want a single
global, synchronized dispatcher instance rather than a serialized copy. Alternatively,
you could bind to a RMI UnicastRemoteObject that acts a stub to your dispatcher, if
you like that sort of thing.
--
Fred Loney
Enterprise Java Consultant
Spirited Software, Inc.
[EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
> I have a somewhat unusual configuration, and I wanted to see if anyone
> could give some advice.
>
> I have created an MBean to act as a queue of jobs that are to be dispatched
> to separate machines to process those jobs (I couldn't create the queue as
> an EJB because I need to manage my own threads here). I'd like to know if
> it's possible to get an instance of this MBean in an EJB to call out to it.
> Thus, here is my standard flow:
>
> Client App:
>
> CommandProcessor cp = commandProcessorHome.create();
> cp.processCommand(arg1, arg2);
>
> And then in the CommandProcessorBean (a stateless session bean):
>
> public void processCommand(String arg1, String arg2) {
>
> DispatcherMBean dispatcher = ???; //how can I get a handle to the MBean?
> dispatcher.dispatch(new CommandObject(arg1, arg2));
> }
>
> Anyone have any clues on how to do this?
>
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user