當前位置: 首頁>>代碼示例>>Java>>正文


Java Cache類代碼示例

本文整理匯總了Java中org.infinispan.Cache的典型用法代碼示例。如果您正苦於以下問題:Java Cache類的具體用法?Java Cache怎麽用?Java Cache使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Cache類屬於org.infinispan包,在下文中一共展示了Cache類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testClusterSize

import org.infinispan.Cache; //導入依賴的package包/類
@Test
public void testClusterSize() {
    System.setProperty("grid.buffer", "10");

    RulesConfigurationTestImpl rulesConfigurationTest = RulesTestBuilder.buildV1();
    RulesManager rulesManager = new RulesManager(rulesConfigurationTest);
    rulesManager.start(null, null, null);

    LOGGER.info("Start test cluster size");
    Cache<Key, HAKieSession> cache1 = startNodes(2, rulesManager).getCache();
    Cache<Key, HAKieSession> cache2 = startNodes(2, rulesManager).getCache();

    assertEquals(2, ((DefaultCacheManager) cache1.getCacheManager()).getClusterSize());
    assertEquals(2, ((DefaultCacheManager) cache2.getCacheManager()).getClusterSize());
    LOGGER.info("End test cluster size");
    rulesManager.stop();
}
 
開發者ID:redhat-italy,項目名稱:hacep,代碼行數:18,代碼來源:ClusterTest.java

示例2: execute

import org.infinispan.Cache; //導入依賴的package包/類
@Override
public boolean execute(UI console, Iterator<String> args) throws IllegalParametersException {

    String cacheName = args.next();
    Cache<Key, Object> cache = application.getCacheManager().getCache(cacheName, false);

    if (cache != null) {
        Set<String> primaryVals = jdgUtility.primaryValuesFromKeys(cache);
        primaryVals.forEach(console::println);
        console.println("Cache Size: " + cache.size() + "\n");
        console.println("Primary Size: " + primaryVals.size() + "\n");
    } else {
        console.println("Cache " + cacheName + " not existent");
    }
    return true;
}
 
開發者ID:redhat-italy,項目名稱:hacep,代碼行數:17,代碼來源:PrimaryConsoleCommand.java

示例3: execute

import org.infinispan.Cache; //導入依賴的package包/類
@Override
public boolean execute(UI console, Iterator<String> args) throws IllegalParametersException {

    String cacheName = args.next();
    Cache<Key, Object> cache = application.getCacheManager().getCache(cacheName, false);

    if (cache != null) {
        Set<String> replicas = jdgUtility.replicaValuesFromKeys(cache);
        replicas.forEach(console::println);
        console.println("Cache Size: " + cache.size() + "\n");
        console.println("Replica Size: " + replicas.size() + "\n");
    } else {
        console.println("Cache " + cacheName + " not existent");
    }
    return true;
}
 
開發者ID:redhat-italy,項目名稱:hacep,代碼行數:17,代碼來源:ReplicaConsoleCommand.java

示例4: execute

import org.infinispan.Cache; //導入依賴的package包/類
@Override
public boolean execute(UI console, Iterator<String> args) throws IllegalParametersException {
    try {
        String cacheName = args.next();
        Cache<Key, Object> cache = application.getCacheManager().getCache(cacheName, false);

        if (cache != null) {
            console.println(buildInfo(cache));
        } else {
            console.println("Cache " + cacheName + " not existent");
        }

    } catch (NoSuchElementException e) {
        console.println(application.info());
    }
    return true;

}
 
開發者ID:redhat-italy,項目名稱:hacep,代碼行數:19,代碼來源:InfoConsoleCommand.java

示例5: put

import org.infinispan.Cache; //導入依賴的package包/類
@GET
@Path("/put")
public String put(@QueryParam("num") int num) {
    log.debugf("PUT START num=%d", num);
    
    int putNum = num == 0 ? 1 : num;
    
    Cache<Long, String> cache = jdg.getManager().getCache("default");
    
    IntStream.rangeClosed(1, putNum).parallel().forEach(i -> {
        cache.put(
                uid.incrementAndGet(),
                kokoro.getRandom(),      // 夏目漱石「こころ」からランダムに1行取得してput
                1,                       // LifeSapn = 1分(putしてから1分後に自動削除)
                TimeUnit.MINUTES );
        });
    
    int cacheSize = cache.size();
    log.debugf("PUT END cacheSize=%,d", cacheSize);
    return "" + cacheSize;
}
 
開發者ID:mkobayas,項目名稱:jdg7-example,代碼行數:22,代碼來源:WordCountAp.java

示例6: fetchAll

import org.infinispan.Cache; //導入依賴的package包/類
public <T extends WithId<T>> ListResult<T> fetchAll(Class<T> model, Function<ListResult<T>, ListResult<T>>... operators) {

        ListResult<T> result;
        if( getDataAccessObject(model)!=null ) {
            result = doWithDataAccessObject(model, d -> d.fetchAll());
        } else {
            Kind kind = Kind.from(model);
            Cache<String, T> cache = caches.getCache(kind.getModelName());
            result = ListResult.of(cache.values());
        }

        for (Function<ListResult<T>, ListResult<T>> operator : operators) {
            result = operator.apply(result);
        }
        return result;
    }
 
開發者ID:syndesisio,項目名稱:syndesis-rest,代碼行數:17,代碼來源:DataManager.java

示例7: create

import org.infinispan.Cache; //導入依賴的package包/類
public <T extends WithId<T>> T create(final T entity) {
    Kind kind = entity.getKind();
    Cache<String, T> cache = caches.getCache(kind.getModelName());
    Optional<String> id = entity.getId();
    String idVal;

    final T entityToCreate;
    if (!id.isPresent()) {
        idVal = KeyGenerator.createKey();
        entityToCreate = entity.withId(idVal);
    } else {
        idVal = id.get();
        if (cache.keySet().contains(idVal)) {
            throw new EntityExistsException("There already exists a "
                + kind + " with id " + idVal);
        }
        entityToCreate = entity;
    }

    this.<T, T>doWithDataAccessObject(kind.getModelClass(), d -> d.create(entityToCreate));
    cache.put(idVal, entityToCreate);
    broadcast("created", kind.getModelName(), idVal);
    return entityToCreate;
}
 
開發者ID:syndesisio,項目名稱:syndesis-rest,代碼行數:25,代碼來源:DataManager.java

示例8: ProcessingNode

import org.infinispan.Cache; //導入依賴的package包/類
/**
 * The first argument is the name of the node.
 */
public ProcessingNode(String name, String configurationFileName) throws Exception
{
    if (name == null)
    {
        this.name = "ANONYMOUS";
    }
    else
    {
        this.name = name;
    }

    this.configurationFileName = configurationFileName;

    caches = new HashMap<String, Cache>();
}
 
開發者ID:NovaOrdis,項目名稱:playground,代碼行數:19,代碼來源:ProcessingNode.java

示例9: doGet

import org.infinispan.Cache; //導入依賴的package包/類
@Override
    public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
    {

        ServiceContainer sc = CurrentServiceContainer.getServiceContainer();

//        for(ServiceName sn: sc.getServiceNames()) {
//            log.info("" + sn);
//        }

        ServiceName sn = ServiceName.of("jboss", "infinispan", "web", "repl");
        ServiceController scon = sc.getService(sn);
        Cache cache = (Cache)scon.getValue();
        log.info("" + cache);


        String path = req.getPathInfo();

        Object o = null;

        if ("/put".equals(path)) {
            cache.put("test", "blah");
        }
        else if ("/get".equals(path)) {

            o = cache.get("test");
        }

        res.setContentType("text/html");
        PrintWriter out = res.getWriter();

        if (o != null) {
            out.println(o);
        }
    }
 
開發者ID:NovaOrdis,項目名稱:playground,代碼行數:36,代碼來源:AccessServlet.java

示例10: start

import org.infinispan.Cache; //導入依賴的package包/類
@Override
public InfinispanEventListener start(InfinispanConsumer consumer) {
    Cache<?, ?> embeddedCache = InfinispanUtil.asEmbedded(consumer.getCache());
    InfinispanConfiguration configuration = consumer.getConfiguration();
    InfinispanEventListener listener;
    if (configuration.hasCustomListener()) {
        listener = configuration.getCustomListener();
        listener.setInfinispanConsumer(consumer);
    } else if (configuration.isClusteredListener()) {
        if (configuration.isSync()) {
            listener = new InfinispanSyncClusteredEventListener(consumer, configuration.getEventTypes());
        } else {
            listener = new InfinispanAsyncClusteredEventListener(consumer, configuration.getEventTypes());
        }
    } else {
        if (configuration.isSync()) {
            listener = new InfinispanSyncLocalEventListener(consumer, configuration.getEventTypes());
        } else {
            listener = new InfinispanAsyncLocalEventListener(consumer, configuration.getEventTypes());
        }
    }
    embeddedCache.addListener(listener);
    return listener;
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:25,代碼來源:InfinispanConsumerEmbeddedHandler.java

示例11: main

import org.infinispan.Cache; //導入依賴的package包/類
public static void main(String[] args) {
   ConfigurationBuilder builder = new ConfigurationBuilder();
   builder.indexing().index(Index.ALL)
      .addProperty("default.directory_provider", "ram")
      .addProperty("lucene_version", "LUCENE_CURRENT");
   // Construct a simple local cache manager with default configuration
   DefaultCacheManager cacheManager = new DefaultCacheManager(builder.build());
   // Obtain the default cache
   Cache<String, Person> cache = cacheManager.getCache();
   // Store some entries
   cache.put("person1", new Person("William", "Shakespeare"));
   cache.put("person2", new Person("William", "Wordsworth"));
   cache.put("person3", new Person("John", "Milton"));
   // Obtain a query factory for the cache
   QueryFactory queryFactory = Search.getQueryFactory(cache);
   // Construct a query
   Query query = queryFactory.from(Person.class).having("name").eq("William").toBuilder().build();
   // Execute the query
   List<Person> matches = query.list();
   // List the results
   matches.forEach(person -> System.out.printf("Match: %s", person));
   // Stop the cache manager and release all resources
   cacheManager.stop();
}
 
開發者ID:infinispan,項目名稱:infinispan-simple-tutorials,代碼行數:25,代碼來源:InfinispanQuery.java

示例12: main

import org.infinispan.Cache; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
   // Setup up a clustered cache manager
   GlobalConfigurationBuilder global = GlobalConfigurationBuilder.defaultClusteredBuilder();
   // Make the default cache a replicated synchronous one
   ConfigurationBuilder builder = new ConfigurationBuilder();
   builder.clustering().cacheMode(CacheMode.REPL_SYNC);
   // Initialize the cache manager
   DefaultCacheManager cacheManager = new DefaultCacheManager(global.build(), builder.build());
   // Obtain the default cache
   Cache<String, String> cache = cacheManager.getCache();
   // Store the current node address in some random keys
   for(int i=0; i < 10; i++) {
      cache.put(UUID.randomUUID().toString(), cacheManager.getNodeAddress());
   }
   // Display the current cache contents for the whole cluster
   cache.entrySet().forEach(entry -> System.out.printf("%s = %s\n", entry.getKey(), entry.getValue()));
   // Display the current cache contents for this node
   cache.getAdvancedCache().withFlags(Flag.SKIP_REMOTE_LOOKUP)
      .entrySet().forEach(entry -> System.out.printf("%s = %s\n", entry.getKey(), entry.getValue()));
   // Stop the cache manager and release all resources
   cacheManager.stop();
}
 
開發者ID:infinispan,項目名稱:infinispan-simple-tutorials,代碼行數:23,代碼來源:InfinispanReplicated.java

示例13: main

import org.infinispan.Cache; //導入依賴的package包/類
public static void main(String[] args) {
   // Construct a simple local cache manager with default configuration
   DefaultCacheManager cacheManager = new DefaultCacheManager();
   // Define local cache configuration
   cacheManager.defineConfiguration("local", new ConfigurationBuilder().build());
   // Obtain the local cache
   Cache<String, String> cache = cacheManager.getCache("local");
   // Store some values
   int range = 10;
   IntStream.range(0, range).boxed().forEach(i -> cache.put(i + "-key", i + "-value"));
   // Map and reduce the keys
   int result = cache.keySet().stream()
      .map((Serializable & Function<String, Integer>) e -> Integer.valueOf(e.substring(0, e.indexOf("-"))))
           .collect(CacheCollectors.serializableCollector(() -> Collectors.summingInt(i -> i.intValue())));
   System.out.printf("Result = %d\n", result);
   // Stop the cache manager and release all resources
   cacheManager.stop();
}
 
開發者ID:infinispan,項目名稱:infinispan-simple-tutorials,代碼行數:19,代碼來源:InfinispanStreams.java

示例14: main

import org.infinispan.Cache; //導入依賴的package包/類
public static void main(String[] args) {
   // Construct a simple local cache manager with default configuration
   DefaultCacheManager cacheManager = new DefaultCacheManager();
   // Define local cache configuration
   cacheManager.defineConfiguration("local", new ConfigurationBuilder().build());
   // Obtain the local cache
   Cache<String, String> cache = cacheManager.getCache("local");
   // Register a listener
   cache.addListener(new MyListener());
   // Store some values
   cache.put("key1", "value1");
   cache.put("key2", "value2");
   cache.put("key1", "newValue");
   // Stop the cache manager and release all resources
   cacheManager.stop();
}
 
開發者ID:infinispan,項目名稱:infinispan-simple-tutorials,代碼行數:17,代碼來源:InfinispanListen.java

示例15: main

import org.infinispan.Cache; //導入依賴的package包/類
public static void main(String[] args) {
   // Setup up a clustered cache manager
   GlobalConfigurationBuilder global = GlobalConfigurationBuilder.defaultClusteredBuilder();
   // Make the default cache a distributed one
   ConfigurationBuilder builder = new ConfigurationBuilder();
   builder.clustering().cacheMode(CacheMode.DIST_SYNC);
   // Initialize the cache manager
   DefaultCacheManager cacheManager = new DefaultCacheManager(global.build(), builder.build());
   // Obtain the default cache
   Cache<String, String> cache = cacheManager.getCache();
   // Create a distributed executor service using the distributed cache to determine the nodes on which to run
   DefaultExecutorService executorService = new DefaultExecutorService(cache);
   // Submit a job to all nodes
   List<Future<Integer>> results = executorService.submitEverywhere((Callable & Serializable) () -> new Random().nextInt());
   // Print out the results
   results.forEach(s -> {
      try {
         System.out.printf("%s\n", s.get(100, TimeUnit.MILLISECONDS));
      } catch (Exception e) {
      }
   });
   // Shuts down the cache manager and all associated resources
   cacheManager.stop();
   System.exit(0);
}
 
開發者ID:infinispan,項目名稱:infinispan-simple-tutorials,代碼行數:26,代碼來源:InfinispanDistExec.java


注:本文中的org.infinispan.Cache類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。