org.infinispan.commons.configuration.XMLStringConfiguration Java Examples

The following examples show how to use org.infinispan.commons.configuration.XMLStringConfiguration. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HotRodSearchClient.java    From apicurio-registry with Apache License 2.0 6 votes vote down vote up
@Override
public CompletionStage<Boolean> initialize(boolean reset) {
    registerProto(reset, COMMON_PROTO_KEY, SEARCH_PROTO_KEY);

    Set<String> caches = manager.getCacheNames();
    boolean hasSearch = caches.contains(cacheName);
    if (reset || !hasSearch) {
        if (hasSearch) {
            manager.administration().removeCache(cacheName);
        }
        String xml = String.format(XML_CACHE_CONFIG, cacheName);
        BasicConfiguration configuration = new XMLStringConfiguration(xml);
        cache = manager.administration().createCache(cacheName, configuration);
    }
    return CompletableFuture.completedFuture(Boolean.TRUE);
}
 
Example #2
Source File: InfinispanRemoteAdminCache.java    From infinispan-simple-tutorials with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a cache named CacheWithXMLConfiguration and uses the
 * XMLStringConfiguration() method to pass the cache definition as
 * valid infinispan.xml.
 */
private void createCacheWithXMLConfiguration() {
    String cacheName = "CacheWithXMLConfiguration";
    String xml = String.format("<infinispan>" +
                                  "<cache-container>" +
                                  "<distributed-cache name=\"%s\" mode=\"SYNC\">" +
                                    "<encoding media-type=\"application/x-protostream\"/>" +
                                    "<locking isolation=\"READ_COMMITTED\"/>" +
                                    "<transaction mode=\"NON_XA\"/>" +
                                    "<expiration lifespan=\"60000\" interval=\"20000\"/>" +
                                  "</distributed-cache>" +
                                  "</cache-container>" +
                                "</infinispan>"
                                , cacheName);
    manager.administration().getOrCreateCache(cacheName, new XMLStringConfiguration(xml));
    System.out.println("Cache with configuration exists or is created.");
}
 
Example #3
Source File: Reader.java    From infinispan-simple-tutorials with Apache License 2.0 5 votes vote down vote up
public Reader(BasqueNamesRepository repository, RemoteCacheManager remoteCacheManager) {
   this.repository = repository;
   random = new Random();
   cache = remoteCacheManager.administration().getOrCreateCache(Data.BASQUE_NAMES_CACHE, new XMLStringConfiguration(XML));
   try {
      cache.clearAsync().get(1, TimeUnit.MINUTES);
   } catch (Exception e) {
      logger.error("Unable to clear the cache", e);
   }
}
 
Example #4
Source File: InfinispanClientApp.java    From quarkus-quickstarts with Apache License 2.0 4 votes vote down vote up
void onStart(@Observes StartupEvent ev) {
    LOGGER.info("Create or get cache named mycache with the default configuration");
    RemoteCache<Object, Object> cache = cacheManager.administration().getOrCreateCache("mycache",
            new XMLStringConfiguration(String.format(CACHE_CONFIG, "mycache")));
    cache.put("hello", "Hello World, Infinispan is up!");
}
 
Example #5
Source File: InfinispanRemoteTx.java    From infinispan-simple-tutorials with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
   // Create a configuration for a locally-running server
   ConfigurationBuilder builder = new ConfigurationBuilder();
   builder.addServer()
            .host("127.0.0.1")
            .port(ConfigurationProperties.DEFAULT_HOTROD_PORT)
          .security().authentication()
            //Add user credentials.
            .username("username")
            .password("password")
            .realm("default")
            .saslMechanism("DIGEST-MD5");

   // Configure the RemoteCacheManager to use a transactional cache as default
   // Use the simple TransactionManager in hot rod client
   builder.transaction().transactionManagerLookup(RemoteTransactionManagerLookup.getInstance());
   // The cache will be enlisted as Synchronization
   builder.transaction().transactionMode(TransactionMode.NON_XA);

   // Connect to the server
   RemoteCacheManager cacheManager = new RemoteCacheManager(builder.build());

   // Create a transactional cache in the server since there is none available by default.
   cacheManager.administration().createCache(CACHE_NAME, new XMLStringConfiguration(TEST_CACHE_XML_CONFIG));
   RemoteCache<String, String> cache = cacheManager.getCache(CACHE_NAME);

   // Obtain the transaction manager
   TransactionManager transactionManager = cache.getTransactionManager();
   // Perform some operations within a transaction and commit it
   transactionManager.begin();
   cache.put("key1", "value1");
   cache.put("key2", "value2");
   transactionManager.commit();
   // Display the current cache contents
   System.out.printf("key1 = %s\nkey2 = %s\n", cache.get("key1"), cache.get("key2"));
   // Perform some operations within a transaction and roll it back
   transactionManager.begin();
   cache.put("key1", "value3");
   cache.put("key2", "value4");
   transactionManager.rollback();
   // Display the current cache contents
   System.out.printf("key1 = %s\nkey2 = %s\n", cache.get("key1"), cache.get("key2"));
   // Stop the cache manager and release all resources
   cacheManager.stop();
}