1
14
15 package com.liferay.portal.cache.cluster.clusterlink;
16
17 import com.liferay.portal.kernel.cache.cluster.PortalCacheClusterChannel;
18 import com.liferay.portal.kernel.cache.cluster.PortalCacheClusterChannelFactory;
19 import com.liferay.portal.kernel.cache.cluster.PortalCacheClusterException;
20 import com.liferay.portal.kernel.cluster.Priority;
21
22 import java.util.Collections;
23 import java.util.List;
24 import java.util.concurrent.atomic.AtomicInteger;
25
26
32 public class ClusterLinkPortalCacheClusterChannelFactory
33 implements PortalCacheClusterChannelFactory {
34
35 public ClusterLinkPortalCacheClusterChannelFactory(
36 String destination, List<Priority> priorities) {
37
38 _counter = new AtomicInteger(0);
39 _destination = destination;
40 _priorities = priorities;
41
42 Collections.sort(priorities);
43 }
44
45 public PortalCacheClusterChannel createPortalCacheClusterChannel()
46 throws PortalCacheClusterException {
47
48 int count = _counter.getAndIncrement();
49
50 if (count >= _priorities.size()) {
51 throw new IllegalStateException(
52 "Cannot create more than " + _priorities.size() + " channels");
53 }
54
55 return new ClusterLinkPortalCacheClusterChannel(
56 _destination, _priorities.get(count));
57 }
58
59 private AtomicInteger _counter;
60 private String _destination;
61 private List<Priority> _priorities;
62
63 }