1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
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  /**
27   * <a href="ClusterLinkPortalCacheClusterChannelFactory.java.html"><b><i>View
28   * Source</i></b></a>
29   *
30   * @author Shuyang Zhou
31   */
32  public class ClusterLinkPortalCacheClusterChannelFactory
33      implements PortalCacheClusterChannelFactory {
34  
35      public PortalCacheClusterChannel createPortalCacheClusterChannel()
36          throws PortalCacheClusterException {
37  
38          int count = _counter.getAndIncrement();
39  
40          if (count >= _priorities.size()) {
41              throw new IllegalStateException(
42                  "Cannot create more than " + _priorities.size() + " channels");
43          }
44  
45          return new ClusterLinkPortalCacheClusterChannel(
46              _destinationName, _priorities.get(count));
47      }
48  
49      public void setDestinationName(String destinationName) {
50          _destinationName = destinationName;
51      }
52  
53      public void setPriorities(List<Priority> priorities) {
54          _priorities = priorities;
55  
56          Collections.sort(priorities);
57      }
58  
59      private AtomicInteger _counter = new AtomicInteger(0);
60      private String _destinationName;
61      private List<Priority> _priorities;
62  
63  }