001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: package com.sun.xml.ws.tx.common;
038:
039: import com.sun.enterprise.transaction.TransactionImport;
040: import java.util.logging.Level;
041: import javax.resource.spi.XATerminator;
042: import javax.transaction.SystemException;
043: import javax.transaction.xa.Xid;
044:
045: /**
046: * Access Transaction Inflow Contract from Java Connector 1.5 API.
047: * Assumption is the underlying TransactionManager is implementing this
048: * interface.
049: *
050: * Separate this from TransactionManagerImpl since this provides mostly service side assistance.
051: * Assists in supporting application client and standalone client to separate from more commonly
052: * used methods in TransactionManagerImpl.
053: */
054: public class TransactionImportManager implements TransactionImport {
055:
056: final static private TxLogger logger = TxLogger
057: .getATLogger(TransactionManagerImpl.class);
058:
059: static final TransactionImport instance = new TransactionImportManager();
060: static private TransactionImport javaeeTM;
061:
062: private TransactionImportManager() {
063: try {
064: javaeeTM = (TransactionImport) TransactionManagerImpl
065: .getInstance().getTransactionManager();
066: } catch (ClassCastException cce) {
067: final String CLASSNAME = javaeeTM == null ? "null"
068: : javaeeTM.getClass().getName();
069: logger.severe("TransactionImportManager",
070: LocalizationMessages.NO_TXN_IMPORT_2014(CLASSNAME),
071: cce);
072: }
073: }
074:
075: public static TransactionImport getInstance() {
076: return instance;
077: }
078:
079: /**
080: * Recreate a transaction based on the Xid. This call causes the calling
081: * thread to be associated with the specified transaction.
082: * <p/>
083: *
084: * @param xid the Xid object representing a transaction.
085: */
086: public void recreate(final Xid xid, final long timeout) {
087: javaeeTM.recreate(xid, timeout);
088: }
089:
090: /**
091: * Release a transaction. This call causes the calling thread to be
092: * dissociated from the specified transaction.
093: *
094: * @param xid the Xid object representing a transaction.
095: */
096: public void release(final Xid xid) {
097: javaeeTM.release(xid);
098: }
099:
100: /**
101: * Used to import an external transaction into Java EE TM.
102: */
103: public XATerminator getXATerminator() {
104: return javaeeTM.getXATerminator();
105: }
106:
107: /**
108: * Returns in seconds duration till current transaction times out.
109: * Returns negative value if transaction has already timedout.
110: * Returns 0 if there is no timeout.
111: * Returns 0 if any exceptions occur looking up remaining transaction timeout.
112: */
113: public int getTransactionRemainingTimeout() throws SystemException {
114: final String METHOD = "getRemainingTimeout";
115: int result = 0;
116: try {
117: result = javaeeTM.getTransactionRemainingTimeout();
118: } catch (IllegalStateException ise) {
119: if (logger.isLogging(Level.FINEST)) {
120: logger
121: .finest(
122: METHOD,
123: "looking up remaining txn timeout, no current transaction",
124: ise);
125: } else {
126: logger.info(METHOD, LocalizationMessages
127: .TXN_MGR_OPERATION_FAILED_2008(
128: "getTransactionRemainingTimeout", ise
129: .getLocalizedMessage()));
130: }
131: } catch (Throwable t) {
132: if (logger.isLogging(Level.FINEST)) {
133: logger.finest(METHOD, "ignoring exception "
134: + t.getClass().getName() + " thrown calling"
135: + "TM.getTransactionRemainingTimeout method");
136: } else {
137: logger.info(METHOD, LocalizationMessages
138: .TXN_MGR_OPERATION_FAILED_2008(
139: "getTransactionRemainingTimeout", t
140: .getLocalizedMessage()));
141:
142: }
143: }
144: return result;
145: }
146: }
|