001 /** 002 * 003 * Copyright 2003-2004 The Apache Software Foundation 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018 package org.apache.geronimo.transaction.manager; 019 020 import java.util.ArrayList; 021 import java.util.Collection; 022 import java.util.List; 023 import javax.transaction.xa.XAException; 024 025 import org.apache.geronimo.gbean.GBeanInfo; 026 import org.apache.geronimo.gbean.GBeanInfoBuilder; 027 import org.apache.geronimo.gbean.ReferenceCollection; 028 import org.apache.geronimo.gbean.ReferenceCollectionEvent; 029 import org.apache.geronimo.gbean.ReferenceCollectionListener; 030 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory; 031 032 /** 033 * Simple implementation of a transaction manager. 034 * 035 * @version $Rev: 430508 $ $Date: 2006-08-10 12:56:47 -0700 (Thu, 10 Aug 2006) $ 036 */ 037 public class TransactionManagerImplGBean extends TransactionManagerImpl { 038 039 /** 040 * TODO NOTE!!! this should be called in an unspecified transaction context, but we cannot enforce this restriction! 041 */ 042 public TransactionManagerImplGBean(int defaultTransactionTimeoutSeconds, XidFactory xidFactory, TransactionLog transactionLog, Collection resourceManagers) throws XAException { 043 super(defaultTransactionTimeoutSeconds, xidFactory, transactionLog, resourceManagers); 044 } 045 046 047 /** 048 * We can track as resources are added into the geronimo kernel. 049 * 050 * @param resourceManagers 051 * @return the original list of resources. 052 */ 053 protected List watchResourceManagers(Collection resourceManagers) { 054 if( resourceManagers instanceof ReferenceCollection ) { 055 List copy; 056 synchronized (resourceManagers) { 057 copy = new ArrayList(resourceManagers); 058 ((ReferenceCollection)resourceManagers).addReferenceCollectionListener(new ReferenceCollectionListener() { 059 public void memberAdded(ReferenceCollectionEvent event) { 060 ResourceManager resourceManager = (ResourceManager) event.getMember(); 061 recoverResourceManager(resourceManager); 062 } 063 064 public void memberRemoved(ReferenceCollectionEvent event) { 065 } 066 067 }); 068 } 069 return copy; 070 } else { 071 return super.watchResourceManagers(resourceManagers); 072 } 073 } 074 075 public static final GBeanInfo GBEAN_INFO; 076 077 static { 078 GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(TransactionManagerImplGBean.class, NameFactory.TRANSACTION_MANAGER); 079 080 infoBuilder.addAttribute("defaultTransactionTimeoutSeconds", int.class, true); 081 infoBuilder.addReference("XidFactory", XidFactory.class, NameFactory.XID_FACTORY); 082 infoBuilder.addReference("TransactionLog", TransactionLog.class, NameFactory.TRANSACTION_LOG); 083 infoBuilder.addReference("ResourceManagers", ResourceManager.class);//two kinds of things, so specify the type in each pattern. 084 085 infoBuilder.setConstructor(new String[]{ 086 "defaultTransactionTimeoutSeconds", 087 "XidFactory", 088 "TransactionLog", 089 "ResourceManagers"}); 090 091 GBEAN_INFO = infoBuilder.getBeanInfo(); 092 } 093 094 095 public static GBeanInfo getGBeanInfo() { 096 return GBEAN_INFO; 097 } 098 }