001
014
015 package com.liferay.portal.cache.cluster.clusterlink;
016
017 import com.liferay.portal.kernel.cache.cluster.PortalCacheClusterChannel;
018 import com.liferay.portal.kernel.cache.cluster.PortalCacheClusterChannelFactory;
019 import com.liferay.portal.kernel.cache.cluster.PortalCacheClusterException;
020 import com.liferay.portal.kernel.cluster.Priority;
021
022 import java.util.Collections;
023 import java.util.List;
024 import java.util.concurrent.atomic.AtomicInteger;
025
026
029 public class ClusterLinkPortalCacheClusterChannelFactory
030 implements PortalCacheClusterChannelFactory {
031
032 public ClusterLinkPortalCacheClusterChannelFactory(
033 String destination, List<Priority> priorities) {
034
035 _counter = new AtomicInteger(0);
036 _destination = destination;
037 _priorities = priorities;
038
039 Collections.sort(priorities);
040 }
041
042 public PortalCacheClusterChannel createPortalCacheClusterChannel()
043 throws PortalCacheClusterException {
044
045 int count = _counter.getAndIncrement();
046
047 if (count >= _priorities.size()) {
048 throw new IllegalStateException(
049 "Cannot create more than " + _priorities.size() + " channels");
050 }
051
052 return new ClusterLinkPortalCacheClusterChannel(
053 _destination, _priorities.get(count));
054 }
055
056 private AtomicInteger _counter;
057 private String _destination;
058 private List<Priority> _priorities;
059
060 }