Search in sources :

Example 1 with DistributedCacheObject

use of org.apereo.cas.DistributedCacheObject in project cas by apereo.

the class CasRegisteredServiceHazelcastStreamPublisher method getCacheObject.

private DistributedCacheObject<RegisteredService> getCacheObject(final RegisteredService service, final ApplicationEvent event) {
    final long time = new Date().getTime();
    final DistributedCacheObject<RegisteredService> item = new DistributedCacheObject<>(time, service);
    item.getProperties().put("event", event);
    return item;
}
Also used : RegisteredService(org.apereo.cas.services.RegisteredService) DistributedCacheObject(org.apereo.cas.DistributedCacheObject) Date(java.util.Date)

Example 2 with DistributedCacheObject

use of org.apereo.cas.DistributedCacheObject in project cas by apereo.

the class DefaultRegisteredServiceReplicationStrategy method updateLoadedRegisteredServicesFromCache.

@Override
public List<RegisteredService> updateLoadedRegisteredServicesFromCache(final List<RegisteredService> services, final ServiceRegistry serviceRegistry) {
    final Collection<DistributedCacheObject<RegisteredService>> cachedServices = this.distributedCacheManager.getAll();
    for (final DistributedCacheObject<RegisteredService> entry : cachedServices) {
        final RegisteredService cachedService = entry.getValue();
        LOGGER.debug("Found cached service definition [{}] in the replication cache [{}]", cachedService, distributedCacheManager.getName());
        if (isRegisteredServiceMarkedAsDeletedInCache(entry)) {
            LOGGER.debug("Service found in the cache [{}] is marked as a deleted service. CAS will update the service registry " + "of this CAS node to remove the local service, if found.", cachedService);
            serviceRegistry.delete(cachedService);
            this.distributedCacheManager.remove(cachedService, entry);
            continue;
        }
        final RegisteredService matchingService = services.stream().filter(s -> s.getId() == cachedService.getId()).findFirst().orElse(null);
        if (matchingService != null) {
            updateServiceRegistryWithMatchingService(services, cachedService, matchingService, serviceRegistry);
        } else {
            updateServiceRegistryWithNoMatchingService(services, cachedService, serviceRegistry);
        }
    }
    return services;
}
Also used : RegisteredService(org.apereo.cas.services.RegisteredService) DistributedCacheObject(org.apereo.cas.DistributedCacheObject)

Example 3 with DistributedCacheObject

use of org.apereo.cas.DistributedCacheObject in project cas by apereo.

the class DefaultRegisteredServiceReplicationStrategy method getRegisteredServiceFromCacheByPredicate.

@Override
public RegisteredService getRegisteredServiceFromCacheByPredicate(final RegisteredService service, final Predicate<DistributedCacheObject<RegisteredService>> predicate, final ServiceRegistry serviceRegistry) {
    final Optional<DistributedCacheObject<RegisteredService>> result = this.distributedCacheManager.find(predicate);
    if (result.isPresent()) {
        final DistributedCacheObject<RegisteredService> item = result.get();
        final RegisteredService cachedService = item.getValue();
        LOGGER.debug("Located cache entry [{}] in service registry cache [{}]", item, this.distributedCacheManager.getName());
        if (isRegisteredServiceMarkedAsDeletedInCache(item)) {
            LOGGER.debug("Service found in the cache [{}] is marked as a deleted service. CAS will update the service registry " + "of this CAS node to remove the local service, if found", cachedService);
            serviceRegistry.delete(cachedService);
            this.distributedCacheManager.remove(cachedService, item);
            return service;
        }
        if (service == null) {
            LOGGER.debug("Service is in not found in the local service registry for this CAS node. CAS will use the cache entry [{}] instead " + "and will update the service registry of this CAS node with the cache entry for future look-ups", item.getValue());
            if (properties.getReplicationMode() == StreamingServiceRegistryProperties.ReplicationModes.ACTIVE_ACTIVE) {
                serviceRegistry.save(item.getValue());
            }
            return item.getValue();
        }
        LOGGER.debug("Service definition cache entry [{}] carries the timestamp [{}]", item.getValue(), item.getTimestamp());
        if (item.getValue().equals(service)) {
            LOGGER.debug("Service definition cache entry is the same as service definition found locally");
            return service;
        }
        LOGGER.debug("Service definition found in the cache [{}] is more recent than its counterpart on this CAS node. CAS will " + "use the cache entry and update the service registry of this CAS node with the cache entry for future look-ups", item.getValue());
        if (properties.getReplicationMode() == StreamingServiceRegistryProperties.ReplicationModes.ACTIVE_ACTIVE) {
            serviceRegistry.save(item.getValue());
        }
        return item.getValue();
    }
    LOGGER.debug("Requested service definition is not found in the replication cache");
    if (service != null) {
        LOGGER.debug("Attempting to update replication cache with service [{}}", service);
        final DistributedCacheObject<RegisteredService> item = new DistributedCacheObject<>(service);
        this.distributedCacheManager.set(service, item);
    }
    return service;
}
Also used : RegisteredService(org.apereo.cas.services.RegisteredService) DistributedCacheObject(org.apereo.cas.DistributedCacheObject)

Aggregations

DistributedCacheObject (org.apereo.cas.DistributedCacheObject)3 RegisteredService (org.apereo.cas.services.RegisteredService)3 Date (java.util.Date)1