Search in sources :

Example 61 with InternalDistributedSystem

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();
    }
}
Also used : InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) After(org.junit.After)

Example 62 with InternalDistributedSystem

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);
}
Also used : ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) DistributedSystem(org.apache.geode.distributed.DistributedSystem) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) LonerDistributionManager(org.apache.geode.distributed.internal.LonerDistributionManager) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 63 with InternalDistributedSystem

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

Example 64 with InternalDistributedSystem

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

Example 65 with InternalDistributedSystem

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();
}
Also used : TreeSet(java.util.TreeSet) Set(java.util.Set) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) CancelException(org.apache.geode.CancelException) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) ReplyException(org.apache.geode.distributed.internal.ReplyException) CancelException(org.apache.geode.CancelException) IOException(java.io.IOException) ReplyException(org.apache.geode.distributed.internal.ReplyException)

Aggregations

InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)209 Properties (java.util.Properties)70 Test (org.junit.Test)60 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)58 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)41 IOException (java.io.IOException)35 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)32 DM (org.apache.geode.distributed.internal.DM)30 File (java.io.File)22 HashSet (java.util.HashSet)21 Set (java.util.Set)20 AttributesFactory (org.apache.geode.cache.AttributesFactory)19 DistributionConfig (org.apache.geode.distributed.internal.DistributionConfig)19 Region (org.apache.geode.cache.Region)17 ArrayList (java.util.ArrayList)16 DistributionManager (org.apache.geode.distributed.internal.DistributionManager)16 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)14 VM (org.apache.geode.test.dunit.VM)14 Cache (org.apache.geode.cache.Cache)13 IgnoredException (org.apache.geode.test.dunit.IgnoredException)13