Search in sources :

Example 21 with Start

use of org.infinispan.factories.annotations.Start in project keycloak by keycloak.

the class PersistenceManagerImpl method start.

@Override
@Start
public void start() {
    enabled = configuration.persistence().usingStores();
    if (!enabled)
        return;
    preloaded = false;
    segmentCount = configuration.clustering().hash().numSegments();
    isInvalidationCache = configuration.clustering().cacheMode().isInvalidation();
    long stamp = lock.writeLock();
    try {
        Completable storeStartup = Flowable.fromIterable(configuration.persistence().stores()).concatMapSingle(storeConfiguration -> {
            NonBlockingStore<?, ?> actualStore = storeFromConfiguration(storeConfiguration);
            NonBlockingStore<?, ?> nonBlockingStore;
            if (storeConfiguration.async().enabled()) {
                nonBlockingStore = new AsyncNonBlockingStore<>(actualStore);
            } else {
                nonBlockingStore = actualStore;
            }
            InitializationContextImpl ctx = new InitializationContextImpl(storeConfiguration, cache.wired(), keyPartitioner, persistenceMarshaller, timeService, byteBufferFactory, marshallableEntryFactory, nonBlockingExecutor, globalConfiguration, blockingManager, nonBlockingManager);
            CompletionStage<Void> stage = nonBlockingStore.start(ctx).whenComplete((ignore, t) -> {
                // On exception, just put a status with only the store - this way we can still invoke stop on it later
                if (t != null) {
                    stores.add(new StoreStatus(nonBlockingStore, null, null));
                }
            });
            return Completable.fromCompletionStage(stage).toSingle(() -> new StoreStatus(nonBlockingStore, storeConfiguration, updateCharacteristics(nonBlockingStore, nonBlockingStore.characteristics(), storeConfiguration)));
        }).doOnNext(stores::add).delay(status -> {
            if (status.config.purgeOnStartup()) {
                return Flowable.fromCompletable(Completable.fromCompletionStage(status.store.clear()));
            }
            return Flowable.empty();
        }).ignoreElements();
        long interval = configuration.persistence().availabilityInterval();
        if (interval > 0) {
            storeStartup = storeStartup.doOnComplete(() -> availabilityTask = nonBlockingManager.scheduleWithFixedDelay(this::pollStoreAvailability, interval, interval, MILLISECONDS));
        }
        // Blocks here waiting for stores and availability task to start if needed
        storeStartup.blockingAwait();
        allSegmentedOrShared = allStoresSegmentedOrShared();
    } catch (Throwable t) {
        log.debug("PersistenceManagerImpl encountered an exception during startup of stores", t);
        throw t;
    } finally {
        lock.unlockWrite(stamp);
    }
}
Also used : WriteCommand(org.infinispan.commands.write.WriteCommand) ComponentName(org.infinispan.factories.annotations.ComponentName) LogFactory(org.infinispan.util.logging.LogFactory) InvocationHelper(org.infinispan.cache.impl.InvocationHelper) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) KnownComponentNames(org.infinispan.factories.KnownComponentNames) StoreUnavailableException(org.infinispan.persistence.spi.StoreUnavailableException) Scopes(org.infinispan.factories.scopes.Scopes) AdvancedCache(org.infinispan.AdvancedCache) TxInvocationContext(org.infinispan.context.impl.TxInvocationContext) InitializationContextImpl(org.infinispan.persistence.InitializationContextImpl) Transaction(javax.transaction.Transaction) MethodHandles(java.lang.invoke.MethodHandles) ByRef(org.infinispan.commons.util.ByRef) Set(java.util.Set) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) IntSet(org.infinispan.commons.util.IntSet) CompletionStage(java.util.concurrent.CompletionStage) ComposedSegmentedLoadWriteStore(org.infinispan.persistence.support.ComposedSegmentedLoadWriteStore) DelegatingNonBlockingStore(org.infinispan.persistence.support.DelegatingNonBlockingStore) InternalCacheValue(org.infinispan.container.entries.InternalCacheValue) DataConversion(org.infinispan.encoding.DataConversion) AsyncInterceptorChain(org.infinispan.interceptors.AsyncInterceptorChain) Single(io.reactivex.rxjava3.core.Single) TransactionalStoreInterceptor(org.infinispan.interceptors.impl.TransactionalStoreInterceptor) NonBlockingStoreAdapter(org.infinispan.persistence.support.NonBlockingStoreAdapter) EnumUtil(org.infinispan.commons.util.EnumUtil) InternalExpirationManager(org.infinispan.expiration.impl.InternalExpirationManager) CacheLoaderInterceptor(org.infinispan.interceptors.impl.CacheLoaderInterceptor) Start(org.infinispan.factories.annotations.Start) ArrayList(java.util.ArrayList) Maybe(io.reactivex.rxjava3.core.Maybe) StoreConfiguration(org.infinispan.configuration.cache.StoreConfiguration) MarshallableEntry(org.infinispan.persistence.spi.MarshallableEntry) DataWriteCommand(org.infinispan.commands.write.DataWriteCommand) AsyncInterceptor(org.infinispan.interceptors.AsyncInterceptor) InternalEntryFactory(org.infinispan.container.impl.InternalEntryFactory) Properties(java.util.Properties) Executor(java.util.concurrent.Executor) Publisher(org.reactivestreams.Publisher) InvalidTransactionException(javax.transaction.InvalidTransactionException) IOException(java.io.IOException) CacheNotifier(org.infinispan.notifications.cachelistener.CacheNotifier) Inject(org.infinispan.factories.annotations.Inject) MVCCEntry(org.infinispan.container.entries.MVCCEntry) InvalidateCommand(org.infinispan.commands.write.InvalidateCommand) Function(io.reactivex.rxjava3.functions.Function) PersistenceMarshaller(org.infinispan.marshall.persistence.PersistenceMarshaller) SystemException(javax.transaction.SystemException) StampedLock(java.util.concurrent.locks.StampedLock) DistributionManager(org.infinispan.distribution.DistributionManager) AggregateCompletionStage(org.infinispan.util.concurrent.AggregateCompletionStage) IntSets(org.infinispan.commons.util.IntSets) MarshallableEntryFactory(org.infinispan.persistence.spi.MarshallableEntryFactory) Stop(org.infinispan.factories.annotations.Stop) InvocationContext(org.infinispan.context.InvocationContext) ComponentRef(org.infinispan.factories.impl.ComponentRef) SingleSegmentPublisher(org.infinispan.persistence.support.SingleSegmentPublisher) CompletableFutures(org.infinispan.util.concurrent.CompletableFutures) Lifecycle(org.infinispan.commons.api.Lifecycle) Scope(org.infinispan.factories.scopes.Scope) ByteBufferFactory(org.infinispan.commons.io.ByteBufferFactory) PERSISTENCE(org.infinispan.util.logging.Log.PERSISTENCE) CommandsFactory(org.infinispan.commands.CommandsFactory) AsyncNonBlockingStore(org.infinispan.persistence.async.AsyncNonBlockingStore) Predicate(java.util.function.Predicate) Collection(java.util.Collection) AbstractCacheTransaction(org.infinispan.transaction.impl.AbstractCacheTransaction) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) PutKeyValueCommand(org.infinispan.commands.write.PutKeyValueCommand) GuardedBy(net.jcip.annotations.GuardedBy) SegmentPublisherWrapper(org.infinispan.persistence.support.SegmentPublisherWrapper) PersistenceException(org.infinispan.persistence.spi.PersistenceException) LocalOnlyCacheLoader(org.infinispan.persistence.spi.LocalOnlyCacheLoader) CompletionStages(org.infinispan.util.concurrent.CompletionStages) CompletableFuture(java.util.concurrent.CompletableFuture) AbstractSegmentedStoreConfiguration(org.infinispan.configuration.cache.AbstractSegmentedStoreConfiguration) FlagBitSets(org.infinispan.context.impl.FlagBitSets) InternalMetadataImpl(org.infinispan.metadata.impl.InternalMetadataImpl) HashSet(java.util.HashSet) Characteristic(org.infinispan.persistence.spi.NonBlockingStore.Characteristic) BiPredicate(java.util.function.BiPredicate) KeyPartitioner(org.infinispan.distribution.ch.KeyPartitioner) Log(org.infinispan.util.logging.Log) CacheWriterInterceptor(org.infinispan.interceptors.impl.CacheWriterInterceptor) Flowable(io.reactivex.rxjava3.core.Flowable) Iterator(java.util.Iterator) NonBlockingStore(org.infinispan.persistence.spi.NonBlockingStore) Util(org.infinispan.commons.util.Util) NonBlockingManager(org.infinispan.util.concurrent.NonBlockingManager) Completable(io.reactivex.rxjava3.core.Completable) PutMapCommand(org.infinispan.commands.write.PutMapCommand) NotSupportedException(javax.transaction.NotSupportedException) PersistenceUtil(org.infinispan.persistence.internal.PersistenceUtil) Configuration(org.infinispan.configuration.cache.Configuration) BlockingManager(org.infinispan.util.concurrent.BlockingManager) TransactionManager(javax.transaction.TransactionManager) TimeService(org.infinispan.commons.time.TimeService) InputStream(java.io.InputStream) AsyncNonBlockingStore(org.infinispan.persistence.async.AsyncNonBlockingStore) Completable(io.reactivex.rxjava3.core.Completable) InitializationContextImpl(org.infinispan.persistence.InitializationContextImpl) DelegatingNonBlockingStore(org.infinispan.persistence.support.DelegatingNonBlockingStore) AsyncNonBlockingStore(org.infinispan.persistence.async.AsyncNonBlockingStore) NonBlockingStore(org.infinispan.persistence.spi.NonBlockingStore) CompletionStage(java.util.concurrent.CompletionStage) AggregateCompletionStage(org.infinispan.util.concurrent.AggregateCompletionStage) Start(org.infinispan.factories.annotations.Start)

Example 22 with Start

use of org.infinispan.factories.annotations.Start in project keycloak by keycloak.

the class PersistenceManagerImpl method preload.

@Override
public CompletionStage<Void> preload() {
    long stamp = acquireReadLock();
    NonBlockingStore<Object, Object> nonBlockingStore = getStoreLocked(status -> status.config.preload());
    if (nonBlockingStore == null) {
        releaseReadLock(stamp);
        return CompletableFutures.completedNull();
    }
    Publisher<MarshallableEntry<Object, Object>> publisher = nonBlockingStore.publishEntries(IntSets.immutableRangeSet(segmentCount), null, true);
    long start = timeService.time();
    final long maxEntries = getMaxEntries();
    final long flags = getFlagsForStateInsertion();
    AdvancedCache<?, ?> tmpCache = this.cache.wired().withStorageMediaType();
    DataConversion keyDataConversion = tmpCache.getKeyDataConversion();
    DataConversion valueDataConversion = tmpCache.getValueDataConversion();
    return Flowable.fromPublisher(publisher).doFinally(() -> releaseReadLock(stamp)).take(maxEntries).concatMapSingle(me -> preloadEntry(flags, me, keyDataConversion, valueDataConversion)).count().toCompletionStage().thenAccept(insertAmount -> {
        this.preloaded = insertAmount < maxEntries;
        log.debugf("Preloaded %d keys in %s", insertAmount, Util.prettyPrintTime(timeService.timeDuration(start, MILLISECONDS)));
    });
}
Also used : DataConversion(org.infinispan.encoding.DataConversion) WriteCommand(org.infinispan.commands.write.WriteCommand) ComponentName(org.infinispan.factories.annotations.ComponentName) LogFactory(org.infinispan.util.logging.LogFactory) InvocationHelper(org.infinispan.cache.impl.InvocationHelper) GlobalConfiguration(org.infinispan.configuration.global.GlobalConfiguration) KnownComponentNames(org.infinispan.factories.KnownComponentNames) StoreUnavailableException(org.infinispan.persistence.spi.StoreUnavailableException) Scopes(org.infinispan.factories.scopes.Scopes) AdvancedCache(org.infinispan.AdvancedCache) TxInvocationContext(org.infinispan.context.impl.TxInvocationContext) InitializationContextImpl(org.infinispan.persistence.InitializationContextImpl) Transaction(javax.transaction.Transaction) MethodHandles(java.lang.invoke.MethodHandles) ByRef(org.infinispan.commons.util.ByRef) Set(java.util.Set) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) IntSet(org.infinispan.commons.util.IntSet) CompletionStage(java.util.concurrent.CompletionStage) ComposedSegmentedLoadWriteStore(org.infinispan.persistence.support.ComposedSegmentedLoadWriteStore) DelegatingNonBlockingStore(org.infinispan.persistence.support.DelegatingNonBlockingStore) InternalCacheValue(org.infinispan.container.entries.InternalCacheValue) DataConversion(org.infinispan.encoding.DataConversion) AsyncInterceptorChain(org.infinispan.interceptors.AsyncInterceptorChain) Single(io.reactivex.rxjava3.core.Single) TransactionalStoreInterceptor(org.infinispan.interceptors.impl.TransactionalStoreInterceptor) NonBlockingStoreAdapter(org.infinispan.persistence.support.NonBlockingStoreAdapter) EnumUtil(org.infinispan.commons.util.EnumUtil) InternalExpirationManager(org.infinispan.expiration.impl.InternalExpirationManager) CacheLoaderInterceptor(org.infinispan.interceptors.impl.CacheLoaderInterceptor) Start(org.infinispan.factories.annotations.Start) ArrayList(java.util.ArrayList) Maybe(io.reactivex.rxjava3.core.Maybe) StoreConfiguration(org.infinispan.configuration.cache.StoreConfiguration) MarshallableEntry(org.infinispan.persistence.spi.MarshallableEntry) DataWriteCommand(org.infinispan.commands.write.DataWriteCommand) AsyncInterceptor(org.infinispan.interceptors.AsyncInterceptor) InternalEntryFactory(org.infinispan.container.impl.InternalEntryFactory) Properties(java.util.Properties) Executor(java.util.concurrent.Executor) Publisher(org.reactivestreams.Publisher) InvalidTransactionException(javax.transaction.InvalidTransactionException) IOException(java.io.IOException) CacheNotifier(org.infinispan.notifications.cachelistener.CacheNotifier) Inject(org.infinispan.factories.annotations.Inject) MVCCEntry(org.infinispan.container.entries.MVCCEntry) InvalidateCommand(org.infinispan.commands.write.InvalidateCommand) Function(io.reactivex.rxjava3.functions.Function) PersistenceMarshaller(org.infinispan.marshall.persistence.PersistenceMarshaller) SystemException(javax.transaction.SystemException) StampedLock(java.util.concurrent.locks.StampedLock) DistributionManager(org.infinispan.distribution.DistributionManager) AggregateCompletionStage(org.infinispan.util.concurrent.AggregateCompletionStage) IntSets(org.infinispan.commons.util.IntSets) MarshallableEntryFactory(org.infinispan.persistence.spi.MarshallableEntryFactory) Stop(org.infinispan.factories.annotations.Stop) InvocationContext(org.infinispan.context.InvocationContext) ComponentRef(org.infinispan.factories.impl.ComponentRef) SingleSegmentPublisher(org.infinispan.persistence.support.SingleSegmentPublisher) CompletableFutures(org.infinispan.util.concurrent.CompletableFutures) Lifecycle(org.infinispan.commons.api.Lifecycle) Scope(org.infinispan.factories.scopes.Scope) ByteBufferFactory(org.infinispan.commons.io.ByteBufferFactory) PERSISTENCE(org.infinispan.util.logging.Log.PERSISTENCE) CommandsFactory(org.infinispan.commands.CommandsFactory) AsyncNonBlockingStore(org.infinispan.persistence.async.AsyncNonBlockingStore) Predicate(java.util.function.Predicate) Collection(java.util.Collection) AbstractCacheTransaction(org.infinispan.transaction.impl.AbstractCacheTransaction) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) PutKeyValueCommand(org.infinispan.commands.write.PutKeyValueCommand) GuardedBy(net.jcip.annotations.GuardedBy) SegmentPublisherWrapper(org.infinispan.persistence.support.SegmentPublisherWrapper) PersistenceException(org.infinispan.persistence.spi.PersistenceException) LocalOnlyCacheLoader(org.infinispan.persistence.spi.LocalOnlyCacheLoader) CompletionStages(org.infinispan.util.concurrent.CompletionStages) CompletableFuture(java.util.concurrent.CompletableFuture) AbstractSegmentedStoreConfiguration(org.infinispan.configuration.cache.AbstractSegmentedStoreConfiguration) FlagBitSets(org.infinispan.context.impl.FlagBitSets) InternalMetadataImpl(org.infinispan.metadata.impl.InternalMetadataImpl) HashSet(java.util.HashSet) Characteristic(org.infinispan.persistence.spi.NonBlockingStore.Characteristic) BiPredicate(java.util.function.BiPredicate) KeyPartitioner(org.infinispan.distribution.ch.KeyPartitioner) Log(org.infinispan.util.logging.Log) CacheWriterInterceptor(org.infinispan.interceptors.impl.CacheWriterInterceptor) Flowable(io.reactivex.rxjava3.core.Flowable) Iterator(java.util.Iterator) NonBlockingStore(org.infinispan.persistence.spi.NonBlockingStore) Util(org.infinispan.commons.util.Util) NonBlockingManager(org.infinispan.util.concurrent.NonBlockingManager) Completable(io.reactivex.rxjava3.core.Completable) PutMapCommand(org.infinispan.commands.write.PutMapCommand) NotSupportedException(javax.transaction.NotSupportedException) PersistenceUtil(org.infinispan.persistence.internal.PersistenceUtil) Configuration(org.infinispan.configuration.cache.Configuration) BlockingManager(org.infinispan.util.concurrent.BlockingManager) TransactionManager(javax.transaction.TransactionManager) TimeService(org.infinispan.commons.time.TimeService) InputStream(java.io.InputStream) MarshallableEntry(org.infinispan.persistence.spi.MarshallableEntry)

Example 23 with Start

use of org.infinispan.factories.annotations.Start in project infinispan by infinispan.

the class KafkaEventSenderImpl method start.

@Start
void start() {
    Properties kafkaProperties = new Properties();
    CloudEventsGlobalConfiguration cloudEventsGlobalConfiguration = globalConfiguration.module(CloudEventsGlobalConfiguration.class);
    kafkaProperties.setProperty("bootstrap.servers", cloudEventsGlobalConfiguration.bootstrapServers());
    kafkaProperties.setProperty("acks", String.valueOf(cloudEventsGlobalConfiguration.acks()));
    kafkaProperties.setProperty("key.serializer", "org.apache.kafka.common.serialization.ByteArraySerializer");
    kafkaProperties.setProperty("value.serializer", "org.apache.kafka.common.serialization.ByteArraySerializer");
    producer = new KafkaProducer<>(kafkaProperties);
    connect(cloudEventsGlobalConfiguration);
}
Also used : CloudEventsGlobalConfiguration(org.infinispan.cloudevents.configuration.CloudEventsGlobalConfiguration) Properties(java.util.Properties) Start(org.infinispan.factories.annotations.Start)

Example 24 with Start

use of org.infinispan.factories.annotations.Start in project infinispan by infinispan.

the class JGroupsTransport method start.

@Start
@Override
public void start() {
    if (running)
        throw new IllegalStateException("Two or more cache managers are using the same JGroupsTransport instance");
    probeHandler.updateThreadPool(nonBlockingExecutor);
    props = TypedProperties.toTypedProperties(configuration.transport().properties());
    requests = new RequestRepository();
    String stack = configuration.transport().stack();
    if (stack != null) {
        CLUSTER.startingJGroupsChannel(configuration.transport().clusterName(), configuration.transport().stack());
    } else {
        CLUSTER.startingJGroupsChannel(configuration.transport().clusterName());
    }
    initChannel();
    channel.setUpHandler(channelCallbacks);
    setXSiteViewListener(channelCallbacks);
    startJGroupsChannelIfNeeded();
    waitForInitialNodes();
    channel.getProtocolStack().getTransport().registerProbeHandler(probeHandler);
    RELAY2 relay2 = findRelay2();
    if (relay2 != null) {
        localSite = XSiteNamedCache.cachedString(relay2.site());
    }
    running = true;
}
Also used : RequestRepository(org.infinispan.remoting.transport.impl.RequestRepository) RELAY2(org.jgroups.protocols.relay.RELAY2) Start(org.infinispan.factories.annotations.Start)

Example 25 with Start

use of org.infinispan.factories.annotations.Start in project infinispan by infinispan.

the class StateReceiverImpl method start.

@Start
public void start() {
    cacheNotifier.addListener(this);
    stateReceiverExecutor = new LimitedExecutor("StateReceiver-" + cacheName, nonBlockingExecutor, 1);
}
Also used : LimitedExecutor(org.infinispan.executors.LimitedExecutor) Start(org.infinispan.factories.annotations.Start)

Aggregations

Start (org.infinispan.factories.annotations.Start)31 Configuration (org.infinispan.configuration.cache.Configuration)7 Inject (org.infinispan.factories.annotations.Inject)7 Scope (org.infinispan.factories.scopes.Scope)7 Scopes (org.infinispan.factories.scopes.Scopes)7 Log (org.infinispan.util.logging.Log)7 LogFactory (org.infinispan.util.logging.LogFactory)7 CompletionStage (java.util.concurrent.CompletionStage)6 TimeService (org.infinispan.commons.time.TimeService)6 HashSet (java.util.HashSet)5 List (java.util.List)5 Transaction (javax.transaction.Transaction)5 CommandsFactory (org.infinispan.commands.CommandsFactory)5 PutKeyValueCommand (org.infinispan.commands.write.PutKeyValueCommand)5 GlobalConfiguration (org.infinispan.configuration.global.GlobalConfiguration)5 InvocationContext (org.infinispan.context.InvocationContext)5 FlagBitSets (org.infinispan.context.impl.FlagBitSets)5 KeyPartitioner (org.infinispan.distribution.ch.KeyPartitioner)5 ComponentRef (org.infinispan.factories.impl.ComponentRef)5 Transport (org.infinispan.remoting.transport.Transport)5