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