001    /**
002     * Copyright (c) 2000-2011 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                    _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    }