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


Java Cache.put方法代碼示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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 distributed synchronous 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();
   // 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,代碼來源:InfinispanDistributed.java

示例7: filterPriorityQueue

import org.infinispan.Cache; //導入方法依賴的package包/類
private void filterPriorityQueue(IPriorityQueue priorityQueue, Predicate<IAttribution> attributionPredicate) {
	Cache<IPriorityQueue, List<IAttribution>> cache = getPriorityQueuesCache();
	boolean commit = false;
	if (!cache.getAdvancedCache().startBatch()) {
		LOGGER.error("Batch attempt on {} failed", priorityQueue);
	}
	try {
		// get lock values
		if (!cache.getAdvancedCache().lock(priorityQueue)) {
			LOGGER.error("Lock attempt on {} failed", priorityQueue);
			commit = false;
			return;
		}
		List<IAttribution> values = cache.getOrDefault(priorityQueue, Lists.<IAttribution> newArrayList());
		List<IAttribution> newValues = Lists.newArrayList(Collections2.filter(values, attributionPredicate));
		cache.put(priorityQueue, newValues);
		commit = true;
	} finally {
		cache.endBatch(commit);
	}
}
 
開發者ID:openwide-java,項目名稱:owsi-core-parent,代碼行數:22,代碼來源:InfinispanClusterServiceImpl.java

示例8: doCreateHttpServerMechanismFactory

import org.infinispan.Cache; //導入方法依賴的package包/類
@Override
protected HttpServerAuthenticationMechanismFactory doCreateHttpServerMechanismFactory(Map<String, ?> properties) {
    HttpServerAuthenticationMechanismFactory delegate = super.doCreateHttpServerMechanismFactory(properties);

    String cacheManagerName = UUID.randomUUID().toString();
    EmbeddedCacheManager cacheManager = new DefaultCacheManager(
            GlobalConfigurationBuilder.defaultClusteredBuilder()
                    .globalJmxStatistics().cacheManagerName(cacheManagerName)
                    .transport().nodeName(cacheManagerName).addProperty(JGroupsTransport.CONFIGURATION_FILE, "fast.xml")
                    .build(),
            new ConfigurationBuilder()
                    .clustering()
                    .cacheMode(CacheMode.REPL_SYNC)
                    .build()
    );

    Cache<String, SingleSignOnEntry> cache = cacheManager.getCache();
    SingleSignOnManager manager = new DefaultSingleSignOnManager(cache, new DefaultSingleSignOnSessionIdentifierFactory(), (id, entry) -> cache.put(id, entry));
    SingleSignOnServerMechanismFactory.SingleSignOnConfiguration signOnConfiguration = new SingleSignOnServerMechanismFactory.SingleSignOnConfiguration("JSESSIONSSOID", null, "/", false, false);

    SingleSignOnSessionFactory singleSignOnSessionFactory = new DefaultSingleSignOnSessionFactory(manager, this.keyPairSupplier.get());

    return new SingleSignOnServerMechanismFactory(delegate, singleSignOnSessionFactory, signOnConfiguration);
}
 
開發者ID:wildfly-security,項目名稱:elytron-web,代碼行數:25,代碼來源:FormAuthenticationWithClusteredSSOTest.java

示例9: testConfigBuilder

import org.infinispan.Cache; //導入方法依賴的package包/類
public void testConfigBuilder() {
   GlobalConfiguration globalConfig = new GlobalConfigurationBuilder().globalJmxStatistics().transport().defaultTransport().build();

   Configuration cacheConfig = new ConfigurationBuilder().persistence().addStore(LevelDBStoreConfigurationBuilder.class).location(tmpDataDirectory)
         .expiredLocation(tmpExpiredDirectory).implementationType(LevelDBStoreConfiguration.ImplementationType.AUTO).build();

   StoreConfiguration cacheLoaderConfig = cacheConfig.persistence().stores().get(0);
   assertTrue(cacheLoaderConfig instanceof LevelDBStoreConfiguration);
   LevelDBStoreConfiguration leveldbConfig = (LevelDBStoreConfiguration) cacheLoaderConfig;
   assertEquals(tmpDataDirectory, leveldbConfig.location());
   assertEquals(tmpExpiredDirectory, leveldbConfig.expiredLocation());

   EmbeddedCacheManager cacheManager = new DefaultCacheManager(globalConfig);

   cacheManager.defineConfiguration("testCache", cacheConfig);

   cacheManager.start();
   Cache<String, String> cache = cacheManager.getCache("testCache");

   cache.put("hello", "there");
   cache.stop();
   cacheManager.stop();
}
 
開發者ID:danberindei,項目名稱:infinispan-cachestore-leveldb,代碼行數:24,代碼來源:ConfigurationTest.java

示例10: testLegacyJavaConfig

import org.infinispan.Cache; //導入方法依賴的package包/類
@Test(enabled = false, description = "ISPN-3388")
public void testLegacyJavaConfig() {
   GlobalConfiguration globalConfig = new GlobalConfigurationBuilder().globalJmxStatistics().transport().defaultTransport().build();

   Configuration cacheConfig = new ConfigurationBuilder().persistence().addStore(LevelDBStoreConfigurationBuilder.class).addProperty("location", tmpDataDirectory)
         .addProperty("expiredLocation", tmpExpiredDirectory).addProperty("implementationType", LevelDBStoreConfiguration.ImplementationType.AUTO.toString()).build();

   EmbeddedCacheManager cacheManager = new DefaultCacheManager(globalConfig);

   cacheManager.defineConfiguration("testCache", cacheConfig);

   cacheManager.start();
   Cache<String, String> cache = cacheManager.getCache("testCache");

   cache.put("hello", "there legacy java");
   cache.stop();
   cacheManager.stop();
}
 
開發者ID:danberindei,項目名稱:infinispan-cachestore-leveldb,代碼行數:19,代碼來源:ConfigurationTest.java

示例11: testConfigBuilder

import org.infinispan.Cache; //導入方法依賴的package包/類
public void testConfigBuilder() {
   GlobalConfiguration globalConfig = new GlobalConfigurationBuilder().globalJmxStatistics().transport().defaultTransport().build();

   Configuration cacheConfig = new ConfigurationBuilder().persistence().addStore(MapDBStoreConfigurationBuilder.class)
         .location(tmpDirectory)
         .compression(true)
         .build();

   StoreConfiguration cacheLoaderConfig = cacheConfig.persistence().stores().get(0);
   assertTrue(cacheLoaderConfig instanceof MapDBStoreConfiguration);
   MapDBStoreConfiguration config = (MapDBStoreConfiguration) cacheLoaderConfig;
   assertEquals(true, config.compression());
   
   EmbeddedCacheManager cacheManager = new DefaultCacheManager(globalConfig);

   cacheManager.defineConfiguration("testCache", cacheConfig);

   cacheManager.start();
   Cache<String, String> cache = cacheManager.getCache("testCache");

   cache.put("hello", "there");
   cache.stop();
   cacheManager.stop();
}
 
開發者ID:saturnism,項目名稱:infinispan-cachestore-mapdb,代碼行數:25,代碼來源:ConfigurationTest.java

示例12: testConfigBuilder

import org.infinispan.Cache; //導入方法依賴的package包/類
public void testConfigBuilder() {
   GlobalConfiguration globalConfig = new GlobalConfigurationBuilder().globalJmxStatistics().transport().defaultTransport().build();

   Configuration cacheConfig = new ConfigurationBuilder().persistence().addStore(OffheapStoreConfigurationBuilder.class)
         .compression(true)
         .build();

   StoreConfiguration cacheLoaderConfig = cacheConfig.persistence().stores().get(0);
   assertTrue(cacheLoaderConfig instanceof OffheapStoreConfiguration);
   OffheapStoreConfiguration config = (OffheapStoreConfiguration) cacheLoaderConfig;
   assertEquals(true, config.compression());
   
   EmbeddedCacheManager cacheManager = new DefaultCacheManager(globalConfig);

   cacheManager.defineConfiguration("testCache", cacheConfig);

   cacheManager.start();
   Cache<String, String> cache = cacheManager.getCache("testCache");

   cache.put("hello", "there");
   cache.stop();
   cacheManager.stop();
}
 
開發者ID:saturnism,項目名稱:infinispan-cachestore-offheap,代碼行數:24,代碼來源:ConfigurationTest.java

示例13: main

import org.infinispan.Cache; //導入方法依賴的package包/類
public static void main(String[] args) {

		String[] inputFileNames = { "data1.xml", "data2.xml", "data3.xml", "data4.xml", "data5.xml" };
		// Create a Money Transfer Object from XML Message using BeaoIO API
		try {
			StreamFactory factory = StreamFactory.newInstance();
			factory.loadResource("mapping.xml");
			Unmarshaller unmarshaller = factory.createUnmarshaller("MoneyTransferStream");

			String record;
			ConfigurationBuilder builder = new ConfigurationBuilder();
			Cache<String, Object> cache = new DefaultCacheManager(builder.build()).getCache();
			
			//Read Transactions and put in cache
			for (String inputFile : inputFileNames) {
				record = FileUtils.getContentsAsString(new File(INPUT_DIR + inputFile));
				MoneyTransfert mt = (MoneyTransfert) unmarshaller.unmarshal(record);
				cache.put(mt.getId() + "", mt);
			}

			//Inspect the cache .
			System.out.println(cache.size());
			System.out.println(cache.getStatus());
			System.out.println(cache.get("3"));

			//Stop the cache
			cache.stop();
			System.out.println(cache.getStatus());

		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
 
開發者ID:PacktPublishing,項目名稱:JBoss-Developers-Guide,代碼行數:36,代碼來源:EmbeddedCacheDemo.java

示例14: main

import org.infinispan.Cache; //導入方法依賴的package包/類
public static void main(String[] args) {

		String[] inputFileNames = { "data1.xml", "data2.xml", "data3.xml", "data4.xml", "data5.xml" };
		// Create a Money Transfer Object from XML Message using BeaoIO API
		try {
			StreamFactory factory = StreamFactory.newInstance();
			factory.loadResource("mapping.xml");
			Unmarshaller unmarshaller = factory.createUnmarshaller("MoneyTransferStream");

			String record;
			ConfigurationBuilder builder = new ConfigurationBuilder();
			Cache<String, Object> cache = new DefaultCacheManager(builder.build()).getCache();
			
			cache.addListener(new DatagridListener());
			//Read Transactions and put in cache
			for (String inputFile : inputFileNames) {
				record = FileUtils.getContentsAsString(new File(INPUT_DIR + inputFile));
				MoneyTransfert mt = (MoneyTransfert) unmarshaller.unmarshal(record);
				cache.put(mt.getId() + "", mt);
			}

			//Inspect the cache .
			System.out.println(cache.size());
			System.out.println(cache.getStatus());
			System.out.println(cache.get("3"));

			//Stop the cache
			cache.stop();
			System.out.println(cache.getStatus());

		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
 
開發者ID:PacktPublishing,項目名稱:JBoss-Developers-Guide,代碼行數:37,代碼來源:EmbeddedCacheListenerDemo.java

示例15: setUp

import org.infinispan.Cache; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Before
public void setUp() {
  Cache cache = entityToCacheMapper.getCache(Fruit.class);

  Fruit fruit = new Fruit(1L, "Cherry");
  cache.put(fruit.getId(), fruit);
  fruit = new Fruit(2L, "Apple");
  cache.put(fruit.getId(), fruit);
  fruit = new Fruit(3L, "Banana");
  cache.put(fruit.getId(), fruit);
}
 
開發者ID:snowdrop,項目名稱:spring-data-snowdrop,代碼行數:13,代碼來源:InfinispanSmokeTest.java


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