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  
25  /***
26   * An implementation of {@link javax.resource.spi.endpoint.MessageEndpointFactory} which always
27   * uses a single shared instance of a {@link javax.jms.MessageListener} for every endpoint, irrespective
28   * of how many physical endpoints are used.
29   *
30   * @version $Revision: 1.1.1.1 $
31   */
32  public class SingletonEndpointFactory extends EndpointFactorySupport implements InitializingBean {
33      private MessageListener messageListener;
34  
35      public SingletonEndpointFactory() {
36      }
37  
38      public SingletonEndpointFactory(MessageListener messageListener) {
39          this.messageListener = messageListener;
40      }
41  
42      public void afterPropertiesSet() throws Exception {
43          if (messageListener == null) {
44              throw new IllegalArgumentException("messageListener property must be set");
45          }
46      }
47  
48      public MessageListener getMessageListener() {
49          return messageListener;
50      }
51  
52      public void setMessageListener(MessageListener messageListener) {
53          this.messageListener = messageListener;
54      }
55  
56      // Implementation methods
57      //-------------------------------------------------------------------------
58      protected MessageListener createMessageListener() throws UnavailableException {
59          return messageListener;
60      }
61  }