001    /**
002     * Copyright (c) 2000-2010 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.dao.shard;
016    
017    import com.liferay.portal.kernel.dao.shard.ShardUtil;
018    import com.liferay.portal.kernel.poller.PollerException;
019    import com.liferay.portal.kernel.poller.PollerProcessor;
020    import com.liferay.portal.kernel.poller.PollerRequest;
021    import com.liferay.portal.kernel.poller.PollerResponse;
022    
023    /**
024     * @author Alexander Chow
025     */
026    public class ShardPollerProcessorWrapper implements PollerProcessor {
027    
028            public ShardPollerProcessorWrapper(PollerProcessor pollerProcessor) {
029                    _pollerProcessor = pollerProcessor;
030            }
031    
032            public void receive(
033                            PollerRequest pollerRequest, PollerResponse pollerResponse)
034                    throws PollerException {
035    
036                    try {
037                            ShardUtil.pushCompanyService(pollerRequest.getCompanyId());
038    
039                            _pollerProcessor.receive(pollerRequest, pollerResponse);
040                    }
041                    finally {
042                            ShardUtil.popCompanyService();
043                    }
044            }
045    
046            public void send(PollerRequest pollerRequest) throws PollerException {
047                    try {
048                            ShardUtil.pushCompanyService(pollerRequest.getCompanyId());
049    
050                            _pollerProcessor.send(pollerRequest);
051                    }
052                    finally {
053                            ShardUtil.popCompanyService();
054                    }
055            }
056    
057            private PollerProcessor _pollerProcessor;
058    
059    }