001    /**
002     *  Licensed to the Apache Software Foundation (ASF) under one or more
003     *  contributor license agreements.  See the NOTICE file distributed with
004     *  this work for additional information regarding copyright ownership.
005     *  The ASF licenses this file to You under the Apache License, Version 2.0
006     *  (the "License"); you may not use this file except in compliance with
007     *  the License.  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.connector.outbound.connectiontracking;
019    
020    import org.apache.geronimo.gbean.GBeanInfo;
021    import org.apache.geronimo.gbean.GBeanInfoBuilder;
022    import org.apache.geronimo.gbean.GBeanLifecycle;
023    import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
024    import org.apache.geronimo.transaction.manager.MonitorableTransactionManager;
025    
026    /**
027     * 
028     * @version $Revision: 494503 $
029     */
030    public class ConnectionTrackingCoordinatorGBean extends ConnectionTrackingCoordinator implements GBeanLifecycle {
031        private final MonitorableTransactionManager monitorableTm;
032        private final GeronimoTransactionListener listener;
033    
034        public ConnectionTrackingCoordinatorGBean(MonitorableTransactionManager monitorableTm, boolean lazyConnect) {
035            super(lazyConnect);
036            this.monitorableTm = monitorableTm;
037            listener = new GeronimoTransactionListener(this);
038        }
039    
040        public void doStart() throws Exception {
041            monitorableTm.addTransactionAssociationListener(listener);
042        }
043    
044        public void doStop() throws Exception {
045            monitorableTm.removeTransactionAssociationListener(listener);
046        }
047    
048        public void doFail() {
049            monitorableTm.removeTransactionAssociationListener(listener);
050        }
051    
052        public final static GBeanInfo GBEAN_INFO;
053    
054        static {
055            GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(ConnectionTrackingCoordinatorGBean.class, NameFactory.JCA_CONNECTION_TRACKER);
056    
057            infoFactory.addReference("TransactionManager", MonitorableTransactionManager.class, NameFactory.TRANSACTION_MANAGER);
058            infoFactory.addAttribute("lazyConnect", boolean.class, true);
059    
060            infoFactory.addInterface(TrackedConnectionAssociator.class);
061            infoFactory.addInterface(ConnectionTracker.class);
062    
063            infoFactory.setConstructor(new String[] {"TransactionManager", "lazyConnect"});
064            GBEAN_INFO = infoFactory.getBeanInfo();
065        }
066    
067        public static GBeanInfo getGBeanInfo() {
068            return GBEAN_INFO;
069        }
070    
071    }