use of org.infinispan.commons.configuration.StringConfiguration in project infinispan by infinispan.
the class RemoteCacheManager method createRemoteCache.
private <K, V> RemoteCache<K, V> createRemoteCache(String cacheName, boolean forceReturnValueOverride, TransactionMode transactionModeOverride, TransactionManager transactionManagerOverride) {
RemoteCacheConfiguration cacheConfiguration = findConfiguration(cacheName);
boolean forceReturnValue = forceReturnValueOverride || (cacheConfiguration != null ? cacheConfiguration.forceReturnValues() : configuration.forceReturnValues());
RemoteCacheKey key = new RemoteCacheKey(cacheName, forceReturnValue);
if (cacheName2RemoteCache.containsKey(key)) {
return cacheName2RemoteCache.get(key).remoteCache();
}
OperationsFactory operationsFactory = createOperationFactory(cacheName, forceReturnValue, codec, null);
PingResponse pingResponse;
if (started) {
// Verify if the cache exists on the server first
pingResponse = await(operationsFactory.newFaultTolerantPingOperation().execute());
// If ping not successful assume that the cache does not exist
if (pingResponse.isCacheNotFound()) {
// We may be able to create it. Don't use RemoteCacheAdmin for this, since it would end up calling this method again
Map<String, byte[]> params = new HashMap<>(2);
params.put(RemoteCacheManagerAdminImpl.CACHE_NAME, cacheName.getBytes(HotRodConstants.HOTROD_STRING_CHARSET));
if (cacheConfiguration != null && cacheConfiguration.templateName() != null) {
params.put(RemoteCacheManagerAdminImpl.CACHE_TEMPLATE, cacheConfiguration.templateName().getBytes(HotRodConstants.HOTROD_STRING_CHARSET));
} else if (cacheConfiguration != null && cacheConfiguration.configuration() != null) {
params.put(RemoteCacheManagerAdminImpl.CACHE_CONFIGURATION, new StringConfiguration(cacheConfiguration.configuration()).toStringConfiguration(cacheName).getBytes(HotRodConstants.HOTROD_STRING_CHARSET));
} else {
// We cannot create the cache
return null;
}
// Create and re-ping
OperationsFactory adminOperationsFactory = new OperationsFactory(channelFactory, codec, listenerNotifier, configuration);
pingResponse = await(adminOperationsFactory.newAdminOperation("@@cache@getorcreate", params).execute().thenCompose(s -> operationsFactory.newFaultTolerantPingOperation().execute()));
}
} else {
pingResponse = PingResponse.EMPTY;
}
TransactionMode transactionMode = getTransactionMode(transactionModeOverride, cacheConfiguration);
InternalRemoteCache<K, V> remoteCache;
if (transactionMode == TransactionMode.NONE) {
remoteCache = createRemoteCache(cacheName);
} else {
if (!await(checkTransactionSupport(cacheName, operationsFactory).toCompletableFuture())) {
throw HOTROD.cacheDoesNotSupportTransactions(cacheName);
} else {
TransactionManager transactionManager = getTransactionManager(transactionManagerOverride, cacheConfiguration);
remoteCache = createRemoteTransactionalCache(cacheName, forceReturnValueOverride, transactionMode == TransactionMode.FULL_XA, transactionMode, transactionManager);
}
}
synchronized (cacheName2RemoteCache) {
startRemoteCache(remoteCache, operationsFactory.getCodec(), forceReturnValue);
RemoteCacheHolder holder = new RemoteCacheHolder(remoteCache, forceReturnValueOverride);
remoteCache.resolveStorage(pingResponse.isObjectStorage());
cacheName2RemoteCache.putIfAbsent(key, holder);
return remoteCache;
}
}
use of org.infinispan.commons.configuration.StringConfiguration in project infinispan by infinispan.
the class RemoteCacheAdminTest method cacheCreateMissingTemplate.
public void cacheCreateMissingTemplate(Method m) throws InterruptedException {
RemoteCacheManagerAdmin admin = client(0).administration().withFlags(CacheContainerAdmin.AdminFlag.VOLATILE);
// Creation with a non-existent template fails
expectException(HotRodClientException.class, () -> admin.createCache("some_name", "some_template_name"));
// Cache can still be created later with a string configuration
admin.createCache("some_name", new StringConfiguration("<infinispan><cache-container>" + "<local-cache name=\"some_name\"/>" + "</cache-container></infinispan>"));
RemoteCache<Object, Object> someCache = client(0).getCache("some_name");
someCache.put("key", "value");
}
use of org.infinispan.commons.configuration.StringConfiguration in project infinispan by infinispan.
the class RemoteQueryRepeatedMappingTest method createCacheXMLConfig.
private StringConfiguration createCacheXMLConfig() {
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.encoding().mediaType(APPLICATION_PROTOSTREAM_TYPE);
builder.indexing().enable().storage(LOCAL_HEAP).addIndexedEntities("Parent");
String config = builder.build().toStringConfiguration(CACHE_NAME);
return new StringConfiguration(config);
}
use of org.infinispan.commons.configuration.StringConfiguration in project infinispan by infinispan.
the class AnchoredKeysIT method testCreateAnchoredKeysCache.
@Test
public void testCreateAnchoredKeysCache() {
BasicConfiguration config = new StringConfiguration("<infinispan><cache-container><replicated-cache name=\"anchored2\">\n" + "<locking concurrency-level=\"100\" acquire-timeout=\"1000\"/>\n" + "<anchored-keys xmlns=\"urn:infinispan:config:anchored-keys:" + Version.getMajorMinor() + "\" enabled=\"true\"/>\n" + "</replicated-cache></cache-container></infinispan>");
RemoteCacheManager rcm = SERVER_TEST.hotrod().createRemoteCacheManager();
rcm.administration().createCache("anchored2", config);
test(rcm.getCache("anchored2"));
}
use of org.infinispan.commons.configuration.StringConfiguration in project infinispan by infinispan.
the class HotRodAdmin method testCreateDeleteCacheFragment.
@Test
public void testCreateDeleteCacheFragment() {
RemoteCacheManager rcm = SERVER_TEST.hotrod().createRemoteCacheManager();
String cacheName = "testCreateDeleteCacheFragment";
String config = String.format("<distributed-cache name=\"%s\"/>", cacheName);
RemoteCache<String, String> cache = rcm.administration().createCache(cacheName, new StringConfiguration(config));
cache.put("k", "v");
assertNotNull(cache.get("k"));
rcm.administration().removeCache(cacheName);
assertNull(rcm.getCache(cacheName));
}
Aggregations