Search in sources :

Example 11 with DistributedObject

use of com.hazelcast.core.DistributedObject in project hazelcast by hazelcast.

the class ReplicatedMapTest method testDestroy.

@Test
public void testDestroy() throws Exception {
    HazelcastInstance instance = createHazelcastInstance();
    ReplicatedMap<Object, Object> replicatedMap = instance.getReplicatedMap(randomName());
    replicatedMap.put(1, 1);
    replicatedMap.destroy();
    Collection<DistributedObject> objects = instance.getDistributedObjects();
    assertEquals(0, objects.size());
}
Also used : DistributedObject(com.hazelcast.core.DistributedObject) HazelcastInstance(com.hazelcast.core.HazelcastInstance) DistributedObject(com.hazelcast.core.DistributedObject) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 12 with DistributedObject

use of com.hazelcast.core.DistributedObject in project hazelcast by hazelcast.

the class HazelcastOSGiInstanceTest method getDistributedObjectCalledSuccessfullyOverOSGiInstance.

@Test
public void getDistributedObjectCalledSuccessfullyOverOSGiInstance() {
    DistributedObject mockDistributedObject = mock(DistributedObject.class);
    HazelcastInstance mockHazelcastInstance = mock(HazelcastInstance.class);
    HazelcastOSGiInstance hazelcastOSGiInstance = HazelcastOSGiTestUtil.createHazelcastOSGiInstance(mockHazelcastInstance);
    when(mockHazelcastInstance.getDistributedObject("my-service", "my-name")).thenReturn(mockDistributedObject);
    assertEquals(mockDistributedObject, hazelcastOSGiInstance.getDistributedObject("my-service", "my-name"));
    verify(mockHazelcastInstance).getDistributedObject("my-service", "my-name");
}
Also used : DistributedObject(com.hazelcast.core.DistributedObject) HazelcastInstance(com.hazelcast.core.HazelcastInstance) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 13 with DistributedObject

use of com.hazelcast.core.DistributedObject in project hazelcast by hazelcast.

the class MapPartitionAwareService method onPartitionLost.

@Override
public void onPartitionLost(IPartitionLostEvent partitionLostEvent) {
    final Address thisAddress = nodeEngine.getThisAddress();
    final int partitionId = partitionLostEvent.getPartitionId();
    Collection<DistributedObject> result = proxyService.getDistributedObjects(MapService.SERVICE_NAME);
    for (DistributedObject object : result) {
        final MapProxyImpl mapProxy = (MapProxyImpl) object;
        final String mapName = mapProxy.getName();
        if (mapProxy.getTotalBackupCount() <= partitionLostEvent.getLostReplicaIndex()) {
            mapServiceContext.getMapEventPublisher().publishMapPartitionLostEvent(thisAddress, mapName, partitionId);
        }
    }
}
Also used : DistributedObject(com.hazelcast.core.DistributedObject) Address(com.hazelcast.nio.Address) MapProxyImpl(com.hazelcast.map.impl.proxy.MapProxyImpl)

Example 14 with DistributedObject

use of com.hazelcast.core.DistributedObject in project hazelcast by hazelcast.

the class ClientMapPartitionLostListenerTest method assertProxyExistsEventually.

private void assertProxyExistsEventually(HazelcastInstance instance, final String proxyName) {
    final InternalProxyService proxyService = getNodeEngineImpl(instance).getProxyService();
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            Collection<DistributedObject> allDistributedObjects = proxyService.getAllDistributedObjects();
            for (DistributedObject distributedObject : allDistributedObjects) {
                if (distributedObject.getName().equals(proxyName)) {
                    return;
                }
            }
            fail("There is no proxy with name " + proxyName + " created (yet)");
        }
    });
}
Also used : DistributedObject(com.hazelcast.core.DistributedObject) AssertTask(com.hazelcast.test.AssertTask) Collection(java.util.Collection) InternalProxyService(com.hazelcast.spi.impl.proxyservice.InternalProxyService)

Example 15 with DistributedObject

use of com.hazelcast.core.DistributedObject in project hazelcast by hazelcast.

the class ProxyRegistry method destroyProxy.

/**
     * Destroys a proxy.
     *
     * @param name         The name of the proxy to destroy.
     * @param publishEvent true if this destroy should be published.
     */
void destroyProxy(String name, boolean publishEvent) {
    final DistributedObjectFuture proxyFuture = proxies.remove(name);
    if (proxyFuture == null) {
        return;
    }
    DistributedObject proxy;
    try {
        proxy = proxyFuture.get();
    } catch (Throwable t) {
        proxyService.logger.warning("Cannot destroy proxy [" + serviceName + ":" + name + "], since its creation is failed with " + t.getClass().getName() + ": " + t.getMessage());
        return;
    }
    InternalEventService eventService = proxyService.nodeEngine.getEventService();
    ProxyEventProcessor callback = new ProxyEventProcessor(proxyService.listeners.values(), DESTROYED, serviceName, name, proxy);
    eventService.executeEventCallback(callback);
    if (publishEvent) {
        publish(new DistributedObjectEventPacket(DESTROYED, serviceName, name));
    }
}
Also used : DistributedObject(com.hazelcast.core.DistributedObject) AbstractDistributedObject(com.hazelcast.spi.AbstractDistributedObject) InternalEventService(com.hazelcast.spi.impl.eventservice.InternalEventService)

Aggregations

DistributedObject (com.hazelcast.core.DistributedObject)17 HazelcastInstance (com.hazelcast.core.HazelcastInstance)6 QuickTest (com.hazelcast.test.annotation.QuickTest)6 Test (org.junit.Test)6 ParallelTest (com.hazelcast.test.annotation.ParallelTest)5 IMap (com.hazelcast.core.IMap)3 MapProxyImpl (com.hazelcast.map.impl.proxy.MapProxyImpl)3 AbstractDistributedObject (com.hazelcast.spi.AbstractDistributedObject)3 Collection (java.util.Collection)3 DistributedObjectInfo (com.hazelcast.client.impl.client.DistributedObjectInfo)2 DistributedObjectEvent (com.hazelcast.core.DistributedObjectEvent)2 DistributedObjectListener (com.hazelcast.core.DistributedObjectListener)2 MapService (com.hazelcast.map.impl.MapService)2 InternalEventService (com.hazelcast.spi.impl.eventservice.InternalEventService)2 AssertTask (com.hazelcast.test.AssertTask)2 NightlyTest (com.hazelcast.test.annotation.NightlyTest)2 HashSet (java.util.HashSet)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)1 ClientGetDistributedObjectsCodec (com.hazelcast.client.impl.protocol.codec.ClientGetDistributedObjectsCodec)1