use of com.hazelcast.spi.OperationService in project hazelcast by hazelcast.
the class AbstractTransactionalCollectionProxy method remove.
public boolean remove(E e) {
checkTransactionActive();
checkObjectNotNull(e);
final NodeEngine nodeEngine = getNodeEngine();
final Data value = nodeEngine.toData(e);
final Iterator<CollectionItem> iterator = getCollection().iterator();
long reservedItemId = -1;
while (iterator.hasNext()) {
final CollectionItem item = iterator.next();
if (value.equals(item.getValue())) {
reservedItemId = item.getItemId();
break;
}
}
final CollectionReserveRemoveOperation operation = new CollectionReserveRemoveOperation(name, reservedItemId, value, tx.getTxnId());
try {
final OperationService operationService = nodeEngine.getOperationService();
Future<CollectionItem> f = operationService.invokeOnPartition(getServiceName(), operation, partitionId);
CollectionItem item = f.get();
if (item != null) {
if (reservedItemId == item.getItemId()) {
iterator.remove();
removeFromRecord(reservedItemId);
itemIdSet.remove(reservedItemId);
return true;
}
if (!itemIdSet.add(item.getItemId())) {
throw new TransactionException("Duplicate itemId: " + item.getItemId());
}
CollectionTxnRemoveOperation op = new CollectionTxnRemoveOperation(name, item.getItemId());
putToRecord(op);
return true;
}
} catch (Throwable t) {
throw ExceptionUtil.rethrow(t);
}
return false;
}
use of com.hazelcast.spi.OperationService 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);
}
}
use of com.hazelcast.spi.OperationService 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());
}
use of com.hazelcast.spi.OperationService in project hazelcast by hazelcast.
the class ConnectedClientOperationTest method testGetConnectedClientsOperation_WhenMoreThanZeroClientConnects.
@Test
public void testGetConnectedClientsOperation_WhenMoreThanZeroClientConnects() throws Exception {
HazelcastInstance instance = factory.newHazelcastInstance();
factory.newHazelcastClient();
factory.newHazelcastClient();
Node node = TestUtil.getNode(instance);
Operation operation = new GetConnectedClientsOperation();
OperationService operationService = node.nodeEngine.getOperationService();
Future<Map<String, ClientType>> future = operationService.invokeOnTarget(ClientEngineImpl.SERVICE_NAME, operation, node.address);
Map<String, ClientType> clients = future.get();
assertEquals(2, clients.size());
}
use of com.hazelcast.spi.OperationService in project hazelcast by hazelcast.
the class AbstractCacheProxy method getAll.
@Override
public Map<K, V> getAll(Set<? extends K> keys, ExpiryPolicy expiryPolicy) {
ensureOpen();
validateNotNull(keys);
if (keys.isEmpty()) {
return Collections.EMPTY_MAP;
}
Set<Data> ks = new HashSet<Data>(keys.size());
for (K key : keys) {
Data dataKey = serializationService.toData(key);
ks.add(dataKey);
}
Map<K, V> result = new HashMap<K, V>();
Collection<Integer> partitions = getPartitionsForKeys(ks);
try {
OperationFactory factory = operationProvider.createGetAllOperationFactory(ks, expiryPolicy);
OperationService operationService = getNodeEngine().getOperationService();
Map<Integer, Object> responses = operationService.invokeOnPartitions(getServiceName(), factory, partitions);
for (Object response : responses.values()) {
MapEntries mapEntries = serializationService.toObject(response);
mapEntries.putAllToMap(serializationService, result);
}
} catch (Throwable e) {
throw rethrowAllowedTypeFirst(e, CacheException.class);
}
return result;
}
Aggregations