| %line | %branch | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| org.apache.jcs.access.GroupCacheAccess |
|
|
| 1 | package org.apache.jcs.access; |
|
| 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.util.Set; |
|
| 23 | ||
| 24 | import org.apache.jcs.access.behavior.IGroupCacheAccess; |
|
| 25 | import org.apache.jcs.access.exception.CacheException; |
|
| 26 | import org.apache.jcs.engine.behavior.ICacheElement; |
|
| 27 | import org.apache.jcs.engine.behavior.ICompositeCacheAttributes; |
|
| 28 | import org.apache.jcs.engine.behavior.IElementAttributes; |
|
| 29 | import org.apache.jcs.engine.control.CompositeCache; |
|
| 30 | import org.apache.jcs.engine.control.CompositeCacheManager; |
|
| 31 | import org.apache.jcs.engine.control.group.GroupAttrName; |
|
| 32 | import org.apache.jcs.engine.control.group.GroupId; |
|
| 33 | ||
| 34 | /** |
|
| 35 | * Access for groups. |
|
| 36 | */ |
|
| 37 | public class GroupCacheAccess |
|
| 38 | extends CacheAccess |
|
| 39 | implements IGroupCacheAccess |
|
| 40 | { |
|
| 41 | /** The underlying cache manager. */ |
|
| 42 | private static CompositeCacheManager cacheMgr; |
|
| 43 | ||
| 44 | /** |
|
| 45 | * Constructor for the GroupCacheAccess object |
|
| 46 | * <p> |
|
| 47 | * @param cacheControl |
|
| 48 | */ |
|
| 49 | public GroupCacheAccess( CompositeCache cacheControl ) |
|
| 50 | 15 | { |
| 51 | 609 | super( cacheControl ); |
| 52 | 594 | } |
| 53 | ||
| 54 | /** |
|
| 55 | * Gets the groupAccess attribute of the GroupCacheAccess class. |
|
| 56 | * <p> |
|
| 57 | * @param region |
|
| 58 | * @return The groupAccess value |
|
| 59 | * @throws CacheException |
|
| 60 | */ |
|
| 61 | public static GroupCacheAccess getGroupAccess( String region ) |
|
| 62 | throws CacheException |
|
| 63 | { |
|
| 64 | 0 | synchronized ( GroupCacheAccess.class ) |
| 65 | { |
|
| 66 | 0 | if ( cacheMgr == null ) |
| 67 | { |
|
| 68 | 0 | cacheMgr = CompositeCacheManager.getInstance(); |
| 69 | } |
|
| 70 | 0 | } |
| 71 | 0 | return new GroupCacheAccess( cacheMgr.getCache( region ) ); |
| 72 | } |
|
| 73 | ||
| 74 | /** |
|
| 75 | * Gets the groupAccess attribute of the GroupCacheAccess class. |
|
| 76 | * <p> |
|
| 77 | * @param region |
|
| 78 | * @param icca |
|
| 79 | * @return The groupAccess value |
|
| 80 | * @throws CacheException |
|
| 81 | */ |
|
| 82 | public static GroupCacheAccess getGroupAccess( String region, ICompositeCacheAttributes icca ) |
|
| 83 | throws CacheException |
|
| 84 | { |
|
| 85 | 0 | synchronized ( GroupCacheAccess.class ) |
| 86 | { |
|
| 87 | 0 | if ( cacheMgr == null ) |
| 88 | { |
|
| 89 | 0 | cacheMgr = CompositeCacheManager.getInstance(); |
| 90 | } |
|
| 91 | 0 | } |
| 92 | ||
| 93 | 0 | return new GroupCacheAccess( cacheMgr.getCache( region, icca ) ); |
| 94 | } |
|
| 95 | ||
| 96 | /** |
|
| 97 | * Gets an item out of the cache that is in a specified group. |
|
| 98 | * <p> |
|
| 99 | * @param name |
|
| 100 | * The key name. |
|
| 101 | * @param group |
|
| 102 | * The group name. |
|
| 103 | * @return The cached value, null if not found. |
|
| 104 | */ |
|
| 105 | public Object getFromGroup( Object name, String group ) |
|
| 106 | { |
|
| 107 | 0 | ICacheElement element = this.cacheControl.get( getGroupAttrName( group, name ) ); |
| 108 | 0 | return ( element != null ) ? element.getVal() : class="keyword">null; |
| 109 | } |
|
| 110 | ||
| 111 | /** |
|
| 112 | * Internal method used for group functionality. |
|
| 113 | * <p> |
|
| 114 | * @param group |
|
| 115 | * @param name |
|
| 116 | * @return GroupAttrName |
|
| 117 | */ |
|
| 118 | private GroupAttrName getGroupAttrName( String group, Object name ) |
|
| 119 | { |
|
| 120 | 0 | GroupId gid = new GroupId( this.cacheControl.getCacheName(), group ); |
| 121 | 0 | return new GroupAttrName( gid, name ); |
| 122 | } |
|
| 123 | ||
| 124 | /** |
|
| 125 | * Allows the user to put an object into a group within a particular cache |
|
| 126 | * region. This method sets the object's attributes to the default for the |
|
| 127 | * region. |
|
| 128 | * <p> |
|
| 129 | * @param name |
|
| 130 | * The key name. |
|
| 131 | * @param groupName |
|
| 132 | * The group name. |
|
| 133 | * @param value |
|
| 134 | * The object to cache |
|
| 135 | * @throws CacheException |
|
| 136 | */ |
|
| 137 | public void putInGroup( Object name, String groupName, Object value ) |
|
| 138 | throws CacheException |
|
| 139 | { |
|
| 140 | 0 | putInGroup( name, groupName, value, null ); |
| 141 | 0 | } |
| 142 | ||
| 143 | /** |
|
| 144 | * Allows the user to put an object into a group within a particular cache |
|
| 145 | * region. This method allows the object's attributes to be individually |
|
| 146 | * specified. |
|
| 147 | * <p> |
|
| 148 | * @param name |
|
| 149 | * The key name. |
|
| 150 | * @param groupName |
|
| 151 | * The group name. |
|
| 152 | * @param value |
|
| 153 | * The object to cache |
|
| 154 | * @param attr |
|
| 155 | * The objects attributes. |
|
| 156 | * @throws CacheException |
|
| 157 | */ |
|
| 158 | public void putInGroup( Object name, String groupName, Object value, IElementAttributes attr ) |
|
| 159 | throws CacheException |
|
| 160 | { |
|
| 161 | // unbind object first if any. |
|
| 162 | 0 | remove( name, groupName ); |
| 163 | ||
| 164 | 0 | if ( attr == null ) |
| 165 | { |
|
| 166 | 0 | put( getGroupAttrName( groupName, name ), value ); |
| 167 | 0 | } |
| 168 | else |
|
| 169 | { |
|
| 170 | 0 | put( getGroupAttrName( groupName, name ), value, attr ); |
| 171 | } |
|
| 172 | 0 | } |
| 173 | ||
| 174 | /** |
|
| 175 | * @param name |
|
| 176 | * @param group |
|
| 177 | */ |
|
| 178 | public void remove( Object name, String group ) |
|
| 179 | { |
|
| 180 | 0 | GroupAttrName key = getGroupAttrName( group, name ); |
| 181 | 0 | this.cacheControl.remove( key ); |
| 182 | 0 | } |
| 183 | ||
| 184 | /** |
|
| 185 | * Gets the set of keys of objects currently in the group. |
|
| 186 | * <p> |
|
| 187 | * @param group |
|
| 188 | * @return A Set of keys. |
|
| 189 | */ |
|
| 190 | public Set getGroupKeys( String group ) |
|
| 191 | { |
|
| 192 | 0 | return this.cacheControl.getGroupKeys( group ); |
| 193 | } |
|
| 194 | ||
| 195 | /** |
|
| 196 | * Invalidates a group: remove all the group members |
|
| 197 | * <p> |
|
| 198 | * @param group |
|
| 199 | * The name of the group to invalidate |
|
| 200 | */ |
|
| 201 | public void invalidateGroup( String group ) |
|
| 202 | { |
|
| 203 | 0 | this.cacheControl.remove( new GroupId( class="keyword">this.cacheControl.getCacheName(), group ) ); |
| 204 | 0 | } |
| 205 | } |
| This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |