You are viewing a plain text version of this content. The canonical link for it is here.
Posted to kandula-dev@ws.apache.org by da...@apache.org on 2006/01/13 23:58:12 UTC

svn commit: r368901 [1/2] - in /webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula: ./ coordinator/ coordinator/at/ geronimo/ utils/

Author: dasarath
Date: Fri Jan 13 14:58:04 2006
New Revision: 368901

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

Added:
    webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/
    webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/KandulaConfig.java
    webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/
    webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/ActivationImpl.java
    webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/ActivationStub.java
    webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/Callback.java
    webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/CallbackRegistry.java
    webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/CoordinationContext.java
    webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/CoordinationService.java
    webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/Coordinator.java
    webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/CoordinatorImpl.java
    webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/FaultDispatcher.java
    webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/InvalidCoordinationProtocolException.java
    webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/RegistrationImpl.java
    webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/RegistrationStub.java
    webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/TimedOutException.java
    webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/UnsupportedCoordinationTypeException.java
    webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/
    webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/AT2PCStatus.java
    webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/ATCoordinator.java
    webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/ATCoordinatorImpl.java
    webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/AbstractParticipant.java
    webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/CompletionCoordinatorImpl.java
    webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/CompletionCoordinatorStub.java
    webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/CompletionInitiatorImpl.java
    webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/CompletionInitiatorStub.java
    webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/CoordinatorImpl.java
    webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/CoordinatorStub.java
    webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/ParticipantImpl.java
    webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/ParticipantStub.java
    webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/TransactionImpl.java
    webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/TransactionManagerImpl.java
    webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/TxHandler.java
    webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/geronimo/
    webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/geronimo/Bridge.java
    webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/geronimo/Mediator.java
    webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/geronimo/TxHandler.java
    webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/utils/
    webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/utils/AddressingHeaders.java
    webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/utils/Service.java
    webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/utils/SoapFaultSender.java
    webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/utils/TCPSnifferHelper.java

Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/KandulaConfig.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/KandulaConfig.java?rev=368901&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/KandulaConfig.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/KandulaConfig.java Fri Jan 13 14:58:04 2006
@@ -0,0 +1,51 @@
+/*
+ * Created on Jan 6, 2006
+ *
+ */
+package org.apache.kandula;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+/**
+ * @author Dasarath Weeratunge
+ *  
+ */
+public class KandulaConfig {
+
+	private static final String PROPERTY_FILE = "kandula.properties";
+
+	private static final String CONTEXT_PROPERTY = "kandula.context";
+
+	private static KandulaConfig instance = new KandulaConfig();
+
+	private Properties properties = null;
+
+	private KandulaConfig() {
+		properties = new Properties();
+		loadProperties();
+	}
+
+	public static KandulaConfig getInstance() {
+		return instance;
+	}
+
+	private void loadProperties() {
+		InputStream in = getClass().getClassLoader().getResourceAsStream(
+			PROPERTY_FILE);
+
+		try {
+			properties.load(in);
+			in.close();
+		} catch (IOException e) {
+			e.printStackTrace();
+			throw new RuntimeException(e);
+		}
+	}
+
+	public String getContext() {
+		return properties.getProperty(CONTEXT_PROPERTY);
+	}
+
+}
\ No newline at end of file

Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/ActivationImpl.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/ActivationImpl.java?rev=368901&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/ActivationImpl.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/ActivationImpl.java Fri Jan 13 14:58:04 2006
@@ -0,0 +1,32 @@
+/*
+ * 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.kandula.coordinator;
+
+import java.rmi.RemoteException;
+
+import org.apache.kandula.wscoor.ActivationPortTypeRPC;
+import org.apache.kandula.wscoor.CreateCoordinationContextResponseType;
+import org.apache.kandula.wscoor.CreateCoordinationContextType;
+
+public class ActivationImpl implements ActivationPortTypeRPC {
+
+	public CreateCoordinationContextResponseType createCoordinationContextOperation(
+			CreateCoordinationContextType params) throws RemoteException {
+		return CoordinationService.getInstance().createCoordinationContextOperation(
+			params);
+	}
+}
\ No newline at end of file

Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/ActivationStub.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/ActivationStub.java?rev=368901&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/ActivationStub.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/ActivationStub.java Fri Jan 13 14:58:04 2006
@@ -0,0 +1,56 @@
+/*
+ * 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.kandula.coordinator;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.rmi.RemoteException;
+
+import org.apache.axis.AxisFault;
+import org.apache.axis.message.addressing.EndpointReference;
+import org.apache.axis.types.URI;
+import org.apache.axis.types.URI.MalformedURIException;
+import org.apache.kandula.utils.AddressingHeaders;
+import org.apache.kandula.utils.Service;
+import org.apache.kandula.utils.TCPSnifferHelper;
+import org.apache.kandula.wscoor.ActivationPortTypeRPCBindingStub;
+import org.apache.kandula.wscoor.CreateCoordinationContextResponseType;
+import org.apache.kandula.wscoor.CreateCoordinationContextType;
+
+/**
+ * @author Dasarath Weeratunge
+ * 
+ * Created on Jun 14, 2004
+ */
+public class ActivationStub extends ActivationPortTypeRPCBindingStub {
+
+	public ActivationStub(EndpointReference epr) throws AxisFault,
+			MalformedURLException {
+		super(new URL(TCPSnifferHelper.redirect(epr.getAddress().toString())),
+				new Service());
+		AddressingHeaders headers = new AddressingHeaders(epr, null);
+		((Service) service).setAddressingHeaders(headers);
+	}
+
+	public CoordinationContext createCoordinationContext(String coordinationType)
+			throws RemoteException, MalformedURIException {
+		CreateCoordinationContextType params = new CreateCoordinationContextType();
+		params.setCoordinationType(new URI(coordinationType));
+		CreateCoordinationContextResponseType response = createCoordinationContextOperation(params);
+		return new CoordinationContext(response.getCoordinationContext());
+	}
+}
\ No newline at end of file

Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/Callback.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/Callback.java?rev=368901&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/Callback.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/Callback.java Fri Jan 13 14:58:04 2006
@@ -0,0 +1,28 @@
+/*
+ * Created on Dec 30, 2005
+ *
+ */
+package org.apache.kandula.coordinator;
+
+import javax.xml.soap.Name;
+
+import org.apache.axis.message.addressing.EndpointReference;
+
+
+
+
+/**
+ * @author Dasarath Weeratunge
+ *  
+ */
+public interface Callback {
+	
+	String getID();
+	
+	void onFault(Name code);
+
+	void timeout() throws TimedOutException;
+	
+	EndpointReference getEndpointReference();
+
+}
\ No newline at end of file

Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/CallbackRegistry.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/CallbackRegistry.java?rev=368901&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/CallbackRegistry.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/CallbackRegistry.java Fri Jan 13 14:58:04 2006
@@ -0,0 +1,103 @@
+/*
+ * Created on Dec 24, 2005
+ *
+ */
+package org.apache.kandula.coordinator;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.Timer;
+import java.util.TimerTask;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axis.MessageContext;
+import org.apache.axis.message.addressing.AddressingHeaders;
+import org.apache.axis.message.addressing.Constants;
+
+/**
+ * @author Dasarath Weeratunge
+ *  
+ */
+public class CallbackRegistry {
+
+	public static final QName CALLBACK_REF = new QName(
+			"http://ws.apache.org/kandula", "CallbackRef");
+
+	// FIXME:
+	public static final int DEFAULT_TIMEOUT_MILLIS = 180 * 1000;
+
+	private static Timer timer = new Timer();
+
+	private static final CallbackRegistry instance = new CallbackRegistry();
+
+	private Map callbacks = new HashMap();
+
+	protected CallbackRegistry() {
+	}
+
+	public static CallbackRegistry getInstance() {
+		return instance;
+	}
+
+	public synchronized void registerCallback(Callback callback) {
+		callbacks.put(callback.getID(), callback);
+	}
+
+	public synchronized void registerCallback(final Callback callback,
+			long timeout) {
+		callbacks.put(callback.getID(), callback);
+
+		if (timeout == 0)
+			timeout = DEFAULT_TIMEOUT_MILLIS;
+
+		System.out.println("[CallbackRegistry] registerCallback: timeout= "
+				+ timeout);
+
+		timer.schedule(new TimerTask() {
+			public void run() {
+				callbacks.remove(callback);
+				try {
+					callback.timeout();
+				} catch (TimedOutException e) {
+					e.printStackTrace();
+				}
+			}
+		}, timeout);
+	}
+
+	public synchronized Callback correlateMessage(QName q, boolean terminal) {
+		String s = getRef(q);
+		if (s == null)
+			return null;
+		else
+			return (Callback) callbacks.get(s);
+	}
+
+	private AddressingHeaders getAddressingHeaders() {
+		return (AddressingHeaders) MessageContext.getCurrentContext().getProperty(
+			Constants.ENV_ADDRESSING_REQUEST_HEADERS);
+	}
+
+	private String getRef(QName q) {
+		AddressingHeaders headers = getAddressingHeaders();
+		try {
+			return headers.getReferenceProperties().get(q).getValue();
+		} catch (NullPointerException e) {
+			return null;
+		}
+	}
+
+	public synchronized void remove(Object callback) {
+		Set s = new HashSet(callbacks.keySet());
+		Iterator iter = s.iterator();
+		while (iter.hasNext()) {
+			Object key = iter.next();
+			if (callbacks.get(key) == callback)
+				callbacks.remove(key);
+		}
+	}
+}
\ No newline at end of file

Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/CoordinationContext.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/CoordinationContext.java?rev=368901&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/CoordinationContext.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/CoordinationContext.java Fri Jan 13 14:58:04 2006
@@ -0,0 +1,140 @@
+/*
+ * 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.kandula.coordinator;
+
+import java.rmi.RemoteException;
+
+import javax.xml.soap.Name;
+import javax.xml.soap.SOAPElement;
+import javax.xml.soap.SOAPHeader;
+import javax.xml.soap.SOAPHeaderElement;
+
+import org.apache.axis.message.MessageElement;
+import org.apache.axis.message.PrefixedQName;
+import org.apache.axis.message.addressing.EndpointReference;
+import org.apache.axis.message.addressing.EndpointReferenceType;
+import org.apache.axis.message.addressing.util.TextExtractor;
+import org.apache.axis.types.URI;
+import org.apache.axis.types.URI.MalformedURIException;
+import org.apache.kandula.wscoor.CoordinationContextType;
+import org.apache.kandula.wscoor.CoordinationContextTypeIdentifier;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+public class CoordinationContext extends CoordinationContextType {
+	private static final Name COORDINATION_CONTEXT = new PrefixedQName(
+			"http://schemas.xmlsoap.org/ws/2004/10/wscoor",
+			"CoordinationContext", "wscoor");
+
+	private static final Name IDENTIFIER = new PrefixedQName(
+			"http://schemas.xmlsoap.org/ws/2004/10/wscoor", "Identifier",
+			"wscoor");
+
+	private static final Name COORDINATION_TYPE = new PrefixedQName(
+			"http://schemas.xmlsoap.org/ws/2004/10/wscoor", "CoordinationType",
+			"wscoor");
+
+	private static final Name REGISTRATION_SERVICE = new PrefixedQName(
+			"http://schemas.xmlsoap.org/ws/2004/10/wscoor",
+			"RegistrationService", "wscoor");
+
+	private static final Name ADDRESS = new PrefixedQName(
+			"http://schemas.xmlsoap.org/ws/2004/08/addressing", "Address",
+			"wsa");
+
+	private static final Name REFERENCE_PROPERTIES = new PrefixedQName(
+			"http://schemas.xmlsoap.org/ws/2004/08/addressing",
+			"ReferenceProperties", "wsa");
+
+	public CoordinationContext(CoordinationContextType c) {
+		this.set_any(c.get_any());
+		this.setCoordinationType(c.getCoordinationType());
+		this.setExpires(c.getExpires());
+		this.setIdentifier(c.getIdentifier());
+		this.setRegistrationService(c.getRegistrationService());
+	}
+
+	public CoordinationContext(String id, String coordinationType,
+			EndpointReference epr) throws MalformedURIException {
+		setIdentifier(new CoordinationContextTypeIdentifier(id));
+		setRegistrationService(epr);
+		setCoordinationType(new URI(coordinationType));
+	}
+
+	public CoordinationContext(SOAPElement el) {
+		try {
+			NodeList list = el.getElementsByTagNameNS(IDENTIFIER.getURI(),
+				IDENTIFIER.getLocalName());
+			Element node = (Element) list.item(0);
+			String s = TextExtractor.getText(node);
+			setIdentifier(new CoordinationContextTypeIdentifier(s));
+
+			list = el.getElementsByTagNameNS(COORDINATION_TYPE.getURI(),
+				COORDINATION_TYPE.getLocalName());
+			node = (Element) list.item(0);
+			setCoordinationType(new URI(TextExtractor.getText(node)));
+
+			list = el.getElementsByTagNameNS(REGISTRATION_SERVICE.getURI(),
+				REGISTRATION_SERVICE.getLocalName());
+			node = (Element) list.item(0);
+
+			EndpointReference epr = new EndpointReference(node);
+			setRegistrationService(epr);
+		} catch (Exception e) {
+			throw new IllegalArgumentException(e.toString());
+		}
+	}
+
+	public static boolean is(SOAPElement e) {
+		return e.getElementName().equals(COORDINATION_CONTEXT);
+	}
+
+	public void toSOAPHeaderElement(SOAPHeader header) {
+		try {
+			SOAPHeaderElement e = header.addHeaderElement(COORDINATION_CONTEXT);
+			e.addChildElement(IDENTIFIER).addTextNode(
+				getIdentifier().toString());
+			e.addChildElement(COORDINATION_TYPE).addTextNode(
+				getCoordinationType().toString());
+			SOAPElement e1 = e.addChildElement(REGISTRATION_SERVICE);
+			EndpointReferenceType epr = getRegistrationService();
+			e1.addChildElement(ADDRESS).addTextNode(epr.getAddress().toString());
+			SOAPElement e3 = e1.addChildElement(REFERENCE_PROPERTIES);
+			MessageElement[] e4 = epr.getProperties().get_any();
+			for (int ii = 0; ii < e4.length; ii++)
+				e3.addChildElement(e4[ii].getElementName()).addTextNode(
+					e4[ii].getValue());
+		} catch (Exception e) {
+			throw new RuntimeException(e);
+		}
+	}
+
+	public EndpointReference register(String p, EndpointReference epr)
+			throws RemoteException {
+		try {
+			RegistrationStub stub = new RegistrationStub(new EndpointReference(
+					getRegistrationService()));
+			return stub.registerOperation(p, epr);
+		} 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/kandula/coordinator/CoordinationService.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/CoordinationService.java?rev=368901&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/CoordinationService.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/CoordinationService.java Fri Jan 13 14:58:04 2006
@@ -0,0 +1,133 @@
+/*
+ * Created on Dec 25, 2005
+ *
+ */
+package org.apache.kandula.coordinator;
+
+import java.rmi.RemoteException;
+
+import org.apache.axis.message.MessageElement;
+import org.apache.axis.message.addressing.EndpointReference;
+import org.apache.axis.message.addressing.ReferencePropertiesType;
+import org.apache.axis.types.URI.MalformedURIException;
+import org.apache.kandula.KandulaConfig;
+import org.apache.kandula.coordinator.at.ATCoordinator;
+import org.apache.kandula.coordinator.at.ATCoordinatorImpl;
+import org.apache.kandula.coordinator.at.AbstractParticipant;
+import org.apache.kandula.wscoor.ActivationPortTypeRPC;
+import org.apache.kandula.wscoor.CreateCoordinationContextResponseType;
+import org.apache.kandula.wscoor.CreateCoordinationContextType;
+import org.apache.kandula.wscoor.Expires;
+
+/**
+ * @author Dasarath Weeratunge
+ *  
+ */
+public class CoordinationService implements ActivationPortTypeRPC {
+
+	private String context = KandulaConfig.getInstance().getContext();
+
+	private static CoordinationService instance = new CoordinationService();
+
+	public static CoordinationService getInstance() {
+		return instance;
+	}
+
+	private CoordinationService() {
+	}
+
+	private CoordinationContext createCoordinationContext(
+			String coordinationType, long timeout)
+			throws UnsupportedCoordinationTypeException, MalformedURIException {
+		if (!ATCoordinator.COORDINATION_TYPE_ID.equals(coordinationType))
+			throw new UnsupportedCoordinationTypeException();
+		Coordinator c = new ATCoordinatorImpl();
+		CallbackRegistry.getInstance().registerCallback(c, timeout);
+		return c.getCoordinationContext();
+	}
+
+	public EndpointReference getActivationCoordinatorService() {
+		return getEndpointReference(context + "activationCoordinator");
+	}
+
+	public EndpointReference getCompletionCoordinatorService(ATCoordinator c) {
+		return getEndpointReference(context + "completionCoordinator", c);
+	}
+
+	public EndpointReference getCoordinatorService(ATCoordinator c,
+			String participantRef) {
+		EndpointReference epr = getEndpointReference(context + "coordinator", c);
+		epr.getProperties().add(
+			new MessageElement(ATCoordinator.PARTICIPANT_REF, participantRef));
+		return epr;
+	}
+
+	public EndpointReference getRegistrationCoordinatorService(Coordinator c) {
+		return getEndpointReference(context + "registrationCoordinator", c);
+	}
+
+	public EndpointReference getCompletionInitiatorService(Callback callback,
+			long timeout) {
+		CallbackRegistry.getInstance().registerCallback(callback, timeout);
+		return getEndpointReference(context + "completionInitiator", callback);
+	}
+
+	public EndpointReference getFaultDispatcherService(Callback callback) {
+		return getEndpointReference(context + "faultDispatcher", callback);
+	}
+
+	public EndpointReference getFaultDispatcherService(Coordinator callback,
+			String participantRef) {
+		EndpointReference epr = getEndpointReference(context
+				+ "faultDispatcher", callback);
+		epr.getProperties().add(
+			new MessageElement(ATCoordinator.PARTICIPANT_REF, participantRef));
+		return epr;
+	}
+
+	public EndpointReference getParticipantService(
+			AbstractParticipant participant, long timeout) {
+		CallbackRegistry.getInstance().registerCallback(participant, timeout);
+		return getEndpointReference(context + "participant", participant);
+	}
+
+	private EndpointReference getEndpointReference(String uri) {
+		try {
+			return new EndpointReference(uri);
+		} catch (MalformedURIException e) {
+			e.printStackTrace();
+			throw new IllegalArgumentException();
+		}
+	}
+
+	private EndpointReference getEndpointReference(String uri, Callback callback) {
+		EndpointReference epr = getEndpointReference(uri);
+		ReferencePropertiesType r = new ReferencePropertiesType();
+		r.add(new MessageElement(CallbackRegistry.CALLBACK_REF,
+				callback.getID()));
+		epr.setProperties(r);
+		return epr;
+	}
+
+	public CreateCoordinationContextResponseType createCoordinationContextOperation(
+			CreateCoordinationContextType parameters) throws RemoteException {
+		String t = parameters.getCoordinationType().toString();
+		Expires ex = parameters.getExpires();
+		long timeout = 0;
+		if (ex != null)
+			timeout = ex.get_value().longValue() * 1000;
+		CoordinationContext ctx;
+		try {
+			ctx = createCoordinationContext(t, timeout);
+		} catch (MalformedURIException e) {
+			e.printStackTrace();
+			throw new RemoteException(e.toString());
+		} catch (UnsupportedCoordinationTypeException e) {
+			e.printStackTrace();
+			throw new RemoteException(e.toString());
+		}
+		CreateCoordinationContextResponseType r = new CreateCoordinationContextResponseType();
+		r.setCoordinationContext(ctx);
+		return r;
+	}
+}
\ No newline at end of file

Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/Coordinator.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/Coordinator.java?rev=368901&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/Coordinator.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/Coordinator.java Fri Jan 13 14:58:04 2006
@@ -0,0 +1,42 @@
+/*
+ * Created on Dec 23, 2005
+ *
+ */
+package org.apache.kandula.coordinator;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axis.AxisFault;
+import org.apache.kandula.wscoor.RegistrationPortTypeRPC;
+
+/**
+ * @author Dasarath Weeratunge
+ *  
+ */
+public interface Coordinator extends RegistrationPortTypeRPC, Callback {
+
+	AxisFault ALREADY_REGISTERED_SOAP_FAULT = new AxisFault(
+			new QName("http://schemas.xmlsoap.org/ws/2004/10/wscoor",
+					"AlreadyRegistered"),
+			"The participant has already registered for the same protocol.",
+			null, null);
+
+	AxisFault INVALID_PROTOCOL_SOAP_FAULT = new AxisFault(new QName(
+			"http://schemas.xmlsoap.org/ws/2004/10/wscoor", "InvalidProtocol"),
+			"The protocol is invalid or is not supported by the coordinator.",
+			null, null);
+
+	AxisFault INVALID_STATE_SOAP_FAULT = new AxisFault(new QName(
+			"http://schemas.xmlsoap.org/ws/2004/10/wscoor", "InvalidState"),
+			"The message was invalid for the current state of the activity.",
+			null, null);
+
+	AxisFault INVALID_PARAMETERS_SOAP_FAULT = new AxisFault(
+			new QName("http://schemas.xmlsoap.org/ws/2004/10/wscoor",
+					"InvalidParameters"),
+			"The message contained invalid parameters and could not be processed.",
+			null, null);
+
+	CoordinationContext getCoordinationContext();
+
+}
\ No newline at end of file

Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/CoordinatorImpl.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/CoordinatorImpl.java?rev=368901&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/CoordinatorImpl.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/CoordinatorImpl.java Fri Jan 13 14:58:04 2006
@@ -0,0 +1,106 @@
+/*
+ * Created on Dec 23, 2005
+ *
+ */
+package org.apache.kandula.coordinator;
+
+import java.net.MalformedURLException;
+import java.rmi.RemoteException;
+
+import javax.xml.rpc.ServiceException;
+
+import org.apache.axis.AxisFault;
+import org.apache.axis.MessageContext;
+import org.apache.axis.components.uuid.UUIDGen;
+import org.apache.axis.components.uuid.UUIDGenFactory;
+import org.apache.axis.message.addressing.AddressingHeaders;
+import org.apache.axis.message.addressing.Constants;
+import org.apache.axis.message.addressing.EndpointReference;
+import org.apache.axis.types.URI.MalformedURIException;
+import org.apache.kandula.utils.SoapFaultSender;
+import org.apache.kandula.wscoor.RegisterResponseType;
+import org.apache.kandula.wscoor.RegisterType;
+
+/**
+ * @author Dasarath Weeratunge
+ *  
+ */
+public abstract class CoordinatorImpl implements Coordinator {
+	
+	private String id;
+	
+	private CoordinationContext ctx;
+
+	protected CoordinatorImpl(String coordinationType)
+			throws MalformedURIException {
+		UUIDGen gen = UUIDGenFactory.getUUIDGen();
+		id = "uuid:" + gen.nextUUID();
+		CoordinationService cs = CoordinationService.getInstance();
+		EndpointReference epr = cs.getRegistrationCoordinatorService(this);
+		ctx = new CoordinationContext(id, coordinationType, epr);
+	}
+
+	public String getID() {
+		return id;
+	}
+
+	public CoordinationContext getCoordinationContext() {
+		return ctx;
+	}
+
+	public abstract EndpointReference register(String prot,
+			EndpointReference pps) throws InvalidCoordinationProtocolException;
+
+	public synchronized RegisterResponseType registerOperation(
+			RegisterType params) throws RemoteException {
+		
+		EndpointReference epr = null;
+		try {
+			epr = register(params.getProtocolIdentifier().toString(),
+				new EndpointReference(params.getParticipantProtocolService()));
+			
+		} catch (InvalidCoordinationProtocolException e) {
+			throw INVALID_PROTOCOL_SOAP_FAULT;
+			
+		} catch (IllegalStateException e) {
+			throw INVALID_STATE_SOAP_FAULT;
+			
+		} catch (IllegalArgumentException e) {
+			throw INVALID_PARAMETERS_SOAP_FAULT;
+		}
+		
+		RegisterResponseType r = new RegisterResponseType();
+		r.setCoordinatorProtocolService(epr);
+		return r;
+	}
+
+	protected AddressingHeaders getAddressingHeaders() {
+		return (AddressingHeaders) MessageContext.getCurrentContext().getProperty(
+			Constants.ENV_ADDRESSING_REQUEST_HEADERS);
+	}
+
+	protected EndpointReference getReplyToEpr() {
+		AddressingHeaders headers = getAddressingHeaders();
+		return headers.getReplyTo();
+	}
+
+	protected EndpointReference getFaultToEpr() {
+		AddressingHeaders headers = getAddressingHeaders();
+		return headers.getFaultTo();
+	}
+
+	protected void throwFault(EndpointReference faultTo, AxisFault fault)
+			throws AxisFault {
+		try {
+			SoapFaultSender.invoke(faultTo,
+				fault.getFaultCode().getNamespaceURI() + "/fault", fault);
+		} catch (MalformedURLException e) {
+			e.printStackTrace();
+			throw new IllegalArgumentException();
+		} catch (ServiceException e) {
+			e.printStackTrace();
+			throw new RuntimeException(e);
+		}
+	}
+
+}
\ No newline at end of file

Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/FaultDispatcher.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/FaultDispatcher.java?rev=368901&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/FaultDispatcher.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/FaultDispatcher.java Fri Jan 13 14:58:04 2006
@@ -0,0 +1,32 @@
+/*
+ * Created on Jan 6, 2006
+ *
+ */
+package org.apache.kandula.coordinator;
+
+import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPEnvelope;
+import javax.xml.soap.SOAPFault;
+
+import org.apache.axis.MessageContext;
+
+/**
+ * @author Dasarath Weeratunge
+ *  
+ */
+public class FaultDispatcher {
+
+	public void process(SOAPEnvelope req, SOAPEnvelope resp)
+			throws javax.xml.soap.SOAPException {
+		SOAPBody body = req.getBody();
+		SOAPFault fault = body.getFault();
+
+		Callback callback = (Callback) CallbackRegistry.getInstance().correlateMessage(
+			CallbackRegistry.CALLBACK_REF, false);
+		if (callback != null)
+			callback.onFault(fault.getFaultCodeAsName());
+
+		MessageContext.getCurrentContext().setResponseMessage(null);
+	}
+
+}
\ No newline at end of file

Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/InvalidCoordinationProtocolException.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/InvalidCoordinationProtocolException.java?rev=368901&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/InvalidCoordinationProtocolException.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/InvalidCoordinationProtocolException.java Fri Jan 13 14:58:04 2006
@@ -0,0 +1,13 @@
+/*
+ * Created on Jan 6, 2006
+ *
+ */
+package org.apache.kandula.coordinator;
+
+/**
+ * @author Dasarath Weeratunge
+ *
+ */
+public class InvalidCoordinationProtocolException extends Exception {
+
+}

Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/RegistrationImpl.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/RegistrationImpl.java?rev=368901&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/RegistrationImpl.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/RegistrationImpl.java Fri Jan 13 14:58:04 2006
@@ -0,0 +1,33 @@
+/*
+ * 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.kandula.coordinator;
+
+import java.rmi.RemoteException;
+
+import org.apache.kandula.wscoor.RegisterResponseType;
+import org.apache.kandula.wscoor.RegisterType;
+import org.apache.kandula.wscoor.RegistrationPortTypeRPC;
+
+public class RegistrationImpl implements RegistrationPortTypeRPC {
+
+	public RegisterResponseType registerOperation(RegisterType params)
+			throws RemoteException {
+		Coordinator c = (Coordinator) CallbackRegistry.getInstance().correlateMessage(
+			CallbackRegistry.CALLBACK_REF, false);
+		return c.registerOperation(params);
+	}
+}
\ No newline at end of file

Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/RegistrationStub.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/RegistrationStub.java?rev=368901&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/RegistrationStub.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/RegistrationStub.java Fri Jan 13 14:58:04 2006
@@ -0,0 +1,56 @@
+/*
+ * 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.kandula.coordinator;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.rmi.RemoteException;
+
+import org.apache.axis.AxisFault;
+import org.apache.axis.message.addressing.EndpointReference;
+import org.apache.axis.types.URI;
+import org.apache.axis.types.URI.MalformedURIException;
+import org.apache.kandula.utils.AddressingHeaders;
+import org.apache.kandula.utils.Service;
+import org.apache.kandula.utils.TCPSnifferHelper;
+import org.apache.kandula.wscoor.RegisterType;
+import org.apache.kandula.wscoor.RegistrationPortTypeRPCBindingStub;
+
+/**
+ * @author Dasarath Weeratunge
+ * 
+ * Created on Jun 14, 2004
+ */
+public class RegistrationStub extends RegistrationPortTypeRPCBindingStub {
+
+	public RegistrationStub(EndpointReference epr) throws AxisFault,
+			MalformedURLException {
+		super(new URL(TCPSnifferHelper.redirect(epr.getAddress().toString())),
+				new Service());
+		AddressingHeaders headers = new AddressingHeaders(epr, null);
+		((Service) service).setAddressingHeaders(headers);
+	}
+
+	public EndpointReference registerOperation(String p, EndpointReference epr)
+			throws RemoteException, MalformedURIException {
+		RegisterType params = new RegisterType();
+		params.setProtocolIdentifier(new URI(p));
+		params.setParticipantProtocolService(epr);
+		return new EndpointReference(
+				registerOperation(params).getCoordinatorProtocolService());
+	}
+}
\ No newline at end of file

Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/TimedOutException.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/TimedOutException.java?rev=368901&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/TimedOutException.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/TimedOutException.java Fri Jan 13 14:58:04 2006
@@ -0,0 +1,13 @@
+/*
+ * Created on Dec 30, 2005
+ *
+ */
+package org.apache.kandula.coordinator;
+
+/**
+ * @author Dasarath Weeratunge
+ *
+ */
+public class TimedOutException extends Exception {
+
+}

Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/UnsupportedCoordinationTypeException.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/UnsupportedCoordinationTypeException.java?rev=368901&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/UnsupportedCoordinationTypeException.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/UnsupportedCoordinationTypeException.java Fri Jan 13 14:58:04 2006
@@ -0,0 +1,13 @@
+/*
+ * Created on Dec 25, 2005
+ *
+ */
+package org.apache.kandula.coordinator;
+
+/**
+ * @author Dasarath Weeratunge
+ *
+ */
+public class UnsupportedCoordinationTypeException extends Exception {
+
+}

Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/AT2PCStatus.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/AT2PCStatus.java?rev=368901&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/AT2PCStatus.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/AT2PCStatus.java Fri Jan 13 14:58:04 2006
@@ -0,0 +1,43 @@
+/*
+ * Created on Dec 23, 2005
+ *
+ */
+package org.apache.kandula.coordinator.at;
+
+import java.lang.reflect.Field;
+
+/**
+ * @author Dasarath Weeratunge
+ *  
+ */
+public class AT2PCStatus {
+	public static final int NONE = 0;
+
+	public static final int ACTIVE = 1;
+
+	public static final int PREPARING_VOLATILE = 2;
+
+	public static final int PREPARING_DURABLE = 3;
+
+	public static final int PREPARING = 4;
+
+	public static final int PREPARED = 5;
+
+	public static final int COMMITTING = 6;
+
+	public static final int ABORTING = 7;
+
+	private static Field[] flds = AT2PCStatus.class.getDeclaredFields();
+
+	public static String getStatusName(int status) {
+		try {
+			for (int i = 0; i < flds.length; i++) {				
+				if (flds[i].getInt(null) == status)
+					return flds[i].getName();
+			}
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		throw new IllegalArgumentException();
+	}
+}
\ No newline at end of file

Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/ATCoordinator.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/ATCoordinator.java?rev=368901&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/ATCoordinator.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/ATCoordinator.java Fri Jan 13 14:58:04 2006
@@ -0,0 +1,39 @@
+/*
+ * 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.kandula.coordinator.at;
+
+import javax.xml.namespace.QName;
+
+import org.apache.kandula.coordinator.Coordinator;
+import org.apache.kandula.wsat.CompletionCoordinatorPortType;
+import org.apache.kandula.wsat.CoordinatorPortType;
+
+public interface ATCoordinator extends Coordinator, CoordinatorPortType,
+		CompletionCoordinatorPortType {
+
+	final QName PARTICIPANT_REF = new QName("http://ws.apache.org/kandula",
+			"ParticipantRef");
+
+	final String COORDINATION_TYPE_ID = "http://schemas.xmlsoap.org/ws/2004/10/wsat";
+
+	final String PROTOCOL_ID_COMPLETION = "http://schemas.xmlsoap.org/ws/2004/10/wsat/Completion";
+
+	final String PROTOCOL_ID_VOLATILE_2PC = "http://schemas.xmlsoap.org/ws/2004/10/wsat/Volatile2PC";
+
+	final String PROTOCOL_ID_DURABLE_2PC = "http://schemas.xmlsoap.org/ws/2004/10/wsat/Durable2PC";
+
+}
\ No newline at end of file

Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/ATCoordinatorImpl.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/ATCoordinatorImpl.java?rev=368901&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/ATCoordinatorImpl.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/ATCoordinatorImpl.java Fri Jan 13 14:58:04 2006
@@ -0,0 +1,510 @@
+/*
+ * Created on Dec 23, 2005
+ *
+ */
+package org.apache.kandula.coordinator.at;
+
+import java.net.MalformedURLException;
+import java.rmi.RemoteException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.soap.Name;
+
+import org.apache.axis.AxisFault;
+import org.apache.axis.components.uuid.UUIDGen;
+import org.apache.axis.components.uuid.UUIDGenFactory;
+import org.apache.axis.message.MessageElement;
+import org.apache.axis.message.addressing.AddressingHeaders;
+import org.apache.axis.message.addressing.EndpointReference;
+import org.apache.axis.types.URI.MalformedURIException;
+import org.apache.kandula.coordinator.CoordinationService;
+import org.apache.kandula.coordinator.CoordinatorImpl;
+import org.apache.kandula.coordinator.InvalidCoordinationProtocolException;
+import org.apache.kandula.coordinator.TimedOutException;
+import org.apache.kandula.wsat.Notification;
+
+/**
+ * @author Dasarath Weeratunge
+ *  
+ */
+public class ATCoordinatorImpl extends CoordinatorImpl implements ATCoordinator {
+
+	int status = AT2PCStatus.ACTIVE;
+
+	Set preparedParticipants = new HashSet();
+
+	List completionParticipants = new ArrayList();
+
+	Map volatile2PCParticipants = new HashMap();
+
+	Map durable2PCParticipants = new HashMap();
+
+	public static int maxRetries = 10;
+
+	public static final int RETRY_DELAY_MILLIS = 20 * 1000;
+
+	public static final int RESPONSE_DELAY_MILLIS = 3 * 1000;
+
+	public ATCoordinatorImpl() throws MalformedURIException {
+		super(COORDINATION_TYPE_ID);
+	}
+
+	public EndpointReference register(String protocol,
+			EndpointReference participantProtocolService)
+			throws InvalidCoordinationProtocolException {
+
+		if (!(status == AT2PCStatus.ACTIVE || status == AT2PCStatus.PREPARING_VOLATILE))
+			throw new IllegalStateException();
+
+		CoordinationService cs = CoordinationService.getInstance();
+		String participantRef = null;
+		EndpointReference epr = null;
+
+		if (protocol.equals(PROTOCOL_ID_COMPLETION)) {
+			if (participantProtocolService != null)
+				completionParticipants.add(participantProtocolService);
+
+			epr = cs.getCompletionCoordinatorService(this);
+		} else {
+			if (participantProtocolService == null)
+				throw new IllegalArgumentException();
+
+			UUIDGen gen = UUIDGenFactory.getUUIDGen();
+			participantRef = "uuid:" + gen.nextUUID();
+
+			if (protocol.equals(PROTOCOL_ID_VOLATILE_2PC))
+				volatile2PCParticipants.put(participantRef,
+					participantProtocolService);
+			else if (protocol.equals(PROTOCOL_ID_DURABLE_2PC))
+				durable2PCParticipants.put(participantRef,
+					participantProtocolService);
+			else
+				throw new InvalidCoordinationProtocolException();
+
+			epr = cs.getCoordinatorService(this, participantRef);
+		}
+
+		return epr;
+	}
+
+	public void forget2PC(String participantRef) {
+		if (volatile2PCParticipants.remove(participantRef) == null)
+			durable2PCParticipants.remove(participantRef);
+	}
+
+	public void rollback() {
+		switch (status) {
+		case AT2PCStatus.ACTIVE:
+		case AT2PCStatus.PREPARING_VOLATILE:
+		case AT2PCStatus.PREPARING_DURABLE:
+			status = AT2PCStatus.ABORTING;
+			terminate();
+			return;
+
+		case AT2PCStatus.COMMITTING:
+		case AT2PCStatus.ABORTING:
+		case AT2PCStatus.NONE:
+		}
+	}
+
+	public void aborted(String participantRef) throws AxisFault {
+		switch (status) {
+		case AT2PCStatus.ACTIVE:
+		case AT2PCStatus.PREPARING_VOLATILE:
+		case AT2PCStatus.PREPARING_DURABLE:
+			forget2PC(participantRef);
+			rollback();
+			return;
+
+		case AT2PCStatus.COMMITTING:
+			throwFault(participantRef, INVALID_STATE_SOAP_FAULT);
+			return;
+
+		case AT2PCStatus.ABORTING:
+			forget2PC(participantRef);
+			return;
+
+		case AT2PCStatus.NONE:
+		}
+	}
+
+	public void readOnly(String participantRef) throws AxisFault {
+		switch (status) {
+		case AT2PCStatus.ACTIVE:
+		case AT2PCStatus.PREPARING_VOLATILE:
+		case AT2PCStatus.PREPARING_DURABLE:
+			forget2PC(participantRef);
+			return;
+
+		case AT2PCStatus.COMMITTING:
+			throwFault(participantRef, INVALID_STATE_SOAP_FAULT);
+			return;
+
+		case AT2PCStatus.ABORTING:
+			forget2PC(participantRef);
+			return;
+
+		case AT2PCStatus.NONE:
+		}
+	}
+
+	private ParticipantStub getParticipantStub(String participantRef,
+			EndpointReference epr) throws AxisFault, MalformedURLException {
+		return new ParticipantStub(this, participantRef, epr);
+	}
+
+	public void replay(String participantRef) throws AxisFault {
+		switch (status) {
+		case AT2PCStatus.ACTIVE:
+		case AT2PCStatus.PREPARING_VOLATILE:
+		case AT2PCStatus.PREPARING_DURABLE:
+			rollback();
+			return;
+
+		case AT2PCStatus.COMMITTING:
+			EndpointReference epr = getEprToRespond(participantRef);
+			if (epr != null)
+				try {
+					getParticipantStub(participantRef, epr).commitOperation(
+						null);
+				} catch (Exception e) {
+					e.printStackTrace();
+				}
+			return;
+
+		case AT2PCStatus.ABORTING:
+			epr = getEprToRespond(participantRef);
+			if (epr != null)
+				try {
+					getParticipantStub(participantRef, epr).rollbackOperation(
+						null);
+				} catch (Exception e) {
+					e.printStackTrace();
+				}
+			return;
+
+		case AT2PCStatus.NONE:
+			if (volatile2PCParticipants.containsKey(participantRef))
+				throwFault(participantRef, INVALID_STATE_SOAP_FAULT);
+			else {
+				epr = (EndpointReference) durable2PCParticipants.get(participantRef);
+				if (epr == null)
+					epr = getReplyToEpr();
+				if (epr != null)
+					try {
+						getParticipantStub(participantRef, epr).rollbackOperation(
+							null);
+					} catch (Exception e) {
+						e.printStackTrace();
+					}
+			}
+		}
+	}
+
+	public void prepared(String participantRef) throws AxisFault {
+		switch (status) {
+		case AT2PCStatus.ACTIVE:
+			try {
+				throwFault(participantRef, INVALID_STATE_SOAP_FAULT);
+			} finally {
+				rollback();
+			}
+			return;
+
+		case AT2PCStatus.PREPARING_VOLATILE:
+		case AT2PCStatus.PREPARING_DURABLE:
+			preparedParticipants.add(participantRef);
+			return;
+
+		case AT2PCStatus.COMMITTING:
+			EndpointReference epr = getEprToRespond(participantRef);
+			if (epr != null)
+				try {
+					getParticipantStub(participantRef, epr).commitOperation(
+						null);
+				} catch (Exception e) {
+					e.printStackTrace();
+				}
+			return;
+
+		case AT2PCStatus.ABORTING:
+			if (volatile2PCParticipants.remove(participantRef) != null)
+				throwFault(participantRef, INVALID_STATE_SOAP_FAULT);
+			else {
+				epr = (EndpointReference) durable2PCParticipants.remove(participantRef);
+				if (epr == null)
+					epr = getReplyToEpr();
+				if (epr != null) {
+					try {
+						getParticipantStub(participantRef, epr).rollbackOperation(
+							null);
+					} catch (Exception e) {
+						e.printStackTrace();
+					}
+				}
+			}
+			return;
+
+		case AT2PCStatus.NONE:
+			if (volatile2PCParticipants.containsKey(participantRef))
+				throwFault(participantRef, INVALID_STATE_SOAP_FAULT);
+			else {
+				epr = (EndpointReference) durable2PCParticipants.get(participantRef);
+				if (epr == null)
+					epr = getReplyToEpr();
+				if (epr != null)
+					try {
+						getParticipantStub(participantRef, epr).rollbackOperation(
+							null);
+					} catch (Exception e) {
+						e.printStackTrace();
+					}
+			}
+		}
+	}
+
+	public void committed(String participantRef) throws AxisFault {
+		switch (status) {
+		case AT2PCStatus.ACTIVE:
+		case AT2PCStatus.PREPARING_VOLATILE:
+		case AT2PCStatus.PREPARING_DURABLE:
+			try {
+				throwFault(participantRef, INVALID_STATE_SOAP_FAULT);
+			} finally {
+				rollback();
+			}
+			return;
+
+		case AT2PCStatus.COMMITTING:
+			forget2PC(participantRef);
+			return;
+
+		case AT2PCStatus.ABORTING:
+			throwFault(participantRef, INVALID_STATE_SOAP_FAULT);
+			return;
+
+		case AT2PCStatus.NONE:
+		}
+	}
+
+	private boolean prepare(Map participants) {
+		int iters = 0;
+		int status_old = status;
+
+		while (iters < maxRetries) {
+			if (iters++ > 0)
+				pause(RETRY_DELAY_MILLIS - RESPONSE_DELAY_MILLIS);
+
+			Iterator iter = participants.keySet().iterator();
+			while (iter.hasNext()) {
+				if (status == AT2PCStatus.ABORTING)
+					return false;
+				try {
+					String participantRef = (String) iter.next();
+					getParticipantStub(participantRef,
+						(EndpointReference) participants.get(participantRef)).prepareOperation(
+						null);
+				} catch (Exception e) {
+					e.printStackTrace();
+				}
+			}
+
+			pause(RESPONSE_DELAY_MILLIS);
+
+			if (preparedParticipants.containsAll(participants.keySet()))
+				return status == status_old;
+		}
+
+		return false;
+	}
+
+	private boolean prepare() {
+		status = AT2PCStatus.PREPARING_VOLATILE;
+		if (!prepare(volatile2PCParticipants))
+			return false;
+
+		status = AT2PCStatus.PREPARING_DURABLE;
+		return prepare(durable2PCParticipants);
+	}
+
+	public void commit() {
+		switch (status) {
+		case AT2PCStatus.ACTIVE:
+			break;
+
+		case AT2PCStatus.PREPARING_VOLATILE:
+		case AT2PCStatus.PREPARING_DURABLE:
+		case AT2PCStatus.COMMITTING:
+		case AT2PCStatus.ABORTING:
+		case AT2PCStatus.NONE:
+			return;
+		}
+
+		if (!prepare()) {
+			rollback();
+			return;
+		}
+
+		status = AT2PCStatus.COMMITTING;
+		terminate();
+	}
+
+	private void pause(long millis) {
+		try {
+			wait(millis);
+		} catch (InterruptedException e) {
+			e.printStackTrace();
+		}
+	}
+
+	private boolean noParticipantsToTerminate() {
+		return volatile2PCParticipants.isEmpty()
+				&& durable2PCParticipants.isEmpty();
+	}
+
+	private void terminate() {
+		int iters = 0;
+		while (iters < maxRetries && !noParticipantsToTerminate()) {
+
+			if (iters++ > 0)
+				pause(RETRY_DELAY_MILLIS - RESPONSE_DELAY_MILLIS);
+
+			Map participants = volatile2PCParticipants;
+			while (true) {
+				Iterator iter = participants.keySet().iterator();
+				while (iter.hasNext())
+					try {
+						String participantRef = (String) iter.next();
+						ParticipantStub p = getParticipantStub(
+							participantRef,
+							(EndpointReference) participants.get(participantRef));
+						if (status == AT2PCStatus.ABORTING)
+							p.rollbackOperation(null);
+						else
+							p.commitOperation(null);
+					} catch (Exception e) {
+						e.printStackTrace();
+					}
+				if (participants == volatile2PCParticipants)
+					participants = durable2PCParticipants;
+				else
+					break;
+			}
+
+			pause(RESPONSE_DELAY_MILLIS);
+		}
+
+		if (noParticipantsToTerminate()) {
+
+			Iterator iter = completionParticipants.iterator();
+			while (iter.hasNext())
+				try {
+					CompletionInitiatorStub p = new CompletionInitiatorStub(
+							(EndpointReference) iter.next());
+					if (status == AT2PCStatus.ABORTING)
+						p.abortedOperation(null);
+					else
+						p.committedOperation(null);
+				} catch (Exception e) {
+					e.printStackTrace();
+				}
+		}
+
+		status = AT2PCStatus.NONE;
+	}
+
+	public synchronized void preparedOperation(Notification parameters)
+			throws RemoteException {
+		prepared(getParticipantRef());
+	}
+
+	public synchronized void abortedOperation(Notification parameters)
+			throws RemoteException {
+		aborted(getParticipantRef());
+	}
+
+	public synchronized void readOnlyOperation(Notification parameters)
+			throws RemoteException {
+		readOnly(getParticipantRef());
+	}
+
+	public synchronized void committedOperation(Notification parameters)
+			throws RemoteException {
+		committed(getParticipantRef());
+	}
+
+	public synchronized void replayOperation(Notification parameters)
+			throws RemoteException {
+		replay(getParticipantRef());
+	}
+
+	private EndpointReference getEprToSendFault(String participantRef) {
+		EndpointReference epr = getFaultToEpr();
+		if (epr != null)
+			return epr;
+		return getEprToRespond(participantRef);
+	}
+
+	private EndpointReference getEprToRespond(String participantRef) {
+		EndpointReference epr = (EndpointReference) volatile2PCParticipants.get(participantRef);
+		if (epr != null)
+			return epr;
+		epr = (EndpointReference) durable2PCParticipants.get(participantRef);
+		if (epr != null)
+			return epr;
+		return getReplyToEpr();
+	}
+
+	private String getParticipantRef() {
+		AddressingHeaders headers = getAddressingHeaders();
+		MessageElement e = headers.getReferenceProperties().get(PARTICIPANT_REF);
+		return e.getValue();
+	}
+
+	public synchronized void commitOperation(Notification parameters)
+			throws RemoteException {
+		commit();
+	}
+
+	public synchronized void rollbackOperation(Notification parameters)
+			throws RemoteException {
+		rollback();
+	}
+
+	public synchronized void timeout() throws TimedOutException {
+		System.out.println("[ATCoordinatorImpl] timeout "
+				+ AT2PCStatus.getStatusName(status));
+
+		if (status != AT2PCStatus.NONE) {
+			maxRetries = 8;
+			rollback();
+			throw new TimedOutException();
+		}
+	}
+
+	private void throwFault(String participantRef, AxisFault fault)
+			throws AxisFault {
+		throwFault(getEprToSendFault(participantRef), fault);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.apache.ws.transaction.coordinator.Callback#onFault(javax.xml.soap.Name)
+	 */
+	public synchronized void onFault(Name code) {
+		// TODO Auto-generated method stub
+
+	}
+
+	public EndpointReference getEndpointReference() {
+		throw new UnsupportedOperationException();
+	}
+
+}
\ No newline at end of file

Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/AbstractParticipant.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/AbstractParticipant.java?rev=368901&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/AbstractParticipant.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/AbstractParticipant.java Fri Jan 13 14:58:04 2006
@@ -0,0 +1,241 @@
+/*
+ * Created on Dec 30, 2005
+ *
+ */
+package org.apache.kandula.coordinator.at;
+
+import java.rmi.RemoteException;
+import java.util.Timer;
+import java.util.TimerTask;
+
+import javax.transaction.xa.XAException;
+import javax.transaction.xa.XAResource;
+import javax.xml.soap.Name;
+
+import org.apache.axis.components.uuid.UUIDGenFactory;
+import org.apache.axis.message.addressing.EndpointReference;
+import org.apache.kandula.coordinator.Callback;
+import org.apache.kandula.coordinator.CoordinationContext;
+import org.apache.kandula.coordinator.CoordinationService;
+import org.apache.kandula.coordinator.Coordinator;
+import org.apache.kandula.coordinator.TimedOutException;
+import org.apache.kandula.wsat.CoordinatorPortType;
+import org.apache.kandula.wsat.Notification;
+import org.apache.kandula.wsat.ParticipantPortType;
+import org.apache.kandula.wscoor.Expires;
+
+/**
+ * @author Dasarath Weeratunge
+ *  
+ */
+public abstract class AbstractParticipant implements ParticipantPortType,
+		Callback {
+
+	private String id;
+
+	private EndpointReference epr;
+
+	private static Timer timer = new Timer();
+
+	public static final int RETRY_DELAY_MILLIS = 3 * 1000;
+
+	private EndpointReference eprOfCoordinator;
+
+	protected abstract int prepare() throws XAException;
+
+	protected abstract void commit() throws XAException;
+
+	protected abstract void rollback() throws XAException;
+
+	protected abstract void forget();
+
+	protected abstract int getStatus();
+
+	protected AbstractParticipant() {
+		id = "uuid:" + UUIDGenFactory.getUUIDGen().nextUUID();
+	}
+
+	public String getID() {
+		return id;
+	}
+
+	protected void register(boolean durable, CoordinationContext ctx)
+			throws RemoteException {
+		long timeout = 0;
+		Expires ex = ctx.getExpires();
+		if (ex != null)
+			timeout = ex.get_value().longValue();
+		epr = CoordinationService.getInstance().getParticipantService(this,
+			timeout);
+		eprOfCoordinator = ctx.register(
+			durable ? ATCoordinator.PROTOCOL_ID_DURABLE_2PC
+					: ATCoordinator.PROTOCOL_ID_VOLATILE_2PC, epr);
+	}
+
+	protected CoordinatorPortType getCoordinator() {
+		try {
+			return new CoordinatorStub(this, eprOfCoordinator);
+		} catch (Exception e) {
+			e.printStackTrace();
+			throw new RuntimeException(e);
+		}
+	}
+
+	public synchronized void prepareOperation(Notification parameters)
+			throws RemoteException {
+		switch (getStatus()) {
+		case AT2PCStatus.NONE:
+			getCoordinator().abortedOperation(null);
+			return;
+
+		case AT2PCStatus.ACTIVE:
+			final CoordinatorPortType p = getCoordinator();
+			try {
+				if (prepare() == XAResource.XA_RDONLY) {
+					forget();
+					p.readOnlyOperation(null);
+				} else {
+					p.preparedOperation(null);
+					timer.schedule(new TimerTask() {
+						public void run() {
+							switch (getStatus()) {
+							case AT2PCStatus.NONE:
+							case AT2PCStatus.ACTIVE:
+							case AT2PCStatus.PREPARING:
+							case AT2PCStatus.ABORTING:
+							case AT2PCStatus.COMMITTING:
+								cancel();
+								return;
+
+							case AT2PCStatus.PREPARED:
+								try {
+									p.preparedOperation(null);
+								} catch (RemoteException e) {
+									// TODO:
+									// identify wscoor:InvalidState Soap fault
+									// and stop
+									e.printStackTrace();
+								}
+							}
+						}
+					}, RETRY_DELAY_MILLIS, RETRY_DELAY_MILLIS);
+				}
+			} catch (XAException e) {
+				forget();
+				p.abortedOperation(null);
+			}
+			return;
+
+		case AT2PCStatus.PREPARING:
+			return;
+
+		case AT2PCStatus.PREPARED:
+			getCoordinator().preparedOperation(null);
+			return;
+
+		case AT2PCStatus.ABORTING:
+			forget();
+			getCoordinator().abortedOperation(null);
+			return;
+
+		case AT2PCStatus.COMMITTING:
+		}
+	}
+
+	public synchronized void commitOperation(Notification parameters)
+			throws RemoteException {
+		switch (getStatus()) {
+		case AT2PCStatus.NONE:
+			getCoordinator().committedOperation(null);
+			return;
+
+		case AT2PCStatus.ACTIVE:
+		case AT2PCStatus.PREPARING:
+			try {
+				rollback();
+				forget();
+				getCoordinator().abortedOperation(null);
+			} catch (XAException e) {
+				e.printStackTrace();
+			}
+			return;
+
+		case AT2PCStatus.PREPARED:
+			try {
+				commit();
+				forget();
+				getCoordinator().committedOperation(null);
+			} catch (XAException e) {
+				e.printStackTrace();
+			}
+			return;
+
+		case AT2PCStatus.ABORTING:
+			throw Coordinator.INVALID_STATE_SOAP_FAULT;
+
+		case AT2PCStatus.COMMITTING:
+		}
+	}
+
+	public synchronized void rollbackOperation(Notification parameters)
+			throws RemoteException {
+		switch (getStatus()) {
+		case AT2PCStatus.NONE:
+			getCoordinator().abortedOperation(null);
+			return;
+
+		case AT2PCStatus.ACTIVE:
+		case AT2PCStatus.PREPARING:
+		case AT2PCStatus.PREPARED:
+			try {
+				rollback();
+				forget();
+				getCoordinator().abortedOperation(null);
+			} catch (XAException e) {
+				e.printStackTrace();
+			}
+			return;
+
+		case AT2PCStatus.ABORTING:
+			forget();
+			getCoordinator().abortedOperation(null);
+			return;
+
+		case AT2PCStatus.COMMITTING:
+			throw Coordinator.INVALID_STATE_SOAP_FAULT;
+		}
+	}
+
+	public synchronized void timeout() throws TimedOutException {
+		System.out.println("[AbstractParticipant] timeout "
+				+ AT2PCStatus.getStatusName(getStatus()));
+
+		if (getStatus() == AT2PCStatus.NONE)
+			return;
+		try {
+			rollback();
+			forget();
+			getCoordinator().abortedOperation(null);
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		throw new TimedOutException();
+	}
+
+	public synchronized void onFault(Name code) {
+		System.out.println("[AbstractParticipant] onFault: " + code);
+
+		// FIXME:
+		try {
+			forget();
+			rollback();			
+		} catch (XAException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+	}
+
+	public EndpointReference getEndpointReference() {
+		return epr;
+	}
+}
\ No newline at end of file

Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/CompletionCoordinatorImpl.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/CompletionCoordinatorImpl.java?rev=368901&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/CompletionCoordinatorImpl.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/CompletionCoordinatorImpl.java Fri Jan 13 14:58:04 2006
@@ -0,0 +1,31 @@
+/*
+ * Created on Dec 23, 2005
+ *
+ */
+package org.apache.kandula.coordinator.at;
+
+import java.rmi.RemoteException;
+
+import org.apache.kandula.coordinator.CallbackRegistry;
+import org.apache.kandula.wsat.CompletionCoordinatorPortType;
+import org.apache.kandula.wsat.Notification;
+
+/**
+ * @author Dasarath Weeratunge
+ *  
+ */
+public class CompletionCoordinatorImpl implements CompletionCoordinatorPortType {
+
+	public void commitOperation(Notification params) throws RemoteException {
+		ATCoordinator c = (ATCoordinator) CallbackRegistry.getInstance().correlateMessage(
+			CallbackRegistry.CALLBACK_REF, false);
+		c.commitOperation(params);
+	}
+
+	public void rollbackOperation(Notification params) throws RemoteException {
+		ATCoordinator c = (ATCoordinator) CallbackRegistry.getInstance().correlateMessage(
+			CallbackRegistry.CALLBACK_REF, false);
+		c.rollbackOperation(params);
+	}
+
+}
\ No newline at end of file

Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/CompletionCoordinatorStub.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/CompletionCoordinatorStub.java?rev=368901&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/CompletionCoordinatorStub.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/CompletionCoordinatorStub.java Fri Jan 13 14:58:04 2006
@@ -0,0 +1,51 @@
+/*
+ * 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.kandula.coordinator.at;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.apache.axis.AxisFault;
+import org.apache.axis.message.addressing.EndpointReference;
+import org.apache.kandula.coordinator.Callback;
+import org.apache.kandula.coordinator.CoordinationService;
+import org.apache.kandula.utils.AddressingHeaders;
+import org.apache.kandula.utils.Service;
+import org.apache.kandula.utils.TCPSnifferHelper;
+import org.apache.kandula.wsat.CompletionCoordinatorBindingStub;
+
+/**
+ * @author Dasarath Weeratunge
+ * 
+ * Created on Jun 14, 2004
+ */
+public class CompletionCoordinatorStub extends CompletionCoordinatorBindingStub {
+
+	public CompletionCoordinatorStub(Callback callback, EndpointReference epr)
+			throws AxisFault, MalformedURLException {
+		super(new URL(TCPSnifferHelper.redirect(epr.getAddress().toString())),
+				new Service());
+
+		CoordinationService cs = CoordinationService.getInstance();
+
+		AddressingHeaders headers = new AddressingHeaders(epr,
+				callback.getEndpointReference());
+		headers.setFaultTo(cs.getFaultDispatcherService(callback));
+		((Service) service).setAddressingHeaders(headers);
+
+	}
+}
\ No newline at end of file

Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/CompletionInitiatorImpl.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/CompletionInitiatorImpl.java?rev=368901&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/CompletionInitiatorImpl.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/CompletionInitiatorImpl.java Fri Jan 13 14:58:04 2006
@@ -0,0 +1,24 @@
+package org.apache.kandula.coordinator.at;
+
+import org.apache.kandula.coordinator.CallbackRegistry;
+import org.apache.kandula.wsat.CompletionInitiatorPortType;
+
+public class CompletionInitiatorImpl implements CompletionInitiatorPortType {
+	public void committedOperation(
+			org.apache.kandula.wsat.Notification parameters)
+			throws java.rmi.RemoteException {
+		CompletionInitiatorPortType callback = (CompletionInitiatorPortType) CallbackRegistry.getInstance().correlateMessage(
+			CallbackRegistry.CALLBACK_REF, false);
+		if (callback != null)
+			callback.committedOperation(parameters);
+	}
+
+	public void abortedOperation(
+			org.apache.kandula.wsat.Notification parameters)
+			throws java.rmi.RemoteException {
+		CompletionInitiatorPortType callback = (CompletionInitiatorPortType) CallbackRegistry.getInstance().correlateMessage(
+			CallbackRegistry.CALLBACK_REF, false);
+		if (callback != null)
+			callback.abortedOperation(parameters);
+	}
+}
\ No newline at end of file

Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/CompletionInitiatorStub.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/CompletionInitiatorStub.java?rev=368901&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/CompletionInitiatorStub.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/CompletionInitiatorStub.java Fri Jan 13 14:58:04 2006
@@ -0,0 +1,46 @@
+/*
+ * 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.kandula.coordinator.at;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.apache.axis.AxisFault;
+import org.apache.axis.message.addressing.EndpointReference;
+import org.apache.kandula.utils.AddressingHeaders;
+import org.apache.kandula.utils.Service;
+import org.apache.kandula.utils.TCPSnifferHelper;
+import org.apache.kandula.wsat.CompletionInitiatorBindingStub;
+
+/**
+ * @author Dasarath Weeratunge
+ * 
+ * Created on Jun 14, 2004
+ */
+public class CompletionInitiatorStub extends CompletionInitiatorBindingStub {
+
+	public CompletionInitiatorStub(EndpointReference epr) throws AxisFault,
+			MalformedURLException {
+		super(new URL(TCPSnifferHelper.redirect(epr.getAddress().toString())),
+				new Service());
+		// FIXME:
+		AddressingHeaders headers = new AddressingHeaders(epr, null);
+		((Service) service).setAddressingHeaders(headers);
+
+	}
+
+}
\ No newline at end of file

Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/CoordinatorImpl.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/CoordinatorImpl.java?rev=368901&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/CoordinatorImpl.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/CoordinatorImpl.java Fri Jan 13 14:58:04 2006
@@ -0,0 +1,48 @@
+/*
+ * Created on Dec 23, 2005
+ *
+ */
+package org.apache.kandula.coordinator.at;
+
+import java.rmi.RemoteException;
+
+import org.apache.kandula.coordinator.CallbackRegistry;
+import org.apache.kandula.wsat.CoordinatorPortType;
+import org.apache.kandula.wsat.Notification;
+
+/**
+ * @author Dasarath Weeratunge
+ *  
+ */
+public class CoordinatorImpl implements CoordinatorPortType {
+
+	public void preparedOperation(Notification params) throws RemoteException {
+		ATCoordinator c = (ATCoordinator) CallbackRegistry.getInstance().correlateMessage(
+			CallbackRegistry.CALLBACK_REF, false);
+		c.preparedOperation(params);
+	}
+
+	public void abortedOperation(Notification params) throws RemoteException {
+		ATCoordinator c = (ATCoordinator) CallbackRegistry.getInstance().correlateMessage(
+			CallbackRegistry.CALLBACK_REF, false);
+		c.abortedOperation(params);
+	}
+
+	public void readOnlyOperation(Notification params) throws RemoteException {
+		ATCoordinator c = (ATCoordinator) CallbackRegistry.getInstance().correlateMessage(
+			CallbackRegistry.CALLBACK_REF, false);
+		c.readOnlyOperation(params);
+	}
+
+	public void committedOperation(Notification params) throws RemoteException {
+		ATCoordinator c = (ATCoordinator) CallbackRegistry.getInstance().correlateMessage(
+			CallbackRegistry.CALLBACK_REF, false);
+		c.committedOperation(params);
+	}
+
+	public void replayOperation(Notification params) throws RemoteException {
+		ATCoordinator c = (ATCoordinator) CallbackRegistry.getInstance().correlateMessage(
+			CallbackRegistry.CALLBACK_REF, false);
+		c.replayOperation(params);
+	}
+}
\ No newline at end of file

Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/CoordinatorStub.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/CoordinatorStub.java?rev=368901&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/CoordinatorStub.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/CoordinatorStub.java Fri Jan 13 14:58:04 2006
@@ -0,0 +1,48 @@
+/*
+ * 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.kandula.coordinator.at;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.apache.axis.AxisFault;
+import org.apache.axis.message.addressing.EndpointReference;
+import org.apache.kandula.coordinator.Callback;
+import org.apache.kandula.coordinator.CoordinationService;
+import org.apache.kandula.utils.AddressingHeaders;
+import org.apache.kandula.utils.Service;
+import org.apache.kandula.utils.TCPSnifferHelper;
+import org.apache.kandula.wsat.CoordinatorBindingStub;
+
+/**
+ * @author Dasarath Weeratunge
+ * 
+ * Created on Jun 14, 2004
+ */
+public class CoordinatorStub extends CoordinatorBindingStub {
+
+	public CoordinatorStub(Callback participant, EndpointReference epr)
+			throws AxisFault, MalformedURLException {
+		super(new URL(TCPSnifferHelper.redirect(epr.getAddress().toString())),
+				new Service());
+		CoordinationService cs = CoordinationService.getInstance();
+		AddressingHeaders headers = new AddressingHeaders(epr, participant.getEndpointReference());
+		headers.setFaultTo(cs.getFaultDispatcherService(participant));
+		((Service) service).setAddressingHeaders(headers);
+	}
+
+}
\ No newline at end of file

Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/ParticipantImpl.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/ParticipantImpl.java?rev=368901&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/ParticipantImpl.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/ParticipantImpl.java Fri Jan 13 14:58:04 2006
@@ -0,0 +1,42 @@
+/*
+ * Created on Dec 25, 2005
+ *
+ */
+package org.apache.kandula.coordinator.at;
+
+import java.rmi.RemoteException;
+
+import org.apache.kandula.coordinator.CallbackRegistry;
+import org.apache.kandula.wsat.Notification;
+import org.apache.kandula.wsat.ParticipantPortType;
+
+/**
+ * @author Dasarath Weeratunge
+ *
+ */
+public class ParticipantImpl implements ParticipantPortType {
+
+	public void prepareOperation(Notification parameters)
+			throws RemoteException {
+		ParticipantPortType callback = (ParticipantPortType) CallbackRegistry.getInstance().correlateMessage(
+			CallbackRegistry.CALLBACK_REF, false);
+		if (callback != null)
+			callback.prepareOperation(parameters);
+	}
+
+	public void commitOperation(Notification parameters) throws RemoteException {
+		ParticipantPortType callback = (ParticipantPortType) CallbackRegistry.getInstance().correlateMessage(
+			CallbackRegistry.CALLBACK_REF, false);
+		if (callback != null)
+			callback.commitOperation(parameters);
+	}
+
+	public void rollbackOperation(Notification parameters)
+			throws RemoteException {
+		ParticipantPortType callback = (ParticipantPortType) CallbackRegistry.getInstance().correlateMessage(
+			CallbackRegistry.CALLBACK_REF, false);
+		if (callback != null)
+			callback.rollbackOperation(parameters);
+	}
+
+}

Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/ParticipantStub.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/ParticipantStub.java?rev=368901&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/ParticipantStub.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/ParticipantStub.java Fri Jan 13 14:58:04 2006
@@ -0,0 +1,52 @@
+/*
+ * 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.kandula.coordinator.at;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.apache.axis.AxisFault;
+import org.apache.axis.message.addressing.EndpointReference;
+import org.apache.kandula.coordinator.CoordinationService;
+import org.apache.kandula.utils.AddressingHeaders;
+import org.apache.kandula.utils.Service;
+import org.apache.kandula.utils.TCPSnifferHelper;
+import org.apache.kandula.wsat.ParticipantBindingStub;
+
+/**
+ * @author Dasarath Weeratunge
+ * 
+ * Created on Jun 14, 2004
+ */
+public class ParticipantStub extends ParticipantBindingStub {
+
+	public ParticipantStub(ATCoordinator coordinator, String participantRef,
+			EndpointReference epr) throws AxisFault, MalformedURLException {
+		super(new URL(TCPSnifferHelper.redirect(epr.getAddress().toString())),
+				new Service());
+
+		CoordinationService cs = CoordinationService.getInstance();
+
+		AddressingHeaders headers = new AddressingHeaders(epr,
+				cs.getCoordinatorService(coordinator, participantRef));
+		headers.setFaultTo(cs.getFaultDispatcherService(coordinator,
+			participantRef));
+		((Service) service).setAddressingHeaders(headers);
+
+	}
+
+}
\ No newline at end of file

Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/TransactionImpl.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/TransactionImpl.java?rev=368901&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/TransactionImpl.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/kandula/coordinator/at/TransactionImpl.java Fri Jan 13 14:58:04 2006
@@ -0,0 +1,196 @@
+/*
+ * 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.kandula.coordinator.at;
+
+import java.net.MalformedURLException;
+import java.rmi.RemoteException;
+
+import javax.transaction.RollbackException;
+import javax.xml.soap.Name;
+
+import org.apache.axis.AxisFault;
+import org.apache.axis.components.uuid.UUIDGenFactory;
+import org.apache.axis.message.addressing.EndpointReference;
+import org.apache.kandula.coordinator.Callback;
+import org.apache.kandula.coordinator.CoordinationContext;
+import org.apache.kandula.coordinator.CoordinationService;
+import org.apache.kandula.coordinator.TimedOutException;
+import org.apache.kandula.wsat.CompletionInitiatorPortType;
+import org.apache.kandula.wsat.Notification;
+import org.apache.kandula.wscoor.Expires;
+
+/**
+ * @author Dasarath Weeratunge
+ */
+public class TransactionImpl {
+
+	private CoordinationContext ctx;
+
+	private EndpointReference eprOfCompletionCoordinator;
+
+	private CompletionInitiatorCallback callback;
+
+	private boolean aborted = false;
+
+	private boolean committed = false;
+
+	private boolean timedOut = false;
+
+	private boolean canInitiateCompletion = false;
+
+	protected TransactionImpl(CoordinationContext ctx) {
+		this.ctx = ctx;
+	}
+
+	private void register() throws RemoteException {
+		long timeout = 0;
+		Expires ex = ctx.getExpires();
+		if (ex != null)
+			timeout = ex.get_value().longValue();
+		callback = new CompletionInitiatorCallback();
+		EndpointReference epr = CoordinationService.getInstance().getCompletionInitiatorService(
+			callback, timeout);
+		callback.setEndpointReference(epr);
+		eprOfCompletionCoordinator = ctx.register(
+			ATCoordinator.PROTOCOL_ID_COMPLETION, epr);
+		canInitiateCompletion = true;
+	}
+
+	private class CompletionInitiatorCallback implements
+			CompletionInitiatorPortType, Callback {
+		
+		private String id;
+
+		private EndpointReference epr;
+
+		public CompletionInitiatorCallback() {
+			id = "uuid:" + UUIDGenFactory.getUUIDGen().nextUUID();
+		}
+
+		public synchronized void committedOperation(Notification parameters) {
+			committed = true;
+			notify();
+		}
+
+		public synchronized void abortedOperation(Notification parameters) {
+			aborted = true;
+			notify();
+		}
+
+		public synchronized void timeout() {
+			timedOut = true;
+			notify();
+		}
+
+		public synchronized void onFault(Name code) {
+			notify();
+		}
+
+		public String getID() {
+			return id;
+		}
+
+		public void setEndpointReference(EndpointReference epr) {
+			this.epr = epr;
+		}
+
+		public EndpointReference getEndpointReference() {
+			return epr;
+		}
+	}
+
+	protected CoordinationContext getCoordinationContex() {
+		return ctx;
+	}
+
+	public void enlistParticipant(boolean durable,
+			AbstractParticipant participant) throws RemoteException {
+
+		TransactionManagerImpl tm = TransactionManagerImpl.getInstance();
+		TransactionImpl tx = tm.suspend();
+
+		participant.register(durable, ctx);
+
+		tm.resume(tx);
+	}
+
+	public void rollback() throws RemoteException {
+		TransactionManagerImpl tm = TransactionManagerImpl.getInstance();
+		TransactionImpl tx = tm.suspend();
+
+		if (!canInitiateCompletion)
+			register();
+
+		try {
+			synchronized (callback) {
+				if (!aborted) {
+					if (committed)
+						throw new IllegalStateException();
+					getCompletionCoordinatorStub().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);
+		} finally {
+			tm.resume(tx);
+		}
+	}
+
+	private CompletionCoordinatorStub getCompletionCoordinatorStub()
+			throws AxisFault, MalformedURLException {
+		return new CompletionCoordinatorStub(callback,
+				eprOfCompletionCoordinator);
+	}
+
+	public void commit() throws RemoteException {
+		TransactionManagerImpl tm = TransactionManagerImpl.getInstance();
+		TransactionImpl tx = tm.suspend();
+
+		if (!canInitiateCompletion)
+			register();
+
+		try {
+			synchronized (callback) {
+				if (!committed) {
+					if (aborted)
+						throw new IllegalStateException();
+					getCompletionCoordinatorStub().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);
+		} finally {
+			tm.resume(tx);
+		}
+	}
+}
\ 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