001package org.apache.commons.jcs3.engine.behavior; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import java.io.IOException; 023import java.rmi.Remote; 024import java.util.Map; 025import java.util.Set; 026 027/** 028 * Used to retrieve and update non local caches, such as the remote and lateral caches. Unlike 029 * ICacheService, the methods here have a requester id. This allows us to avoid propagating events 030 * to ourself. 031 * <p> 032 * TODO consider not extending ICacheService 033 */ 034public interface ICacheServiceNonLocal<K, V> 035 extends Remote, ICacheService<K, V> 036{ 037 /** 038 * Puts a cache item to the cache. 039 * <p> 040 * @param item 041 * @param requesterId 042 * @throws IOException 043 */ 044 void update( ICacheElement<K, V> item, long requesterId ) 045 throws IOException; 046 047 /** 048 * Removes the given key from the specified cache. 049 * <p> 050 * @param cacheName 051 * @param key 052 * @param requesterId 053 * @throws IOException 054 */ 055 void remove( String cacheName, K key, long requesterId ) 056 throws IOException; 057 058 /** 059 * Remove all keys from the specified cache. 060 * <p> 061 * @param cacheName 062 * @param requesterId 063 * @throws IOException 064 */ 065 void removeAll( String cacheName, long requesterId ) 066 throws IOException; 067 068 /** 069 * Returns a cache bean from the specified cache; or null if the key does not exist. 070 * <p> 071 * Adding the requester id, allows the cache to determine the source of the get. 072 * <p> 073 * @param cacheName 074 * @param key 075 * @param requesterId 076 * @return ICacheElement 077 * @throws IOException 078 */ 079 ICacheElement<K, V> get( String cacheName, K key, long requesterId ) 080 throws IOException; 081 082 /** 083 * Gets multiple items from the cache based on the given set of keys. 084 * <p> 085 * @param cacheName 086 * @param keys 087 * @param requesterId 088 * @return a map of K key to ICacheElement<K, V> element, or an empty map if there is no 089 * data in cache for any of these keys 090 * @throws IOException 091 */ 092 Map<K, ICacheElement<K, V>> getMultiple( String cacheName, Set<K> keys, long requesterId ) 093 throws IOException; 094 095 /** 096 * Gets multiple items from the cache matching the pattern. 097 * <p> 098 * @param cacheName 099 * @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}