001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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    }