io.joynr.messaging.bounceproxy.controller.directory.ehcache.BounceProxyEhcacheAdapter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ehcache Show documentation
Show all versions of ehcache Show documentation
ehcache implementation for directories needed by bounceproxy controller
/*
* #%L
* %%
* Copyright (C) 2011 - 2017 BMW Car IT GmbH
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package io.joynr.messaging.bounceproxy.controller.directory.ehcache;
import io.joynr.messaging.bounceproxy.controller.directory.BounceProxyDirectory;
import io.joynr.messaging.bounceproxy.controller.directory.BounceProxyRecord;
import io.joynr.messaging.info.BounceProxyInformation;
import io.joynr.messaging.info.BounceProxyStatusInformation;
import io.joynr.messaging.info.ControlledBounceProxyInformation;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;
import net.sf.ehcache.distribution.CacheManagerPeerProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.inject.Inject;
import com.google.inject.name.Named;
/**
* {@link BounceProxyDirectory} implementation which uses Ehcache to store
* bounce proxy information.
*
* @author christina.strobel
*
*/
public class BounceProxyEhcacheAdapter implements BounceProxyDirectory {
private static final Logger log = LoggerFactory.getLogger(BounceProxyEhcacheAdapter.class);
public final static String PROPERTY_BP_CACHE_NAME = "joynr.bounceproxy.controller.bp_cache_name";
public final static String PROPERTY_BP_CACHE_CONFIGURATION = "joynr.bounceproxy.controller.bp_cache_config_file";
private final CacheManager manager;
private final String cacheName;
@Inject
public BounceProxyEhcacheAdapter(@Named(PROPERTY_BP_CACHE_NAME) String cacheName, CacheManager cacheManager) {
this.cacheName = cacheName;
this.manager = cacheManager;
}
@Override
public List getAssignableBounceProxies() {
if (log.isTraceEnabled()) {
log.trace("Retrieving assignable bounce proxies from cache {}", cacheName);
tracePeers();
}
List result = new LinkedList();
Cache cache = manager.getCache(cacheName);
@SuppressWarnings("rawtypes")
List keys = cache.getKeys();
Map