Search in sources :

Example 6 with InternalDistributedMember

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;
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) CancelException(org.apache.geode.CancelException) IncompatibleSystemException(org.apache.geode.IncompatibleSystemException) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) CancelException(org.apache.geode.CancelException) InternalGemFireException(org.apache.geode.InternalGemFireException) InvalidDeltaException(org.apache.geode.InvalidDeltaException) ForcedDisconnectException(org.apache.geode.ForcedDisconnectException) SystemConnectException(org.apache.geode.SystemConnectException) NoSuchElementException(java.util.NoSuchElementException) NotSerializableException(java.io.NotSerializableException) UnknownHostException(java.net.UnknownHostException) ReenteredConnectException(org.apache.geode.internal.tcp.ReenteredConnectException) ToDataException(org.apache.geode.ToDataException) HashSet(java.util.HashSet)

Example 7 with InternalDistributedMember

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;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) HashSet(java.util.HashSet)

Example 8 with InternalDistributedMember

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);
    }
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) InternalGemFireException(org.apache.geode.InternalGemFireException) NetView(org.apache.geode.distributed.internal.membership.NetView) IncompatibleSystemException(org.apache.geode.IncompatibleSystemException) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) CancelException(org.apache.geode.CancelException) InternalGemFireException(org.apache.geode.InternalGemFireException) InvalidDeltaException(org.apache.geode.InvalidDeltaException) ForcedDisconnectException(org.apache.geode.ForcedDisconnectException) SystemConnectException(org.apache.geode.SystemConnectException) NoSuchElementException(java.util.NoSuchElementException) NotSerializableException(java.io.NotSerializableException) UnknownHostException(java.net.UnknownHostException) ReenteredConnectException(org.apache.geode.internal.tcp.ReenteredConnectException) ToDataException(org.apache.geode.ToDataException)

Example 9 with InternalDistributedMember

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));
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 10 with InternalDistributedMember

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
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember)

Aggregations

InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)516 Test (org.junit.Test)162 HashSet (java.util.HashSet)124 Set (java.util.Set)77 MembershipTest (org.apache.geode.test.junit.categories.MembershipTest)63 NetView (org.apache.geode.distributed.internal.membership.NetView)60 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)56 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)55 ArrayList (java.util.ArrayList)54 DistributedMember (org.apache.geode.distributed.DistributedMember)49 UnitTest (org.apache.geode.test.junit.categories.UnitTest)49 HashMap (java.util.HashMap)46 IOException (java.io.IOException)36 Iterator (java.util.Iterator)34 PartitionedRegionLoadModel (org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel)34 CompositeDirector (org.apache.geode.internal.cache.partitioned.rebalance.CompositeDirector)33 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)32 Map (java.util.Map)29 CancelException (org.apache.geode.CancelException)29 DM (org.apache.geode.distributed.internal.DM)29