通过 Hot Rod 协议使用 cache-service 和 datagrid-service 远程创建缓存定义,如下所示:
实例化 RemoteCacheManager 类以连接到该服务。
调用 createCache() 方法以创建缓存,如下例所示:
private static void createCache(String appName) {
//Connect to the Hot Rod service.
final String host = appName;
//Use the configuration bean.
ConfigurationBuilder cfg = ...
System.out.printf("--- Connecting to %s ---%n", appName);
//Create a new RemoteCacheManager and start it.
final RemoteCacheManager remote = new RemoteCacheManager(cfg.build());
//Set a name for the cache.
final String cacheName = "custom";
System.out.printf("--- Creating cache in %s ---%n", appName);
//Perform remote administration operations.
remote.administration()
//Include a flag to make the cache permanent.
.withFlags(CacheContainerAdmin.AdminFlag.PERMANENT)
//Create a cache on the remote server.
//Pass null instead of XML to use the default cache configuration.
.createCache(cacheName, null);
System.out.printf("--- Cache '%s' created in '%s' ---%n", cacheName, appName);
}
private static void createCache(String appName) {
//Connect to the Hot Rod service.
final String host = appName;
//Use the configuration bean.
ConfigurationBuilder cfg = ...
System.out.printf("--- Connecting to %s ---%n", appName);
//Create a new RemoteCacheManager and start it.
final RemoteCacheManager remote = new RemoteCacheManager(cfg.build());
//Set a name for the cache.
final String cacheName = "custom";
System.out.printf("--- Creating cache in %s ---%n", appName);
//Perform remote administration operations.
remote.administration()
//Include a flag to make the cache permanent.
.withFlags(CacheContainerAdmin.AdminFlag.PERMANENT)
//Create a cache on the remote server.
//Pass null instead of XML to use the default cache configuration.
.createCache(cacheName, null);
System.out.printf("--- Cache '%s' created in '%s' ---%n", cacheName, appName);
}
Copy to ClipboardCopied!Toggle word wrapToggle overflow