DefaultLocalCacheStrategy.java 2.42 KB
Newer Older
1
/**
2 3 4
 * $RCSfile$
 * $Revision: $
 * $Date: $
5
 *
6 7 8 9
 * Copyright (C) 2007 Jive Software. All rights reserved.
 *
 * This software is published under the terms of the GNU Public License (GPL),
 * a copy of which is included in this distribution.
10
 */
11

12 13
package org.jivesoftware.util.cache;

Gaston Dombiak's avatar
Gaston Dombiak committed
14
import org.jivesoftware.openfire.cluster.ClusterNodeInfo;
15 16 17

import java.util.Collection;
import java.util.Collections;
18
import java.util.Map;
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40

/**
 * CacheFactoryStrategy for use in Openfire. It creates and manages local caches, and it's cluster
 * related method implementations do nothing.
 *
 * @see Cache
 * @see CacheFactory
 */
public class DefaultLocalCacheStrategy implements CacheFactoryStrategy {


    public DefaultLocalCacheStrategy() {
    }

    public boolean startCluster() {
        return false;
    }

    public void stopCluster() {
    }

    public Cache createCache(String name) {
41 42 43
        // Get cache configuration from system properties or default (hardcoded) values
        long maxSize = CacheFactory.getMaxCacheSize(name);
        long lifetime = CacheFactory.getMaxCacheLifetime(name);
44
        // Create cache with located properties
45
        return new DefaultCache(name, maxSize, lifetime);
46 47 48 49
    }

    public void destroyCache(Cache cache) {
        cache.clear();
50 51 52 53
    }

    public boolean isSeniorClusterMember() {
        return true;
Gaston Dombiak's avatar
Gaston Dombiak committed
54 55 56 57
    }

    public Collection<ClusterNodeInfo> getClusterNodesInfo() {
        return Collections.emptyList();
Gaston Dombiak's avatar
Gaston Dombiak committed
58 59 60 61
    }

    public int getMaxClusterNodes() {
        return 0;
62 63
    }

64 65 66 67
    public byte[] getSeniorClusterMemberID() {
        return null;
    }

68
    public byte[] getClusterMemberID() {
69
        return new byte[0];
70 71 72 73 74
    }

    public void doClusterTask(final ClusterTask task) {
    }

75
    public boolean doClusterTask(ClusterTask task, byte[] nodeID) {
76
        throw new IllegalStateException("Cluster service is not available");
77 78
    }

79 80 81 82
    public Collection<Object> doSynchronousClusterTask(ClusterTask task, boolean includeLocalMember) {
        return Collections.emptyList();
    }

83
    public Object doSynchronousClusterTask(ClusterTask task, byte[] nodeID) {
84
        throw new IllegalStateException("Cluster service is not available");
85 86
    }

87 88 89 90 91 92 93 94 95
    public void updateCacheStats(Map<String, Cache> caches) {
    }

    public void lockKey(Object key, long timeout) {
    }

    public void unlockKey(Object key) {
    }
}