use of org.apache.geode.distributed.internal.membership.gms.messages.LeaveRequestMessage in project geode by apache.
the class GMSJoinLeave method leave.
@Override
public void leave() {
synchronized (viewInstallationLock) {
NetView view = currentView;
isStopping = true;
stopCoordinatorServices();
if (view != null) {
if (view.size() > 1) {
List<InternalDistributedMember> coords = view.getPreferredCoordinators(Collections.emptySet(), localAddress, 5);
logger.debug("Sending my leave request to {}", coords);
LeaveRequestMessage m = new LeaveRequestMessage(coords, this.localAddress, "this member is shutting down");
services.getMessenger().send(m);
}
// view.size
}
// view != null
}
}
use of org.apache.geode.distributed.internal.membership.gms.messages.LeaveRequestMessage in project geode by apache.
the class GMSJoinLeave method installView.
public void installView(NetView newView) {
synchronized (viewInstallationLock) {
if (currentView != null && currentView.getViewId() >= newView.getViewId()) {
// old view - ignore it
return;
}
logger.info("received new view: {}\nold view is: {}", newView, currentView);
if (currentView == null && !this.isJoined) {
boolean found = false;
for (InternalDistributedMember mbr : newView.getMembers()) {
if (this.localAddress.equals(mbr)) {
found = true;
this.birthViewId = mbr.getVmViewId();
this.localAddress.setVmViewId(this.birthViewId);
GMSMember me = (GMSMember) this.localAddress.getNetMember();
me.setBirthViewId(birthViewId);
break;
}
}
if (!found) {
logger.info("rejecting view (not yet joined)");
return;
}
}
if (isJoined && isNetworkPartition(newView, true)) {
if (quorumRequired) {
Set<InternalDistributedMember> crashes = newView.getActualCrashedMembers(currentView);
forceDisconnect(LocalizedStrings.Network_partition_detected.toLocalizedString(crashes.size(), crashes));
return;
}
}
previousView = currentView;
currentView = newView;
preparedView = null;
lastConflictingView = null;
services.installView(newView);
if (!isJoined) {
logger.debug("notifying join thread");
isJoined = true;
synchronized (joinResponse) {
joinResponse.notifyAll();
}
}
if (!newView.getCreator().equals(this.localAddress)) {
if (newView.shouldBeCoordinator(this.localAddress)) {
becomeCoordinator();
} else if (this.isCoordinator) {
// stop being coordinator
stopCoordinatorServices();
this.isCoordinator = false;
}
}
if (!this.isCoordinator) {
// resend these
synchronized (viewRequests) {
for (Iterator<DistributionMessage> it = viewRequests.iterator(); it.hasNext(); ) {
DistributionMessage m = it.next();
if (m instanceof JoinRequestMessage) {
if (currentView.contains(((JoinRequestMessage) m).getMemberID())) {
it.remove();
}
} else if (m instanceof LeaveRequestMessage) {
if (!currentView.contains(((LeaveRequestMessage) m).getMemberID())) {
it.remove();
}
} else if (m instanceof RemoveMemberMessage) {
if (!currentView.contains(((RemoveMemberMessage) m).getMemberID())) {
it.remove();
}
}
}
}
}
}
synchronized (removedMembers) {
removeMembersFromCollectionIfNotInView(removedMembers, currentView);
}
synchronized (leftMembers) {
removeMembersFromCollectionIfNotInView(leftMembers, currentView);
}
}
use of org.apache.geode.distributed.internal.membership.gms.messages.LeaveRequestMessage in project geode by apache.
the class GMSJoinLeave method memberShutdown.
@Override
public void memberShutdown(DistributedMember mbr, String reason) {
LeaveRequestMessage msg = new LeaveRequestMessage(Collections.singleton(this.localAddress), (InternalDistributedMember) mbr, reason);
msg.setSender((InternalDistributedMember) mbr);
processLeaveRequest(msg);
}
use of org.apache.geode.distributed.internal.membership.gms.messages.LeaveRequestMessage in project geode by apache.
the class JGroupsMessengerJUnitTest method doTestMessageDeliveredToHandler.
private void doTestMessageDeliveredToHandler(boolean mcast) throws Exception {
initMocks(mcast);
MessageHandler mh = mock(MessageHandler.class);
messenger.addHandler(JoinRequestMessage.class, mh);
InternalDistributedMember addr = messenger.getMemberID();
NetView v = new NetView(addr);
when(joinLeave.getView()).thenReturn(v);
InternalDistributedMember sender = createAddress(8888);
JoinRequestMessage msg = new JoinRequestMessage(messenger.localAddress, sender, null, -1, 0);
Message jmsg = messenger.createJGMessage(msg, messenger.jgAddress, Version.CURRENT_ORDINAL);
interceptor.up(new Event(Event.MSG, jmsg));
verify(mh, times(1)).processMessage(any(JoinRequestMessage.class));
LeaveRequestMessage lmsg = new LeaveRequestMessage(messenger.localAddress, sender, "testing");
when(joinLeave.getMemberID(any())).thenReturn(sender);
jmsg = messenger.createJGMessage(lmsg, messenger.jgAddress, Version.CURRENT_ORDINAL);
interceptor.up(new Event(Event.MSG, jmsg));
verify(manager).processMessage(any(LeaveRequestMessage.class));
}
use of org.apache.geode.distributed.internal.membership.gms.messages.LeaveRequestMessage in project geode by apache.
the class GMSJoinLeaveJUnitTest method testLeaveCausesForcedDisconnect.
@Test
public void testLeaveCausesForcedDisconnect() throws Exception {
String reason = "testing";
initMocks();
prepareAndInstallView(gmsJoinLeaveMemberId, createMemberList(gmsJoinLeaveMemberId, mockMembers[0]));
gmsJoinLeave.getView().add(mockMembers[1]);
LeaveRequestMessage msg = new LeaveRequestMessage(gmsJoinLeave.getMemberID(), gmsJoinLeave.getMemberID(), reason);
msg.setSender(mockMembers[1]);
gmsJoinLeave.processMessage(msg);
verify(manager).forceDisconnect(reason);
}
Aggregations