001 /**
002 *
003 * Copyright 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 * Used to provide the GBean metadata for the GeronimoTransactionManager class
034 *
035 * @version $Rev: 430508 $ $Date: 2006-08-10 12:56:47 -0700 (Thu, 10 Aug 2006) $
036 */
037 public class GeronimoTransactionManagerGBean extends GeronimoTransactionManager {
038
039 /**
040 * TODO NOTE!!! this should be called in an unspecified transaction context, but we cannot enforce this restriction!
041 */
042 public GeronimoTransactionManagerGBean(int defaultTransactionTimeoutSeconds, XidFactory xidFactory, TransactionLog transactionLog, Collection resourceManagers) throws XAException {
043 super(defaultTransactionTimeoutSeconds == 0 ? DEFAULT_TIMEOUT : defaultTransactionTimeoutSeconds,
044 xidFactory,
045 transactionLog,
046 resourceManagers);
047 }
048
049
050 /**
051 * We can track as resources are added into the geronimo kernel.
052 *
053 * @param resourceManagers
054 * @return the original list of resources.
055 */
056 protected List watchResourceManagers(Collection resourceManagers) {
057 if( resourceManagers instanceof ReferenceCollection ) {
058 List copy;
059 synchronized (resourceManagers) {
060 copy = new ArrayList(resourceManagers);
061 ((ReferenceCollection)resourceManagers).addReferenceCollectionListener(new ReferenceCollectionListener() {
062 public void memberAdded(ReferenceCollectionEvent event) {
063 ResourceManager resourceManager = (ResourceManager) event.getMember();
064 recoverResourceManager(resourceManager);
065 }
066
067 public void memberRemoved(ReferenceCollectionEvent event) {
068 }
069
070 });
071 }
072 return copy;
073 } else {
074 return super.watchResourceManagers(resourceManagers);
075 }
076 }
077
078 public static final GBeanInfo GBEAN_INFO;
079
080 static {
081 GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(GeronimoTransactionManagerGBean.class,
082 TransactionManagerImplGBean.GBEAN_INFO,
083 NameFactory.TRANSACTION_MANAGER);
084 GBEAN_INFO = infoFactory.getBeanInfo();
085 }
086
087 public static GBeanInfo getGBeanInfo() {
088 return GBEAN_INFO;
089 }
090
091 }