Search in sources :

Example 76 with NodeEngine

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

the class TransactionalSetProxy method add.

@Override
public boolean add(E e) {
    checkTransactionActive();
    checkObjectNotNull(e);
    final NodeEngine nodeEngine = getNodeEngine();
    final Data value = nodeEngine.toData(e);
    if (!getCollection().add(new CollectionItem(-1, value))) {
        return false;
    }
    CollectionReserveAddOperation operation = new CollectionReserveAddOperation(name, tx.getTxnId(), value);
    try {
        Future<Long> f = nodeEngine.getOperationService().invokeOnPartition(getServiceName(), operation, partitionId);
        Long itemId = f.get();
        if (itemId != null) {
            if (!itemIdSet.add(itemId)) {
                throw new TransactionException("Duplicate itemId: " + itemId);
            }
            CollectionTxnAddOperation op = new CollectionTxnAddOperation(name, itemId, value);
            putToRecord(op);
            return true;
        }
    } catch (Throwable t) {
        throw ExceptionUtil.rethrow(t);
    }
    return false;
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) TransactionException(com.hazelcast.transaction.TransactionException) CollectionTxnAddOperation(com.hazelcast.collection.impl.txncollection.operations.CollectionTxnAddOperation) CollectionReserveAddOperation(com.hazelcast.collection.impl.txncollection.operations.CollectionReserveAddOperation) Data(com.hazelcast.nio.serialization.Data) CollectionItem(com.hazelcast.collection.impl.collection.CollectionItem)

Example 77 with NodeEngine

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

the class QueueProxySupport method invokeAndGetData.

private Object invokeAndGetData(QueueOperation operation) {
    final NodeEngine nodeEngine = getNodeEngine();
    try {
        OperationService operationService = nodeEngine.getOperationService();
        Future f = operationService.invokeOnPartition(QueueService.SERVICE_NAME, operation, partitionId);
        return f.get();
    } catch (Throwable throwable) {
        throw ExceptionUtil.rethrow(throwable);
    }
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) InternalCompletableFuture(com.hazelcast.spi.InternalCompletableFuture) Future(java.util.concurrent.Future) OperationService(com.hazelcast.spi.OperationService)

Example 78 with NodeEngine

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

the class QueueProxySupport method initialize.

@Override
public void initialize() {
    final NodeEngine nodeEngine = getNodeEngine();
    final List<ItemListenerConfig> itemListenerConfigs = config.getItemListenerConfigs();
    for (ItemListenerConfig itemListenerConfig : itemListenerConfigs) {
        ItemListener listener = itemListenerConfig.getImplementation();
        if (listener == null && itemListenerConfig.getClassName() != null) {
            try {
                listener = ClassLoaderUtil.newInstance(nodeEngine.getConfigClassLoader(), itemListenerConfig.getClassName());
            } catch (Exception e) {
                throw ExceptionUtil.rethrow(e);
            }
        }
        if (listener != null) {
            if (listener instanceof HazelcastInstanceAware) {
                ((HazelcastInstanceAware) listener).setHazelcastInstance(nodeEngine.getHazelcastInstance());
            }
            addItemListener(listener, itemListenerConfig.isIncludeValue());
        }
    }
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) ItemListenerConfig(com.hazelcast.config.ItemListenerConfig) ItemListener(com.hazelcast.core.ItemListener) HazelcastInstanceAware(com.hazelcast.core.HazelcastInstanceAware)

Example 79 with NodeEngine

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

the class QueueProxySupport method invoke.

private InternalCompletableFuture invoke(Operation operation) {
    final NodeEngine nodeEngine = getNodeEngine();
    OperationService operationService = nodeEngine.getOperationService();
    return operationService.invokeOnPartition(QueueService.SERVICE_NAME, operation, getPartitionId());
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) OperationService(com.hazelcast.spi.OperationService)

Example 80 with NodeEngine

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

the class QueueReplicationOperation method run.

@Override
public void run() {
    QueueService service = getService();
    NodeEngine nodeEngine = getNodeEngine();
    Config config = nodeEngine.getConfig();
    for (Map.Entry<String, QueueContainer> entry : migrationData.entrySet()) {
        String name = entry.getKey();
        QueueContainer container = entry.getValue();
        QueueConfig conf = config.findQueueConfig(name);
        container.setConfig(conf, nodeEngine, service);
        service.addContainer(name, container);
    }
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) QueueConfig(com.hazelcast.config.QueueConfig) Config(com.hazelcast.config.Config) QueueConfig(com.hazelcast.config.QueueConfig) QueueContainer(com.hazelcast.collection.impl.queue.QueueContainer) QueueService(com.hazelcast.collection.impl.queue.QueueService) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

NodeEngine (com.hazelcast.spi.NodeEngine)163 Data (com.hazelcast.nio.serialization.Data)50 OperationService (com.hazelcast.spi.OperationService)30 Address (com.hazelcast.nio.Address)25 ILogger (com.hazelcast.logging.ILogger)20 Operation (com.hazelcast.spi.Operation)14 IPartitionService (com.hazelcast.spi.partition.IPartitionService)14 Member (com.hazelcast.core.Member)12 Future (java.util.concurrent.Future)12 InternalCompletableFuture (com.hazelcast.spi.InternalCompletableFuture)11 Test (org.junit.Test)10 InitializingObject (com.hazelcast.spi.InitializingObject)9 ParallelTest (com.hazelcast.test.annotation.ParallelTest)9 QuickTest (com.hazelcast.test.annotation.QuickTest)9 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)8 AbstractDistributedObject (com.hazelcast.spi.AbstractDistributedObject)8 ArrayList (java.util.ArrayList)8 Map (java.util.Map)8 HazelcastInstance (com.hazelcast.core.HazelcastInstance)7 InternalPartitionServiceImpl (com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl)7