private void addClusterNodes(final String clusterName, final Map<String, List<ClientMapping>> addedNodes) { if (addedNodes == null || addedNodes.isEmpty()) { return; } final List<EJBReceiverContext> receiverContexts = this.contexts; for (final EJBReceiverContext receiverContext : receiverContexts) { this.addClusterNodes(receiverContext.getClientContext(), clusterName, addedNodes); } }
@Override public void registryAdded(Registry<String, List<ClientMapping>> cluster) { final String clusterName = cluster.getName(); this.addClusterNodes(clusterName, cluster.getEntries()); // Register a listener for listening to removed/added nodes from the cluster final ClusterTopologyUpdateListener clusterTopologyUpdateListener = new ClusterTopologyUpdateListener(cluster); cluster.addListener(clusterTopologyUpdateListener); // keep track of this update listener so that we cleanup properly this.clusterTopologyUpdateListeners.add(clusterTopologyUpdateListener); }
@Override protected void associate(final EJBReceiverContext receiverContext) { this.contexts.add(receiverContext); final RegistryCollector<String, List<ClientMapping>> clusters = this.clusterRegistryCollector.getOptionalValue(); if (clusters == null) { return; } // for each cluster update the EJB client context with the current nodes in the cluster for (final Registry<String, List<ClientMapping>> cluster : clusters.getRegistries()) { this.addClusterNodes(receiverContext.getClientContext(), cluster.getName(), cluster.getEntries()); } }
@Override public void start(final StartContext context) throws StartException { deploymentRepository.getValue().addListener(deploymentListener); // register ourselves as a listener to new cluster formations/removal @SuppressWarnings("unchecked") final RegistryCollector<String, List<ClientMapping>> clusters = this.clusterRegistryCollector.getValue(); // register for cluster formation/removal events clusters.addListener(this); // for each cluster add a listener for cluster node addition/removal events and also // update the EJB client context with the current nodes in the cluster for (final Registry<String, List<ClientMapping>> cluster : clusters.getRegistries()) { this.addClusterNodes(cluster.getName(), cluster.getEntries()); final ClusterTopologyUpdateListener clusterTopologyUpdateListener = new ClusterTopologyUpdateListener(cluster); cluster.addListener(clusterTopologyUpdateListener); // keep track of this update listener so that we cleanup properly this.clusterTopologyUpdateListeners.add(clusterTopologyUpdateListener); } }