Search in sources :

Example 6 with DistributedObjectNamespace

use of com.hazelcast.internal.services.DistributedObjectNamespace in project hazelcast by hazelcast.

the class PartitionReplicaVersionsCorrectnessStressTest method verifyReplicaVersions.

private void verifyReplicaVersions(PartitionReplicaVersionsView initialReplicaVersions, PartitionReplicaVersionsView replicaVersions, int minSurvivingReplicaIndex, String message) {
    Set<String> lostMapNames = new HashSet<String>();
    for (int i = 0; i < minSurvivingReplicaIndex; i++) {
        lostMapNames.add(getIthMapName(i));
    }
    for (ServiceNamespace namespace : initialReplicaVersions.getNamespaces()) {
        if (replicaVersions.getVersions(namespace) == null) {
            if (namespace instanceof DistributedObjectNamespace) {
                String objectName = ((DistributedObjectNamespace) namespace).getObjectName();
                assertThat(objectName, Matchers.isIn(lostMapNames));
                continue;
            } else {
                fail("No replica version found for " + namespace);
            }
        }
        verifyReplicaVersions(initialReplicaVersions.getVersions(namespace), replicaVersions.getVersions(namespace), minSurvivingReplicaIndex, message);
    }
}
Also used : ServiceNamespace(com.hazelcast.internal.services.ServiceNamespace) DistributedObjectNamespace(com.hazelcast.internal.services.DistributedObjectNamespace) HashSet(java.util.HashSet)

Example 7 with DistributedObjectNamespace

use of com.hazelcast.internal.services.DistributedObjectNamespace in project hazelcast by hazelcast.

the class ProxyManager method getOrCreateProxyInternal.

private ClientProxy getOrCreateProxyInternal(@Nonnull String service, @Nonnull String id, boolean remote) {
    checkNotNull(service, "Service name is required!");
    checkNotNull(id, "Object name is required!");
    final ObjectNamespace ns = new DistributedObjectNamespace(service, id);
    ClientProxyFuture proxyFuture = proxies.get(ns);
    if (proxyFuture != null) {
        return proxyFuture.get();
    }
    ClientProxyFactory factory = proxyFactories.get(service);
    if (factory == null) {
        throw new ClientServiceNotFoundException("No factory registered for service: " + service);
    }
    proxyFuture = new ClientProxyFuture();
    ClientProxyFuture current = proxies.putIfAbsent(ns, proxyFuture);
    if (current != null) {
        return current.get();
    }
    try {
        ClientProxy clientProxy = createClientProxy(id, factory);
        if (remote) {
            initialize(clientProxy);
        } else {
            clientProxy.onInitialize();
        }
        proxyFuture.set(clientProxy);
        return clientProxy;
    } catch (Throwable e) {
        proxies.remove(ns);
        proxyFuture.set(e);
        throw rethrow(e);
    }
}
Also used : DistributedObjectNamespace(com.hazelcast.internal.services.DistributedObjectNamespace) ClientServiceNotFoundException(com.hazelcast.client.impl.spi.impl.ClientServiceNotFoundException) DistributedObjectNamespace(com.hazelcast.internal.services.DistributedObjectNamespace) ObjectNamespace(com.hazelcast.internal.services.ObjectNamespace)

Example 8 with DistributedObjectNamespace

use of com.hazelcast.internal.services.DistributedObjectNamespace in project hazelcast by hazelcast.

the class ProxyManager method destroyProxy.

/**
 * Destroys the given proxy in a cluster-wide way.
 * <p>
 * Upon successful completion the proxy is unregistered in this proxy
 * manager, all local resources associated with the proxy are released and
 * a distributed object destruction operation is issued to the cluster.
 * <p>
 * If the given proxy instance is not registered in this proxy manager, the
 * proxy instance is considered stale. In this case, this stale instance is
 * a subject to a local-only destruction and its registered counterpart, if
 * there is any, is a subject to a cluster-wide destruction.
 *
 * @param proxy the proxy to destroy.
 */
public void destroyProxy(ClientProxy proxy) {
    ObjectNamespace objectNamespace = new DistributedObjectNamespace(proxy.getServiceName(), proxy.getDistributedObjectName());
    ClientProxyFuture registeredProxyFuture = proxies.remove(objectNamespace);
    ClientProxy registeredProxy = registeredProxyFuture == null ? null : registeredProxyFuture.get();
    try {
        if (registeredProxy != null) {
            try {
                registeredProxy.destroyLocally();
            } finally {
                registeredProxy.destroyRemotely();
            }
        }
    } finally {
        if (proxy != registeredProxy) {
            // The given proxy is stale and was already destroyed, but the caller
            // may have allocated local resources in the context of this stale proxy
            // instance after it was destroyed, so we have to cleanup it locally one
            // more time to make sure there are no leaking local resources.
            proxy.destroyLocally();
        }
    }
}
Also used : DistributedObjectNamespace(com.hazelcast.internal.services.DistributedObjectNamespace) DistributedObjectNamespace(com.hazelcast.internal.services.DistributedObjectNamespace) ObjectNamespace(com.hazelcast.internal.services.ObjectNamespace)

Example 9 with DistributedObjectNamespace

use of com.hazelcast.internal.services.DistributedObjectNamespace in project hazelcast by hazelcast.

the class EventJournalReadOperation method beforeRun.

/**
 * {@inheritDoc}
 * Checks the precondition that the start sequence is already
 * available (in the event journal) or is the sequence of the
 * next event to be added into the journal.
 */
@Override
public void beforeRun() {
    namespace = new DistributedObjectNamespace(getServiceName(), name);
    final EventJournal<J> journal = getJournal();
    if (!journal.hasEventJournal(namespace)) {
        throw new UnsupportedOperationException("Cannot subscribe to event journal because it is either not configured or disabled for " + namespace);
    }
    final int partitionId = getPartitionId();
    journal.cleanup(namespace, partitionId);
    startSequence = clampToBounds(journal, partitionId, startSequence);
    journal.isAvailableOrNextSequence(namespace, partitionId, startSequence);
    // we'll store the wait notify key because ICache destroys the record store
    // and the cache config is unavailable at the time operations are being
    // cancelled. Hence, we cannot create the journal and fetch it's wait notify
    // key
    waitNotifyKey = journal.getWaitNotifyKey(namespace, partitionId);
}
Also used : DistributedObjectNamespace(com.hazelcast.internal.services.DistributedObjectNamespace)

Example 10 with DistributedObjectNamespace

use of com.hazelcast.internal.services.DistributedObjectNamespace in project hazelcast by hazelcast.

the class Invocation_BlockingTest method sync_whenGetTimeout.

/**
 * Checks if a get with a timeout is called, and the timeout expires, that we get a TimeoutException.
 */
@Test
public void sync_whenGetTimeout() throws Exception {
    Config config = new Config();
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance local = factory.newHazelcastInstance(config);
    HazelcastInstance remote = factory.newHazelcastInstance(config);
    warmUpPartitions(factory.getAllHazelcastInstances());
    NodeEngineImpl nodeEngine = getNodeEngineImpl(local);
    String key = generateKeyOwnedBy(remote);
    int partitionId = nodeEngine.getPartitionService().getPartitionId(key);
    // first we execute an operation that stall the partition
    OperationServiceImpl opService = nodeEngine.getOperationService();
    opService.invokeOnPartition(null, new SlowOperation(SECONDS.toMillis(5)), partitionId);
    // then we execute a lock operation that won't be executed because the partition is blocked.
    LockOperation op = new LockOperation(new DistributedObjectNamespace(SERVICE_NAME, key), nodeEngine.toData(key), 1, -1, -1);
    InternalCompletableFuture<Object> future = opService.createInvocationBuilder(null, op, partitionId).invoke();
    // we do a get with a very short timeout; so we should get a TimeoutException
    try {
        future.get(1, SECONDS);
        fail();
    } catch (TimeoutException expected) {
        ignore(expected);
    }
    // if we do a get with a long enough timeout, the call will complete without a problem
    Object result = future.get(60, SECONDS);
    assertEquals(Boolean.TRUE, result);
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Accessors.getNodeEngineImpl(com.hazelcast.test.Accessors.getNodeEngineImpl) LockOperation(com.hazelcast.internal.locksupport.operations.LockOperation) Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) DistributedObjectNamespace(com.hazelcast.internal.services.DistributedObjectNamespace) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) TimeoutException(java.util.concurrent.TimeoutException) OperationTimeoutException(com.hazelcast.core.OperationTimeoutException) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

DistributedObjectNamespace (com.hazelcast.internal.services.DistributedObjectNamespace)14 Config (com.hazelcast.config.Config)8 HazelcastInstance (com.hazelcast.core.HazelcastInstance)8 LockOperation (com.hazelcast.internal.locksupport.operations.LockOperation)7 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)7 Accessors.getNodeEngineImpl (com.hazelcast.test.Accessors.getNodeEngineImpl)7 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)7 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)7 QuickTest (com.hazelcast.test.annotation.QuickTest)7 Test (org.junit.Test)7 UnlockOperation (com.hazelcast.internal.locksupport.operations.UnlockOperation)4 ObjectNamespace (com.hazelcast.internal.services.ObjectNamespace)4 OperationTimeoutException (com.hazelcast.core.OperationTimeoutException)3 IsLockedOperation (com.hazelcast.internal.locksupport.operations.IsLockedOperation)3 NodeEngine (com.hazelcast.spi.impl.NodeEngine)2 Operation (com.hazelcast.spi.impl.operationservice.Operation)2 TimeoutException (java.util.concurrent.TimeoutException)2 ClientServiceNotFoundException (com.hazelcast.client.impl.spi.impl.ClientServiceNotFoundException)1 ServiceConfig (com.hazelcast.config.ServiceConfig)1 LockProxySupport (com.hazelcast.internal.locksupport.LockProxySupport)1