1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.apache.jetspeed.components.portletregistry; |
18 |
|
|
19 |
|
import java.util.List; |
20 |
|
import java.util.Properties; |
21 |
|
|
22 |
|
import org.apache.jetspeed.cache.CacheElement; |
23 |
|
import org.apache.jetspeed.cache.DistributedCacheObject; |
24 |
|
import org.apache.jetspeed.cache.JetspeedCache; |
25 |
|
import org.apache.jetspeed.cache.impl.EhCacheElementImpl; |
26 |
|
import org.apache.jetspeed.om.common.portlet.MutablePortletApplication; |
27 |
|
import org.apache.ojb.broker.Identity; |
28 |
|
import org.apache.ojb.broker.PersistenceBroker; |
29 |
|
import org.apache.ojb.broker.cache.ObjectCache; |
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
public class RegistryApplicationCache implements ObjectCache |
38 |
|
{ |
39 |
|
private static JetspeedCache oidCache; |
40 |
|
private static JetspeedCache nameCache; |
41 |
|
private static PortletRegistry registry; |
42 |
0 |
private static List listeners = null; |
43 |
|
|
44 |
|
public RegistryApplicationCache(PersistenceBroker broker, Properties props) |
45 |
0 |
{ |
46 |
0 |
} |
47 |
|
|
48 |
|
public synchronized static void cacheInit(PortletRegistry r, JetspeedCache o, JetspeedCache n, List l) |
49 |
|
{ |
50 |
0 |
registry = r; |
51 |
0 |
oidCache = o; |
52 |
0 |
nameCache = n; |
53 |
0 |
listeners = l; |
54 |
0 |
} |
55 |
|
|
56 |
|
public Object lookup(Identity oid) |
57 |
|
{ |
58 |
0 |
return cacheLookup(oid); |
59 |
|
} |
60 |
|
public synchronized static Object cacheLookup(Identity oid) |
61 |
|
{ |
62 |
0 |
CacheElement element = oidCache.get(oid); |
63 |
0 |
if (element != null) |
64 |
|
{ |
65 |
0 |
return element.getContent(); |
66 |
|
} |
67 |
0 |
return null; |
68 |
|
} |
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
public void cache(Identity oid, Object obj) |
74 |
|
{ |
75 |
0 |
cacheAdd(oid, obj); |
76 |
0 |
} |
77 |
|
public synchronized static void cacheAdd(Identity oid, Object obj) |
78 |
|
{ |
79 |
0 |
oidCache.remove(oid); |
80 |
0 |
CacheElement entry = new EhCacheElementImpl(oid, obj); |
81 |
0 |
oidCache.put(entry); |
82 |
|
|
83 |
0 |
MutablePortletApplication pa = (MutablePortletApplication)obj; |
84 |
0 |
DistributedCacheObject wrapper = new RegistryCacheObjectWrapper(oid, pa.getName()); |
85 |
0 |
nameCache.remove(pa.getName()); |
86 |
0 |
CacheElement nameEntry = nameCache.createElement(pa.getName(), wrapper); |
87 |
0 |
nameCache.put(nameEntry); |
88 |
|
|
89 |
0 |
if (listeners != null) |
90 |
|
{ |
91 |
0 |
for (int ix=0; ix < listeners.size(); ix++) |
92 |
|
{ |
93 |
0 |
RegistryEventListener listener = (RegistryEventListener)listeners.get(ix); |
94 |
0 |
listener.applicationUpdated((MutablePortletApplication)obj); |
95 |
|
} |
96 |
|
} |
97 |
0 |
} |
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
public void clear() |
103 |
|
{ |
104 |
0 |
cacheClear(); |
105 |
0 |
} |
106 |
|
public synchronized static void cacheClear() |
107 |
|
{ |
108 |
0 |
oidCache.clear(); |
109 |
0 |
nameCache.clear(); |
110 |
0 |
} |
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
public void remove(Identity oid) |
117 |
|
{ |
118 |
0 |
cacheRemove(oid); |
119 |
0 |
} |
120 |
|
|
121 |
|
|
122 |
|
|
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
public synchronized static void cacheRemove(Identity oid) |
128 |
|
{ |
129 |
0 |
MutablePortletApplication pd = (MutablePortletApplication)cacheLookup(oid); |
130 |
0 |
if (pd == null) |
131 |
0 |
return; |
132 |
|
|
133 |
0 |
oidCache.remove(oid); |
134 |
0 |
nameCache.remove(pd.getName()); |
135 |
|
|
136 |
0 |
if (listeners != null) |
137 |
|
{ |
138 |
0 |
for (int ix=0; ix < listeners.size(); ix++) |
139 |
|
{ |
140 |
0 |
RegistryEventListener listener = (RegistryEventListener)listeners.get(ix); |
141 |
0 |
listener.applicationRemoved(pd); |
142 |
|
} |
143 |
|
} |
144 |
|
|
145 |
0 |
} |
146 |
|
|
147 |
|
public synchronized static void cacheRemoveQuiet(String key, RegistryCacheObjectWrapper w) |
148 |
|
{ |
149 |
0 |
RegistryCacheObjectWrapper wrapper = w; |
150 |
0 |
if (wrapper == null) |
151 |
|
{ |
152 |
0 |
wrapper = (RegistryCacheObjectWrapper)nameCache.get(key); |
153 |
0 |
if (wrapper == null) |
154 |
0 |
return; |
155 |
|
} |
156 |
0 |
Identity oid = wrapper.getId(); |
157 |
|
|
158 |
0 |
MutablePortletApplication pd = (MutablePortletApplication)cacheLookup(oid); |
159 |
0 |
if (pd == null) |
160 |
0 |
return; |
161 |
|
|
162 |
0 |
oidCache.removeQuiet(oid); |
163 |
0 |
nameCache.removeQuiet(pd.getName()); |
164 |
0 |
} |
165 |
|
|
166 |
|
} |