use of org.apache.geode.distributed.internal.InternalDistributedSystem in project geode by apache.
the class JtaNoninvolvementJUnitTest method after.
@After
public void after() {
closeCache();
InternalDistributedSystem ids = InternalDistributedSystem.getAnyInstance();
if (ids != null) {
ids.disconnect();
}
}
use of org.apache.geode.distributed.internal.InternalDistributedSystem in project geode by apache.
the class LonerDMJUnitTest method testMemberId.
@Test
public void testMemberId() throws UnknownHostException {
String host = InetAddress.getLocalHost().getCanonicalHostName();
String name = "Foo";
Properties cfg = new Properties();
cfg.setProperty(MCAST_PORT, "0");
cfg.setProperty(LOCATORS, "");
cfg.setProperty(ROLES, "lonelyOne");
cfg.setProperty(NAME, name);
cfg.setProperty(ENABLE_NETWORK_PARTITION_DETECTION, "false");
DistributedSystem ds = DistributedSystem.connect(cfg);
System.out.println("MemberId = " + ds.getMemberId());
assertEquals(host.toString(), ds.getDistributedMember().getHost());
assertEquals(OSProcess.getId(), ds.getDistributedMember().getProcessId());
if (!PureJavaMode.isPure()) {
String pid = String.valueOf(OSProcess.getId());
assertTrue(ds.getMemberId().indexOf(pid) > -1);
}
assertTrue(ds.getMemberId().indexOf(name) > -1);
String memberid = ds.getMemberId();
String shortname = shortName(host);
assertTrue("'" + memberid + "' does not contain '" + shortname + "'", memberid.indexOf(shortname) > -1);
// make sure the loner port can be updated
((LonerDistributionManager) ((InternalDistributedSystem) ds).getDM()).updateLonerPort(100);
}
use of org.apache.geode.distributed.internal.InternalDistributedSystem in project geode by apache.
the class InternalRole method getCount.
public int getCount() {
InternalDistributedSystem sys = InternalDistributedSystem.getAnyInstance();
if (sys == null) {
throw new IllegalStateException(LocalizedStrings.InternalRole_GETCOUNT_REQUIRES_A_CONNECTION_TO_THE_DISTRIBUTED_SYSTEM.toLocalizedString());
}
DM dm = sys.getDistributionManager();
return dm.getRoleCount(this);
}
use of org.apache.geode.distributed.internal.InternalDistributedSystem in project geode by apache.
the class ShutdownAllRequest method createResponse.
@Override
protected AdminResponse createResponse(DistributionManager dm) {
boolean isToShutdown = hasCache();
if (isToShutdown) {
boolean isSuccess = false;
try {
GemFireCacheImpl.getInstance().shutDownAll();
isSuccess = true;
} 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();
if (t instanceof InternalGemFireError) {
logger.fatal("DistributedSystem is closed due to InternalGemFireError", t);
} else {
logger.fatal("DistributedSystem is closed due to unexpected exception", t);
}
} finally {
if (!isSuccess) {
InternalDistributedMember me = dm.getDistributionManagerId();
InternalDistributedSystem ids = dm.getSystem();
if (!this.getSender().equals(me)) {
if (ids.isConnected()) {
logger.fatal("ShutdownAllRequest: disconnect distributed without response.");
ids.disconnect();
}
}
}
}
}
return new ShutdownAllResponse(this.getSender(), isToShutdown);
}
use of org.apache.geode.distributed.internal.InternalDistributedSystem in project geode by apache.
the class ShutdownAllRequest method send.
/**
* Sends a shutdownAll request to all other members and performs local shutdownAll processing in
* the waitingThreadPool.
*/
public static Set send(final DM dm, long timeout) {
boolean hadCache = hasCache();
DistributionManager dism = dm instanceof DistributionManager ? (DistributionManager) dm : null;
InternalDistributedMember myId = dm.getDistributionManagerId();
Set recipients = dm.getOtherNormalDistributionManagerIds();
recipients.remove(myId);
// now do shutdownall
ShutdownAllRequest request = new ShutdownAllRequest();
request.setRecipients(recipients);
ShutDownAllReplyProcessor replyProcessor = new ShutDownAllReplyProcessor(dm, recipients);
request.msgId = replyProcessor.getProcessorId();
dm.putOutgoing(request);
if (!InternalLocator.isDedicatedLocator()) {
if (hadCache && dism != null) {
AdminResponse response;
try {
request.setSender(myId);
response = request.createResponse(dism);
} catch (Exception ex) {
if (logger.isDebugEnabled()) {
logger.debug("caught exception while processing shutdownAll locally", ex);
}
response = AdminFailureResponse.create(dism, myId, ex);
}
response.setSender(myId);
replyProcessor.process(response);
}
}
boolean interrupted = false;
try {
if (!replyProcessor.waitForReplies(timeout)) {
return null;
}
} catch (ReplyException e) {
if (!(e.getCause() instanceof CancelException)) {
e.handleAsUnexpected();
}
} catch (CancelException ignore) {
// expected
} catch (InterruptedException ignore) {
interrupted = true;
}
// wait until all the recipients send response, shut down itself (if not a locator)
if (hadCache) {
// because the cache is closed at GemFireCacheImpl.getInstance().shutDownAll()
if (!InternalLocator.isDedicatedLocator()) {
InternalDistributedSystem ids = dm.getSystem();
if (ids.isConnected()) {
ids.disconnect();
}
}
}
if (interrupted) {
Thread.currentThread().interrupt();
}
try {
Thread.sleep(3 * SLEEP_TIME_BEFORE_DISCONNECT_DS);
} catch (InterruptedException ignore) {
}
return replyProcessor.getResults();
}
Aggregations