All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.milton.cache.HazelcastCacheManager Maven / Gradle / Ivy

Go to download

Milton Community Edition: Supports DAV level 1 and is available on Apache2 license

There is a newer version: 4.0.3.2215
Show newest version
/* 
 *       Copyright McEvoy Software Ltd
 */
package io.milton.cache;

import com.hazelcast.cluster.Cluster;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * Attempts to connect to a hazelcast cluster. To use this, be sure to include
 * the optional hazelcast dependencies
 *
 * @author brad
 */
public class HazelcastCacheManager implements CacheManager {
    
    private static final Logger log = LoggerFactory.getLogger(HazelcastCacheManager.class);
    
    private final HazelcastInstance hazel;
    private final Cluster cluster;

    public HazelcastCacheManager() {
        hazel = Hazelcast.newHazelcastInstance();
        log.info("Connected to hazelcast cluster");
        cluster = hazel.getCluster();
    }

	@Override
    public Map getMap(String name) {
        if( hazel != null ) {
            return hazel.getMap(name);
        } else {
			log.warn("Not connected to hazelcast, using local data only");
            return new ConcurrentHashMap();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy