| Home >> All >> org >> activemq >> [ ra Javadoc ] |
Source code: org/activemq/ra/ActiveMQBaseEndpointWorker.java
1 /** 2 * 3 * Copyright 2004 Hiram Chirino 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.activemq.ra; 19 20 import java.lang.reflect.Method; 21 22 import javax.jms.Connection; 23 import javax.jms.ConnectionConsumer; 24 import javax.jms.JMSException; 25 import javax.jms.Message; 26 import javax.jms.MessageListener; 27 import javax.jms.Session; 28 import javax.resource.ResourceException; 29 import javax.resource.spi.endpoint.MessageEndpointFactory; 30 import javax.resource.spi.work.WorkException; 31 import javax.resource.spi.work.WorkManager; 32 33 import org.apache.commons.logging.Log; 34 import org.apache.commons.logging.LogFactory; 35 36 /** 37 * @version $Revision: 1.1.1.1 $ $Date: 2005/03/11 21:15:09 $ 38 */ 39 public abstract class ActiveMQBaseEndpointWorker { 40 41 private static final Log log = LogFactory.getLog(ActiveMQBaseEndpointWorker.class); 42 public static final Method ON_MESSAGE_METHOD; 43 44 static { 45 try { 46 ON_MESSAGE_METHOD = MessageListener.class.getMethod("onMessage", new Class[]{Message.class}); 47 } 48 catch (Exception e) { 49 throw new ExceptionInInitializerError(e); 50 } 51 } 52 53 protected ActiveMQResourceAdapter adapter; 54 protected ActiveMQEndpointActivationKey endpointActivationKey; 55 protected MessageEndpointFactory endpointFactory; 56 protected WorkManager workManager; 57 protected boolean transacted; 58 59 /** 60 * @param s 61 */ 62 public static void safeClose(Session s) { 63 try { 64 if (s != null) { 65 s.close(); 66 } 67 } 68 catch (JMSException e) { 69 } 70 } 71 72 /** 73 * @param c 74 */ 75 public static void safeClose(Connection c) { 76 try { 77 if (c != null) { 78 c.close(); 79 } 80 } 81 catch (JMSException e) { 82 } 83 } 84 85 /** 86 * @param cc 87 */ 88 public static void safeClose(ConnectionConsumer cc) { 89 try { 90 if (cc != null) { 91 cc.close(); 92 } 93 } 94 catch (JMSException e) { 95 } 96 } 97 98 public ActiveMQBaseEndpointWorker(ActiveMQResourceAdapter adapter, ActiveMQEndpointActivationKey key) throws ResourceException { 99 this.endpointActivationKey = key; 100 this.adapter = adapter; 101 this.endpointFactory = endpointActivationKey.getMessageEndpointFactory(); 102 this.workManager = adapter.getBootstrapContext().getWorkManager(); 103 try { 104 this.transacted = endpointFactory.isDeliveryTransacted(ON_MESSAGE_METHOD); 105 } 106 catch (NoSuchMethodException e) { 107 throw new ResourceException("Endpoint does not implement the onMessage method."); 108 } 109 } 110 111 public abstract void start() throws WorkException, ResourceException; 112 113 public abstract void stop() throws InterruptedException; 114 115 116 }