Search in sources :

Example 1 with HazelcastInstanceImpl

use of com.hazelcast.instance.impl.HazelcastInstanceImpl in project hazelcast by hazelcast.

the class ClusterServiceImpl method shutdownNodesConcurrently.

private void shutdownNodesConcurrently(final long timeoutNanos) {
    Operation op = new ShutdownNodeOp();
    Collection<Member> members = getMembers(NON_LOCAL_MEMBER_SELECTOR);
    long startTimeNanos = Timer.nanos();
    logger.info("Sending shut down operations to all members...");
    while (Timer.nanosElapsed(startTimeNanos) < timeoutNanos && !members.isEmpty()) {
        for (Member member : members) {
            nodeEngine.getOperationService().send(op, member.getAddress());
        }
        try {
            Thread.sleep(CLUSTER_SHUTDOWN_SLEEP_DURATION_IN_MILLIS);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            logger.warning("Shutdown sleep interrupted. ", e);
            break;
        }
        members = getMembers(NON_LOCAL_MEMBER_SELECTOR);
    }
    logger.info("Number of other members remaining: " + getSize(NON_LOCAL_MEMBER_SELECTOR) + ". Shutting down itself.");
    HazelcastInstanceImpl hazelcastInstance = node.hazelcastInstance;
    hazelcastInstance.getLifecycleService().shutdown();
}
Also used : HazelcastInstanceImpl(com.hazelcast.instance.impl.HazelcastInstanceImpl) ShutdownNodeOp(com.hazelcast.internal.cluster.impl.operations.ShutdownNodeOp) Operation(com.hazelcast.spi.impl.operationservice.Operation) Member(com.hazelcast.cluster.Member)

Example 2 with HazelcastInstanceImpl

use of com.hazelcast.instance.impl.HazelcastInstanceImpl in project hazelcast by hazelcast.

the class TestProcessorMetaSupplierContext method setHazelcastInstance.

/**
 * Sets the Hazelcast instance.
 */
@Nonnull
public TestProcessorMetaSupplierContext setHazelcastInstance(@Nonnull HazelcastInstance instance) {
    this.instance = instance;
    if (this.instance instanceof HazelcastInstanceProxy || this.instance instanceof HazelcastInstanceImpl) {
        NodeEngineImpl nodeEngine = Util.getNodeEngine(this.instance);
        this.partitionAssignment = ExecutionPlanBuilder.getPartitionAssignment(nodeEngine, Util.getMembersView(nodeEngine).getMembers()).entrySet().stream().collect(toMap(en -> en.getKey().getAddress(), Entry::getValue));
    }
    return this;
}
Also used : HazelcastInstanceImpl(com.hazelcast.instance.impl.HazelcastInstanceImpl) NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Entry(java.util.Map.Entry) HazelcastInstanceProxy(com.hazelcast.instance.impl.HazelcastInstanceProxy) Nonnull(javax.annotation.Nonnull)

Example 3 with HazelcastInstanceImpl

use of com.hazelcast.instance.impl.HazelcastInstanceImpl in project hazelcast by hazelcast.

the class StreamEventJournalP method init.

@Override
protected void init(@Nonnull Context context) throws Exception {
    @SuppressWarnings("unchecked") CompletableFuture<EventJournalInitialSubscriberState>[] futures = new CompletableFuture[partitionIds.length];
    Arrays.setAll(futures, i -> eventJournalReader.subscribeToEventJournal(partitionIds[i]));
    for (int i = 0; i < futures.length; i++) {
        emitOffsets[i] = readOffsets[i] = getSequence(futures[i].get());
    }
    if (!isRemoteReader) {
        // try to serde projection/predicate to fail fast if they aren't known to IMDG
        HazelcastInstanceImpl hzInstance = Util.getHazelcastInstanceImpl(context.hazelcastInstance());
        InternalSerializationService ss = hzInstance.getSerializationService();
        try {
            deserializeWithCustomClassLoader(ss, hzInstance.getClass().getClassLoader(), ss.toData(predicate));
            deserializeWithCustomClassLoader(ss, hzInstance.getClass().getClassLoader(), ss.toData(projection));
        } catch (HazelcastSerializationException e) {
            throw new JetException("The projection or predicate classes are not known to IMDG. It's not enough to " + "add them to the job class path, they must be deployed using User code deployment: " + e, e);
        }
    }
}
Also used : HazelcastInstanceImpl(com.hazelcast.instance.impl.HazelcastInstanceImpl) CompletableFuture(java.util.concurrent.CompletableFuture) HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) JetException(com.hazelcast.jet.JetException)

Example 4 with HazelcastInstanceImpl

use of com.hazelcast.instance.impl.HazelcastInstanceImpl in project hazelcast by hazelcast.

the class CacheThroughHazelcastInstanceTest method getCache_whenOtherHazelcastExceptionIsThrown_thenFail.

@Test
public void getCache_whenOtherHazelcastExceptionIsThrown_thenFail() {
    // when one attempts to getCache but a HazelcastException other than ServiceNotFoundException is thrown
    HazelcastInstanceImpl hzInstanceImpl = mock(HazelcastInstanceImpl.class);
    when(hzInstanceImpl.getDistributedObject(anyString(), anyString())).thenThrow(new HazelcastException("mock hz exception"));
    // then the thrown HazelcastException is rethrown by getCache
    ICacheManager hzCacheManager = new HazelcastInstanceCacheManager(hzInstanceImpl);
    thrown.expect(HazelcastException.class);
    hzCacheManager.getCache("any-cache");
}
Also used : HazelcastInstanceImpl(com.hazelcast.instance.impl.HazelcastInstanceImpl) HazelcastInstanceCacheManager(com.hazelcast.cache.impl.HazelcastInstanceCacheManager) HazelcastException(com.hazelcast.core.HazelcastException) ICacheManager(com.hazelcast.core.ICacheManager) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with HazelcastInstanceImpl

use of com.hazelcast.instance.impl.HazelcastInstanceImpl in project hazelcast by hazelcast.

the class HazelcastStarterTest method testHazelcastInstanceCompatibility.

private static void testHazelcastInstanceCompatibility(HazelcastInstance instance, TestHazelcastInstanceFactory factory) {
    Node node = TestUtil.getNode(instance);
    HazelcastInstanceImpl instanceImpl = TestUtil.getHazelcastInstanceImpl(instance);
    if (factory != null) {
        assertEquals("Expected one active HazelcastInstance in the factory", 1, factory.getAllHazelcastInstances().size());
    }
    assertNode(node, true);
    assertHazelcastInstanceImpl(instanceImpl);
    assertSafePartitionServiceState(instance);
    instance.shutdown();
    assertNode(node, false);
    if (factory != null) {
        assertEquals("Expected no active HazelcastInstances in the factory", 0, factory.getAllHazelcastInstances().size());
    }
    assertGetNodeFromShutdownInstance(instance);
    assertGetHazelcastInstanceImplFromShutdownInstance(instance);
    assertSafePartitionServiceState(instance);
}
Also used : HazelcastInstanceImpl(com.hazelcast.instance.impl.HazelcastInstanceImpl) Node(com.hazelcast.instance.impl.Node)

Aggregations

HazelcastInstanceImpl (com.hazelcast.instance.impl.HazelcastInstanceImpl)14 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)4 QuickTest (com.hazelcast.test.annotation.QuickTest)4 Test (org.junit.Test)4 CacheTestSupport.createServerCachingProvider (com.hazelcast.cache.CacheTestSupport.createServerCachingProvider)3 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)3 Operation (com.hazelcast.spi.impl.operationservice.Operation)3 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)3 Field (java.lang.reflect.Field)3 CachingProvider (javax.cache.spi.CachingProvider)3 HazelcastCacheManager (com.hazelcast.cache.HazelcastCacheManager)2 CacheService (com.hazelcast.cache.impl.CacheService)2 HazelcastServerCacheManager (com.hazelcast.cache.impl.HazelcastServerCacheManager)2 Address (com.hazelcast.cluster.Address)2 Member (com.hazelcast.cluster.Member)2 HazelcastInstanceProxy (com.hazelcast.instance.impl.HazelcastInstanceProxy)2 Node (com.hazelcast.instance.impl.Node)2 ShutdownNodeOp (com.hazelcast.internal.cluster.impl.operations.ShutdownNodeOp)2 Accessors.getHazelcastInstanceImpl (com.hazelcast.test.Accessors.getHazelcastInstanceImpl)2