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 @Override
033 public PortalCacheClusterChannel createPortalCacheClusterChannel()
034 throws PortalCacheClusterException {
035
036 int count = _counter.getAndIncrement();
037
038 if (count >= _priorities.size()) {
039 throw new IllegalStateException(
040 "Cannot create more than " + _priorities.size() + " channels");
041 }
042
043 return new ClusterLinkPortalCacheClusterChannel(
044 _destinationName, _priorities.get(count));
045 }
046
047 public void setDestinationName(String destinationName) {
048 _destinationName = destinationName;
049 }
050
051 public void setPriorities(List<Priority> priorities) {
052 _priorities = priorities;
053
054 Collections.sort(priorities);
055 }
056
057 private AtomicInteger _counter = new AtomicInteger(0);
058 private String _destinationName;
059 private List<Priority> _priorities;
060
061 }