[Mc4j-development] Using Jini to find MBeans
Brought to you by:
ghinkl
From: James R. <jam...@db...> - 2005-02-08 17:09:07
|
Hi, I've just discovered this project, and it seems very useful. I noticed on the tracker page that there are plans to put jini discovery into some future version, and I wondered whether this would be forthcoming soon. I would almost volunteer to do the work, but I'm not really a GUI person! Basically you need to pop some code into a wizard a bit like this, with some stuff for updating the set of connections based on being informed of new services registering that match the service template. If somebody would like to give me a bit of insight into where I might start, I could possibly have a bit of a go. I'm using IntelliJ, and it doesn't seem to like the "form" files... Anyhow, crap bit of code, which will find a single service for you: protected WhateverInterfaceYouSpecify getServiceInterface(ServiceItem item) { if (item == null) { return null; } return (WhateverInterfaceYouSpecify) item.service; } protected ServiceTemplate getServiceTemplate() { Class[] classes = new Class[]{WhateverInterfaceYouSpecify.class}; ServiceTemplate template = new ServiceTemplate(null, classes, null); return template; } protected ServiceItem lookupServerMulticast(ServiceTemplate template) { ServiceDiscoveryManager serviceDiscoveryManager = null; try { LookupDiscoveryManager lookupDiscoveryManager = new LookupDiscoveryManager(new String[]{ jiniGroupname }, null, null); serviceDiscoveryManager = new ServiceDiscoveryManager(lookupDiscoveryManager, new LeaseRenewalManager()); } catch (IOException e) { System.exit(1); } try { // This only finds one service... serviceItem = serviceDiscoveryManager.lookup(template, null, 10 * 1000); return serviceItem; } catch (InterruptedException e) { ; } catch (RemoteException e) { ; } return null; } public void doIt{ WhateverInterfaceYouSpecify admin = getServiceInterface(lookupServerMulticast(getServiceTemplate())); JMXConnector jmx = admin.getJMXConnector(); jmx.connect(); MBeanServerConnection mbeanserver = jmx.getMBeanServerConnection(); .... whatever..... } public interface WhateverInterfaceYouSpecify{ public JMXConnector getJMXConnector() throws RemoteException; } |