1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.dao.shard;
16  
17  import com.liferay.portal.kernel.poller.PollerException;
18  import com.liferay.portal.kernel.poller.PollerProcessor;
19  import com.liferay.portal.kernel.poller.PollerRequest;
20  import com.liferay.portal.kernel.poller.PollerResponse;
21  
22  /**
23   * <a href="ShardPollerProcessorWrapper.java.html"><b><i>View Source</i></b></a>
24   *
25   * @author Alexander Chow
26   */
27  public class ShardPollerProcessorWrapper implements PollerProcessor {
28  
29      public ShardPollerProcessorWrapper(PollerProcessor pollerProcessor) {
30          _pollerProcessor = pollerProcessor;
31      }
32  
33      public void receive(
34              PollerRequest pollerRequest, PollerResponse pollerResponse)
35          throws PollerException {
36  
37          try {
38              ShardUtil.pushCompanyService(pollerRequest.getCompanyId());
39  
40              _pollerProcessor.receive(pollerRequest, pollerResponse);
41          }
42          finally {
43              ShardUtil.popCompanyService();
44          }
45      }
46  
47      public void send(PollerRequest pollerRequest) throws PollerException {
48          try {
49              ShardUtil.pushCompanyService(pollerRequest.getCompanyId());
50  
51              _pollerProcessor.send(pollerRequest);
52          }
53          finally {
54              ShardUtil.popCompanyService();
55          }
56      }
57  
58      private PollerProcessor _pollerProcessor;
59  
60  }