このコンテンツは選択した言語では利用できません。
11.9.3. Hot Rod Java Client Basic API
The following code shows how the client API can be used to store or retrieve information from a Hot Rod server using the Hot Rod Java client. This example assumes that a Hot Rod server has been started bound to the default location,
localhost:11222
.
Example 11.3. Basic API
//API entry point, by default it connects to localhost:11222 CacheContainer cacheContainer = new RemoteCacheManager(); //obtain a handle to the remote default cache Cache<String, String> cache = cacheContainer.getCache(); //now add something to the cache and make sure it is there cache.put("car", "ferrari");] assert cache.get("car").equals("ferrari"); //remove the data cache.remove("car"); assert !cache.containsKey("car") : "Value must have been removed!";
The
RemoteCacheManager
corresponds to DefaultCacheManager
, and both implement CacheContainer
.
This API facilitates migration from local calls to remote calls via Hot Rod. This can be done by switching between
DefaultCacheManager
and RemoteCacheManager
, which is simplified by the common CacheContainer
interface.
All keys can be retrieved from the remote cache using the
keySet()
method. If the remote cache is a distributed cache, the server will start a Map/Reduce job to retrieve all keys from clustered nodes and return all keys to the client.
Use this method with caution if there are a large number of keys.
Set keys = remoteCache.keySet();