use of org.infinispan.factories.GlobalComponentRegistry in project infinispan by infinispan.
the class TestingUtil method replaceComponent.
/**
* Same as {@link TestingUtil#replaceComponent(CacheContainer, Class, Object, boolean)} except that you can provide
* an optional name, to replace specifically named components.
*
* @param cacheContainer cache in which to replace component
* @param componentType component type of which to replace
* @param name name of the component
* @param replacementComponent new instance
* @param rewire if true, ComponentRegistry.rewire() is called after replacing.
*
* @return the original component that was replaced
*/
public static <T> T replaceComponent(CacheContainer cacheContainer, Class<T> componentType, String name, T replacementComponent, boolean rewire) {
GlobalComponentRegistry cr = extractGlobalComponentRegistry(cacheContainer);
BasicComponentRegistry bcr = cr.getComponent(BasicComponentRegistry.class);
ComponentRef<T> old = bcr.getComponent(componentType);
bcr.replaceComponent(name, replacementComponent, true);
if (rewire) {
cr.rewire();
cr.rewireNamedRegistries();
}
return old != null ? old.wired() : null;
}
use of org.infinispan.factories.GlobalComponentRegistry in project infinispan by infinispan.
the class DataConversionTest method testObjectEncoder.
@Test
public void testObjectEncoder() {
GenericJbossMarshallerEncoder encoder = new GenericJbossMarshallerEncoder(org.infinispan.dataconversion.DataConversionTest.class.getClassLoader());
withCacheManager(new CacheManagerCallable(createCacheManager(new ConfigurationBuilder())) {
GenericJBossMarshaller marshaller = new GenericJBossMarshaller();
private byte[] marshall(Object o) {
try {
return marshaller.objectToByteBuffer(o);
} catch (IOException | InterruptedException e) {
throw new AssertionError("Cannot marshall content", e);
}
}
@Override
public void call() {
GlobalComponentRegistry registry = cm.getGlobalComponentRegistry();
EncoderRegistry encoderRegistry = registry.getComponent(EncoderRegistry.class);
encoderRegistry.registerEncoder(encoder);
cm.getClassAllowList().addClasses(Person.class);
Cache<byte[], byte[]> cache = cm.getCache();
// Write encoded content to the cache
Person key1 = new Person("key1");
Person value1 = new Person("value1");
byte[] encodedKey1 = marshall(key1);
byte[] encodedValue1 = marshall(value1);
cache.put(encodedKey1, encodedValue1);
// Read encoded content
assertEquals(cache.get(encodedKey1), encodedValue1);
// Read with a different valueEncoder
AdvancedCache<Person, Person> encodingCache = (AdvancedCache<Person, Person>) cache.getAdvancedCache().withEncoding(GenericJbossMarshallerEncoder.class);
assertEquals(encodingCache.get(key1), value1);
}
});
}
use of org.infinispan.factories.GlobalComponentRegistry in project infinispan by infinispan.
the class DistributedServerTask method apply.
@Override
public T apply(EmbeddedCacheManager embeddedCacheManager) {
Cache<Object, Object> cache = embeddedCacheManager.getCache(cacheName);
// todo inject global component registry to be independent of existence of cache.
GlobalComponentRegistry componentRegistry = SecurityActions.getGlobalComponentRegistry(embeddedCacheManager);
ServerTaskEngine serverTaskEngine = componentRegistry.getComponent(ServerTaskEngine.class);
Marshaller marshaller = componentRegistry.getComponent(StreamingMarshaller.class);
ServerTaskWrapper<T> task = serverTaskEngine.getTask(taskName);
task.inject(prepareContext(embeddedCacheManager, cache, marshaller));
try {
return task.run();
} catch (Exception e) {
throw new CacheException(e);
}
}
use of org.infinispan.factories.GlobalComponentRegistry in project infinispan by infinispan.
the class CheckAddressTask method startInternal.
@Override
protected void startInternal() {
GlobalComponentRegistry gcr = SecurityActions.getGlobalComponentRegistry(cacheManager);
this.iterationManager = new DefaultIterationManager(gcr.getTimeService());
this.hasDefaultCache = configuration.defaultCacheName() != null || cacheManager.getCacheManagerConfiguration().defaultCacheName().isPresent();
// Initialize query-specific stuff
queryFacade = loadQueryFacade();
clientListenerRegistry = new ClientListenerRegistry(gcr.getComponent(EncoderRegistry.class), gcr.getComponent(ExecutorService.class, NON_BLOCKING_EXECUTOR));
clientCounterNotificationManager = new ClientCounterManagerNotificationManager(asCounterManager(cacheManager));
addKeyValueFilterConverterFactory(ToEmptyBytesKeyValueFilterConverter.class.getName(), new ToEmptyBytesFactory());
addCacheEventConverterFactory("key-value-with-previous-converter-factory", new KeyValueWithPreviousEventConverterFactory());
addCacheEventConverterFactory("___eager-key-value-version-converter", KeyValueVersionConverterFactory.SINGLETON);
loadFilterConverterFactories(ParamKeyValueFilterConverterFactory.class, this::addKeyValueFilterConverterFactory);
loadFilterConverterFactories(CacheEventFilterConverterFactory.class, this::addCacheEventFilterConverterFactory);
loadFilterConverterFactories(CacheEventConverterFactory.class, this::addCacheEventConverterFactory);
loadFilterConverterFactories(KeyValueFilterConverterFactory.class, this::addKeyValueFilterConverterFactory);
DefaultThreadFactory factory = new DefaultThreadFactory(getQualifiedName() + "-Scheduled");
scheduledExecutor = Executors.newSingleThreadScheduledExecutor(factory);
removeCacheListener = new RemoveCacheListener();
SecurityActions.addListener(cacheManager, removeCacheListener);
// Start default cache and the endpoint before adding self to
// topology in order to avoid topology updates being used before
// endpoint is available.
super.startInternal();
// Add self to topology cache last, after everything is initialized
if (Configurations.isClustered(SecurityActions.getCacheManagerConfiguration(cacheManager))) {
defineTopologyCacheConfig(cacheManager);
if (log.isDebugEnabled())
log.debugf("Externally facing address is %s:%d", configuration.proxyHost(), configuration.proxyPort());
addSelfToTopologyView(cacheManager);
}
}
use of org.infinispan.factories.GlobalComponentRegistry in project infinispan by infinispan.
the class BackupReader method restoreContainer.
private CompletionStage<Void> restoreContainer(String containerName, BackupManager.Resources params, ZipFile zip) {
// TODO validate container config
EmbeddedCacheManager cm = cacheManagers.get(containerName);
GlobalComponentRegistry gcr = SecurityActions.getGlobalComponentRegistry(cm);
Path containerRoot = Paths.get(CONTAINER_KEY, containerName);
Properties properties = readProperties(containerRoot.resolve(CONTAINERS_PROPERTIES_FILE), zip);
Collection<ContainerResource> resources = ContainerResourceFactory.getResources(params, blockingManager, cm, gcr, parserRegistry, containerRoot);
resources.forEach(r -> r.prepareAndValidateRestore(properties));
AggregateCompletionStage<Void> stages = CompletionStages.aggregateCompletionStage();
for (ContainerResource cr : resources) stages.dependsOn(cr.restore(zip));
return stages.freeze();
}
Aggregations