本文整理汇总了Java中org.infinispan.client.hotrod.RemoteCache类的典型用法代码示例。如果您正苦于以下问题:Java RemoteCache类的具体用法?Java RemoteCache怎么用?Java RemoteCache使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RemoteCache类属于org.infinispan.client.hotrod包,在下文中一共展示了RemoteCache类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: registerProtoBufSchema
import org.infinispan.client.hotrod.RemoteCache; //导入依赖的package包/类
private void registerProtoBufSchema() {
SerializationContext serCtx = ProtoStreamMarshaller.getSerializationContext(cacheManager);
String generatedSchema = null;
try {
ProtoSchemaBuilder protoSchemaBuilder = new ProtoSchemaBuilder();
generatedSchema = protoSchemaBuilder.fileName("heschema.proto").packageName("model")
.addClass(HEElementModel.class).addClass(HEElementCategoryModel.class).build(serCtx);
// register the schemas with the server too
RemoteCache<String, String> metadataCache = cacheManager
.getCache(ProtobufMetadataManagerConstants.PROTOBUF_METADATA_CACHE_NAME);
metadataCache.put("heschema.proto", generatedSchema);
} catch (Exception e1) {
StringBuilder sb = new StringBuilder();
sb.append("No schema generated because of Exception");
log.error(sb.toString(), e1);
}
log.debug(generatedSchema);
}
示例2: setUp
import org.infinispan.client.hotrod.RemoteCache; //导入依赖的package包/类
@Before
public void setUp() {
ConfigurationBuilder builder = new ConfigurationBuilder().addServer().host("localhost").port(11222)
.marshaller(new ProtoStreamMarshaller());
cacheManager = new RemoteCacheManager(builder.build());
SerializationContext serCtx = ProtoStreamMarshaller.getSerializationContext(cacheManager);
ProtoSchemaBuilder protoSchemaBuilder = new ProtoSchemaBuilder();
String memoSchemaFile = null;
try {
memoSchemaFile = protoSchemaBuilder.fileName("file.proto").packageName("test").addClass(Author.class)
.build(serCtx);
} catch (ProtoSchemaBuilderException | IOException e) {
e.printStackTrace();
}
// register the schemas with the server too
RemoteCache<String, String> metadataCache = cacheManager
.getCache(ProtobufMetadataManagerConstants.PROTOBUF_METADATA_CACHE_NAME);
metadataCache.put("file.proto", memoSchemaFile);
}
示例3: doGet
import org.infinispan.client.hotrod.RemoteCache; //导入依赖的package包/类
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String host = System.getenv("DATAGRID_APP_HOTROD_SERVICE_HOST");
int port = Integer.parseInt(System.getenv("DATAGRID_APP_HOTROD_SERVICE_PORT"));
Configuration conf = new ConfigurationBuilder().addServer().host(host).port(port).build();
RemoteCacheManager manager = new RemoteCacheManager(conf);
RemoteCache cache = manager.getCache();
char[] data = new char[1000000];
int index = 0;
while (true) {
System.out.println("populating the cache index " + index);
cache.put(index++, data,1, TimeUnit.DAYS);
}
}
示例4: execute
import org.infinispan.client.hotrod.RemoteCache; //导入依赖的package包/类
@Override
public void execute(String restOfTheLine) throws Exception {
if (restOfTheLine == null || restOfTheLine.trim().length() == 0) {
throw new UserErrorException("key name missing");
}
int i = restOfTheLine.indexOf(' ');
if (i == -1) {
throw new UserErrorException("key value pair missing");
}
String keyName = restOfTheLine.substring(0, i);
restOfTheLine = restOfTheLine.substring(i + 1);
String keyValue = restOfTheLine.replaceAll(" .*$", "");
RemoteCache defaultCache = insureConnected();
defaultCache.put(keyName, keyValue);
}
示例5: start
import org.infinispan.client.hotrod.RemoteCache; //导入依赖的package包/类
@Override
public InfinispanEventListener start(InfinispanConsumer consumer) {
if (consumer.getConfiguration().isSync()) {
throw new UnsupportedOperationException("Sync listeners not supported for remote caches.");
}
RemoteCache<?, ?> remoteCache = InfinispanUtil.asRemote(consumer.getCache());
InfinispanConfiguration configuration = consumer.getConfiguration();
InfinispanEventListener listener;
if (configuration.hasCustomListener()) {
listener = configuration.getCustomListener();
listener.setInfinispanConsumer(consumer);
} else {
listener = new InfinispanRemoteEventListener(consumer, configuration.getEventTypes());
}
remoteCache.addClientListener(listener);
listener.setCacheName(remoteCache.getName());
return listener;
}
示例6: remoteCacheWithoutProperties
import org.infinispan.client.hotrod.RemoteCache; //导入依赖的package包/类
@Test
public void remoteCacheWithoutProperties() throws Exception {
InfinispanConfiguration configuration = new InfinispanConfiguration();
configuration.setHost("localhost");
configuration.setCacheName("misc_cache");
InfinispanManager manager = new InfinispanManager(configuration);
manager.start();
BasicCache<Object, Object> cache = manager.getCache();
assertNotNull(cache);
assertTrue(cache instanceof RemoteCache);
RemoteCache<Object, Object> remoteCache = InfinispanUtil.asRemote(cache);
String key = UUID.randomUUID().toString();
assertNull(remoteCache.put(key, "val1"));
assertNull(remoteCache.put(key, "val2"));
manager.stop();
}
示例7: remoteCacheWithPropertiesTest
import org.infinispan.client.hotrod.RemoteCache; //导入依赖的package包/类
@Test
public void remoteCacheWithPropertiesTest() throws Exception {
InfinispanConfiguration configuration = new InfinispanConfiguration();
configuration.setHost("localhost");
configuration.setCacheName("misc_cache");
configuration.setConfigurationUri("infinispan/client.properties");
InfinispanManager manager = new InfinispanManager(configuration);
manager.start();
BasicCache<Object, Object> cache = manager.getCache();
assertNotNull(cache);
assertTrue(cache instanceof RemoteCache);
String key = UUID.randomUUID().toString();
assertNull(cache.put(key, "val1"));
assertNotNull(cache.put(key, "val2"));
manager.stop();
}
示例8: doPreSetup
import org.infinispan.client.hotrod.RemoteCache; //导入依赖的package包/类
@Override
protected void doPreSetup() throws IOException {
ConfigurationBuilder builder = new ConfigurationBuilder()
.addServer()
.host("localhost")
.port(11222)
.marshaller(new ProtoStreamMarshaller());
manager = new RemoteCacheManager(builder.build());
RemoteCache<String, String> metadataCache = manager
.getCache(ProtobufMetadataManagerConstants.PROTOBUF_METADATA_CACHE_NAME);
metadataCache
.put("sample_bank_account/bank.proto",
Util.read(InfinispanRemoteQueryProducerIT.class
.getResourceAsStream("/sample_bank_account/bank.proto")));
MarshallerRegistration.registerMarshallers(ProtoStreamMarshaller
.getSerializationContext(manager));
SerializationContext serCtx = ProtoStreamMarshaller
.getSerializationContext(manager);
serCtx.registerProtoFiles(FileDescriptorSource
.fromResources("/sample_bank_account/bank.proto"));
serCtx.registerMarshaller(new UserMarshaller());
serCtx.registerMarshaller(new GenderMarshaller());
}
示例9: doPostSetup
import org.infinispan.client.hotrod.RemoteCache; //导入依赖的package包/类
@Override
protected void doPostSetup() throws Exception {
// pre-load data
RemoteCache<Object, Object> cache = manager.getCache("remote_query");
assertNotNull(cache);
cache.clear();
assertTrue(cache.isEmpty());
for (final User user : USERS) {
String key = createKey(user);
cache.put(key, user);
assertTrue(cache.containsKey(key));
}
}
示例10: main
import org.infinispan.client.hotrod.RemoteCache; //导入依赖的package包/类
public static void main(String[] args) {
// Create a configuration for a locally-running server
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.addServer().host("127.0.0.1").port(ConfigurationProperties.DEFAULT_HOTROD_PORT);
// Connect to the server
RemoteCacheManager cacheManager = new RemoteCacheManager(builder.build());
// Retrieve the cache containing the scripts
RemoteCache<String, String> scriptCache = cacheManager.getCache("___script_cache");
// Create a simple script which multiplies to numbers
scriptCache.put("simple.js", "multiplicand * multiplier");
// Obtain the remote cache
RemoteCache<String, Integer> cache = cacheManager.getCache();
// Create the parameters for script execution
Map<String, Object> params = new HashMap<>();
params.put("multiplicand", 10);
params.put("multiplier", 20);
// Run the script on the server, passing in the parameters
Object result = cache.execute("simple.js", params);
// Print the result
System.out.printf("Result = %s\n", result);
// Stop the cache manager and release resources
cacheManager.stop();
}
示例11: main
import org.infinispan.client.hotrod.RemoteCache; //导入依赖的package包/类
public static void main(String[] args) throws InterruptedException {
// Create a configuration for a locally-running server
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.addServer().host("127.0.0.1").port(ConfigurationProperties.DEFAULT_HOTROD_PORT);
// Connect to the server
RemoteCacheManager cacheManager = new RemoteCacheManager(builder.build());
// Obtain the remote cache
RemoteCache<String, String> cache = cacheManager.getCache();
// Register a listener
MyListener listener = new MyListener();
cache.addClientListener(listener);
// Store some values
cache.put("key1", "value1");
cache.put("key2", "value2");
cache.put("key1", "newValue");
// Remote events are asynchronous, so wait a bit
Thread.sleep(1000);
// Remove listener
cache.removeClientListener(listener);
// Stop the cache manager and release all resources
cacheManager.stop();
}
示例12: executeOnCache
import org.infinispan.client.hotrod.RemoteCache; //导入依赖的package包/类
private static <K, V> int executeOnCache(RemoteCacheRunnable<K, V> runnable, Map<Argument, String> map) throws Exception {
RemoteCacheManager remoteCacheManager = new RemoteCacheManager(map.get(Argument.HOST),
Integer.parseInt(map.get(Argument.PORT)));
RemoteCache<K, V> remoteCache = remoteCacheManager.getCache(map.get(Argument.CACHE_NAME));
try {
if (remoteCache == null) {
System.err.println("Unable to connect to cache");
return -1;
}
return runnable.execute(remoteCache, map);
} finally {
if (remoteCache != null) {
remoteCache.stop();
}
remoteCacheManager.stop();
}
}
示例13: setupMetadataCache
import org.infinispan.client.hotrod.RemoteCache; //导入依赖的package包/类
private boolean setupMetadataCache() throws IOException {
log.log(Level.INFO, "setupMetadataCache");
try {
final RemoteCache<String, String> metadataCache = cacheManagerForIndexableCaches.getCache(ProtobufMetadataManagerConstants.PROTOBUF_METADATA_CACHE_NAME);
metadataCache.put(RULE_PROTOBUF_DEFINITION_RESOURCE, readResource(RULE_PROTOBUF_DEFINITION_RESOURCE));
metadataCache.put(CUSTOM_LIST_PROTOBUF_DEFINITION_RESOURCE, readResource(CUSTOM_LIST_PROTOBUF_DEFINITION_RESOURCE));
final String errors = metadataCache.get(ProtobufMetadataManagerConstants.ERRORS_KEY_SUFFIX);
if (errors != null) {
log.log(Level.SEVERE, "Protobuffer files, either Rule or CustomLists contained errors:\n" + errors);
return false;
}
} catch (TransportException ex) {
return false;
}
return true;
}
示例14: getRules
import org.infinispan.client.hotrod.RemoteCache; //导入依赖的package包/类
@Override
public List<?> getRules(final String clientIPAddress) {
try {
final RemoteCache<String, Rule> ruleCache = cacheManagerForIndexableCaches.getCache(SinkitCacheName.infinispan_rules.toString());
final ImmutablePair<String, String> startEndAddresses = CIDRUtils.getStartEndAddresses(clientIPAddress);
final String clientIPAddressPaddedBigInt = startEndAddresses.getLeft();
log.log(Level.FINE, "Getting key [" + clientIPAddress + "] which actually translates to BigInteger zero padded representation " + "[" + clientIPAddressPaddedBigInt + "]");
// Let's try to hit it
Rule rule = ruleCache.withFlags(Flag.SKIP_CACHE_LOAD).get(clientIPAddressPaddedBigInt);
if (rule != null) {
return Collections.singletonList(rule);
}
QueryFactory qf = Search.getQueryFactory(ruleCache);
Query query = qf.from(Rule.class)
.having("startAddress").lte(clientIPAddressPaddedBigInt)
.and()
.having("endAddress").gte(clientIPAddressPaddedBigInt)
.toBuilder().build();
return query.list();
} catch (Exception e) {
log.log(Level.SEVERE, "getRules client address troubles", e);
// TODO: Proper Error codes.
return null;
}
}
示例15: getAllRules
import org.infinispan.client.hotrod.RemoteCache; //导入依赖的package包/类
@Override
public List<?> getAllRules() {
try {
final RemoteCache<String, Rule> ruleCache = cacheManagerForIndexableCaches.getCache(SinkitCacheName.infinispan_rules.toString());
log.log(Level.SEVERE, "getAllRules: This is a very expensive operation.");
final QueryFactory qf = Search.getQueryFactory(ruleCache);
final Query query = qf.from(Rule.class).build();
// Hundreds of records...
List<Rule> results = query.list();
return results;
} catch (Exception e) {
log.log(Level.SEVERE, "getRules client address troubles", e);
// TODO: Proper Error codes.
return null;
}
}