KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > ra > InboundContextSupport


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.ra;
19
20 /**
21  * A helper class used to provide access to the current active
22  * {@link InboundContext} instance being used to process a message
23  * in the current thread so that messages can be produced using the same
24  * session.
25  *
26  * @version $Revision$
27  */

28 public class InboundContextSupport {
29     private static final ThreadLocal JavaDoc threadLocal = new ThreadLocal JavaDoc();
30
31     /**
32      * Returns the current {@link InboundContext} used by the current thread which is processing a message.
33      * This allows us to access the current Session to send a message using the same underlying
34      * session to avoid unnecessary XA or to use regular JMS transactions while using message driven POJOs.
35      *
36      * @return
37      */

38     public static InboundContext getActiveSessionAndProducer() {
39         return (InboundContext) threadLocal.get();
40     }
41
42
43     /**
44      * Registers the session and producer which should be called before the
45      * {@link javax.resource.spi.endpoint.MessageEndpoint#beforeDelivery(java.lang.reflect.Method)}
46      * method is called.
47      *
48      * @param sessionAndProducer
49      */

50     public static void register(InboundContext sessionAndProducer) {
51         threadLocal.set(sessionAndProducer);
52     }
53
54     /**
55      * Unregisters the session and producer which should be called after the
56      * {@link javax.resource.spi.endpoint.MessageEndpoint#afterDelivery()}
57      * method is called.
58      *
59      * @param sessionAndProducer
60      */

61     public static void unregister(InboundContext sessionAndProducer) {
62         threadLocal.set(null);
63     }
64 }
65
Popular Tags