public String getLocalNodeName() { ClusterNode localNode = this.partition == null ? null : this.partition.getClusterNode(); return localNode == null ? null : localNode.getName(); }
@Override public List<ClusterNode> lookupReplicantsNodes(String key) { boolean local = this.localReplicants.containsKey(key); Map<String, Serializable> replicant = this.replicants.get(key); if (replicant == null) { return local ? Collections.singletonList(this.partition.getClusterNode()) : null; } Set<String> keys = replicant.keySet(); ClusterNode[] nodes = this.partition.getClusterNodes(); List<ClusterNode> rtn = new ArrayList<ClusterNode>(nodes.length); for (ClusterNode node : nodes) { String name = node.getName(); if (local && this.partition.getNodeName().equals(name)) { rtn.add(this.partition.getClusterNode()); } else if (keys.contains(name)) { rtn.add(node); } } return rtn; }
public RemoteDiscrepancies getDiscrepancies() { Map<Server, TimestampDiscrepancy> result = null; synchronized (discrepancies) { result = new HashMap<Server, TimestampDiscrepancy>(discrepancies); } return new RemoteDiscrepancies(partition.getClusterNode(), result); }
public TimestampResponse getLocalTimestamp() { return new TimestampResponse(partition.getClusterNode()); }
final RemoteDiscrepancies arg = new RemoteDiscrepancies(partition.getClusterNode(), map); final HAPartition haPartition = this.partition; Runnable r = new Runnable()
private void handleInitiateSynchronization(SynchronizationId<ClusterNode> id, List<ContentModification> modifications, RepositoryContentMetadata toInstall) { boolean localLed = id.getOriginator().equals(partition.getClusterNode()); List<? extends SynchronizationAction<?>> actions = contentManager.initiateSynchronization(id, modifications, toInstall, localLed); activeSynchronization = new ActiveSynchronization(id, actions); }
private boolean elected() { boolean result; if (this.electionPolicy == null) { result = this.isDRMMasterReplica(); } else { ClusterNode electedNode = this.election(); result = (electedNode != null) ? electedNode.equals(this.getHAPartition().getClusterNode()) : false; } if( log.isDebugEnabled()) { log.debug("election result =" + result + ", electionPolicy=" + (electionPolicy != null? electionPolicy.getClass().getName():"DistributedReplicantManager")); } return result; }
private void sendDiscoveryEventToPartition(InetSocketAddress socketAddress, boolean addition) { synchronized (this.pendingDiscoveryEvents) { // Ensure discovery event enters queue sequentially by index MCMPServerDiscoveryEvent event = new MCMPServerDiscoveryEvent(this.serviceKeyProvider.getHAPartition().getClusterNode(), socketAddress, addition, this.discoveryEventIndex.incrementAndGet()); this.pendingDiscoveryEvents.add(event); try { this.rpcStub.mcmpServerDiscoveryEvent(event).getResult(); } catch (RuntimeException e) { // Just log it; we'll retry later Strings key = addition ? Strings.ERROR_DISCOVERY_ADD : Strings.ERROR_DISCOVERY_REMOVE; log.error(key.getString(socketAddress), e); } } }
List<ClusterNode> nodes = drm.lookupReplicantsNodes(getServiceHAName()); ClusterNode coord = (nodes != null && nodes.size() > 0 ? nodes.get(0) : null); if (coord != null && coord.equals(partition.getClusterNode()) == false)
private void notifyClusterStatusComplete(Set<MCMPServerState> masterList, Map<ClusterNode, PeerMCMPDiscoveryStatus> statuses) { // Determine who should update DRM first -- us or the rest of the nodes Set<ModClusterServiceDRMEntry> allStatuses = new HashSet<ModClusterServiceDRMEntry>(statuses.values()); ModClusterServiceDRMEntry ourCurrentStatus = HAModClusterService.this.lookupLocalDRMEntry(); allStatuses.add(ourCurrentStatus); ClusterNode node = HAModClusterService.this.getHAPartition().getClusterNode(); boolean othersFirst = HAModClusterService.this.findMasterCandidates(allStatuses).contains(node); ModClusterServiceDRMEntry newStatus = new ModClusterServiceDRMEntry(node, masterList, HAModClusterService.this.drmEntry.getJvmRoutes()); boolean updated = !newStatus.getMCMPServerStates().equals(ourCurrentStatus.getMCMPServerStates()); if (othersFirst) { HAModClusterService.this.rpcStub.clusterStatusComplete(statuses); } if (updated) { HAModClusterService.this.updateLocalDRM(newStatus); } if (!othersFirst) { HAModClusterService.this.rpcStub.clusterStatusComplete(statuses); } } }
nonresponsive.remove(HAModClusterService.this.getHAPartition().getClusterNode());
drm.add(getServiceHAName(), this.partition.getClusterNode()); this.serviceView = drm.lookupReplicantsNodes(getServiceHAName()); drm.registerListener(getServiceHAName(), drmListener);
@SuppressWarnings("synthetic-access") public void clusterStatusComplete(Map<ClusterNode, PeerMCMPDiscoveryStatus> statuses) { ClusterNode node = HAModClusterService.this.getHAPartition().getClusterNode(); PeerMCMPDiscoveryStatus status = statuses.get(node); if (status != null) { // Notify our handler that discovery events have been processed HAModClusterService.this.clusteredHandler.discoveryEventsReceived(status); // Notify our handler that any reset requests have been processed HAModClusterService.this.clusteredHandler.resetCompleted(); ModClusterServiceDRMEntry previousStatus = HAModClusterService.this.lookupLocalDRMEntry(); if (!status.getMCMPServerStates().equals(previousStatus.getMCMPServerStates())) { try { HAModClusterService.this.updateLocalDRM(new ModClusterServiceDRMEntry(node, status.getMCMPServerStates(), previousStatus.getJvmRoutes())); } catch (Exception e) { HAModClusterService.this.log.error(Strings.ERROR_DRM.getString(), e); } } } }
for (ClusterNode node : nodes) if (node.equals(this.partition.getClusterNode()))
private void executePull(SynchronizationId<?> id, SynchronizationWriteAction<?> action) throws Exception peers.remove(this.partition.getClusterNode());
protected HAModClusterService(EventFactory<HAServiceEvent> eventFactory, HAConfiguration haConfig, NodeConfiguration nodeConfig, BalancerConfiguration balancerConfig, MCMPHandlerConfiguration mcmpConfig, LoadBalanceFactorProviderFactory loadBalanceFactorProviderFactory, HAPartition partition, HASingletonElectionPolicy electionPolicy, MCMPRequestFactory requestFactory, MCMPResponseParser responseParser, ResetRequestSource resetRequestSource, MCMPHandler localHandler, ClusteredMCMPHandler clusteredHandler, AdvertiseListenerFactory advertiseListenerFactory) { super(eventFactory); this.setHAPartition(partition); this.setElectionPolicy(electionPolicy); this.rpcHandler = new RpcHandler(); this.requestFactory = requestFactory; this.responseParser = responseParser; this.resetRequestSource = resetRequestSource; this.localHandler = localHandler; this.clusteredHandler = clusteredHandler; this.drmEntry = new ModClusterServiceDRMEntry(partition.getClusterNode(), null); this.service = new ClusteredModClusterService(nodeConfig, balancerConfig, mcmpConfig, loadBalanceFactorProviderFactory, requestFactory, responseParser, resetRequestSource, clusteredHandler, advertiseListenerFactory); this.loadBalancingGroup = nodeConfig.getLoadBalancingGroup(); this.masterPerLoadBalancingGroup = haConfig.isMasterPerLoadBalancingGroup(); }
for (ClusterNode node : nodes) if (node.equals(this.partition.getClusterNode()))
/** * Bring the service into active operation. * * @throws Exception */ public void start() throws Exception { partition.registerRPCHandler(getServiceHAName(), rpcTarget); DistributedReplicantManager drm = partition.getDistributedReplicantManager(); drm.add(getServiceHAName(), partition.getClusterNode()); coordinator = drm.isMasterReplica(getServiceHAName()); drm.registerListener(getServiceHAName(), drmListener); statusCheck(); }
private void installModifications(List<ContentModification> modifications, RepositoryContentMetadata toInstall) new SynchronizationId<ClusterNode>(this.partition.getClusterNode());
public HAModClusterService(HAModClusterConfig config, LoadBalanceFactorProvider loadBalanceFactorProvider, HAPartition partition, HASingletonElectionPolicy electionPolicy) { super(new HAServiceEventFactory()); this.setHAPartition(partition); this.setElectionPolicy(electionPolicy); this.rpcHandler = new RpcHandler(); this.requestFactory = new DefaultMCMPRequestFactory(); this.responseParser = new DefaultMCMPResponseParser(); this.resetRequestSource = new ClusteredResetRequestSource(config, config, this.requestFactory, this, this); this.localHandler = new DefaultMCMPHandler(config, this.resetRequestSource, this.requestFactory, this.responseParser); this.clusteredHandler = new ClusteredMCMPHandlerImpl(this.localHandler, this, this); this.drmEntry = new ModClusterServiceDRMEntry(partition.getClusterNode(), null); this.service = new ClusteredModClusterService(config, config, config, new SimpleLoadBalanceFactorProviderFactory(loadBalanceFactorProvider), this.requestFactory, this.responseParser, this.resetRequestSource, this.clusteredHandler, new AdvertiseListenerFactoryImpl()); this.loadBalancingGroup = config.getLoadBalancingGroup(); this.masterPerLoadBalancingGroup = config.isMasterPerLoadBalancingGroup(); }