View Javadoc

1   /***
2    * 
3    * Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
4    * 
5    * Licensed under the Apache License, Version 2.0 (the "License"); 
6    * you may not use this file except in compliance with the License. 
7    * You may obtain a copy of the License at 
8    * 
9    * http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS, 
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
14   * See the License for the specific language governing permissions and 
15   * limitations under the License. 
16   * 
17   **/
18  package org.jencks;
19  
20  import org.springframework.beans.factory.InitializingBean;
21  
22  import javax.jms.MessageListener;
23  import javax.resource.spi.UnavailableException;
24  import javax.transaction.TransactionManager;
25  
26  /***
27   * An implementation of {@link javax.resource.spi.endpoint.MessageEndpointFactory} which always
28   * uses a single shared instance of a {@link javax.jms.MessageListener} for every endpoint, irrespective
29   * of how many physical endpoints are used.
30   *
31   * @version $Revision: 1.2 $
32   */
33  public class SingletonEndpointFactory extends EndpointFactorySupport implements InitializingBean {
34      private MessageListener messageListener;
35  
36      public SingletonEndpointFactory() {
37      }
38  
39      public SingletonEndpointFactory(MessageListener messageListener) {
40          this.messageListener = messageListener;
41      }
42  
43      public SingletonEndpointFactory(MessageListener messageListener, TransactionManager tm) {
44          this.messageListener = messageListener;
45          this.transactionManager = tm;
46      }
47  
48      public void afterPropertiesSet() throws Exception {
49          if (messageListener == null) {
50              throw new IllegalArgumentException("messageListener property must be set");
51          }
52      }
53  
54      public MessageListener getMessageListener() {
55          return messageListener;
56      }
57  
58      public void setMessageListener(MessageListener messageListener) {
59          this.messageListener = messageListener;
60      }
61  
62      // Implementation methods
63      //-------------------------------------------------------------------------
64      protected MessageListener createMessageListener() throws UnavailableException {
65          return messageListener;
66      }
67  }