1 /**
2 *
3 * Copyright 2003-2004 The Apache Software Foundation
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.apache.geronimo.transaction.manager;
19
20 import java.util.ArrayList;
21 import java.util.Collection;
22 import java.util.List;
23 import javax.transaction.xa.XAException;
24
25 import org.apache.geronimo.gbean.GBeanInfo;
26 import org.apache.geronimo.gbean.GBeanInfoBuilder;
27 import org.apache.geronimo.gbean.ReferenceCollection;
28 import org.apache.geronimo.gbean.ReferenceCollectionEvent;
29 import org.apache.geronimo.gbean.ReferenceCollectionListener;
30 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
31
32 /**
33 * Simple implementation of a transaction manager.
34 *
35 * @version $Rev: 430508 $ $Date: 2006-08-10 12:56:47 -0700 (Thu, 10 Aug 2006) $
36 */
37 public class TransactionManagerImplGBean extends TransactionManagerImpl {
38
39 /**
40 * TODO NOTE!!! this should be called in an unspecified transaction context, but we cannot enforce this restriction!
41 */
42 public TransactionManagerImplGBean(int defaultTransactionTimeoutSeconds, XidFactory xidFactory, TransactionLog transactionLog, Collection resourceManagers) throws XAException {
43 super(defaultTransactionTimeoutSeconds, xidFactory, transactionLog, resourceManagers);
44 }
45
46
47 /**
48 * We can track as resources are added into the geronimo kernel.
49 *
50 * @param resourceManagers
51 * @return the original list of resources.
52 */
53 protected List watchResourceManagers(Collection resourceManagers) {
54 if( resourceManagers instanceof ReferenceCollection ) {
55 List copy;
56 synchronized (resourceManagers) {
57 copy = new ArrayList(resourceManagers);
58 ((ReferenceCollection)resourceManagers).addReferenceCollectionListener(new ReferenceCollectionListener() {
59 public void memberAdded(ReferenceCollectionEvent event) {
60 ResourceManager resourceManager = (ResourceManager) event.getMember();
61 recoverResourceManager(resourceManager);
62 }
63
64 public void memberRemoved(ReferenceCollectionEvent event) {
65 }
66
67 });
68 }
69 return copy;
70 } else {
71 return super.watchResourceManagers(resourceManagers);
72 }
73 }
74
75 public static final GBeanInfo GBEAN_INFO;
76
77 static {
78 GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(TransactionManagerImplGBean.class, NameFactory.TRANSACTION_MANAGER);
79
80 infoBuilder.addAttribute("defaultTransactionTimeoutSeconds", int.class, true);
81 infoBuilder.addReference("XidFactory", XidFactory.class, NameFactory.XID_FACTORY);
82 infoBuilder.addReference("TransactionLog", TransactionLog.class, NameFactory.TRANSACTION_LOG);
83 infoBuilder.addReference("ResourceManagers", ResourceManager.class);
84
85 infoBuilder.setConstructor(new String[]{
86 "defaultTransactionTimeoutSeconds",
87 "XidFactory",
88 "TransactionLog",
89 "ResourceManagers"});
90
91 GBEAN_INFO = infoBuilder.getBeanInfo();
92 }
93
94
95 public static GBeanInfo getGBeanInfo() {
96 return GBEAN_INFO;
97 }
98 }