Search in sources :

Example 11 with ServiceInfo

use of com.hazelcast.spi.impl.servicemanager.ServiceInfo in project hazelcast by hazelcast.

the class ServiceManagerImplTest method getServiceInfos.

// ===================== getServiceInfos ================================
@Test
public void getServiceInfos() {
    List<ServiceInfo> result = serviceManager.getServiceInfos(MapService.class);
    assertNotNull(result);
    assertEquals(1, result.size());
    ServiceInfo serviceInfo = result.get(0);
    assertEquals(MapService.SERVICE_NAME, serviceInfo.getName());
    assertInstanceOf(MapService.class, serviceInfo.getService());
}
Also used : ServiceInfo(com.hazelcast.spi.impl.servicemanager.ServiceInfo) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 12 with ServiceInfo

use of com.hazelcast.spi.impl.servicemanager.ServiceInfo in project hazelcast by hazelcast.

the class ServiceManagerImpl method registerService.

public synchronized void registerService(String serviceName, Object service) {
    if (logger.isFinestEnabled()) {
        logger.finest("Registering service: '" + serviceName + "'");
    }
    final ServiceInfo serviceInfo = new ServiceInfo(serviceName, service);
    final ServiceInfo currentServiceInfo = services.putIfAbsent(serviceName, serviceInfo);
    if (currentServiceInfo != null) {
        logger.warning("Replacing " + currentServiceInfo + " with " + serviceInfo);
        if (currentServiceInfo.isCoreService()) {
            throw new HazelcastException("Can not replace a CoreService! Name: " + serviceName + ", Service: " + currentServiceInfo.getService());
        }
        if (currentServiceInfo.isManagedService()) {
            shutdownService(currentServiceInfo.getService(), false);
        }
        services.put(serviceName, serviceInfo);
    }
}
Also used : ServiceInfo(com.hazelcast.spi.impl.servicemanager.ServiceInfo) HazelcastException(com.hazelcast.core.HazelcastException)

Example 13 with ServiceInfo

use of com.hazelcast.spi.impl.servicemanager.ServiceInfo in project hazelcast by hazelcast.

the class NodeEngineRaftIntegration method takeSnapshot.

@Override
public Object takeSnapshot(long commitIndex) {
    try {
        List<RestoreSnapshotOp> snapshotOps = new ArrayList<>();
        for (ServiceInfo serviceInfo : nodeEngine.getServiceInfos(SnapshotAwareService.class)) {
            SnapshotAwareService service = serviceInfo.getService();
            Object snapshot = service.takeSnapshot(groupId, commitIndex);
            if (snapshot != null) {
                snapshotOps.add(new RestoreSnapshotOp(serviceInfo.getName(), snapshot));
            }
        }
        return snapshotOps;
    } catch (Throwable t) {
        return t;
    }
}
Also used : ServiceInfo(com.hazelcast.spi.impl.servicemanager.ServiceInfo) ArrayList(java.util.ArrayList) SnapshotAwareService(com.hazelcast.cp.internal.raft.SnapshotAwareService) RestoreSnapshotOp(com.hazelcast.cp.internal.raftop.snapshot.RestoreSnapshotOp)

Example 14 with ServiceInfo

use of com.hazelcast.spi.impl.servicemanager.ServiceInfo in project hazelcast by hazelcast.

the class AbstractPartitionOperation method createReplicationOperations.

private Collection<Operation> createReplicationOperations(PartitionReplicationEvent event, boolean nonFragmentedOnly) {
    Collection<Operation> operations = new ArrayList<>();
    NodeEngineImpl nodeEngine = (NodeEngineImpl) getNodeEngine();
    Collection<ServiceInfo> services = nodeEngine.getServiceInfos(MigrationAwareService.class);
    for (ServiceInfo serviceInfo : services) {
        MigrationAwareService service = serviceInfo.getService();
        if (nonFragmentedOnly && service instanceof FragmentedMigrationAwareService) {
            // skip fragmented services
            continue;
        }
        Operation op = service.prepareReplicationOperation(event);
        if (op != null) {
            op.setServiceName(serviceInfo.getName());
            operations.add(op);
        }
    }
    return operations;
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) ServiceInfo(com.hazelcast.spi.impl.servicemanager.ServiceInfo) ArrayList(java.util.ArrayList) MigrationAwareService(com.hazelcast.internal.partition.MigrationAwareService) ChunkedMigrationAwareService(com.hazelcast.internal.partition.ChunkedMigrationAwareService) FragmentedMigrationAwareService(com.hazelcast.internal.partition.FragmentedMigrationAwareService) Operation(com.hazelcast.spi.impl.operationservice.Operation) FragmentedMigrationAwareService(com.hazelcast.internal.partition.FragmentedMigrationAwareService)

Example 15 with ServiceInfo

use of com.hazelcast.spi.impl.servicemanager.ServiceInfo in project hazelcast by hazelcast.

the class ServiceManagerImplTest method getServiceInfos.

// ===================== getServiceInfos ================================
@Test
public void getServiceInfos() {
    List<ServiceInfo> result = serviceManager.getServiceInfos(MapService.class);
    assertNotNull(result);
    assertEquals(1, result.size());
    ServiceInfo serviceInfo = result.get(0);
    assertEquals(MapService.SERVICE_NAME, serviceInfo.getName());
    assertInstanceOf(MapService.class, serviceInfo.getService());
}
Also used : ServiceInfo(com.hazelcast.spi.impl.servicemanager.ServiceInfo) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

ServiceInfo (com.hazelcast.spi.impl.servicemanager.ServiceInfo)15 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)6 QuickTest (com.hazelcast.test.annotation.QuickTest)6 Test (org.junit.Test)6 FragmentedMigrationAwareService (com.hazelcast.internal.partition.FragmentedMigrationAwareService)3 Operation (com.hazelcast.spi.impl.operationservice.Operation)3 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)3 ParallelTest (com.hazelcast.test.annotation.ParallelTest)3 ArrayList (java.util.ArrayList)3 NonFragmentedServiceNamespace (com.hazelcast.internal.partition.NonFragmentedServiceNamespace)2 MigrationAwareService (com.hazelcast.spi.MigrationAwareService)2 Operation (com.hazelcast.spi.Operation)2 PartitionReplicationEvent (com.hazelcast.spi.PartitionReplicationEvent)2 LinkedList (java.util.LinkedList)2 HazelcastException (com.hazelcast.core.HazelcastException)1 CPGroupDestroyedException (com.hazelcast.cp.exception.CPGroupDestroyedException)1 RaftManagedService (com.hazelcast.cp.internal.datastructures.spi.RaftManagedService)1 CannotRemoveCPMemberException (com.hazelcast.cp.internal.exception.CannotRemoveCPMemberException)1 SnapshotAwareService (com.hazelcast.cp.internal.raft.SnapshotAwareService)1 RaftNode (com.hazelcast.cp.internal.raft.impl.RaftNode)1