Search in sources :

Example 6 with DistributedObject

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

the class MapFlushMessageTask method call.

@Override
protected Object call() throws Exception {
    MapService mapService = getService(SERVICE_NAME);
    MapServiceContext mapServiceContext = mapService.getMapServiceContext();
    NodeEngine nodeEngine = mapServiceContext.getNodeEngine();
    ProxyService proxyService = nodeEngine.getProxyService();
    DistributedObject distributedObject = proxyService.getDistributedObject(SERVICE_NAME, parameters.name);
    MapProxyImpl mapProxy = (MapProxyImpl) distributedObject;
    mapProxy.flush();
    return null;
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) DistributedObject(com.hazelcast.core.DistributedObject) ProxyService(com.hazelcast.spi.ProxyService) MapProxyImpl(com.hazelcast.map.impl.proxy.MapProxyImpl) MapService(com.hazelcast.map.impl.MapService) MapServiceContext(com.hazelcast.map.impl.MapServiceContext)

Example 7 with DistributedObject

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

the class MapLoadAllMessageTask method call.

@Override
protected Object call() {
    final MapService mapService = getService(MapService.SERVICE_NAME);
    final DistributedObject distributedObject = mapService.getMapServiceContext().getNodeEngine().getProxyService().getDistributedObject(MapService.SERVICE_NAME, parameters.name);
    final MapProxyImpl mapProxy = (MapProxyImpl) distributedObject;
    mapProxy.loadAll(parameters.replaceExistingValues);
    return null;
}
Also used : DistributedObject(com.hazelcast.core.DistributedObject) MapProxyImpl(com.hazelcast.map.impl.proxy.MapProxyImpl) MapService(com.hazelcast.map.impl.MapService)

Example 8 with DistributedObject

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

the class HazelcastClientInstanceImpl method getDistributedObjects.

@Override
public Collection<DistributedObject> getDistributedObjects() {
    try {
        ClientMessage request = ClientGetDistributedObjectsCodec.encodeRequest();
        final Future<ClientMessage> future = new ClientInvocation(this, request).invoke();
        ClientMessage response = future.get();
        ClientGetDistributedObjectsCodec.ResponseParameters resultParameters = ClientGetDistributedObjectsCodec.decodeResponse(response);
        Collection<? extends DistributedObject> distributedObjects = proxyManager.getDistributedObjects();
        Set<DistributedObjectInfo> localDistributedObjects = new HashSet<DistributedObjectInfo>();
        for (DistributedObject localInfo : distributedObjects) {
            localDistributedObjects.add(new DistributedObjectInfo(localInfo.getServiceName(), localInfo.getName()));
        }
        Collection<DistributedObjectInfo> newDistributedObjectInfo = resultParameters.response;
        for (DistributedObjectInfo distributedObjectInfo : newDistributedObjectInfo) {
            localDistributedObjects.remove(distributedObjectInfo);
            getDistributedObject(distributedObjectInfo.getServiceName(), distributedObjectInfo.getName());
        }
        for (DistributedObjectInfo distributedObjectInfo : localDistributedObjects) {
            proxyManager.removeProxy(distributedObjectInfo.getServiceName(), distributedObjectInfo.getName());
        }
        return (Collection<DistributedObject>) proxyManager.getDistributedObjects();
    } catch (Exception e) {
        throw ExceptionUtil.rethrow(e);
    }
}
Also used : DistributedObject(com.hazelcast.core.DistributedObject) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) TransactionException(com.hazelcast.transaction.TransactionException) DistributedObjectInfo(com.hazelcast.client.impl.client.DistributedObjectInfo) Collection(java.util.Collection) ClientGetDistributedObjectsCodec(com.hazelcast.client.impl.protocol.codec.ClientGetDistributedObjectsCodec) HashSet(java.util.HashSet)

Example 9 with DistributedObject

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

the class ProxyRegistry method getDistributedObjects.

/**
     * Gets the DistributedObjects in this registry. The result is written into 'result'.
     *
     * @param result The DistributedObjects in this registry.
     */
public void getDistributedObjects(Collection<DistributedObject> result) {
    Collection<DistributedObjectFuture> futures = proxies.values();
    for (DistributedObjectFuture future : futures) {
        try {
            DistributedObject object = future.get();
            result.add(object);
        } catch (Throwable ignored) {
            // ignore if proxy creation failed
            EmptyStatement.ignore(ignored);
        }
    }
}
Also used : DistributedObject(com.hazelcast.core.DistributedObject) AbstractDistributedObject(com.hazelcast.spi.AbstractDistributedObject)

Example 10 with DistributedObject

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

the class ProxyRegistry method doCreateProxy.

private DistributedObjectFuture doCreateProxy(String name, boolean publishEvent, boolean initialize, DistributedObjectFuture proxyFuture) {
    DistributedObject proxy;
    try {
        proxy = service.createDistributedObject(name);
        if (initialize && proxy instanceof InitializingObject) {
            try {
                ((InitializingObject) proxy).initialize();
            } catch (Exception e) {
                // log and throw exception to be handled in outer catch block
                proxyService.logger.warning("Error while initializing proxy: " + proxy, e);
                throw e;
            }
        }
        proxyFuture.set(proxy);
    } catch (Throwable e) {
        // proxy creation or initialization failed
        // deregister future to avoid infinite hang on future.get()
        proxyFuture.setError(e);
        proxies.remove(name);
        throw ExceptionUtil.rethrow(e);
    }
    InternalEventService eventService = proxyService.nodeEngine.getEventService();
    ProxyEventProcessor callback = new ProxyEventProcessor(proxyService.listeners.values(), CREATED, serviceName, name, proxy);
    eventService.executeEventCallback(callback);
    if (publishEvent) {
        publish(new DistributedObjectEventPacket(CREATED, serviceName, name));
    }
    return proxyFuture;
}
Also used : DistributedObject(com.hazelcast.core.DistributedObject) AbstractDistributedObject(com.hazelcast.spi.AbstractDistributedObject) InitializingObject(com.hazelcast.spi.InitializingObject) InternalEventService(com.hazelcast.spi.impl.eventservice.InternalEventService) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException)

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