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.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    }