1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| package com.opensymphony.oscache.web; |
6 |
| |
7 |
| import com.opensymphony.oscache.base.*; |
8 |
| import com.opensymphony.oscache.base.events.CacheEventListener; |
9 |
| import com.opensymphony.oscache.base.events.ScopeEvent; |
10 |
| import com.opensymphony.oscache.base.events.ScopeEventListener; |
11 |
| import com.opensymphony.oscache.base.events.ScopeEventType; |
12 |
| |
13 |
| import org.apache.commons.logging.Log; |
14 |
| import org.apache.commons.logging.LogFactory; |
15 |
| |
16 |
| import java.io.Serializable; |
17 |
| |
18 |
| import java.util.*; |
19 |
| |
20 |
| import javax.servlet.ServletContext; |
21 |
| import javax.servlet.http.HttpServletRequest; |
22 |
| import javax.servlet.http.HttpSession; |
23 |
| import javax.servlet.jsp.PageContext; |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| |
34 |
| |
35 |
| |
36 |
| |
37 |
| |
38 |
| |
39 |
| |
40 |
| |
41 |
| public class ServletCacheAdministrator extends AbstractCacheAdministrator implements Serializable { |
42 |
| private static final transient Log log = LogFactory.getLog(ServletCacheAdministrator.class); |
43 |
| |
44 |
| |
45 |
| |
46 |
| |
47 |
| private final static String CACHE_USE_HOST_DOMAIN_KEY = "cache.use.host.domain.in.key"; |
48 |
| private final static String CACHE_KEY_KEY = "cache.key"; |
49 |
| |
50 |
| |
51 |
| |
52 |
| |
53 |
| private final static String DEFAULT_CACHE_KEY = "__oscache_cache"; |
54 |
| |
55 |
| |
56 |
| |
57 |
| |
58 |
| public final static String SESSION_SCOPE_NAME = "session"; |
59 |
| public final static String APPLICATION_SCOPE_NAME = "application"; |
60 |
| |
61 |
| |
62 |
| |
63 |
| |
64 |
| |
65 |
| private final static String CACHE_ADMINISTRATOR_KEY_SUFFIX = "_admin"; |
66 |
| |
67 |
| |
68 |
| |
69 |
| |
70 |
| |
71 |
| private final static String CACHE_ADMINISTRATORS_KEY = "__oscache_admins"; |
72 |
| |
73 |
| |
74 |
| |
75 |
| |
76 |
| |
77 |
| |
78 |
| public final static String HASH_KEY_SCOPE = "scope"; |
79 |
| |
80 |
| |
81 |
| |
82 |
| |
83 |
| |
84 |
| |
85 |
| public final static String HASH_KEY_SESSION_ID = "sessionId"; |
86 |
| |
87 |
| |
88 |
| |
89 |
| |
90 |
| |
91 |
| |
92 |
| public final static String HASH_KEY_CONTEXT_TMPDIR = "context.tempdir"; |
93 |
| |
94 |
| |
95 |
| |
96 |
| |
97 |
| private final static String FILE_SEPARATOR = "/"; |
98 |
| |
99 |
| |
100 |
| |
101 |
| |
102 |
| private final static char FILE_SEPARATOR_CHAR = FILE_SEPARATOR.charAt(0); |
103 |
| |
104 |
| |
105 |
| |
106 |
| |
107 |
| private final static short AVERAGE_KEY_LENGTH = 30; |
108 |
| |
109 |
| |
110 |
| |
111 |
| |
112 |
| private static final String m_strBase64Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; |
113 |
| |
114 |
| |
115 |
| |
116 |
| |
117 |
| private Map flushTimes; |
118 |
| |
119 |
| |
120 |
| |
121 |
| |
122 |
| private transient ServletContext context; |
123 |
| |
124 |
| |
125 |
| |
126 |
| |
127 |
| private String cacheKey; |
128 |
| |
129 |
| |
130 |
| |
131 |
| |
132 |
| |
133 |
| private boolean useHostDomainInKey = false; |
134 |
| |
135 |
| |
136 |
| |
137 |
| |
138 |
| |
139 |
| |
140 |
0
| private ServletCacheAdministrator(ServletContext context, Properties p) {
|
141 |
0
| super(p);
|
142 |
0
| config.set(HASH_KEY_CONTEXT_TMPDIR, context.getAttribute("javax.servlet.context.tempdir"));
|
143 |
| |
144 |
0
| flushTimes = new HashMap();
|
145 |
0
| initHostDomainInKey();
|
146 |
0
| this.context = context;
|
147 |
| } |
148 |
| |
149 |
| |
150 |
| |
151 |
| |
152 |
| |
153 |
| |
154 |
| |
155 |
0
| public static ServletCacheAdministrator getInstance(ServletContext context) {
|
156 |
0
| return getInstance(context, null);
|
157 |
| } |
158 |
| |
159 |
| |
160 |
| |
161 |
| |
162 |
| |
163 |
| |
164 |
| |
165 |
| |
166 |
| |
167 |
0
| public static ServletCacheAdministrator getInstanceFromKey(ServletContext context, String key) {
|
168 |
| |
169 |
0
| if (!key.endsWith(CACHE_ADMINISTRATOR_KEY_SUFFIX)) {
|
170 |
0
| key = key + CACHE_ADMINISTRATOR_KEY_SUFFIX;
|
171 |
| } |
172 |
0
| return (ServletCacheAdministrator) context.getAttribute(key);
|
173 |
| } |
174 |
| |
175 |
| |
176 |
| |
177 |
| |
178 |
| |
179 |
| |
180 |
| |
181 |
| |
182 |
| |
183 |
| |
184 |
| |
185 |
0
| public synchronized static ServletCacheAdministrator getInstance(ServletContext context, Properties p)
|
186 |
| { |
187 |
0
| String adminKey = null;
|
188 |
0
| if (p!= null) {
|
189 |
0
| adminKey = p.getProperty(CACHE_KEY_KEY);
|
190 |
| } |
191 |
0
| if (adminKey == null) {
|
192 |
0
| adminKey = DEFAULT_CACHE_KEY;
|
193 |
| } |
194 |
0
| adminKey += CACHE_ADMINISTRATOR_KEY_SUFFIX;
|
195 |
| |
196 |
0
| ServletCacheAdministrator admin = (ServletCacheAdministrator) context.getAttribute(adminKey);
|
197 |
| |
198 |
| |
199 |
| |
200 |
0
| if (admin == null) {
|
201 |
0
| admin = new ServletCacheAdministrator(context, p);
|
202 |
0
| Map admins = (Map) context.getAttribute(CACHE_ADMINISTRATORS_KEY);
|
203 |
0
| if (admins == null) {
|
204 |
0
| admins = new HashMap();
|
205 |
| } |
206 |
0
| admins.put(adminKey, admin);
|
207 |
0
| context.setAttribute(CACHE_ADMINISTRATORS_KEY, admins);
|
208 |
0
| context.setAttribute(adminKey, admin);
|
209 |
| |
210 |
0
| if (log.isInfoEnabled()) {
|
211 |
0
| log.info("Created new instance of ServletCacheAdministrator with key "+adminKey);
|
212 |
| } |
213 |
| |
214 |
0
| admin.getAppScopeCache(context);
|
215 |
| } |
216 |
| |
217 |
0
| if (admin.context == null) {
|
218 |
0
| admin.context = context;
|
219 |
| } |
220 |
| |
221 |
0
| return admin;
|
222 |
| } |
223 |
| |
224 |
| |
225 |
| |
226 |
| |
227 |
| |
228 |
0
| public static void destroyInstance(ServletContext context)
|
229 |
| { |
230 |
0
| ServletCacheAdministrator admin;
|
231 |
0
| Map admins = (Map) context.getAttribute(CACHE_ADMINISTRATORS_KEY);
|
232 |
0
| if (admins != null)
|
233 |
| { |
234 |
0
| Set keys = admins.keySet();
|
235 |
0
| Iterator it = keys.iterator();
|
236 |
0
| while (it.hasNext())
|
237 |
| { |
238 |
0
| String adminKey = (String) it.next();
|
239 |
0
| admin = (ServletCacheAdministrator) admins.get( adminKey );
|
240 |
0
| if (admin != null)
|
241 |
| { |
242 |
| |
243 |
0
| Cache cache = (Cache) context.getAttribute(admin.getCacheKey());
|
244 |
0
| if (cache != null) {
|
245 |
0
| admin.finalizeListeners(cache);
|
246 |
0
| context.removeAttribute(admin.getCacheKey());
|
247 |
0
| context.removeAttribute(adminKey);
|
248 |
0
| cache = null;
|
249 |
0
| if (log.isInfoEnabled()) {
|
250 |
0
| log.info("Shut down the ServletCacheAdministrator "+adminKey);
|
251 |
| } |
252 |
| } |
253 |
0
| admin = null;
|
254 |
| } |
255 |
| } |
256 |
0
| context.removeAttribute(CACHE_ADMINISTRATORS_KEY);
|
257 |
| } |
258 |
| } |
259 |
| |
260 |
| |
261 |
| |
262 |
| |
263 |
| |
264 |
| |
265 |
| |
266 |
| |
267 |
| |
268 |
| |
269 |
0
| public Cache getCache(HttpServletRequest request, int scope) {
|
270 |
0
| if (scope == PageContext.APPLICATION_SCOPE) {
|
271 |
0
| return getAppScopeCache(context);
|
272 |
| } |
273 |
| |
274 |
0
| if (scope == PageContext.SESSION_SCOPE) {
|
275 |
0
| return getSessionScopeCache(request.getSession(true));
|
276 |
| } |
277 |
| |
278 |
0
| throw new RuntimeException("The supplied scope value of " + scope + " is invalid. Acceptable values are PageContext.APPLICATION_SCOPE and PageContext.SESSION_SCOPE");
|
279 |
| } |
280 |
| |
281 |
| |
282 |
| |
283 |
| |
284 |
| |
285 |
| |
286 |
| |
287 |
| |
288 |
0
| public Cache getAppScopeCache(ServletContext context) {
|
289 |
0
| Cache cache;
|
290 |
0
| Object obj = context.getAttribute(getCacheKey());
|
291 |
| |
292 |
0
| if ((obj == null) || !(obj instanceof Cache)) {
|
293 |
0
| if (log.isInfoEnabled()) {
|
294 |
0
| log.info("Created new application-scoped cache at key: " + getCacheKey());
|
295 |
| } |
296 |
| |
297 |
0
| cache = createCache(PageContext.APPLICATION_SCOPE, null);
|
298 |
0
| context.setAttribute(getCacheKey(), cache);
|
299 |
| } else { |
300 |
0
| cache = (Cache) obj;
|
301 |
| } |
302 |
| |
303 |
0
| return cache;
|
304 |
| } |
305 |
| |
306 |
| |
307 |
| |
308 |
| |
309 |
| |
310 |
| |
311 |
| |
312 |
| |
313 |
0
| public Cache getSessionScopeCache(HttpSession session) {
|
314 |
0
| Cache cache;
|
315 |
0
| Object obj = session.getAttribute(getCacheKey());
|
316 |
| |
317 |
0
| if ((obj == null) || !(obj instanceof Cache)) {
|
318 |
0
| if (log.isInfoEnabled()) {
|
319 |
0
| log.info("Created new session-scoped cache in session " + session.getId() + " at key: " + getCacheKey());
|
320 |
| } |
321 |
| |
322 |
0
| cache = createCache(PageContext.SESSION_SCOPE, session.getId());
|
323 |
0
| session.setAttribute(getCacheKey(), cache);
|
324 |
| } else { |
325 |
0
| cache = (Cache) obj;
|
326 |
| } |
327 |
| |
328 |
0
| return cache;
|
329 |
| } |
330 |
| |
331 |
| |
332 |
| |
333 |
| |
334 |
| |
335 |
| |
336 |
| |
337 |
0
| public String getCacheKey() {
|
338 |
0
| if (cacheKey == null) {
|
339 |
0
| cacheKey = getProperty(CACHE_KEY_KEY);
|
340 |
| |
341 |
0
| if (cacheKey == null) {
|
342 |
0
| cacheKey = DEFAULT_CACHE_KEY;
|
343 |
| } |
344 |
| } |
345 |
| |
346 |
0
| return cacheKey;
|
347 |
| } |
348 |
| |
349 |
| |
350 |
| |
351 |
| |
352 |
| |
353 |
| |
354 |
| |
355 |
0
| public void setFlushTime(Date date, int scope) {
|
356 |
0
| if (log.isInfoEnabled()) {
|
357 |
0
| log.info("Flushing scope " + scope + " at " + date);
|
358 |
| } |
359 |
| |
360 |
0
| synchronized (flushTimes) {
|
361 |
0
| if (date != null) {
|
362 |
| |
363 |
0
| dispatchScopeEvent(ScopeEventType.SCOPE_FLUSHED, scope, date, null);
|
364 |
0
| flushTimes.put(new Integer(scope), date);
|
365 |
| } else { |
366 |
0
| logError("setFlushTime called with a null date.");
|
367 |
0
| throw new IllegalArgumentException("setFlushTime called with a null date.");
|
368 |
| } |
369 |
| } |
370 |
| } |
371 |
| |
372 |
| |
373 |
| |
374 |
| |
375 |
| |
376 |
| |
377 |
0
| public void setFlushTime(int scope) {
|
378 |
0
| setFlushTime(new Date(), scope);
|
379 |
| } |
380 |
| |
381 |
| |
382 |
| |
383 |
| |
384 |
| |
385 |
| |
386 |
| |
387 |
| |
388 |
0
| public Date getFlushTime(int scope) {
|
389 |
0
| synchronized (flushTimes) {
|
390 |
0
| return (Date) flushTimes.get(new Integer(scope));
|
391 |
| } |
392 |
| } |
393 |
| |
394 |
| |
395 |
| |
396 |
| |
397 |
| |
398 |
| |
399 |
| |
400 |
| |
401 |
| |
402 |
| |
403 |
| |
404 |
0
| public Object getFromCache(int scope, HttpServletRequest request, String key, int refreshPeriod) throws NeedsRefreshException {
|
405 |
0
| Cache cache = getCache(request, scope);
|
406 |
0
| key = this.generateEntryKey(key, request, scope);
|
407 |
0
| return cache.getFromCache(key, refreshPeriod);
|
408 |
| } |
409 |
| |
410 |
| |
411 |
| |
412 |
| |
413 |
| |
414 |
| |
415 |
| |
416 |
| |
417 |
| |
418 |
| |
419 |
0
| public boolean isScopeFlushed(CacheEntry cacheEntry, int scope) {
|
420 |
0
| Date flushDateTime = getFlushTime(scope);
|
421 |
| |
422 |
0
| if (flushDateTime != null) {
|
423 |
0
| long lastUpdate = cacheEntry.getLastUpdate();
|
424 |
0
| return (flushDateTime.getTime() >= lastUpdate);
|
425 |
| } else { |
426 |
0
| return false;
|
427 |
| } |
428 |
| } |
429 |
| |
430 |
| |
431 |
| |
432 |
| |
433 |
| |
434 |
| |
435 |
0
| public void addScopeEventListener(ScopeEventListener listener) {
|
436 |
0
| listenerList.add(ScopeEventListener.class, listener);
|
437 |
| } |
438 |
| |
439 |
| |
440 |
| |
441 |
| |
442 |
| |
443 |
| |
444 |
| |
445 |
| |
446 |
| |
447 |
| |
448 |
0
| public void cancelUpdate(int scope, HttpServletRequest request, String key) {
|
449 |
0
| Cache cache = getCache(request, scope);
|
450 |
0
| key = this.generateEntryKey(key, request, scope);
|
451 |
0
| cache.cancelUpdate(key);
|
452 |
| } |
453 |
| |
454 |
| |
455 |
| |
456 |
| |
457 |
| |
458 |
| |
459 |
0
| public void flushAll(Date date) {
|
460 |
0
| synchronized (flushTimes) {
|
461 |
0
| setFlushTime(date, PageContext.APPLICATION_SCOPE);
|
462 |
0
| setFlushTime(date, PageContext.SESSION_SCOPE);
|
463 |
0
| setFlushTime(date, PageContext.REQUEST_SCOPE);
|
464 |
0
| setFlushTime(date, PageContext.PAGE_SCOPE);
|
465 |
| } |
466 |
| |
467 |
| |
468 |
0
| dispatchScopeEvent(ScopeEventType.ALL_SCOPES_FLUSHED, -1, date, null);
|
469 |
| } |
470 |
| |
471 |
| |
472 |
| |
473 |
| |
474 |
0
| public void flushAll() {
|
475 |
0
| flushAll(new Date());
|
476 |
| } |
477 |
| |
478 |
| |
479 |
| |
480 |
| |
481 |
| |
482 |
| |
483 |
| |
484 |
| |
485 |
| |
486 |
| |
487 |
| |
488 |
| |
489 |
| |
490 |
| |
491 |
| |
492 |
| |
493 |
| |
494 |
| |
495 |
0
| public String generateEntryKey(String key, HttpServletRequest request, int scope) {
|
496 |
0
| return generateEntryKey(key, request, scope, null, null);
|
497 |
| } |
498 |
| |
499 |
| |
500 |
| |
501 |
| |
502 |
| |
503 |
| |
504 |
| |
505 |
| |
506 |
| |
507 |
| |
508 |
| |
509 |
| |
510 |
| |
511 |
| |
512 |
| |
513 |
| |
514 |
| |
515 |
| |
516 |
| |
517 |
0
| public String generateEntryKey(String key, HttpServletRequest request, int scope, String language) {
|
518 |
0
| return generateEntryKey(key, request, scope, language, null);
|
519 |
| } |
520 |
| |
521 |
| |
522 |
| |
523 |
| |
524 |
| |
525 |
| |
526 |
| |
527 |
| |
528 |
| |
529 |
| |
530 |
| |
531 |
| |
532 |
| |
533 |
| |
534 |
| |
535 |
| |
536 |
| |
537 |
| |
538 |
| |
539 |
| |
540 |
0
| public String generateEntryKey(String key, HttpServletRequest request, int scope, String language, String suffix) {
|
541 |
| |
542 |
| |
543 |
| |
544 |
0
| StringBuffer cBuffer = new StringBuffer(AVERAGE_KEY_LENGTH);
|
545 |
| |
546 |
| |
547 |
0
| if (language != null) {
|
548 |
0
| cBuffer.append(FILE_SEPARATOR).append(language);
|
549 |
| } |
550 |
| |
551 |
| |
552 |
0
| if (useHostDomainInKey) {
|
553 |
0
| cBuffer.append(FILE_SEPARATOR).append(request.getServerName());
|
554 |
| } |
555 |
| |
556 |
0
| if (key != null) {
|
557 |
0
| cBuffer.append(FILE_SEPARATOR).append(key);
|
558 |
| } else { |
559 |
0
| String generatedKey = request.getRequestURI();
|
560 |
| |
561 |
0
| if (generatedKey.charAt(0) != FILE_SEPARATOR_CHAR) {
|
562 |
0
| cBuffer.append(FILE_SEPARATOR_CHAR);
|
563 |
| } |
564 |
| |
565 |
0
| cBuffer.append(generatedKey);
|
566 |
0
| cBuffer.append("_").append(request.getMethod()).append("_");
|
567 |
| |
568 |
0
| generatedKey = getSortedQueryString(request);
|
569 |
| |
570 |
0
| if (generatedKey != null) {
|
571 |
0
| try {
|
572 |
0
| java.security.MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
|
573 |
0
| byte[] b = digest.digest(generatedKey.getBytes());
|
574 |
0
| cBuffer.append('_');
|
575 |
| |
576 |
| |
577 |
0
| cBuffer.append(toBase64(b).replace('/', '_'));
|
578 |
| } catch (Exception e) { |
579 |
| |
580 |
| } |
581 |
| } |
582 |
| } |
583 |
| |
584 |
| |
585 |
0
| if ((suffix != null) && (suffix.length() > 0)) {
|
586 |
0
| cBuffer.append(suffix);
|
587 |
| } |
588 |
| |
589 |
0
| return cBuffer.toString();
|
590 |
| } |
591 |
| |
592 |
| |
593 |
| |
594 |
| |
595 |
| |
596 |
| |
597 |
| |
598 |
| |
599 |
| |
600 |
0
| protected String getSortedQueryString(HttpServletRequest request) {
|
601 |
0
| Map paramMap = request.getParameterMap();
|
602 |
| |
603 |
0
| if (paramMap.isEmpty()) {
|
604 |
0
| return null;
|
605 |
| } |
606 |
| |
607 |
0
| Set paramSet = new TreeMap(paramMap).entrySet();
|
608 |
| |
609 |
0
| StringBuffer buf = new StringBuffer();
|
610 |
| |
611 |
0
| boolean first = true;
|
612 |
| |
613 |
0
| for (Iterator it = paramSet.iterator(); it.hasNext();) {
|
614 |
0
| Map.Entry entry = (Map.Entry) it.next();
|
615 |
0
| String[] values = (String[]) entry.getValue();
|
616 |
| |
617 |
0
| for (int i = 0; i < values.length; i++) {
|
618 |
0
| String key = (String) entry.getKey();
|
619 |
| |
620 |
0
| if ((key.length() != 10) || !"jsessionid".equals(key)) {
|
621 |
0
| if (first) {
|
622 |
0
| first = false;
|
623 |
| } else { |
624 |
0
| buf.append('&');
|
625 |
| } |
626 |
| |
627 |
0
| buf.append(key).append('=').append(values[i]);
|
628 |
| } |
629 |
| } |
630 |
| } |
631 |
| |
632 |
| |
633 |
0
| if (buf.length() == 0) {
|
634 |
0
| return null;
|
635 |
| } else { |
636 |
0
| return buf.toString();
|
637 |
| } |
638 |
| } |
639 |
| |
640 |
| |
641 |
| |
642 |
| |
643 |
| |
644 |
| |
645 |
0
| public void logError(String message) {
|
646 |
0
| log.error("[oscache]: " + message);
|
647 |
| } |
648 |
| |
649 |
| |
650 |
| |
651 |
| |
652 |
| |
653 |
| |
654 |
| |
655 |
| |
656 |
| |
657 |
| |
658 |
| |
659 |
| |
660 |
| |
661 |
0
| public void putInCache(int scope, HttpServletRequest request, String key, Object content) {
|
662 |
0
| putInCache(scope, request, key, content, null);
|
663 |
| } |
664 |
| |
665 |
| |
666 |
| |
667 |
| |
668 |
| |
669 |
| |
670 |
| |
671 |
| |
672 |
| |
673 |
| |
674 |
| |
675 |
| |
676 |
| |
677 |
| |
678 |
0
| public void putInCache(int scope, HttpServletRequest request, String key, Object content, EntryRefreshPolicy policy) {
|
679 |
0
| Cache cache = getCache(request, scope);
|
680 |
0
| key = this.generateEntryKey(key, request, scope);
|
681 |
0
| cache.putInCache(key, content, policy);
|
682 |
| } |
683 |
| |
684 |
| |
685 |
| |
686 |
| |
687 |
| |
688 |
| |
689 |
| |
690 |
| |
691 |
| |
692 |
| |
693 |
0
| public void setCacheCapacity(int scope, HttpServletRequest request, int capacity) {
|
694 |
0
| setCacheCapacity(capacity);
|
695 |
0
| getCache(request, scope).setCapacity(capacity);
|
696 |
| } |
697 |
| |
698 |
| |
699 |
| |
700 |
| |
701 |
| |
702 |
| |
703 |
0
| public void removeScopeEventListener(ScopeEventListener listener) {
|
704 |
0
| listenerList.remove(ScopeEventListener.class, listener);
|
705 |
| } |
706 |
| |
707 |
| |
708 |
| |
709 |
| |
710 |
0
| protected void finalizeListeners(Cache cache) {
|
711 |
0
| super.finalizeListeners(cache);
|
712 |
| } |
713 |
| |
714 |
| |
715 |
| |
716 |
| |
717 |
0
| private static String toBase64(byte[] aValue) {
|
718 |
0
| int byte1;
|
719 |
0
| int byte2;
|
720 |
0
| int byte3;
|
721 |
0
| int iByteLen = aValue.length;
|
722 |
0
| StringBuffer tt = new StringBuffer();
|
723 |
| |
724 |
0
| for (int i = 0; i < iByteLen; i += 3) {
|
725 |
0
| boolean bByte2 = (i + 1) < iByteLen;
|
726 |
0
| boolean bByte3 = (i + 2) < iByteLen;
|
727 |
0
| byte1 = aValue[i] & 0xFF;
|
728 |
0
| byte2 = (bByte2) ? (aValue[i + 1] & 0xFF) : 0;
|
729 |
0
| byte3 = (bByte3) ? (aValue[i + 2] & 0xFF) : 0;
|
730 |
| |
731 |
0
| tt.append(m_strBase64Chars.charAt(byte1 / 4));
|
732 |
0
| tt.append(m_strBase64Chars.charAt((byte2 / 16) + ((byte1 & 0x3) * 16)));
|
733 |
0
| tt.append(((bByte2) ? m_strBase64Chars.charAt((byte3 / 64) + ((byte2 & 0xF) * 4)) : '='));
|
734 |
0
| tt.append(((bByte3) ? m_strBase64Chars.charAt(byte3 & 0x3F) : '='));
|
735 |
| } |
736 |
| |
737 |
0
| return tt.toString();
|
738 |
| } |
739 |
| |
740 |
| |
741 |
| |
742 |
| |
743 |
| |
744 |
| |
745 |
| |
746 |
| |
747 |
0
| private ServletCache createCache(int scope, String sessionId) {
|
748 |
0
| ServletCache newCache = new ServletCache(this, algorithmClass, cacheCapacity, scope);
|
749 |
| |
750 |
| |
751 |
| |
752 |
| |
753 |
| |
754 |
0
| config.set(HASH_KEY_SCOPE, "" + scope);
|
755 |
0
| config.set(HASH_KEY_SESSION_ID, sessionId);
|
756 |
| |
757 |
0
| newCache = (ServletCache) configureStandardListeners(newCache);
|
758 |
| |
759 |
0
| if (config.getProperty(CACHE_ENTRY_EVENT_LISTENERS_KEY) != null) {
|
760 |
| |
761 |
0
| CacheEventListener[] listeners = getCacheEventListeners();
|
762 |
| |
763 |
0
| for (int i = 0; i < listeners.length; i++) {
|
764 |
0
| if (listeners[i] instanceof ScopeEventListener) {
|
765 |
0
| newCache.addCacheEventListener(listeners[i]);
|
766 |
| } |
767 |
| } |
768 |
| } |
769 |
| |
770 |
0
| return newCache;
|
771 |
| } |
772 |
| |
773 |
| |
774 |
| |
775 |
| |
776 |
| |
777 |
| |
778 |
| |
779 |
| |
780 |
| |
781 |
0
| private void dispatchScopeEvent(ScopeEventType eventType, int scope, Date date, String origin) {
|
782 |
| |
783 |
0
| ScopeEvent event = new ScopeEvent(eventType, scope, date, origin);
|
784 |
| |
785 |
| |
786 |
0
| Object[] listeners = listenerList.getListenerList();
|
787 |
| |
788 |
| |
789 |
| |
790 |
0
| for (int i = listeners.length - 2; i >= 0; i -= 2) {
|
791 |
0
| if (listeners[i+1] instanceof ScopeEventListener) {
|
792 |
0
| ((ScopeEventListener) listeners[i + 1]).scopeFlushed(event);
|
793 |
| } |
794 |
| } |
795 |
| } |
796 |
| |
797 |
| |
798 |
| |
799 |
| |
800 |
| |
801 |
0
| private void initHostDomainInKey() {
|
802 |
0
| String propStr = getProperty(CACHE_USE_HOST_DOMAIN_KEY);
|
803 |
| |
804 |
0
| useHostDomainInKey = "true".equalsIgnoreCase(propStr);
|
805 |
| } |
806 |
| } |