Search in sources :

Example 6 with TimeService

use of org.infinispan.commons.time.TimeService in project infinispan by infinispan.

the class DefaultTakeOfflineManager method start.

@Start
public void start() {
    String localSiteName = rpcManager.getTransport().localSiteName();
    config.sites().allBackupsStream().filter(bc -> !localSiteName.equals(bc.site())).forEach(bc -> {
        String siteName = bc.site();
        OfflineStatus offline = new OfflineStatus(bc.takeOffline(), timeService, new Listener(siteName));
        offlineStatus.put(siteName, offline);
    });
}
Also used : XSiteResponse(org.infinispan.remoting.transport.XSiteResponse) LogFactory(org.infinispan.util.logging.LogFactory) SiteStatusListener(org.infinispan.xsite.notification.SiteStatusListener) TakeOfflineConfiguration(org.infinispan.configuration.cache.TakeOfflineConfiguration) TimeoutException(java.util.concurrent.TimeoutException) MBeanMetadata(org.infinispan.factories.impl.MBeanMetadata) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Start(org.infinispan.factories.annotations.Start) Scopes(org.infinispan.factories.scopes.Scopes) EventLogCategory(org.infinispan.util.logging.events.EventLogCategory) Map(java.util.Map) Log(org.infinispan.util.logging.Log) Scope(org.infinispan.factories.scopes.Scope) CacheUnreachableException(org.infinispan.remoting.CacheUnreachableException) XSiteBackup(org.infinispan.xsite.XSiteBackup) EventLogger(org.infinispan.util.logging.events.EventLogger) InternalDataContainer(org.infinispan.container.impl.InternalDataContainer) EventLogManager(org.infinispan.util.logging.events.EventLogManager) CacheConfigurationException(org.infinispan.commons.CacheConfigurationException) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) RpcManager(org.infinispan.remoting.rpc.RpcManager) MESSAGES(org.infinispan.util.logging.events.Messages.MESSAGES) Inject(org.infinispan.factories.annotations.Inject) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) MetricUtils(org.infinispan.metrics.impl.MetricUtils) Configuration(org.infinispan.configuration.cache.Configuration) OfflineStatus(org.infinispan.xsite.OfflineStatus) Optional(java.util.Optional) RemoteException(org.infinispan.remoting.RemoteException) UnreachableException(org.jgroups.UnreachableException) TimeService(org.infinispan.commons.time.TimeService) SuspectException(org.infinispan.remoting.transport.jgroups.SuspectException) SiteStatusListener(org.infinispan.xsite.notification.SiteStatusListener) OfflineStatus(org.infinispan.xsite.OfflineStatus) Start(org.infinispan.factories.annotations.Start)

Example 7 with TimeService

use of org.infinispan.commons.time.TimeService in project infinispan by infinispan.

the class MaxIdlePessimisticTxTest method createCacheManagers.

@Override
protected void createCacheManagers() throws Throwable {
    ConfigurationBuilder builder = getDefaultClusteredCacheConfig(CacheMode.DIST_SYNC, true);
    builder.transaction().lockingMode(LockingMode.PESSIMISTIC);
    createCluster(builder, NUM_NODES);
    cacheManagers.forEach(cm -> replaceComponent(cm, TimeService.class, timeService, true));
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) ControlledTimeService(org.infinispan.util.ControlledTimeService) TimeService(org.infinispan.commons.time.TimeService)

Example 8 with TimeService

use of org.infinispan.commons.time.TimeService in project infinispan by infinispan.

the class IndexWorker method apply.

@Override
public Void apply(EmbeddedCacheManager embeddedCacheManager) {
    AdvancedCache<Object, Object> cache = SecurityActions.getUnwrappedCache(embeddedCacheManager.getCache(cacheName)).getAdvancedCache();
    DataConversion valueDataConversion = cache.getValueDataConversion();
    AdvancedCache<Object, Object> reindexCache = cache.withStorageMediaType();
    SearchMapping searchMapping = ComponentRegistryUtils.getSearchMapping(cache);
    TimeService timeService = ComponentRegistryUtils.getTimeService(cache);
    MassIndexerProgressNotifier notifier = new MassIndexerProgressNotifier(searchMapping, timeService);
    IndexUpdater indexUpdater = new IndexUpdater(searchMapping);
    KeyPartitioner keyPartitioner = ComponentRegistryUtils.getKeyPartitioner(cache);
    if (keys == null || keys.size() == 0) {
        preIndex(cache, indexUpdater);
        MassIndexerProgressState progressState = new MassIndexerProgressState(notifier);
        if (!skipIndex) {
            try (Stream<CacheEntry<Object, Object>> stream = reindexCache.getAdvancedCache().withFlags(Flag.CACHE_MODE_LOCAL).cacheEntrySet().stream()) {
                stream.forEach(entry -> {
                    Object key = entry.getKey();
                    Object value = valueDataConversion.extractIndexable(entry.getValue());
                    int segment = keyPartitioner.getSegment(key);
                    if (value != null && indexedTypes.contains(indexUpdater.toConvertedEntityJavaClass(value))) {
                        progressState.addItem(key, value, indexUpdater.updateIndex(key, value, segment));
                    }
                });
            }
        }
        postIndex(indexUpdater, progressState, notifier);
    } else {
        DataConversion keyDataConversion = cache.getKeyDataConversion();
        Set<Class<?>> classSet = new HashSet<>();
        for (Object key : keys) {
            Object storedKey = keyDataConversion.toStorage(key);
            Object unwrappedKey = keyDataConversion.extractIndexable(storedKey);
            Object value = cache.get(key);
            if (value != null) {
                indexUpdater.updateIndex(unwrappedKey, value, keyPartitioner.getSegment(storedKey));
                classSet.add(value.getClass());
            }
        }
        indexUpdater.flush(classSet);
        indexUpdater.refresh(classSet);
    }
    return null;
}
Also used : SearchMapping(org.infinispan.search.mapper.mapping.SearchMapping) TimeService(org.infinispan.commons.time.TimeService) CacheEntry(org.infinispan.container.entries.CacheEntry) DataConversion(org.infinispan.encoding.DataConversion) KeyPartitioner(org.infinispan.distribution.ch.KeyPartitioner) HashSet(java.util.HashSet)

Example 9 with TimeService

use of org.infinispan.commons.time.TimeService in project infinispan by infinispan.

the class ContainerResourceTest method createCacheManagers.

@Override
protected void createCacheManagers() throws Exception {
    Util.recursiveFileRemove(PERSISTENT_LOCATION);
    super.createCacheManagers();
    cacheManagerClient = client.cacheManager("default");
    adminCacheManagerClient = adminClient.cacheManager("default");
    timeService = new ControlledTimeService();
    cacheManagers.forEach(cm -> TestingUtil.replaceComponent(cm, TimeService.class, timeService, true));
}
Also used : ControlledTimeService(org.infinispan.util.ControlledTimeService) TimeService(org.infinispan.commons.time.TimeService) ControlledTimeService(org.infinispan.util.ControlledTimeService)

Example 10 with TimeService

use of org.infinispan.commons.time.TimeService in project keycloak by keycloak.

the class InfinispanUtil method setTimeServiceToKeycloakTime.

/**
 * Replaces the {@link TimeService} in infinispan with the one that respects Keycloak {@link Time}.
 * @param cacheManager
 * @return Runnable to revert replacement of the infinispan time service
 */
public static Runnable setTimeServiceToKeycloakTime(EmbeddedCacheManager cacheManager) {
    TimeService previousTimeService = replaceComponent(cacheManager, TimeService.class, KEYCLOAK_TIME_SERVICE, true);
    AtomicReference<TimeService> ref = new AtomicReference<>(previousTimeService);
    return () -> {
        if (ref.get() == null) {
            logger.warn("Calling revert of the TimeService when testing TimeService was already reverted");
            return;
        }
        logger.info("Revert set KeycloakIspnTimeService to the infinispan cacheManager");
        replaceComponent(cacheManager, TimeService.class, ref.getAndSet(null), true);
    };
}
Also used : EmbeddedTimeService(org.infinispan.util.EmbeddedTimeService) TimeService(org.infinispan.commons.time.TimeService) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Aggregations

TimeService (org.infinispan.commons.time.TimeService)18 ControlledTimeService (org.infinispan.util.ControlledTimeService)4 HashSet (java.util.HashSet)3 AdvancedCache (org.infinispan.AdvancedCache)3 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)3 EmbeddedTimeService (org.infinispan.util.EmbeddedTimeService)3 Log (org.infinispan.util.logging.Log)3 LogFactory (org.infinispan.util.logging.LogFactory)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 List (java.util.List)2 Map (java.util.Map)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 CompletionStage (java.util.concurrent.CompletionStage)2 TimeUnit (java.util.concurrent.TimeUnit)2 Configuration (org.infinispan.configuration.cache.Configuration)2 GlobalConfigurationBuilder (org.infinispan.configuration.global.GlobalConfigurationBuilder)2 DataContainer (org.infinispan.container.DataContainer)2 KeyPartitioner (org.infinispan.distribution.ch.KeyPartitioner)2 DataConversion (org.infinispan.encoding.DataConversion)2