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