001    /**
002     * Copyright (c) 2000-2013 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            @Override
033            public void receive(
034                            PollerRequest pollerRequest, PollerResponse pollerResponse)
035                    throws PollerException {
036    
037                    try {
038                            ShardUtil.pushCompanyService(pollerRequest.getCompanyId());
039    
040                            _pollerProcessor.receive(pollerRequest, pollerResponse);
041                    }
042                    finally {
043                            ShardUtil.popCompanyService();
044                    }
045            }
046    
047            @Override
048            public void send(PollerRequest pollerRequest) throws PollerException {
049                    try {
050                            ShardUtil.pushCompanyService(pollerRequest.getCompanyId());
051    
052                            _pollerProcessor.send(pollerRequest);
053                    }
054                    finally {
055                            ShardUtil.popCompanyService();
056                    }
057            }
058    
059            private PollerProcessor _pollerProcessor;
060    
061    }