/** * return the singleton instance * * @return */ public static final NetworkRegistry getInstance() { if(singleton == null) { new NetworkRegistry(); } return singleton; }
/** * update the invokers for a given server * * @param identity * @param invokers */ public void updateServer(final Identity identity, final ServerInvokerMetadata invokers[]) { boolean found = false; synchronized(servers) { if(servers.containsKey(identity)) { servers.put(identity, new NetworkInstance(identity, invokers)); found = true; } } if(found) { // TODO: let's put this in a thread pool thread -JGH // put this on a separate thread so we don't block further detection ... new Thread() { public void run() { broadcaster.sendNotification(new NetworkNotification(objectName, NetworkNotification.SERVER_UPDATED, identity, invokers)); } }.start(); } }
/** * remove a server no longer available on the network * * @param identity */ public void removeServer(final Identity identity) { NetworkInstance instance = null; synchronized(servers) { instance = (NetworkInstance) servers.remove(identity); } if(instance != null) { log.debug("removeServer - " + identity); final ServerInvokerMetadata il[] = instance.getServerInvokers(); // put this on a separate thread so we don't block further detection ... // TODO: let's put this is a thread pool thread -JGH new Thread() { public void run() { broadcaster.sendNotification(new NetworkNotification(objectName, NetworkNotification.SERVER_REMOVED, identity, il)); } }.start(); } }
/** * query the network registry for <tt>0..*</tt> of servers based on a * filter. if the filter is null, it is considered a wildcard. * * @param filter * @return */ public NetworkInstance[] queryServers(NetworkFilter filter) { NetworkInstance servers[] = getServers(); if(servers == null || servers.length <= 0) { return new NetworkInstance[0]; } Set result = new HashSet(); for(int c = 0; c < servers.length; c++) { NetworkInstance instance = (NetworkInstance) this.servers.get(servers[c]); if(filter == null || filter.filter(servers[c].getIdentity(), instance.getLocators())) { if(result.contains(servers[c]) == false) { // the filter passed, add it result.add(servers[c]); } } } return (NetworkInstance[]) result.toArray(new NetworkInstance[result.size()]); }
/** * Processes the {@link NetworkNotification#SERVER_REMOVED} notification. This notification means a previously known * "server VM" has gone offline and has taken all of its remote endpoints with it. * * @param networkNotification the notification */ private void serverRemovedNotification(NetworkNotification networkNotification) { List<AutoDiscoveryListener> listeners_copy; InvokerLocator[] notif_locators = networkNotification.getLocator(); synchronized (m_lock) { // the server has gone down, remove it from our map of known servers m_discoveredServers.remove(networkNotification.getIdentity()); // make a copy while we are synchronized - then release the lock so we let other notifications to get processed listeners_copy = new ArrayList<AutoDiscoveryListener>(m_discoveryListeners); } // notify all of our listeners of the invoker locators that have gone down for (int x = 0; x < notif_locators.length; x++) { notifyListenersOffline(listeners_copy, notif_locators[x]); } return; }
/** * change the main domain of the local server * * @param newDomain */ public synchronized void changeDomain(String newDomain) { System.setProperty("jboss.remoting.domain", newDomain); NetworkInstance servers[] = getServers(); if(servers == null || servers.length <= 0) { return; } // remove entries that don't match out new domain for(int c = 0; c < servers.length; c++) { NetworkInstance instance = (NetworkInstance) this.servers.get(servers[c]); if(newDomain.equals(instance.getIdentity().getDomain()) == false) { this.servers.remove(servers[c]); } } new Thread() { public void run() { broadcaster.sendNotification(new NetworkNotification(objectName, NetworkNotification.DOMAIN_CHANGED, Identity.get(mBeanServer), InvokerRegistry.getRegisteredServerLocators())); } }.start(); }
/** * When a new server is detected or an old server goes away, this method will be notified. This method notifies all * listeners when added/removed/updated notifications are received. * * @see NotificationListener#handleNotification(Notification, Object) */ public void handleNotification(Notification notification, Object handback) { // check to see if its a network notification if (notification instanceof NetworkNotification) { LOG.debug(CommI18NResourceKeys.GOT_NOTIF, notification.getType()); NetworkNotification networkNotification = (NetworkNotification) notification; if (NetworkNotification.SERVER_ADDED.equals(networkNotification.getType())) { serverAddedNotification(networkNotification); } else if (NetworkNotification.SERVER_REMOVED.equals(networkNotification.getType())) { serverRemovedNotification(networkNotification); } else if (NetworkNotification.SERVER_UPDATED.equals(networkNotification.getType())) { serverUpdatedNotification(networkNotification); } } return; }
private void initTransporterServices() throws Exception { // create MBeanServer MBeanServer mbeanServer = MBeanServerFactory.createMBeanServer(); NetworkRegistry registry = NetworkRegistry.getInstance(); String host = InetAddress.getLocalHost().getHostAddress(); JNDIDetector jndiDetector = new JNDIDetector(); jndiDetector.setPort(JNDIServer.JNDI_PORT); jndiDetector.setHost(host); jndiDetector.setContextFactory("org.jnp.interfaces.NamingContextFactory"); jndiDetector.setURLPackage("org.jboss.naming:org.jnp.interfaces"); InternalTransporterServices transporterService = InternalTransporterServices.getInstance(); transporterService.setup(mbeanServer, jndiDetector, new ObjectName("remoting:type=Detector,transport=jndi"), registry, new ObjectName("remoting:type=NetworkRegistry"), true, true); //TODO: -TME Have to start the detector after setup() call? jndiDetector.start(); }
servers.put(identity, new NetworkInstance(identity, invokers)); found = true; }.start();
public MBeanNotificationCache(ServerInvoker invoker, MBeanServer server) throws Exception { this.server = server; this.serverInvoker = invoker; this.localServerId = JMXUtil.getServerId(server); networkRegistry = NetworkRegistryFinder.find(server); if(networkRegistry == null) { throw new Exception("Couldn't find the required NetworkRegistryMBean in this MBeanServer"); } // add ourself as a listener for detection failed events server.addNotificationListener(networkRegistry, this, null, this); }
public void run() { broadcaster.sendNotification(new NetworkNotification(objectName, NetworkNotification.SERVER_UPDATED, identity, invokers)); } }.start();
/** * To be used to force detection to occur in synchronouse manner * instead of being passive and waiting for detection messages to * come in from remote detectors. The servers returned should be * the remote servers that are online at this point in time. Note, calling this * method may take a few seconds to complete. * @return */ public NetworkInstance[] forceDetection() { forceHeartbeat(); if(networkRegistry != null) { return networkRegistry.getServers(); } else { return null; } }
/** * find the ObjectName to the NetworkRegistryMBean instance on the MBeanServer * * @param server * @return */ public static ObjectName find(MBeanServer server) { Set set = server.queryMBeans(null, new NetworkRegistryQuery()); if(set.isEmpty()) { return null; } return ((ObjectInstance) set.iterator().next()).getObjectName(); } }
/** * Processes the {@link NetworkNotification#SERVER_REMOVED} notification. This notification means a previously known * "server VM" has gone offline and has taken all of its remote endpoints with it. * * @param networkNotification the notification */ private void serverRemovedNotification(NetworkNotification networkNotification) { List<AutoDiscoveryListener> listeners_copy; InvokerLocator[] notif_locators = networkNotification.getLocator(); synchronized (m_lock) { // the server has gone down, remove it from our map of known servers m_discoveredServers.remove(networkNotification.getIdentity()); // make a copy while we are synchronized - then release the lock so we let other notifications to get processed listeners_copy = new ArrayList<AutoDiscoveryListener>(m_discoveryListeners); } // notify all of our listeners of the invoker locators that have gone down for (int x = 0; x < notif_locators.length; x++) { notifyListenersOffline(listeners_copy, notif_locators[x]); } return; }
/** * When a new server is detected or an old server goes away, this method will be notified. This method notifies all * listeners when added/removed/updated notifications are received. * * @see NotificationListener#handleNotification(Notification, Object) */ public void handleNotification(Notification notification, Object handback) { // check to see if its a network notification if (notification instanceof NetworkNotification) { LOG.debug(CommI18NResourceKeys.GOT_NOTIF, notification.getType()); NetworkNotification networkNotification = (NetworkNotification) notification; if (NetworkNotification.SERVER_ADDED.equals(networkNotification.getType())) { serverAddedNotification(networkNotification); } else if (NetworkNotification.SERVER_REMOVED.equals(networkNotification.getType())) { serverRemovedNotification(networkNotification); } else if (NetworkNotification.SERVER_UPDATED.equals(networkNotification.getType())) { serverUpdatedNotification(networkNotification); } } return; }
private void initTransporterServices() throws Exception { // create MBeanServer MBeanServer mbeanServer = MBeanServerFactory.createMBeanServer(); NetworkRegistry registry = NetworkRegistry.getInstance(); String host = InetAddress.getLocalHost().getHostAddress(); JNDIDetector jndiDetector = new JNDIDetector(); jndiDetector.setPort(JNDIServer.JNDI_PORT); jndiDetector.setHost(host); jndiDetector.setContextFactory("org.jnp.interfaces.NamingContextFactory"); jndiDetector.setURLPackage("org.jboss.naming:org.jnp.interfaces"); InternalTransporterServices transporterService = InternalTransporterServices.getInstance(); transporterService.setup(mbeanServer, jndiDetector, new ObjectName("remoting:type=Detector,transport=jndi"), registry, new ObjectName("remoting:type=NetworkRegistry"), true, true); //TODO: -TME Have to start the detector after setup() call? jndiDetector.start(); }
public void run() { broadcaster.sendNotification(new NetworkNotification(objectName, NetworkNotification.SERVER_ADDED, identity, invokers)); } }.start();
private void initTransporterServices() throws Exception { // create MBeanServer MBeanServer mbeanServer = MBeanServerFactory.createMBeanServer(); NetworkRegistry registry = NetworkRegistry.getInstance(); String host = InetAddress.getLocalHost().getHostAddress(); JNDIDetector jndiDetector = new JNDIDetector(); jndiDetector.setPort(JNDIServer.JNDI_PORT); jndiDetector.setHost(host); jndiDetector.setContextFactory("org.jnp.interfaces.NamingContextFactory"); jndiDetector.setURLPackage("org.jboss.naming:org.jnp.interfaces"); InternalTransporterServices transporterService = InternalTransporterServices.getInstance(); transporterService.setup(mbeanServer, jndiDetector, new ObjectName("remoting:type=Detector,transport=jndi"), registry, new ObjectName("remoting:type=NetworkRegistry"), true, true); //TODO: -TME Have to start the detector after setup() call? jndiDetector.start(); }
public void run() { broadcaster.sendNotification(new NetworkNotification(objectName, NetworkNotification.SERVER_REMOVED, identity, il)); } }.start();
public void run() { broadcaster.sendNotification(new NetworkNotification(objectName, NetworkNotification.DOMAIN_CHANGED, Identity.get(mBeanServer), InvokerRegistry.getRegisteredServerLocators())); } }.start();