Search in sources :

Example 66 with OperationService

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

the class ClientEngineImpl method getConnectedClientStats.

@Override
public Map<ClientType, Integer> getConnectedClientStats() {
    int numberOfCppClients = 0;
    int numberOfDotNetClients = 0;
    int numberOfJavaClients = 0;
    int numberOfNodeJSClients = 0;
    int numberOfPythonClients = 0;
    int numberOfOtherClients = 0;
    OperationService operationService = node.nodeEngine.getOperationService();
    Map<ClientType, Integer> resultMap = new HashMap<ClientType, Integer>();
    Map<String, ClientType> clientsMap = new HashMap<String, ClientType>();
    for (Member member : node.getClusterService().getMembers()) {
        Address target = member.getAddress();
        Operation clientInfoOperation = new GetConnectedClientsOperation();
        Future<Map<String, ClientType>> future = operationService.invokeOnTarget(SERVICE_NAME, clientInfoOperation, target);
        try {
            Map<String, ClientType> endpoints = future.get();
            if (endpoints == null) {
                continue;
            }
            //Merge connected clients according to their uuid.
            for (Map.Entry<String, ClientType> entry : endpoints.entrySet()) {
                clientsMap.put(entry.getKey(), entry.getValue());
            }
        } catch (Exception e) {
            logger.warning("Cannot get client information from: " + target.toString(), e);
        }
    }
    //Now we are regrouping according to the client type
    for (ClientType clientType : clientsMap.values()) {
        switch(clientType) {
            case JAVA:
                numberOfJavaClients++;
                break;
            case CSHARP:
                numberOfDotNetClients++;
                break;
            case CPP:
                numberOfCppClients++;
                break;
            case NODEJS:
                numberOfNodeJSClients++;
                break;
            case PYTHON:
                numberOfPythonClients++;
                break;
            default:
                numberOfOtherClients++;
        }
    }
    resultMap.put(ClientType.CPP, numberOfCppClients);
    resultMap.put(ClientType.CSHARP, numberOfDotNetClients);
    resultMap.put(ClientType.JAVA, numberOfJavaClients);
    resultMap.put(ClientType.NODEJS, numberOfNodeJSClients);
    resultMap.put(ClientType.PYTHON, numberOfPythonClients);
    resultMap.put(ClientType.OTHER, numberOfOtherClients);
    return resultMap;
}
Also used : ClientType(com.hazelcast.core.ClientType) Address(com.hazelcast.nio.Address) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) GetConnectedClientsOperation(com.hazelcast.client.impl.operations.GetConnectedClientsOperation) ClientDisconnectionOperation(com.hazelcast.client.impl.operations.ClientDisconnectionOperation) Operation(com.hazelcast.spi.Operation) PostJoinClientOperation(com.hazelcast.client.impl.operations.PostJoinClientOperation) UrgentSystemOperation(com.hazelcast.spi.UrgentSystemOperation) GetConnectedClientsOperation(com.hazelcast.client.impl.operations.GetConnectedClientsOperation) ClientEndpoint(com.hazelcast.client.ClientEndpoint) LoginException(javax.security.auth.login.LoginException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) OperationService(com.hazelcast.spi.OperationService) InternalOperationService(com.hazelcast.spi.impl.operationservice.InternalOperationService) Member(com.hazelcast.core.Member) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 67 with OperationService

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

the class TransactionLogTest method prepare_partitionSpecificRecord.

@Test
public void prepare_partitionSpecificRecord() throws Exception {
    OperationService operationService = mock(OperationService.class);
    NodeEngine nodeEngine = mock(NodeEngine.class);
    when(nodeEngine.getOperationService()).thenReturn(operationService);
    TransactionLog log = new TransactionLog();
    TransactionLogRecord partitionRecord = mock(TransactionLogRecord.class);
    Operation partitionOperation = new DummyPartitionOperation();
    when(partitionRecord.newPrepareOperation()).thenReturn(partitionOperation);
    log.add(partitionRecord);
    log.prepare(nodeEngine);
    verify(operationService, times(1)).invokeOnPartition(partitionOperation.getServiceName(), partitionOperation, partitionOperation.getPartitionId());
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) OperationService(com.hazelcast.spi.OperationService) Operation(com.hazelcast.spi.Operation) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 68 with OperationService

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

the class TransactionLogTest method prepare_targetAwareRecord.

@Test
public void prepare_targetAwareRecord() throws Exception {
    OperationService operationService = mock(OperationService.class);
    NodeEngine nodeEngine = mock(NodeEngine.class);
    when(nodeEngine.getOperationService()).thenReturn(operationService);
    TransactionLog log = new TransactionLog();
    Address target = new Address(InetAddress.getLocalHost(), 5000);
    TargetAwareTransactionLogRecord targetRecord = mock(TargetAwareTransactionLogRecord.class);
    when(targetRecord.getTarget()).thenReturn(target);
    DummyTargetOperation targetOperation = new DummyTargetOperation();
    when(targetRecord.newPrepareOperation()).thenReturn(targetOperation);
    log.add(targetRecord);
    log.prepare(nodeEngine);
    verify(operationService, times(1)).invokeOnTarget(targetOperation.getServiceName(), targetOperation, target);
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) Address(com.hazelcast.nio.Address) InetAddress(java.net.InetAddress) OperationService(com.hazelcast.spi.OperationService) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 69 with OperationService

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

the class TransactionLogTest method rollback_partitionSpecificRecord.

@Test
public void rollback_partitionSpecificRecord() throws Exception {
    OperationService operationService = mock(OperationService.class);
    NodeEngine nodeEngine = mock(NodeEngine.class);
    when(nodeEngine.getOperationService()).thenReturn(operationService);
    TransactionLog log = new TransactionLog();
    TransactionLogRecord partitionRecord = mock(TransactionLogRecord.class);
    Operation partitionOperation = new DummyPartitionOperation();
    when(partitionRecord.newRollbackOperation()).thenReturn(partitionOperation);
    log.add(partitionRecord);
    log.rollback(nodeEngine);
    verify(operationService, times(1)).invokeOnPartition(partitionOperation.getServiceName(), partitionOperation, partitionOperation.getPartitionId());
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) OperationService(com.hazelcast.spi.OperationService) Operation(com.hazelcast.spi.Operation) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 70 with OperationService

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

the class TransactionLogTest method rollback_targetAwareRecord.

@Test
public void rollback_targetAwareRecord() throws Exception {
    OperationService operationService = mock(OperationService.class);
    NodeEngine nodeEngine = mock(NodeEngine.class);
    when(nodeEngine.getOperationService()).thenReturn(operationService);
    TransactionLog log = new TransactionLog();
    Address target = new Address(InetAddress.getLocalHost(), 5000);
    TargetAwareTransactionLogRecord targetRecord = mock(TargetAwareTransactionLogRecord.class);
    when(targetRecord.getTarget()).thenReturn(target);
    DummyTargetOperation targetOperation = new DummyTargetOperation();
    when(targetRecord.newRollbackOperation()).thenReturn(targetOperation);
    log.add(targetRecord);
    log.rollback(nodeEngine);
    verify(operationService, times(1)).invokeOnTarget(targetOperation.getServiceName(), targetOperation, target);
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) Address(com.hazelcast.nio.Address) InetAddress(java.net.InetAddress) OperationService(com.hazelcast.spi.OperationService) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

OperationService (com.hazelcast.spi.OperationService)135 Test (org.junit.Test)49 QuickTest (com.hazelcast.test.annotation.QuickTest)48 ParallelTest (com.hazelcast.test.annotation.ParallelTest)46 HazelcastInstance (com.hazelcast.core.HazelcastInstance)45 Operation (com.hazelcast.spi.Operation)39 NodeEngine (com.hazelcast.spi.NodeEngine)30 Address (com.hazelcast.nio.Address)26 Future (java.util.concurrent.Future)26 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)24 Config (com.hazelcast.config.Config)21 InternalCompletableFuture (com.hazelcast.spi.InternalCompletableFuture)21 Member (com.hazelcast.core.Member)19 Data (com.hazelcast.nio.serialization.Data)14 ArrayList (java.util.ArrayList)11 Node (com.hazelcast.instance.Node)7 InternalOperationService (com.hazelcast.spi.impl.operationservice.InternalOperationService)7 ExecutionException (java.util.concurrent.ExecutionException)7 TimeoutException (java.util.concurrent.TimeoutException)7 OperationTimeoutException (com.hazelcast.core.OperationTimeoutException)6