1 package org.apache.commons.jcs.engine.behavior;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import java.io.IOException;
23 import java.rmi.Remote;
24 import java.util.Map;
25 import java.util.Set;
26
27 /**
28 * Used to retrieve and update non local caches, such as the remote and lateral caches. Unlike
29 * ICacheService, the methods here have a requester id. This allows us to avoid propagating events
30 * to ourself.
31 * <p>
32 * TODO consider not extending ICacheService
33 */
34 public interface ICacheServiceNonLocal<K, V>
35 extends Remote, ICacheService<K, V>
36 {
37 /**
38 * Puts a cache item to the cache.
39 * <p>
40 * @param item
41 * @param requesterId
42 * @throws IOException
43 */
44 void update( ICacheElement<K, V> item, long requesterId )
45 throws IOException;
46
47 /**
48 * Removes the given key from the specified cache.
49 * <p>
50 * @param cacheName
51 * @param key
52 * @param requesterId
53 * @throws IOException
54 */
55 void remove( String cacheName, K key, long requesterId )
56 throws IOException;
57
58 /**
59 * Remove all keys from the specified cache.
60 * <p>
61 * @param cacheName
62 * @param requesterId
63 * @throws IOException
64 */
65 void removeAll( String cacheName, long requesterId )
66 throws IOException;
67
68 /**
69 * Returns a cache bean from the specified cache; or null if the key does not exist.
70 * <p>
71 * Adding the requester id, allows the cache to determine the source of the get.
72 * <p>
73 * @param cacheName
74 * @param key
75 * @param requesterId
76 * @return ICacheElement
77 * @throws IOException
78 */
79 ICacheElement<K, V> get( String cacheName, K key, long requesterId )
80 throws IOException;
81
82 /**
83 * Gets multiple items from the cache based on the given set of keys.
84 * <p>
85 * @param cacheName
86 * @param keys
87 * @param requesterId
88 * @return a map of K key to ICacheElement<K, V> element, or an empty map if there is no
89 * data in cache for any of these keys
90 * @throws IOException
91 */
92 Map<K, ICacheElement<K, V>> getMultiple( String cacheName, Set<K> keys, long requesterId )
93 throws IOException;
94
95 /**
96 * Gets multiple items from the cache matching the pattern.
97 * <p>
98 * @param cacheName
99 * @param pattern
100 * @param requesterId
101 * @return a map of K key to ICacheElement<K, V> element, or an empty map if there is no
102 * data in cache matching the pattern.
103 * @throws IOException
104 */
105 Map<K, ICacheElement<K, V>> getMatching( String cacheName, String pattern, long requesterId )
106 throws IOException;
107
108 /**
109 * Get a set of the keys for all elements in the cache.
110 * <p>
111 * @param cacheName the name of the cache
112 * @return a set of the key type
113 * TODO This should probably be done in chunks with a range passed in. This
114 * will be a problem if someone puts a 1,000,000 or so items in a
115 * region.
116 */
117 Set<K> getKeySet( String cacheName ) throws IOException;
118 }