001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.kernel.cluster;
016    
017    import java.io.Serializable;
018    
019    import java.util.HashMap;
020    import java.util.Map;
021    import java.util.concurrent.BlockingQueue;
022    import java.util.concurrent.LinkedBlockingQueue;
023    
024    /**
025     * @author Michael C. Han
026     */
027    public class ClusterNodeResponses implements Serializable {
028    
029            public static final ClusterNodeResponses EMPTY_CLUSTER_NODE_RESPONSES =
030                    new ClusterNodeResponses();
031    
032            public void addClusterResponse(ClusterNodeResponse clusterNodeResponse) {
033                    _clusterResponsesByAddress.put(
034                            clusterNodeResponse.getAddress(), clusterNodeResponse);
035                    _clusterResponsesByClusterNode.put(
036                            clusterNodeResponse.getClusterNode(), clusterNodeResponse);
037                    _clusterResponsesQueue.offer(clusterNodeResponse);
038            }
039    
040            public ClusterNodeResponse getClusterResponse(Address address) {
041                    return _clusterResponsesByAddress.get(address);
042            }
043    
044            public ClusterNodeResponse getClusterResponse(ClusterNode clusterNode) {
045                    return _clusterResponsesByClusterNode.get(clusterNode);
046            }
047    
048            public BlockingQueue<ClusterNodeResponse> getClusterResponses() {
049                    return _clusterResponsesQueue;
050            }
051    
052            public int size() {
053                    return _clusterResponsesByClusterNode.size();
054            }
055    
056            private Map<Address, ClusterNodeResponse> _clusterResponsesByAddress =
057                    new HashMap<Address, ClusterNodeResponse>();
058            private Map<ClusterNode, ClusterNodeResponse>
059                    _clusterResponsesByClusterNode =
060                            new HashMap<ClusterNode, ClusterNodeResponse>();
061            private BlockingQueue<ClusterNodeResponse> _clusterResponsesQueue =
062                    new LinkedBlockingQueue<ClusterNodeResponse>();
063    
064    }