01: /**
02: * $RCSfile$
03: * $Revision: $
04: * $Date: $
05: *
06: * Copyright (C) 2007 Jive Software. All rights reserved.
07: *
08: * This software is published under the terms of the GNU Public License (GPL),
09: * a copy of which is included in this distribution.
10: */package org.jivesoftware.util.cache;
11:
12: import org.jivesoftware.openfire.cluster.ClusterNodeInfo;
13:
14: import java.util.Collection;
15: import java.util.Collections;
16: import java.util.Map;
17:
18: /**
19: * CacheFactoryStrategy for use in Openfire. It creates and manages local caches, and it's cluster
20: * related method implementations do nothing.
21: *
22: * @see Cache
23: * @see CacheFactory
24: */
25: public class DefaultLocalCacheStrategy implements CacheFactoryStrategy {
26:
27: public DefaultLocalCacheStrategy() {
28: }
29:
30: public boolean startCluster() {
31: return false;
32: }
33:
34: public void stopCluster() {
35: }
36:
37: public Cache createCache(String name) {
38: // Get cache configuration from system properties or default (hardcoded) values
39: long maxSize = CacheFactory.getMaxCacheSize(name);
40: long lifetime = CacheFactory.getMaxCacheLifetime(name);
41: // Create cache with located properties
42: return new DefaultCache(name, maxSize, lifetime);
43: }
44:
45: public void destroyCache(Cache cache) {
46: cache.clear();
47: }
48:
49: public boolean isSeniorClusterMember() {
50: return true;
51: }
52:
53: public Collection<ClusterNodeInfo> getClusterNodesInfo() {
54: return Collections.emptyList();
55: }
56:
57: public int getMaxClusterNodes() {
58: return 0;
59: }
60:
61: public byte[] getSeniorClusterMemberID() {
62: return null;
63: }
64:
65: public byte[] getClusterMemberID() {
66: return new byte[0];
67: }
68:
69: public void doClusterTask(final ClusterTask task) {
70: }
71:
72: public boolean doClusterTask(ClusterTask task, byte[] nodeID) {
73: throw new IllegalStateException(
74: "Cluster service is not available");
75: }
76:
77: public Collection<Object> doSynchronousClusterTask(
78: ClusterTask task, boolean includeLocalMember) {
79: return Collections.emptyList();
80: }
81:
82: public Object doSynchronousClusterTask(ClusterTask task,
83: byte[] nodeID) {
84: throw new IllegalStateException(
85: "Cluster service is not available");
86: }
87:
88: public void updateCacheStats(Map<String, Cache> caches) {
89: }
90:
91: public void lockKey(Object key, long timeout) {
92: }
93:
94: public void unlockKey(Object key) {
95: }
96: }
|