Search in sources :

Example 6 with OperationFactory

use of com.hazelcast.spi.OperationFactory in project hazelcast by hazelcast.

the class MapProxySupport method invokePutAllOperationFactory.

protected void invokePutAllOperationFactory(Address address, final long size, int[] partitions, MapEntries[] entries) throws Exception {
    OperationFactory factory = operationProvider.createPutAllOperationFactory(name, partitions, entries);
    final long time = System.currentTimeMillis();
    operationService.invokeOnPartitions(SERVICE_NAME, factory, partitions);
    localMapStats.incrementPuts(size, System.currentTimeMillis() - time);
}
Also used : OperationFactory(com.hazelcast.spi.OperationFactory) IsEmptyOperationFactory(com.hazelcast.map.impl.operation.IsEmptyOperationFactory) BinaryOperationFactory(com.hazelcast.spi.impl.BinaryOperationFactory) IsPartitionLoadedOperationFactory(com.hazelcast.map.impl.operation.IsPartitionLoadedOperationFactory)

Example 7 with OperationFactory

use of com.hazelcast.spi.OperationFactory in project hazelcast by hazelcast.

the class MapProxySupport method getAllObjectInternal.

protected void getAllObjectInternal(List<Data> keys, List<Object> resultingKeyValuePairs) {
    if (keys == null || keys.isEmpty()) {
        return;
    }
    if (keys.isEmpty()) {
        return;
    }
    Collection<Integer> partitions = getPartitionsForKeys(keys);
    Map<Integer, Object> responses;
    try {
        OperationFactory operationFactory = operationProvider.createGetAllOperationFactory(name, keys);
        long time = System.currentTimeMillis();
        responses = operationService.invokeOnPartitions(SERVICE_NAME, operationFactory, partitions);
        for (Object response : responses.values()) {
            MapEntries entries = toObject(response);
            for (int i = 0; i < entries.size(); i++) {
                resultingKeyValuePairs.add(toObject(entries.getKey(i)));
                resultingKeyValuePairs.add(toObject(entries.getValue(i)));
            }
        }
        localMapStats.incrementGets(keys.size(), System.currentTimeMillis() - time);
    } catch (Exception e) {
        throw rethrow(e);
    }
}
Also used : MapEntries(com.hazelcast.map.impl.MapEntries) AbstractDistributedObject(com.hazelcast.spi.AbstractDistributedObject) InitializingObject(com.hazelcast.spi.InitializingObject) OperationFactory(com.hazelcast.spi.OperationFactory) IsEmptyOperationFactory(com.hazelcast.map.impl.operation.IsEmptyOperationFactory) BinaryOperationFactory(com.hazelcast.spi.impl.BinaryOperationFactory) IsPartitionLoadedOperationFactory(com.hazelcast.map.impl.operation.IsPartitionLoadedOperationFactory)

Example 8 with OperationFactory

use of com.hazelcast.spi.OperationFactory in project hazelcast by hazelcast.

the class MapProxySupport method size.

public int size() {
    try {
        OperationFactory sizeOperationFactory = operationProvider.createMapSizeOperationFactory(name);
        Map<Integer, Object> results = operationService.invokeOnAllPartitions(SERVICE_NAME, sizeOperationFactory);
        int total = 0;
        for (Object result : results.values()) {
            Integer size = toObject(result);
            total += size;
        }
        return total;
    } catch (Throwable t) {
        throw rethrow(t);
    }
}
Also used : AbstractDistributedObject(com.hazelcast.spi.AbstractDistributedObject) InitializingObject(com.hazelcast.spi.InitializingObject) OperationFactory(com.hazelcast.spi.OperationFactory) IsEmptyOperationFactory(com.hazelcast.map.impl.operation.IsEmptyOperationFactory) BinaryOperationFactory(com.hazelcast.spi.impl.BinaryOperationFactory) IsPartitionLoadedOperationFactory(com.hazelcast.map.impl.operation.IsPartitionLoadedOperationFactory)

Example 9 with OperationFactory

use of com.hazelcast.spi.OperationFactory in project hazelcast by hazelcast.

the class MapProxySupport method executeOnKeysInternal.

public Map executeOnKeysInternal(Set<Data> keys, EntryProcessor entryProcessor) {
    // TODO: why are we not forwarding to executeOnKeysInternal(keys, entryProcessor, null) or some other kind of fake
    // callback? now there is a lot of code duplication
    Map<Object, Object> result = new HashMap<Object, Object>();
    Collection<Integer> partitionsForKeys = getPartitionsForKeys(keys);
    try {
        OperationFactory operationFactory = operationProvider.createMultipleEntryOperationFactory(name, keys, entryProcessor);
        Map<Integer, Object> results = operationService.invokeOnPartitions(SERVICE_NAME, operationFactory, partitionsForKeys);
        for (Object object : results.values()) {
            if (object != null) {
                MapEntries mapEntries = (MapEntries) object;
                mapEntries.putAllToMap(serializationService, result);
            }
        }
    } catch (Throwable t) {
        throw rethrow(t);
    }
    return result;
}
Also used : HashMap(java.util.HashMap) MapEntries(com.hazelcast.map.impl.MapEntries) AbstractDistributedObject(com.hazelcast.spi.AbstractDistributedObject) InitializingObject(com.hazelcast.spi.InitializingObject) OperationFactory(com.hazelcast.spi.OperationFactory) IsEmptyOperationFactory(com.hazelcast.map.impl.operation.IsEmptyOperationFactory) BinaryOperationFactory(com.hazelcast.spi.impl.BinaryOperationFactory) IsPartitionLoadedOperationFactory(com.hazelcast.map.impl.operation.IsPartitionLoadedOperationFactory)

Example 10 with OperationFactory

use of com.hazelcast.spi.OperationFactory in project hazelcast by hazelcast.

the class MapProxySupport method waitUntilLoaded.

public void waitUntilLoaded() {
    try {
        int mapNamePartition = partitionService.getPartitionId(name);
        // first we have to check if key-load finished - otherwise the loading on other partitions might not have started.
        // In this case we can't invoke IsPartitionLoadedOperation -> they will return "true", but it won't be correct.
        int sleepDurationMillis = INITIAL_WAIT_LOAD_SLEEP_MILLIS;
        while (true) {
            Operation op = new IsKeyLoadFinishedOperation(name);
            Future<Boolean> loadingFuture = operationService.invokeOnPartition(SERVICE_NAME, op, mapNamePartition);
            if (loadingFuture.get()) {
                break;
            }
            // sleep with some back-off
            TimeUnit.MILLISECONDS.sleep(sleepDurationMillis);
            sleepDurationMillis = (sleepDurationMillis * 2 < MAXIMAL_WAIT_LOAD_SLEEP_MILLIS) ? sleepDurationMillis * 2 : MAXIMAL_WAIT_LOAD_SLEEP_MILLIS;
        }
        OperationFactory opFactory = new IsPartitionLoadedOperationFactory(name);
        Map<Integer, Object> results = operationService.invokeOnAllPartitions(SERVICE_NAME, opFactory);
        // wait for all the data to be loaded on all partitions - wait forever
        waitAllTrue(results, opFactory);
    } catch (Throwable t) {
        throw rethrow(t);
    }
}
Also used : IsKeyLoadFinishedOperation(com.hazelcast.map.impl.operation.IsKeyLoadFinishedOperation) IsPartitionLoadedOperationFactory(com.hazelcast.map.impl.operation.IsPartitionLoadedOperationFactory) AbstractDistributedObject(com.hazelcast.spi.AbstractDistributedObject) InitializingObject(com.hazelcast.spi.InitializingObject) Operation(com.hazelcast.spi.Operation) IsKeyLoadFinishedOperation(com.hazelcast.map.impl.operation.IsKeyLoadFinishedOperation) AddIndexOperation(com.hazelcast.map.impl.operation.AddIndexOperation) AwaitMapFlushOperation(com.hazelcast.map.impl.operation.AwaitMapFlushOperation) AddInterceptorOperation(com.hazelcast.map.impl.operation.AddInterceptorOperation) RemoveInterceptorOperation(com.hazelcast.map.impl.operation.RemoveInterceptorOperation) MapOperation(com.hazelcast.map.impl.operation.MapOperation) OperationFactory(com.hazelcast.spi.OperationFactory) IsEmptyOperationFactory(com.hazelcast.map.impl.operation.IsEmptyOperationFactory) BinaryOperationFactory(com.hazelcast.spi.impl.BinaryOperationFactory) IsPartitionLoadedOperationFactory(com.hazelcast.map.impl.operation.IsPartitionLoadedOperationFactory)

Aggregations

OperationFactory (com.hazelcast.spi.OperationFactory)18 IsEmptyOperationFactory (com.hazelcast.map.impl.operation.IsEmptyOperationFactory)7 IsPartitionLoadedOperationFactory (com.hazelcast.map.impl.operation.IsPartitionLoadedOperationFactory)7 BinaryOperationFactory (com.hazelcast.spi.impl.BinaryOperationFactory)7 AbstractDistributedObject (com.hazelcast.spi.AbstractDistributedObject)6 InitializingObject (com.hazelcast.spi.InitializingObject)6 MapEntries (com.hazelcast.map.impl.MapEntries)4 InternalOperationService (com.hazelcast.spi.impl.operationservice.InternalOperationService)4 CacheException (javax.cache.CacheException)4 Data (com.hazelcast.nio.serialization.Data)3 Operation (com.hazelcast.spi.Operation)3 OperationService (com.hazelcast.spi.OperationService)3 ClientEndpoint (com.hazelcast.client.ClientEndpoint)2 OperationFactoryWrapper (com.hazelcast.client.impl.operations.OperationFactoryWrapper)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)1 MapService (com.hazelcast.map.impl.MapService)1 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)1