%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.jcs.auxiliary.lateral.LateralCacheAbstractManager |
|
|
1 | package org.apache.jcs.auxiliary.lateral; |
|
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.util.HashMap; |
|
24 | import java.util.Iterator; |
|
25 | import java.util.Map; |
|
26 | ||
27 | import org.apache.commons.logging.Log; |
|
28 | import org.apache.commons.logging.LogFactory; |
|
29 | import org.apache.jcs.auxiliary.AuxiliaryCache; |
|
30 | import org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheAttributes; |
|
31 | import org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheListener; |
|
32 | import org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheManager; |
|
33 | import org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheObserver; |
|
34 | import org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheService; |
|
35 | ||
36 | /** |
|
37 | * Creates lateral caches. Lateral caches are primarily used for removing non |
|
38 | * laterally configured caches. Non laterally configured cache regions should |
|
39 | * still be able to participate in removal. But if there is a non laterally |
|
40 | * configured cache hub, then lateral removals may be necessary. For flat |
|
41 | * webserver production environments, without a strong machine at the app server |
|
42 | * level, distribution and search may need to occur at the lateral cache level. |
|
43 | * This is currently not implemented in the lateral cache. |
|
44 | * <p> |
|
45 | * |
|
46 | * @TODO: - need freeCache, release, getStats - need to find an interface |
|
47 | * acceptible for all - cache managers or a manager within a type |
|
48 | */ |
|
49 | 14 | public abstract class LateralCacheAbstractManager |
50 | implements ILateralCacheManager |
|
51 | { |
|
52 | 28 | private final static Log log = LogFactory.getLog( LateralCacheAbstractManager.class ); |
53 | ||
54 | /** |
|
55 | * Each manager instance has caches. |
|
56 | */ |
|
57 | 14 | protected final Map caches = new HashMap(); |
58 | ||
59 | /** |
|
60 | * Description of the Field |
|
61 | */ |
|
62 | protected ILateralCacheAttributes lca; |
|
63 | ||
64 | /** |
|
65 | * Handle to the lateral cache service; or a zombie handle if failed to |
|
66 | * connect. |
|
67 | */ |
|
68 | private ILateralCacheService lateralService; |
|
69 | ||
70 | /** |
|
71 | * Wrapper of the lateral cache watch service; or wrapper of a zombie |
|
72 | * service if failed to connect. |
|
73 | */ |
|
74 | private LateralCacheWatchRepairable lateralWatch; |
|
75 | ||
76 | /** |
|
77 | * Adds the lateral cache listener to the underlying cache-watch service. |
|
78 | * |
|
79 | * @param cacheName |
|
80 | * The feature to be added to the LateralCacheListener attribute |
|
81 | * @param listener |
|
82 | * The feature to be added to the LateralCacheListener attribute |
|
83 | * @exception IOException |
|
84 | */ |
|
85 | public void addLateralCacheListener( String cacheName, ILateralCacheListener listener ) |
|
86 | throws IOException |
|
87 | { |
|
88 | 0 | synchronized ( this.caches ) |
89 | { |
|
90 | 0 | this.lateralWatch.addCacheListener( cacheName, listener ); |
91 | 0 | } |
92 | 0 | } |
93 | ||
94 | /** |
|
95 | * Called to access a precreated region or construct one with defaults. |
|
96 | * Since all aux cache access goes through the manager, this will never be |
|
97 | * called. |
|
98 | * <p> |
|
99 | * After getting the manager instance for a server, the factory gets a cache |
|
100 | * for the region name it is constructing. |
|
101 | * <p> |
|
102 | * There should be one manager per server and one cache per region per |
|
103 | * manager. |
|
104 | * |
|
105 | * @return AuxiliaryCache |
|
106 | * @param cacheName |
|
107 | */ |
|
108 | public abstract AuxiliaryCache getCache( String cacheName ); |
|
109 | ||
110 | /** |
|
111 | * Gets the cacheType attribute of the LateralCacheManager object |
|
112 | * |
|
113 | * @return The cache type value |
|
114 | */ |
|
115 | public int getCacheType() |
|
116 | { |
|
117 | 0 | return LATERAL_CACHE; |
118 | } |
|
119 | ||
120 | /** |
|
121 | * Gets the stats attribute of the LateralCacheManager object |
|
122 | * |
|
123 | * @return String |
|
124 | */ |
|
125 | public String getStats() |
|
126 | { |
|
127 | // add something here |
|
128 | 0 | return ""; |
129 | } |
|
130 | ||
131 | /** |
|
132 | * Fixes up all the caches managed by this cache manager. |
|
133 | * |
|
134 | * @param lateralService |
|
135 | * @param lateralWatch |
|
136 | */ |
|
137 | public void fixCaches( ILateralCacheService lateralService, ILateralCacheObserver lateralWatch ) |
|
138 | { |
|
139 | 0 | log.debug( "Fixing lateral caches:" ); |
140 | ||
141 | 0 | synchronized ( this.caches ) |
142 | { |
|
143 | 0 | this.lateralService = lateralService; |
144 | // need to implment an observer for some types of laterals( http and |
|
145 | // tcp) |
|
146 | //this.lateralWatch.setCacheWatch(lateralWatch); |
|
147 | 0 | for ( Iterator en = this.caches.values().iterator(); en.hasNext(); ) |
148 | { |
|
149 | 0 | LateralCacheNoWait cache = (LateralCacheNoWait) en.next(); |
150 | 0 | cache.fixCache( this.lateralService ); |
151 | 0 | } |
152 | 0 | } |
153 | 0 | } |
154 | ||
155 | /* (non-Javadoc) |
|
156 | * @see org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheManager#getCaches() |
|
157 | */ |
|
158 | public Map getCaches() |
|
159 | { |
|
160 | 42 | return caches; |
161 | } |
|
162 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |