1 package org.apache.jcs.auxiliary.lateral;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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 public abstract class LateralCacheAbstractManager
50 implements ILateralCacheManager
51 {
52 private final static Log log = LogFactory.getLog( LateralCacheAbstractManager.class );
53
54 /***
55 * Each manager instance has caches.
56 */
57 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 synchronized ( this.caches )
89 {
90 this.lateralWatch.addCacheListener( cacheName, listener );
91 }
92 }
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 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
128 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 log.debug( "Fixing lateral caches:" );
140
141 synchronized ( this.caches )
142 {
143 this.lateralService = lateralService;
144
145
146
147 for ( Iterator en = this.caches.values().iterator(); en.hasNext(); )
148 {
149 LateralCacheNoWait cache = (LateralCacheNoWait) en.next();
150 cache.fixCache( this.lateralService );
151 }
152 }
153 }
154
155
156
157
158 public Map getCaches()
159 {
160 return caches;
161 }
162 }