001: /*
002: * @(#) RmRegistration.java
003: *
004: * JOTM: Java Open Transaction Manager
005: *
006: *
007: * This module was originally developed by
008: *
009: * - Bull S.A. as part of the JOnAS application server code released in
010: * July 1999 (www.bull.com)
011: *
012: * --------------------------------------------------------------------------
013: * The original code and portions created by Bull SA are
014: * Copyright (c) 1999 BULL SA
015: * All rights reserved.
016: *
017: * Redistribution and use in source and binary forms, with or without
018: * modification, are permitted provided that the following conditions are met:
019: *
020: * -Redistributions of source code must retain the above copyright notice, this
021: * list of conditions and the following disclaimer.
022: *
023: * -Redistributions in binary form must reproduce the above copyright notice,
024: * this list of conditions and the following disclaimer in the documentation
025: * and/or other materials provided with the distribution.
026: *
027: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
028: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
029: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
030: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
031: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
032: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
033: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
034: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
035: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
036: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
037: * POSSIBILITY OF SUCH DAMAGE.
038: *
039: * --------------------------------------------------------------------------
040: * $Id: RmRegistration.java,v 1.3 2005/05/03 23:20:17 tonyortiz Exp $
041: * --------------------------------------------------------------------------
042: */
043: package org.objectweb.jotm;
044:
045: import javax.transaction.xa.XAResource;
046: import javax.transaction.xa.XAException;
047:
048: /**
049: * Resource Managers currently registered.
050: *
051: * @author Tony Ortiz
052: *
053: */
054:
055: public class RmRegistration {
056:
057: private String rmName = null;
058: private XAResource rmXares = null;
059: private String rmXaName = null;
060: private boolean rmReference = false;
061: private String rmReferenceName = "";
062:
063: public void rmAddRegistration(String prmName, XAResource prmXares,
064: String prmxaName) {
065: if (TraceTm.recovery.isDebugEnabled()) {
066: TraceTm.recovery
067: .debug("Add registration Resource manager= "
068: + prmName);
069: TraceTm.recovery.debug("Add registration XAResource = "
070: + prmXares);
071: TraceTm.recovery
072: .debug("Add registration XAResource Name = "
073: + prmxaName);
074: }
075:
076: rmName = prmName;
077: rmXares = prmXares;
078: rmXaName = prmxaName;
079: }
080:
081: public void rmAddName(String prmName) {
082: rmName = prmName;
083: }
084:
085: public void rmAddXaRes(XAResource prmXares) {
086: rmXares = prmXares;
087: }
088:
089: public String rmGetName() {
090: if (TraceTm.recovery.isDebugEnabled()) {
091: TraceTm.recovery.debug("rmName= " + rmName);
092: }
093: return rmName;
094: }
095:
096: public XAResource rmGetXaRes() {
097: if (TraceTm.recovery.isDebugEnabled()) {
098: TraceTm.recovery.debug("rmXares= " + rmXares);
099: }
100: return rmXares;
101: }
102:
103: public String rmGetXaResName() {
104: if (TraceTm.recovery.isDebugEnabled()) {
105: TraceTm.recovery.debug("rmXaName= " + rmXaName);
106: }
107: return rmXaName;
108: }
109:
110: public XAResource rmCheckoutXARes() throws XAException {
111: if (TraceTm.recovery.isDebugEnabled()) {
112: TraceTm.recovery.debug("rmCheckoutXares= " + rmXares);
113: }
114:
115: if (rmXares == null) {
116: throw new XAException(
117: "Attempt to use unregistered Resource Manager");
118: }
119:
120: synchronized (this ) {
121: while (true) {
122: if (rmReference == false) {
123: rmReferenceName = Thread.currentThread().getName();
124: rmReference = true;
125: return rmXares;
126: }
127: try {
128: wait();
129: } catch (InterruptedException e) {
130: ;
131: }
132: }
133: }
134: }
135:
136: public void rmCheckinXARes() {
137: if (TraceTm.recovery.isDebugEnabled()) {
138: TraceTm.recovery.debug("rmCheckinXares= " + rmXares);
139: }
140:
141: synchronized (this ) {
142: rmReference = false; // leave the name with the last using thread
143: notifyAll();
144: }
145: }
146: }
|