当前位置: 首页>>代码示例>>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;未经允许,请勿转载。