Search in sources :

Example 1 with BinaryOperationFactory

use of com.hazelcast.spi.impl.operationservice.BinaryOperationFactory in project hazelcast by hazelcast.

the class MapProxySupport method clearInternal.

public void clearInternal() {
    try {
        Operation clearOperation = operationProvider.createClearOperation(name);
        clearOperation.setServiceName(SERVICE_NAME);
        BinaryOperationFactory factory = new BinaryOperationFactory(clearOperation, getNodeEngine());
        Map<Integer, Object> resultMap = operationService.invokeOnAllPartitions(SERVICE_NAME, factory);
        int clearedCount = 0;
        for (Object object : resultMap.values()) {
            clearedCount += (Integer) object;
        }
        if (clearedCount > 0) {
            publishMapEvent(clearedCount, CLEAR_ALL);
        }
        incrementOtherOperationsStat();
    } catch (Throwable t) {
        throw rethrow(t);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BinaryOperationFactory(com.hazelcast.spi.impl.operationservice.BinaryOperationFactory) AbstractDistributedObject(com.hazelcast.spi.impl.AbstractDistributedObject) InitializingObject(com.hazelcast.spi.impl.InitializingObject) AddIndexOperation(com.hazelcast.map.impl.operation.AddIndexOperation) AwaitMapFlushOperation(com.hazelcast.map.impl.operation.AwaitMapFlushOperation) IsKeyLoadFinishedOperation(com.hazelcast.map.impl.operation.IsKeyLoadFinishedOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) MapOperation(com.hazelcast.map.impl.operation.MapOperation)

Example 2 with BinaryOperationFactory

use of com.hazelcast.spi.impl.operationservice.BinaryOperationFactory in project hazelcast by hazelcast.

the class EntryProcessorTest method multiple_entry_with_predicate_operation_returns_empty_response_when_map_is_empty.

@Test
public void multiple_entry_with_predicate_operation_returns_empty_response_when_map_is_empty() throws Exception {
    Config config = getConfig();
    MapConfig mapConfig = config.getMapConfig(MAP_NAME);
    mapConfig.setInMemoryFormat(inMemoryFormat);
    HazelcastInstance node = createHazelcastInstance(config);
    NodeEngineImpl nodeEngineImpl = getNodeEngineImpl(node);
    OperationServiceImpl operationService = nodeEngineImpl.getOperationService();
    int keyCount = 1000;
    Set<Data> dataKeys = new HashSet<>();
    for (int i = 0; i < keyCount; i++) {
        dataKeys.add(nodeEngineImpl.toData(i));
    }
    Operation operation = new MultipleEntryWithPredicateOperation(MAP_NAME, dataKeys, new NoOpEntryProcessor<>(), Predicates.sql("this < " + keyCount));
    OperationFactory operationFactory = new BinaryOperationFactory(operation, nodeEngineImpl);
    Map<Integer, Object> partitionResponses = operationService.invokeOnAllPartitions(MapService.SERVICE_NAME, operationFactory);
    for (Object response : partitionResponses.values()) {
        assertEquals(0, ((MapEntries) response).size());
    }
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Accessors.getNodeEngineImpl(com.hazelcast.test.Accessors.getNodeEngineImpl) MultipleEntryWithPredicateOperation(com.hazelcast.map.impl.operation.MultipleEntryWithPredicateOperation) MapConfig(com.hazelcast.config.MapConfig) IndexConfig(com.hazelcast.config.IndexConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) BinaryOperationFactory(com.hazelcast.spi.impl.operationservice.BinaryOperationFactory) Data(com.hazelcast.internal.serialization.Data) MultipleEntryWithPredicateOperation(com.hazelcast.map.impl.operation.MultipleEntryWithPredicateOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) EntryObject(com.hazelcast.query.PredicateBuilder.EntryObject) MapConfig(com.hazelcast.config.MapConfig) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) HashSet(java.util.HashSet) BinaryOperationFactory(com.hazelcast.spi.impl.operationservice.BinaryOperationFactory) OperationFactory(com.hazelcast.spi.impl.operationservice.OperationFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with BinaryOperationFactory

use of com.hazelcast.spi.impl.operationservice.BinaryOperationFactory in project hazelcast by hazelcast.

the class MapProxySupport method evictAllInternal.

protected void evictAllInternal() {
    try {
        Operation operation = operationProvider.createEvictAllOperation(name);
        BinaryOperationFactory factory = new BinaryOperationFactory(operation, getNodeEngine());
        Map<Integer, Object> resultMap = operationService.invokeOnAllPartitions(SERVICE_NAME, factory);
        int evictedCount = 0;
        for (Object object : resultMap.values()) {
            evictedCount += (Integer) object;
        }
        if (evictedCount > 0) {
            publishMapEvent(evictedCount, EntryEventType.EVICT_ALL);
        }
    } catch (Throwable t) {
        throw rethrow(t);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BinaryOperationFactory(com.hazelcast.spi.impl.operationservice.BinaryOperationFactory) AbstractDistributedObject(com.hazelcast.spi.impl.AbstractDistributedObject) InitializingObject(com.hazelcast.spi.impl.InitializingObject) AddIndexOperation(com.hazelcast.map.impl.operation.AddIndexOperation) AwaitMapFlushOperation(com.hazelcast.map.impl.operation.AwaitMapFlushOperation) IsKeyLoadFinishedOperation(com.hazelcast.map.impl.operation.IsKeyLoadFinishedOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) MapOperation(com.hazelcast.map.impl.operation.MapOperation)

Example 4 with BinaryOperationFactory

use of com.hazelcast.spi.impl.operationservice.BinaryOperationFactory in project hazelcast by hazelcast.

the class MapProxySupport method addIndex.

@Override
public void addIndex(IndexConfig indexConfig) {
    checkNotNull(indexConfig, "Index config cannot be null.");
    checkFalse(isNativeMemoryAndBitmapIndexingEnabled(indexConfig.getType()), "BITMAP indexes are not supported by NATIVE storage");
    IndexConfig indexConfig0 = IndexUtils.validateAndNormalize(name, indexConfig);
    try {
        AddIndexOperation addIndexOperation = new AddIndexOperation(name, indexConfig0);
        operationService.invokeOnAllPartitions(SERVICE_NAME, new BinaryOperationFactory(addIndexOperation, getNodeEngine()));
    } catch (Throwable t) {
        throw rethrow(t);
    }
}
Also used : IndexConfig(com.hazelcast.config.IndexConfig) AddIndexOperation(com.hazelcast.map.impl.operation.AddIndexOperation) BinaryOperationFactory(com.hazelcast.spi.impl.operationservice.BinaryOperationFactory)

Example 5 with BinaryOperationFactory

use of com.hazelcast.spi.impl.operationservice.BinaryOperationFactory in project hazelcast by hazelcast.

the class MapProxySupport method flush.

@Override
public void flush() {
    // TODO: add a feature to Management Center to sync cache to db completely
    try {
        MapOperation mapFlushOperation = operationProvider.createMapFlushOperation(name);
        BinaryOperationFactory operationFactory = new BinaryOperationFactory(mapFlushOperation, getNodeEngine());
        Map<Integer, Object> results = operationService.invokeOnAllPartitions(SERVICE_NAME, operationFactory);
        List<Future> futures = new ArrayList<>();
        for (Entry<Integer, Object> entry : results.entrySet()) {
            Integer partitionId = entry.getKey();
            Long count = ((Long) entry.getValue());
            if (count != 0) {
                Operation operation = new AwaitMapFlushOperation(name, count);
                futures.add(operationService.invokeOnPartition(MapService.SERVICE_NAME, operation, partitionId));
            }
        }
        for (Future future : futures) {
            future.get();
        }
    } catch (Throwable t) {
        throw rethrow(t);
    }
}
Also used : ArrayList(java.util.ArrayList) BinaryOperationFactory(com.hazelcast.spi.impl.operationservice.BinaryOperationFactory) AddIndexOperation(com.hazelcast.map.impl.operation.AddIndexOperation) AwaitMapFlushOperation(com.hazelcast.map.impl.operation.AwaitMapFlushOperation) IsKeyLoadFinishedOperation(com.hazelcast.map.impl.operation.IsKeyLoadFinishedOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) MapOperation(com.hazelcast.map.impl.operation.MapOperation) MapOperation(com.hazelcast.map.impl.operation.MapOperation) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MutableLong(com.hazelcast.internal.util.MutableLong) Future(java.util.concurrent.Future) InternalCompletableFuture.newCompletedFuture(com.hazelcast.spi.impl.InternalCompletableFuture.newCompletedFuture) InvocationFuture(com.hazelcast.spi.impl.operationservice.impl.InvocationFuture) InternalCompletableFuture(com.hazelcast.spi.impl.InternalCompletableFuture) CompletableFuture(java.util.concurrent.CompletableFuture) AbstractDistributedObject(com.hazelcast.spi.impl.AbstractDistributedObject) InitializingObject(com.hazelcast.spi.impl.InitializingObject) AwaitMapFlushOperation(com.hazelcast.map.impl.operation.AwaitMapFlushOperation)

Aggregations

BinaryOperationFactory (com.hazelcast.spi.impl.operationservice.BinaryOperationFactory)5 AddIndexOperation (com.hazelcast.map.impl.operation.AddIndexOperation)4 Operation (com.hazelcast.spi.impl.operationservice.Operation)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 AwaitMapFlushOperation (com.hazelcast.map.impl.operation.AwaitMapFlushOperation)3 IsKeyLoadFinishedOperation (com.hazelcast.map.impl.operation.IsKeyLoadFinishedOperation)3 MapOperation (com.hazelcast.map.impl.operation.MapOperation)3 AbstractDistributedObject (com.hazelcast.spi.impl.AbstractDistributedObject)3 InitializingObject (com.hazelcast.spi.impl.InitializingObject)3 IndexConfig (com.hazelcast.config.IndexConfig)2 Config (com.hazelcast.config.Config)1 MapConfig (com.hazelcast.config.MapConfig)1 MapStoreConfig (com.hazelcast.config.MapStoreConfig)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 Data (com.hazelcast.internal.serialization.Data)1 MutableLong (com.hazelcast.internal.util.MutableLong)1 MultipleEntryWithPredicateOperation (com.hazelcast.map.impl.operation.MultipleEntryWithPredicateOperation)1 EntryObject (com.hazelcast.query.PredicateBuilder.EntryObject)1 InternalCompletableFuture (com.hazelcast.spi.impl.InternalCompletableFuture)1 InternalCompletableFuture.newCompletedFuture (com.hazelcast.spi.impl.InternalCompletableFuture.newCompletedFuture)1