001    /**
002     * Copyright (c) 2000-2012 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.poller;
016    
017    import com.liferay.portal.kernel.util.StringBundler;
018    import com.liferay.portal.kernel.util.Validator;
019    
020    import java.util.Collections;
021    import java.util.Map;
022    
023    /**
024     * @author Brian Wing Shun Chan
025     */
026    public class PollerRequest {
027    
028            public PollerRequest(
029                    PollerHeader pollerHeader, String portletId,
030                    Map<String, String> parameterMap, String chunkId,
031                    boolean receiveRequest) {
032    
033                    _pollerHeader = pollerHeader;
034                    _portletId = portletId;
035                    _parameterMap = parameterMap;
036                    _chunkId = chunkId;
037                    _receiveRequest = receiveRequest;
038            }
039    
040            @Override
041            public boolean equals(Object obj) {
042                    if (this == obj) {
043                            return true;
044                    }
045    
046                    if (!(obj instanceof PollerRequest)) {
047                            return false;
048                    }
049    
050                    PollerRequest portletRequest = (PollerRequest)obj;
051    
052                    if (Validator.equals(_portletId, portletRequest._portletId)) {
053                            return true;
054                    }
055    
056                    return false;
057            }
058    
059            public long getBrowserKey() {
060                    return _pollerHeader.getBrowserKey();
061            }
062    
063            public String getChunkId() {
064                    return _chunkId;
065            }
066    
067            public long getCompanyId() {
068                    return _pollerHeader.getCompanyId();
069            }
070    
071            public Map<String, String> getParameterMap() {
072                    return _parameterMap;
073            }
074    
075            public PollerHeader getPollerHeader() {
076                    return _pollerHeader;
077            }
078    
079            public String getPortletId() {
080                    return _portletId;
081            }
082    
083            public String[] getPortletIds() {
084                    return _pollerHeader.getPortletIds();
085            }
086    
087            public long getTimestamp() {
088                    return _pollerHeader.getTimestamp();
089            }
090    
091            public long getUserId() {
092                    return _pollerHeader.getUserId();
093            }
094    
095            @Override
096            public int hashCode() {
097                    if (_portletId != null) {
098                            return _portletId.hashCode();
099                    }
100                    else {
101                            return 0;
102                    }
103            }
104    
105            public boolean isInitialRequest() {
106                    return _pollerHeader.isInitialRequest();
107            }
108    
109            public boolean isReceiveRequest() {
110                    return _receiveRequest;
111            }
112    
113            public boolean isStartPolling() {
114                    return _pollerHeader.isStartPolling();
115            }
116    
117            @Override
118            public String toString() {
119                    StringBundler sb = new StringBundler(11);
120    
121                    sb.append("{chunkId=");
122                    sb.append(_chunkId);
123                    sb.append(", parameterMap=");
124                    sb.append(_parameterMap);
125                    sb.append(", pollerHeader=");
126                    sb.append(_pollerHeader);
127                    sb.append(", portletId=");
128                    sb.append(_portletId);
129                    sb.append(", receiveRequest=");
130                    sb.append(_receiveRequest);
131                    sb.append("}");
132    
133                    return sb.toString();
134            }
135    
136            private String _chunkId;
137            private Map<String, String> _parameterMap = Collections.emptyMap();
138            private PollerHeader _pollerHeader;
139            private String _portletId;
140            private boolean _receiveRequest;
141    
142    }