KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > transaction > jta11 > GeronimoTransactionManagerJTA11GBean


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. 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.apache.geronimo.transaction.jta11;
19
20 import java.util.Collection JavaDoc;
21 import java.util.List JavaDoc;
22 import java.util.ArrayList JavaDoc;
23
24 import javax.transaction.xa.XAException JavaDoc;
25 import javax.transaction.TransactionSynchronizationRegistry JavaDoc;
26
27 import org.apache.geronimo.transaction.manager.XidFactory;
28 import org.apache.geronimo.transaction.manager.TransactionLog;
29 import org.apache.geronimo.transaction.manager.ResourceManager;
30 import org.apache.geronimo.transaction.manager.TransactionManagerImplGBean;
31 import org.apache.geronimo.transaction.jta11.GeronimoTransactionManagerJTA11;
32 import org.apache.geronimo.gbean.ReferenceCollection;
33 import org.apache.geronimo.gbean.ReferenceCollectionListener;
34 import org.apache.geronimo.gbean.ReferenceCollectionEvent;
35 import org.apache.geronimo.gbean.GBeanInfo;
36 import org.apache.geronimo.gbean.GBeanInfoBuilder;
37 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
38
39 /**
40  * @version $Rev: 482336 $ $Date: 2006-12-04 15:12:19 -0500 (Mon, 04 Dec 2006) $
41  */

42 public class GeronimoTransactionManagerJTA11GBean extends GeronimoTransactionManagerJTA11 {
43     /**
44      * TODO NOTE!!! this should be called in an unspecified transaction context, but we cannot enforce this restriction!
45      */

46     public GeronimoTransactionManagerJTA11GBean(int defaultTransactionTimeoutSeconds, XidFactory xidFactory, TransactionLog transactionLog, Collection JavaDoc resourceManagers) throws XAException JavaDoc {
47         super(defaultTransactionTimeoutSeconds == 0 ? DEFAULT_TIMEOUT : defaultTransactionTimeoutSeconds,
48                 xidFactory,
49                 transactionLog,
50                 resourceManagers);
51     }
52
53
54     /**
55      * We can track as resources are added into the geronimo kernel.
56      *
57      * @param resourceManagers
58      * @return the original list of resources.
59      */

60     protected List JavaDoc watchResourceManagers(Collection JavaDoc resourceManagers) {
61         if( resourceManagers instanceof ReferenceCollection ) {
62             List JavaDoc copy;
63             synchronized (resourceManagers) {
64                 copy = new ArrayList JavaDoc(resourceManagers);
65                     ((ReferenceCollection)resourceManagers).addReferenceCollectionListener(new ReferenceCollectionListener() {
66                     public void memberAdded(ReferenceCollectionEvent event) {
67                         ResourceManager resourceManager = (ResourceManager) event.getMember();
68                         recoverResourceManager(resourceManager);
69                     }
70
71                     public void memberRemoved(ReferenceCollectionEvent event) {
72                     }
73
74                 });
75             }
76             return copy;
77         } else {
78             return super.watchResourceManagers(resourceManagers);
79         }
80     }
81
82     public static final GBeanInfo GBEAN_INFO;
83
84     static {
85         GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(GeronimoTransactionManagerJTA11GBean.class,
86                 TransactionManagerImplGBean.GBEAN_INFO,
87                 NameFactory.TRANSACTION_MANAGER);
88         infoBuilder.addInterface(TransactionSynchronizationRegistry JavaDoc.class);
89
90         GBEAN_INFO = infoBuilder.getBeanInfo();
91     }
92
93     public static GBeanInfo getGBeanInfo() {
94         return GBEAN_INFO;
95     }
96 }
97
Popular Tags