ws-kandula-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dasar...@apache.org
Subject svn commit: r360232 - in /webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/j2ee: Bridge.java Mediator.java
Date Sat, 31 Dec 2005 03:58:03 GMT
Author: dasarath
Date: Fri Dec 30 19:58:01 2005
New Revision: 360232

URL: http://svn.apache.org/viewcvs?rev=360232&view=rev
Log: (empty)

Modified:
    webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/j2ee/Bridge.java
    webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/j2ee/Mediator.java

Modified: webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/j2ee/Bridge.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/j2ee/Bridge.java?rev=360232&r1=360231&r2=360232&view=diff
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/j2ee/Bridge.java
(original)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/j2ee/Bridge.java
Fri Dec 30 19:58:01 2005
@@ -24,7 +24,7 @@
 
 	private static Bridge instance = new Bridge();
 
-	private static final int TIMEOUT = 60 * 60;
+	private static final int TIMEOUT_S = 60 * 60;
 
 	public static Bridge getInstance() {
 		return instance;
@@ -36,7 +36,7 @@
 
 	private Bridge() {
 		try {
-			tm = new TransactionManagerImpl(TIMEOUT, null, null);
+			tm = new TransactionManagerImpl(TIMEOUT_S, null, null);
 		} catch (XAException e) {
 			e.printStackTrace();
 			throw new RuntimeException(e);
@@ -79,9 +79,5 @@
 
 	public void forget(String id) {
 		inM.remove(id);
-	}
-
-	public boolean isMapped(String id) {
-		return inM.containsKey(id);
 	}
 }

Modified: webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/j2ee/Mediator.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/j2ee/Mediator.java?rev=360232&r1=360231&r2=360232&view=diff
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/j2ee/Mediator.java
(original)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/j2ee/Mediator.java
Fri Dec 30 19:58:01 2005
@@ -7,26 +7,23 @@
 import java.rmi.RemoteException;
 
 import javax.transaction.Status;
+import javax.transaction.SystemException;
 import javax.transaction.Transaction;
 import javax.transaction.xa.XAException;
 import javax.transaction.xa.XAResource;
 import javax.transaction.xa.Xid;
 
-import org.apache.axis.message.addressing.EndpointReference;
 import org.apache.geronimo.transaction.manager.NamedXAResource;
 import org.apache.geronimo.transaction.manager.TransactionManagerImpl;
 import org.apache.ws.transaction.coordinator.CoordinationContext;
-import org.apache.ws.transaction.coordinator.ParticipantService;
-import org.apache.ws.transaction.coordinator.at.ATCoordinator;
-import org.apache.ws.transaction.coordinator.at.CoordinatorStub;
-import org.apache.ws.transaction.wsat.Notification;
-import org.apache.ws.transaction.wsat.ParticipantPortType;
+import org.apache.ws.transaction.coordinator.at.AT2PCStatus;
+import org.apache.ws.transaction.coordinator.at.BasicParticipant;
 
 /**
  * @author Dasarath Weeratunge
  *  
  */
-public class Mediator implements ParticipantPortType, NamedXAResource {
+public class Mediator extends BasicParticipant implements NamedXAResource {
 
 	private int timeout = Integer.MAX_VALUE;
 
@@ -34,19 +31,17 @@
 
 	private Transaction tx;
 
-	private EndpointReference c;
-
 	private Bridge bridge = Bridge.getInstance();
 
 	private TransactionManagerImpl tm = (TransactionManagerImpl) bridge.getTM();
 
+	private boolean bridged = true;
+
 	public Mediator(Transaction tx, CoordinationContext ctx)
 			throws RemoteException {
+		super(true, ctx);
 		id = ctx.getIdentifier().toString();
 		this.tx = tx;
-		EndpointReference epr = ParticipantService.getInstance().getParticipantService(
-			this);
-		c = ctx.register(ATCoordinator.PROTOCOL_ID_DURABLE_2PC, epr);
 		try {
 			tx.enlistResource(this);
 		} catch (Exception e) {
@@ -55,11 +50,13 @@
 	}
 
 	public void commit(Xid arg0, boolean arg1) throws XAException {
-		if (bridge.isMapped(id))
+		if (bridged) {
+			forget();
 			try {
-				new CoordinatorStub(c).committedOperation(null);
+				getCoordinator().committedOperation(null);
 			} catch (Exception e) {
 			}
+		}
 	}
 
 	public void end(Xid arg0, int arg1) throws XAException {
@@ -76,14 +73,15 @@
 		return timeout;
 	}
 
-	public boolean isSameRM(XAResource arg0) throws XAException {
-		return this == arg0;
+	public boolean isSameRM(XAResource rm) throws XAException {
+		return this == rm;
 	}
 
 	public int prepare(Xid arg0) throws XAException {
-		if (bridge.isMapped(id)) {
+		if (bridged) {
+			forget();
 			try {
-				new CoordinatorStub(c).abortedOperation(null);
+				getCoordinator().abortedOperation(null);
 			} catch (Exception e) {
 			}
 			throw new XAException();
@@ -96,111 +94,74 @@
 	}
 
 	public void rollback(Xid arg0) throws XAException {
-		if (bridge.isMapped(id))
+		if (bridged) {
+			forget();
 			try {
-				new CoordinatorStub(c).abortedOperation(null);
+				getCoordinator().abortedOperation(null);
 			} catch (Exception e) {
 			}
+		}
 	}
 
-	public boolean setTransactionTimeout(int arg0) throws XAException {
-		timeout = arg0;
-		return false;
+	public boolean setTransactionTimeout(int timeout) throws XAException {
+		this.timeout = timeout;
+		return true;
 	}
 
 	public void start(Xid arg0, int arg1) throws XAException {
 	}
 
-	public synchronized void commitOperation(Notification parameters)
-			throws RemoteException {
-		done();
-		try {
-			tm.commit(tx, false);
-			new CoordinatorStub(c).committedOperation(null);
-		} catch (RemoteException e) {
-			e.printStackTrace();
-			throw e;
-		} catch (Exception e) {
-			e.printStackTrace();
-			throw new RemoteException(e.getMessage());
-		}
+	protected int prepare() throws XAException {
+		forget();
+		return tm.prepare(tx);
 	}
 
-	private void done() {
-		ParticipantService.getInstance().forget(this);
+	protected void commit() throws XAException {
+		tm.commit(tx, false);
 	}
 
-	public synchronized void prepareOperation(Notification parameters)
-			throws RemoteException {
-		try {
-			bridge.forget(id);
-			CoordinatorStub p = new CoordinatorStub(c);
-			int status = tx.getStatus();
-			switch (status) {
-			case Status.STATUS_ACTIVE:
-				try {
-					if (tm.prepare(tx) == XAResource.XA_RDONLY) {
-						done();
-						p.readOnlyOperation(null);
-					} else
-						p.preparedOperation(null);
-					return;
-				} catch (XAException e) {
-					done();
-					p.abortedOperation(null);
-					return;
-				}
+	protected void rollback() throws XAException {
+		tm.rollback(tx);
+	}
 
-			case Status.STATUS_COMMITTED:
-			case Status.STATUS_COMMITTING:
-				p.committedOperation(null);
-				return;
+	protected void forget() {
+		if (bridged) {
+			bridge.forget(id);
+			bridged = false;
+		}
+	}
 
+	protected int getStatus() {
+		try {
+			switch (tm.getStatus()) {
+			case Status.STATUS_ACTIVE:
 			case Status.STATUS_MARKED_ROLLBACK:
-				done();
-				p.abortedOperation(null);
-				tx.rollback();
-				return;
+				return AT2PCStatus.ACTIVE;
+
+			case Status.STATUS_PREPARING:
+				return AT2PCStatus.PREPARING;
 
-			case Status.STATUS_ROLLEDBACK:
 			case Status.STATUS_ROLLING_BACK:
-				done();
-				p.abortedOperation(null);
-				return;
+			case Status.STATUS_ROLLEDBACK:
+				return AT2PCStatus.ABORTING;
 
 			case Status.STATUS_PREPARED:
-				p.preparedOperation(null);
-				return;
+				return AT2PCStatus.PREPARED;
 
-			case Status.STATUS_PREPARING:
-				return;
+			case Status.STATUS_COMMITTING:
+			case Status.STATUS_COMMITTED:
+				return AT2PCStatus.COMMITTING;
 
 			case Status.STATUS_NO_TRANSACTION:
+				return AT2PCStatus.NONE;
+
 			case Status.STATUS_UNKNOWN:
-				done();
-				p.abortedOperation(null);
-				return;
+			default:
+				throw new RuntimeException();
 			}
-		} catch (Exception e) {
+		} catch (SystemException e) {
 			e.printStackTrace();
-			throw new RemoteException(e.getMessage());
-		}
-	}
-
-	public synchronized void rollbackOperation(Notification parameters)
-			throws RemoteException {
-		bridge.forget(id);
-		done();
-		try {
-			tx.rollback();
-			new CoordinatorStub(c).abortedOperation(null);
-		} catch (RemoteException e) {
-			e.printStackTrace();
-			throw e;
-		} catch (Exception e) {
-			e.printStackTrace();
-			throw new RemoteException(e.getMessage());
+			throw new RuntimeException(e);
 		}
 	}
-
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: kandula-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: kandula-dev-help@ws.apache.org


Mime
View raw message