You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fx-dev@ws.apache.org by da...@apache.org on 2005/12/31 04:59:44 UTC

svn commit: r360234 - in /webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/utility: Callback.java TransactionImpl.java TransactionManagerImpl.java TxHandler.java

Author: dasarath
Date: Fri Dec 30 19:59:42 2005
New Revision: 360234

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

Added:
    webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/utility/Callback.java
    webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/utility/TransactionImpl.java
    webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/utility/TransactionManagerImpl.java
    webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/utility/TxHandler.java

Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/utility/Callback.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/utility/Callback.java?rev=360234&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/utility/Callback.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/utility/Callback.java Fri Dec 30 19:59:42 2005
@@ -0,0 +1,15 @@
+/*
+ * Created on Dec 30, 2005
+ *
+ */
+package org.apache.ws.transaction.utility;
+
+/**
+ * @author Dasarath Weeratunge
+ *  
+ */
+public interface Callback {
+
+	void timeout();
+
+}
\ No newline at end of file

Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/utility/TransactionImpl.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/utility/TransactionImpl.java?rev=360234&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/utility/TransactionImpl.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/utility/TransactionImpl.java Fri Dec 30 19:59:42 2005
@@ -0,0 +1,128 @@
+/*
+ * Copyright  2004 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.ws.transaction.utility;
+
+import java.rmi.RemoteException;
+
+import javax.transaction.RollbackException;
+
+import org.apache.axis.message.addressing.EndpointReference;
+import org.apache.ws.transaction.coordinator.CoordinationContext;
+import org.apache.ws.transaction.coordinator.ParticipantService;
+import org.apache.ws.transaction.coordinator.TimedOutException;
+import org.apache.ws.transaction.coordinator.at.ATCoordinator;
+import org.apache.ws.transaction.coordinator.at.CompletionCoordinatorStub;
+import org.apache.ws.transaction.wsat.CompletionInitiatorPortType;
+import org.apache.ws.transaction.wsat.Notification;
+import org.apache.ws.transaction.wscoor.Expires;
+
+/**
+ * @author Dasarath Weeratunge
+ */
+public class TransactionImpl {
+	private CoordinationContext ctx;
+
+	private EndpointReference epr;
+
+	private CompletionInitiatorCallback callback;
+
+	private boolean aborted = false;
+
+	private boolean committed = false;
+
+	private boolean timedOut = false;
+
+	public TransactionImpl(CoordinationContext ctx) throws RemoteException {
+		this.ctx = ctx;
+		long timeout = 0;
+		Expires ex = ctx.getExpires();
+		if (ex != null)
+			timeout = ex.get_value().longValue();
+		callback = new CompletionInitiatorCallback();
+		epr = ctx.register(ATCoordinator.PROTOCOL_ID_COMPLETION,
+			ParticipantService.getInstance().getCompletionInitiatorService(
+				callback, timeout));
+	}
+
+	private class CompletionInitiatorCallback implements
+			CompletionInitiatorPortType, Callback {
+		public synchronized void committedOperation(Notification parameters)
+				throws RemoteException {
+			committed = true;
+			notify();
+		}
+
+		public synchronized void abortedOperation(Notification parameters)
+				throws RemoteException {
+			aborted = true;
+			notify();
+		}
+
+		public synchronized void timeout() {
+			timedOut = true;
+			notify();
+		}
+	}
+
+	public CoordinationContext getCoordinationContex() {
+		return ctx;
+	}
+
+	public void rollback() throws RemoteException {
+		try {
+			synchronized (callback) {
+				if (aborted)
+					return;
+				if (committed)
+					throw new IllegalStateException();
+				new CompletionCoordinatorStub(epr).rollbackOperation(null);
+				callback.wait();
+			}
+			if (timedOut)
+				throw new TimedOutException();
+			if (!aborted)
+				throw new RollbackException();
+		} catch (RemoteException e) {
+			throw e;
+		} catch (Exception e) {
+			e.printStackTrace();
+			throw new RuntimeException(e);
+		}
+	}
+
+	public void commit() throws RemoteException {
+		try {
+			synchronized (callback) {
+				if (committed)
+					return;
+				if (aborted)
+					throw new IllegalStateException();
+				new CompletionCoordinatorStub(epr).commitOperation(null);
+				callback.wait();
+			}
+			if (timedOut)
+				throw new TimedOutException();
+			if (!committed)
+				throw new RollbackException();
+		} catch (RemoteException e) {
+			throw e;
+		} catch (Exception e) {
+			e.printStackTrace();
+			throw new RuntimeException(e);
+		}
+	}
+}
\ No newline at end of file

Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/utility/TransactionManagerImpl.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/utility/TransactionManagerImpl.java?rev=360234&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/utility/TransactionManagerImpl.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/utility/TransactionManagerImpl.java Fri Dec 30 19:59:42 2005
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ *  
+ */
+package org.apache.ws.transaction.utility;
+
+import java.rmi.RemoteException;
+
+import org.apache.axis.message.addressing.EndpointReference;
+import org.apache.ws.transaction.coordinator.ActivationStub;
+import org.apache.ws.transaction.coordinator.CoordinationContext;
+import org.apache.ws.transaction.coordinator.CoordinationService;
+import org.apache.ws.transaction.coordinator.at.ATCoordinator;
+
+public class TransactionManagerImpl {
+	private static TransactionManagerImpl instance = new TransactionManagerImpl();
+
+	private static ThreadLocal threadInfo = new ThreadLocal();
+
+	public static TransactionManagerImpl getInstance() {
+		return instance;
+	}
+
+	private TransactionManagerImpl() {
+	}
+
+	public void begin() throws RemoteException {
+		begin(CoordinationService.getInstance().getActivationService());
+	}
+
+	public void begin(EndpointReference epr) throws RemoteException {
+		if (threadInfo.get() != null)
+			throw new IllegalStateException();
+		CoordinationContext ctx;
+		try {
+			ctx = new ActivationStub(epr).createCoordinationContext(ATCoordinator.COORDINATION_TYPE_ID);
+			threadInfo.set(new TransactionImpl(ctx));
+		} catch (RemoteException e) {
+			throw e;
+		} catch (Exception e) {
+			e.printStackTrace();
+			throw new RuntimeException(e);
+		}
+	}
+
+	public void commit() throws RemoteException {
+		TransactionImpl tx = getTransaction();
+		if (tx == null)
+			throw new IllegalStateException();
+		forget();
+		tx.commit();
+	}
+
+	public void rollback() throws RemoteException {
+		TransactionImpl tx = getTransaction();
+		if (tx == null)
+			throw new IllegalStateException();
+		forget();
+		tx.rollback();
+	}
+
+	public TransactionImpl suspend() {
+		TransactionImpl tx = getTransaction();
+		forget();
+		return tx;
+	}
+
+	public void resume(TransactionImpl tx) {
+		if (threadInfo.get() != null)
+			throw new IllegalStateException();
+		threadInfo.set(tx);
+	}
+
+	public void forget() {
+		threadInfo.set(null);
+	}
+
+	public TransactionImpl getTransaction() {
+		return (TransactionImpl) threadInfo.get();
+	}
+}
\ No newline at end of file

Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/utility/TxHandler.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/utility/TxHandler.java?rev=360234&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/utility/TxHandler.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/utility/TxHandler.java Fri Dec 30 19:59:42 2005
@@ -0,0 +1,42 @@
+/*
+ * Copyright  2004 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.ws.transaction.utility;
+
+import javax.xml.soap.SOAPHeader;
+
+import org.apache.axis.AxisFault;
+import org.apache.axis.MessageContext;
+import org.apache.axis.handlers.BasicHandler;
+
+/**
+ * @author Dasarath Weeratunge
+ */
+public class TxHandler extends BasicHandler {
+	TransactionManagerImpl tm = TransactionManagerImpl.getInstance();
+
+	public void invoke(MessageContext msgContext) throws AxisFault {
+		TransactionImpl tx = tm.getTransaction();
+		if (tx != null) {
+			try {
+				SOAPHeader header = msgContext.getCurrentMessage().getSOAPEnvelope().getHeader();
+				tx.getCoordinationContex().toSOAPHeaderElement(header);
+			} catch (Exception e) {
+				throw AxisFault.makeFault(e);
+			}
+		}
+	}
+}
\ No newline at end of file



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