001    /**
002     * Copyright (c) 2000-2012 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    
036                    ClusterNode clusterNode = clusterNodeResponse.getClusterNode();
037    
038                    _clusterResponsesByClusterNode.put(
039                            clusterNode.getClusterNodeId(), clusterNodeResponse);
040    
041                    _clusterResponsesQueue.offer(clusterNodeResponse);
042            }
043    
044            public ClusterNodeResponse getClusterResponse(Address address) {
045                    return _clusterResponsesByAddress.get(address);
046            }
047    
048            public ClusterNodeResponse getClusterResponse(ClusterNode clusterNode) {
049                    return getClusterResponse(clusterNode.getClusterNodeId());
050            }
051    
052            public ClusterNodeResponse getClusterResponse(String clusterNodeId) {
053                    return _clusterResponsesByClusterNode.get(clusterNodeId);
054            }
055    
056            public BlockingQueue<ClusterNodeResponse> getClusterResponses() {
057                    return _clusterResponsesQueue;
058            }
059    
060            public int size() {
061                    return _clusterResponsesByClusterNode.size();
062            }
063    
064            private Map<Address, ClusterNodeResponse> _clusterResponsesByAddress =
065                    new HashMap<Address, ClusterNodeResponse>();
066            private Map<String, ClusterNodeResponse> _clusterResponsesByClusterNode =
067                    new HashMap<String, ClusterNodeResponse>();
068            private BlockingQueue<ClusterNodeResponse> _clusterResponsesQueue =
069                    new LinkedBlockingQueue<ClusterNodeResponse>();
070    
071    }