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);
}
}
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);
}
}
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();
}
}
}
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);
}
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);
}
Aggregations