use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.
the class DistributionManager method sendShutdownMessage.
/**
* Sends the shutdown message. Not all DistributionManagers need to do this.
*/
protected void sendShutdownMessage() {
if (getDMType() == ADMIN_ONLY_DM_TYPE && Locator.getLocators().size() == 0) {
// If two locators are simultaneously shut down this may not occur.
return;
}
ShutdownMessage m = new ShutdownMessage();
InternalDistributedMember theId = this.getDistributionManagerId();
m.setDistributionManagerId(theId);
Set allOthers = new HashSet(getViewMembers());
allOthers.remove(getDistributionManagerId());
// ReplyProcessor21 rp = new ReplyProcessor21(this, allOthers);
// m.setProcessorId(rp.getProcessorId());
// m.setMulticast(system.getConfig().getMcastPort() != 0);
m.setRecipients(allOthers);
// Address recipient = (Address) m.getRecipient();
if (logger.isTraceEnabled()) {
logger.trace("{} Sending {} to {}", this.getDistributionManagerId(), m, m.getRecipientsDescription());
}
try {
// m.resetTimestamp(); // nanotimers across systems don't match
long startTime = DistributionStats.getStatTime();
channel.send(m.getRecipients(), m, this, stats);
this.stats.incSentMessages(1L);
if (DistributionStats.enableClockStats) {
stats.incSentMessagesTime(DistributionStats.getStatTime() - startTime);
}
} catch (CancelException e) {
logger.debug("CancelException caught sending shutdown: {}", e.getMessage(), e);
} catch (Exception ex2) {
logger.fatal(LocalizedMessage.create(LocalizedStrings.DistributionManager_WHILE_SENDING_SHUTDOWN_MESSAGE), ex2);
} finally {
// Even if the message wasn't sent, *lie* about it, so that
// everyone believes that message distribution is done.
this.shutdownMsgSent = true;
}
}
use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.
the class DistributionManager method getOtherNormalDistributionManagerIds.
@Override
public Set getOtherNormalDistributionManagerIds() {
// We return a modified copy of the list, so
// collect the old list and copy under the lock.
Set result = new HashSet(getNormalDistributionManagerIds());
InternalDistributedMember me = getDistributionManagerId();
result.remove(me);
// It's okay for my own id to not be in the list of all ids yet.
return result;
}
use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.
the class DistributionManager method startThreads.
/**
* Need to do this outside the constructor so that the child constructor can finish.
*/
protected void startThreads() {
// fix for bug 33362
this.system.setDM(this);
if (this.memberEventThread != null)
this.memberEventThread.start();
try {
// And the distinguished guests today are...
NetView v = membershipManager.getView();
logger.info(LocalizedMessage.create(LocalizedStrings.DistributionManager_INITIAL_MEMBERSHIPMANAGER_VIEW___0, printView(v)));
// Add them all to our view
Iterator<InternalDistributedMember> it = v.getMembers().iterator();
while (it.hasNext()) {
addNewMember(it.next());
}
// Figure out who the elder is...
// ShutdownException could be thrown here
selectElder();
} catch (Exception ex) {
throw new InternalGemFireException(LocalizedStrings.DistributionManager_COULD_NOT_PROCESS_INITIAL_VIEW.toLocalizedString(), ex);
}
try {
getWaitingThreadPool().execute(new Runnable() {
public void run() {
// call in background since it might need to send a reply
// and we are not ready to send messages until startup is finished
isStartupThread.set(Boolean.TRUE);
readyForMessages();
}
});
} catch (VirtualMachineError err) {
SystemFailure.initiateFailure(err);
// now, so don't let this thread continue.
throw err;
} catch (Throwable t) {
// Whenever you catch Error or Throwable, you must also
// catch VirtualMachineError (see above). However, there is
// _still_ a possibility that you are dealing with a cascading
// error condition, so you also need to check to see if the JVM
// is still usable:
SystemFailure.checkFailure();
logger.fatal(LocalizedMessage.create(LocalizedStrings.DistributionManager_UNCAUGHT_EXCEPTION_CALLING_READYFORMESSAGES), t);
}
}
use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.
the class DistributionManager method handleManagerStartup.
/**
* Makes note of a new distribution manager that has started up in the distributed cache. Invokes
* the appropriately listeners.
*
* @param theId The id of the distribution manager starting up
*
*/
private void handleManagerStartup(InternalDistributedMember theId) {
HashMap<InternalDistributedMember, InternalDistributedMember> tmp = null;
synchronized (this.membersLock) {
// Note test is under membersLock
if (members.containsKey(theId)) {
// already accounted for
return;
}
// Note we don't modify in place. This allows reader to get snapshots
// without locking.
tmp = new HashMap(this.members);
tmp.put(theId, theId);
this.members = Collections.unmodifiableMap(tmp);
Set stmp = new HashSet(this.membersAndAdmin);
stmp.add(theId);
this.membersAndAdmin = Collections.unmodifiableSet(stmp);
}
if (theId.getVmKind() != DistributionManager.LOCATOR_DM_TYPE) {
this.stats.incNodes(1);
}
logger.info(LocalizedMessage.create(LocalizedStrings.DistributionManager_ADMITTING_MEMBER_0_NOW_THERE_ARE_1_NONADMIN_MEMBERS, new Object[] { theId, Integer.valueOf(tmp.size()) }));
addMemberEvent(new MemberJoinedEvent(theId));
}
use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.
the class DistributionManager method selectElder.
/**
* Select a new elder
*
*/
protected void selectElder() {
// bug 37884, if DS is
getSystem().getCancelCriterion().checkCancelInProgress(null);
// Once we are the elder, we're stuck until we leave the view.
if (this.myid.equals(this.elder)) {
return;
}
// Determine who is the elder...
InternalDistributedMember candidate = getElderCandidate();
if (candidate == null) {
changeElder(null);
// No valid elder in current context
return;
}
// Carefully switch to new elder
synchronized (this.elderMonitor) {
if (!candidate.equals(this.elder)) {
if (logger.isDebugEnabled()) {
logger.debug("The elder is: {} (was {})", candidate, this.elder);
}
changeElder(candidate);
}
}
// synchronized
}
Aggregations