Search in sources :

Example 1 with ClientAwareService

use of com.hazelcast.internal.services.ClientAwareService in project hazelcast by hazelcast.

the class AbstractMapServiceFactory method createMapService.

/**
 * Returns a {@link MapService} object by populating it with required
 * auxiliary services.
 *
 * @return {@link MapService} object
 */
@Override
public MapService createMapService() {
    NodeEngine nodeEngine = getNodeEngine();
    MapServiceContext mapServiceContext = getMapServiceContext();
    ManagedService managedService = createManagedService();
    CountingMigrationAwareService migrationAwareService = createMigrationAwareService();
    TransactionalService transactionalService = createTransactionalService();
    RemoteService remoteService = createRemoteService();
    EventPublishingService eventPublishingService = createEventPublishingService();
    PostJoinAwareService postJoinAwareService = createPostJoinAwareService();
    SplitBrainHandlerService splitBrainHandlerService = createSplitBrainHandlerService();
    WanSupportingService wanSupportingService = createReplicationSupportingService();
    StatisticsAwareService statisticsAwareService = createStatisticsAwareService();
    PartitionAwareService partitionAwareService = createPartitionAwareService();
    MapSplitBrainProtectionAwareService splitBrainProtectionAwareService = createSplitBrainProtectionAwareService();
    ClientAwareService clientAwareService = createClientAwareService();
    checkNotNull(nodeEngine, "nodeEngine should not be null");
    checkNotNull(mapServiceContext, "mapServiceContext should not be null");
    checkNotNull(managedService, "managedService should not be null");
    checkNotNull(migrationAwareService, "migrationAwareService should not be null");
    checkNotNull(transactionalService, "transactionalService should not be null");
    checkNotNull(remoteService, "remoteService should not be null");
    checkNotNull(eventPublishingService, "eventPublishingService should not be null");
    checkNotNull(postJoinAwareService, "postJoinAwareService should not be null");
    checkNotNull(splitBrainHandlerService, "splitBrainHandlerService should not be null");
    checkNotNull(wanSupportingService, "replicationSupportingService should not be null");
    checkNotNull(statisticsAwareService, "statisticsAwareService should not be null");
    checkNotNull(partitionAwareService, "partitionAwareService should not be null");
    checkNotNull(splitBrainProtectionAwareService, "splitBrainProtectionAwareService should not be null");
    checkNotNull(clientAwareService, "clientAwareService should not be null");
    MapService mapService = new MapService();
    mapService.managedService = managedService;
    mapService.migrationAwareService = migrationAwareService;
    mapService.transactionalService = transactionalService;
    mapService.remoteService = remoteService;
    mapService.eventPublishingService = eventPublishingService;
    mapService.postJoinAwareService = postJoinAwareService;
    mapService.splitBrainHandlerService = splitBrainHandlerService;
    mapService.wanSupportingService = wanSupportingService;
    mapService.statisticsAwareService = statisticsAwareService;
    mapService.mapServiceContext = mapServiceContext;
    mapService.partitionAwareService = partitionAwareService;
    mapService.splitBrainProtectionAwareService = splitBrainProtectionAwareService;
    mapService.clientAwareService = clientAwareService;
    mapServiceContext.setService(mapService);
    return mapService;
}
Also used : ManagedService(com.hazelcast.internal.services.ManagedService) StatisticsAwareService(com.hazelcast.internal.services.StatisticsAwareService) TransactionalService(com.hazelcast.internal.services.TransactionalService) CountingMigrationAwareService(com.hazelcast.spi.impl.CountingMigrationAwareService) NodeEngine(com.hazelcast.spi.impl.NodeEngine) ClientAwareService(com.hazelcast.internal.services.ClientAwareService) PostJoinAwareService(com.hazelcast.internal.services.PostJoinAwareService) RemoteService(com.hazelcast.internal.services.RemoteService) WanSupportingService(com.hazelcast.internal.services.WanSupportingService) SplitBrainHandlerService(com.hazelcast.internal.services.SplitBrainHandlerService) PartitionAwareService(com.hazelcast.internal.partition.PartitionAwareService) EventPublishingService(com.hazelcast.spi.impl.eventservice.EventPublishingService)

Example 2 with ClientAwareService

use of com.hazelcast.internal.services.ClientAwareService in project hazelcast by hazelcast.

the class ClientLifecycleMonitor method run.

@Override
public void run() {
    Set<UUID> allClients = null;
    Set<UUID> localClients = clientEndpointManager.getLocalClientUuids();
    for (Map.Entry<UUID, Long> entry : lastLiveTime.entrySet()) {
        UUID clientUuid = entry.getKey();
        if (localClients.contains(clientUuid)) {
            // This member has a connection to client, update the time and continue
            lastLiveTime.put(clientUuid, System.currentTimeMillis());
            continue;
        }
        long millisSinceLastLive = System.currentTimeMillis() - entry.getValue();
        if (millisSinceLastLive > timeoutMillis) {
            if (allClients == null) {
                allClients = clientEngine.getClientsInCluster().keySet();
            }
            // A member has connection to client, update the time and continue
            if (allClients.contains(clientUuid)) {
                lastLiveTime.put(clientUuid, System.currentTimeMillis());
                continue;
            }
            // No one have connection left to this client, clean the resources
            logger.warning("No connection left to client cluster wide " + entry.getKey() + " for " + millisSinceLastLive + " millis," + " cleaning resources of the client");
            lastLiveTime.remove(entry.getKey(), entry.getValue());
            // This part cleans up locks conditions semaphore etc..
            Collection<ClientAwareService> services = nodeEngine.getServices(ClientAwareService.class);
            for (ClientAwareService service : services) {
                service.clientDisconnected(clientUuid);
            }
        }
    }
}
Also used : ClientAwareService(com.hazelcast.internal.services.ClientAwareService) UUID(java.util.UUID) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

ClientAwareService (com.hazelcast.internal.services.ClientAwareService)2 PartitionAwareService (com.hazelcast.internal.partition.PartitionAwareService)1 ManagedService (com.hazelcast.internal.services.ManagedService)1 PostJoinAwareService (com.hazelcast.internal.services.PostJoinAwareService)1 RemoteService (com.hazelcast.internal.services.RemoteService)1 SplitBrainHandlerService (com.hazelcast.internal.services.SplitBrainHandlerService)1 StatisticsAwareService (com.hazelcast.internal.services.StatisticsAwareService)1 TransactionalService (com.hazelcast.internal.services.TransactionalService)1 WanSupportingService (com.hazelcast.internal.services.WanSupportingService)1 CountingMigrationAwareService (com.hazelcast.spi.impl.CountingMigrationAwareService)1 NodeEngine (com.hazelcast.spi.impl.NodeEngine)1 EventPublishingService (com.hazelcast.spi.impl.eventservice.EventPublishingService)1 Map (java.util.Map)1 UUID (java.util.UUID)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1