use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.
the class AdminDistributedSystemImpl method removeSystemMember.
/**
* Removes a SystemMember from this system's list of known members. This method is called in
* response to a member leaving the system. TODO: this method is a mess of defns
*
* @param internalId the unique id that specifies which member to remove
* @return the system member that was removed; null if no match was found
*/
protected SystemMember removeSystemMember(InternalDistributedMember internalId) {
if (internalId == null)
return null;
// this.logger.info("DEBUG: removeSystemMember: " + internalId, new RuntimeException("STACK"));
boolean found = false;
SystemMemberImpl member = null;
synchronized (this.cacheServerSet) {
SERVERS: for (Iterator iter = this.cacheServerSet.iterator(); iter.hasNext() && !found; ) {
Future future = (Future) iter.next();
if (future instanceof AdminFutureTask) {
AdminFutureTask task = (AdminFutureTask) future;
if (task.getMemberId().equals(internalId)) {
// this.logger.info("DEBUG: removeSystemMember cs cancelling: " + future);
future.cancel(true);
} else {
// This is not the member we are looking for...
continue SERVERS;
}
}
for (; ; ) {
checkCancellation();
boolean interrupted = Thread.interrupted();
try {
member = (SystemMemberImpl) future.get();
// success
break;
} catch (InterruptedException ex) {
interrupted = true;
// keep trying
continue;
} catch (CancellationException ex) {
continue SERVERS;
} catch (ExecutionException ex) {
handle(ex);
// Dead code
return null;
} finally {
if (interrupted) {
Thread.currentThread().interrupt();
}
}
}
InternalDistributedMember cacheServerId = member.getInternalId();
if (internalId.equals(cacheServerId)) {
// found a match...
iter.remove();
found = true;
}
}
// SERVERS
}
synchronized (this.applicationSet) {
for (Iterator iter = this.applicationSet.iterator(); iter.hasNext() && !found; ) {
Future future = (Future) iter.next();
try {
if (future instanceof AdminFutureTask) {
AdminFutureTask task = (AdminFutureTask) future;
if (task.getMemberId().equals(internalId)) {
// Only remove applications
iter.remove();
found = true;
if (future.isDone()) {
member = (SystemMemberImpl) future.get();
}
break;
} else {
// This is not the member we are looking for...
continue;
}
}
if (future.isDone()) {
member = (SystemMemberImpl) future.get();
} else {
// this.logger.info("DEBUG: removeSystemMember as cancelling: " + future);
future.cancel(true);
}
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
checkCancellation();
throw new RuntimeException(LocalizedStrings.AdminDistributedSystemImpl_INTERRUPTED.toLocalizedString(), ex);
} catch (CancellationException ex) {
continue;
} catch (ExecutionException ex) {
handle(ex);
// Dead code
return null;
}
InternalDistributedMember applicationId = member.getInternalId();
if (internalId.equals(applicationId)) {
// found a match...
// Only remove applications
iter.remove();
found = true;
}
}
}
if (found) {
try {
if (member != null) {
member.setGemFireVM(null);
}
} catch (AdminException ex) {
logger.fatal(LocalizedMessage.create(LocalizedStrings.AdminDistributedSystem_UNEXPECTED_ADMINEXCEPTION), ex);
}
return member;
} else {
if (logger.isDebugEnabled()) {
logger.debug("Couldn't remove member {}", internalId);
}
return null;
}
}
use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.
the class AdminDistributedSystemImpl method isSame.
/**
* Returns whether or not a <code>SystemMember</code> corresponds to a <code>GemFireVM</code>.
*
* @param examineConfig Should we take the configuration of the member into consideration? In
* general, we want to consider the configuration when a member starts up. But when we are
* notified that it has shut down, we do not want to examine the configuration because that
* might involve contacting the member. Which, of course, cannot be done because it has
* shut down.
*/
private boolean isSame(SystemMemberImpl member, GemFireVM vm, boolean examineConfig) {
if (vm.equals(member.getGemFireVM())) {
return true;
}
InternalDistributedMember memberId = member.getInternalId();
InternalDistributedMember vmId = vm.getId();
if (vmId.equals(memberId)) {
return true;
}
if ((member instanceof ManagedSystemMemberImpl) && examineConfig) {
// We can't compare information about managers because the
// member might have already gone away. Attempts to send it
// messages (to get its product directory, for instance) will
// time out.
ManagedSystemMemberImpl entity = (ManagedSystemMemberImpl) member;
// type of the internal admin object.
if (entity instanceof CacheServer) {
if (!(vm instanceof ApplicationVM)) {
return false;
}
ApplicationVM app = (ApplicationVM) vm;
if (!app.isDedicatedCacheServer()) {
return false;
}
}
ManagedEntityConfig conf = entity.getEntityConfig();
InetAddress managedHost = InetAddressUtil.toInetAddress(conf.getHost());
File managedWorkingDir = new File(conf.getWorkingDirectory());
File managedProdDir = new File(conf.getProductDirectory());
InetAddress vmHost = vm.getHost();
File vmWorkingDir = vm.getWorkingDirectory();
File vmProdDir = vm.getGeodeHomeDir();
if (vmHost.equals(managedHost) && isSameFile(vmWorkingDir, managedWorkingDir) && isSameFile(vmProdDir, managedProdDir)) {
return true;
}
}
return false;
}
use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.
the class GemFireMemberStatus method initializePeers.
protected void initializePeers(DistributedSystem distributedSystem) {
InternalDistributedSystem ids = (InternalDistributedSystem) distributedSystem;
DM dm = ids.getDistributionManager();
Set connections = dm.getOtherNormalDistributionManagerIds();
Set connectionsIDs = new HashSet(connections.size());
for (Iterator iter = connections.iterator(); iter.hasNext(); ) {
InternalDistributedMember idm = (InternalDistributedMember) iter.next();
connectionsIDs.add(idm.getId());
}
setConnectedPeers(connectionsIDs);
}
use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.
the class DistributionManager method getRoleCount.
/** Returns count of members filling the specified role */
public int getRoleCount(Role role) {
int count = 0;
Set mbrs = getDistributionManagerIds();
for (Iterator mbrIter = mbrs.iterator(); mbrIter.hasNext(); ) {
Set roles = ((InternalDistributedMember) mbrIter.next()).getRoles();
for (Iterator rolesIter = roles.iterator(); rolesIter.hasNext(); ) {
Role mbrRole = (Role) rolesIter.next();
if (mbrRole.equals(role)) {
count++;
break;
}
}
}
return count;
}
use of org.apache.geode.distributed.internal.membership.InternalDistributedMember in project geode by apache.
the class DistributionManager method getMembersInSameZone.
public Set<InternalDistributedMember> getMembersInSameZone(InternalDistributedMember targetMember) {
Set<InternalDistributedMember> buddyMembers = new HashSet<InternalDistributedMember>();
if (!redundancyZones.isEmpty()) {
synchronized (redundancyZones) {
String targetZone = redundancyZones.get(targetMember);
for (Map.Entry<InternalDistributedMember, String> entry : redundancyZones.entrySet()) {
if (entry.getValue().equals(targetZone)) {
buddyMembers.add(entry.getKey());
}
}
}
} else {
buddyMembers.add(targetMember);
Set targetAddrs = getEquivalents(targetMember.getInetAddress());
for (Iterator i = getDistributionManagerIds().iterator(); i.hasNext(); ) {
InternalDistributedMember o = (InternalDistributedMember) i.next();
if (SetUtils.intersectsWith(targetAddrs, getEquivalents(o.getInetAddress()))) {
buddyMembers.add(o);
}
}
}
return buddyMembers;
}
Aggregations