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 2005/12/28 05:17:36 UTC
svn commit: r359386 [1/3] - in /webservices/kandula/branches/Kandula_1/src:
./ conf/ java/ java/org/ java/org/apache/ java/org/apache/ws/
java/org/apache/ws/transaction/ java/org/apache/ws/transaction/coordinator/
java/org/apache/ws/transaction/coordin...
Author: dasarath
Date: Tue Dec 27 20:17:27 2005
New Revision: 359386
URL: http://svn.apache.org/viewcvs?rev=359386&view=rev
Log: (empty)
Added:
webservices/kandula/branches/Kandula_1/src/
webservices/kandula/branches/Kandula_1/src/conf/
webservices/kandula/branches/Kandula_1/src/conf/endpoints.conf
webservices/kandula/branches/Kandula_1/src/java/
webservices/kandula/branches/Kandula_1/src/java/org/
webservices/kandula/branches/Kandula_1/src/java/org/apache/
webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/
webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/
webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/
webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/ActivationImpl.java
webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/ActivationStub.java
webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/CoordinationContext.java
webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/CoordinationService.java
webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/Coordinator.java
webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/CoordinatorImpl.java
webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/InvalidCoordinationProtocolException.java
webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/ParticipantService.java
webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/RegistrationImpl.java
webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/RegistrationStub.java
webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/UnsupportedCoordinationTypeException.java
webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/
webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/AT.java
webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/AT2PCStatus.java
webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/ATCoordinator.java
webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/ATCoordinatorImpl.java
webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/ATManager.java
webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/ATOutHandler.java
webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/CompletionCoordinatorImpl.java
webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/CompletionCoordinatorStub.java
webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/CompletionInitiatorImpl.java
webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/CompletionInitiatorStub.java
webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/CoordinatorImpl.java
webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/CoordinatorStub.java
webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/ParticipantImpl.java
webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/ParticipantStub.java
webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/j2ee/
webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/j2ee/Bridge.java
webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/j2ee/Mediator.java
webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/j2ee/TxHandler.java
webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/utility/
webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/utility/CallbackRegistry.java
webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/utility/EndpointReferenceFactory.java
webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/utility/Service.java
webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/utility/TCPSnifferHelper.java
webservices/kandula/branches/Kandula_1/src/samples/
webservices/kandula/branches/Kandula_1/src/samples/test-suite1/
webservices/kandula/branches/Kandula_1/src/samples/test-suite1/TestSuite1.wsdl
webservices/kandula/branches/Kandula_1/src/samples/test-suite1/TestSuite1PortType.java
webservices/kandula/branches/Kandula_1/src/samples/test-suite1/build/
webservices/kandula/branches/Kandula_1/src/samples/test-suite1/build.xml
webservices/kandula/branches/Kandula_1/src/samples/test-suite1/client-config.wsdd
webservices/kandula/branches/Kandula_1/src/samples/test-suite1/src/
webservices/kandula/branches/Kandula_1/src/samples/test-suite1/src/TestSuite1PortTypeServiceTestCase.java
webservices/kandula/branches/Kandula_1/src/samples/test-suite1/src/TestSuite1SoapBindingImpl.java
webservices/kandula/branches/Kandula_1/src/schema/
webservices/kandula/branches/Kandula_1/src/schema/addr.xsd
webservices/kandula/branches/Kandula_1/src/schema/wsat.wsdl
webservices/kandula/branches/Kandula_1/src/schema/wsat.xsd
webservices/kandula/branches/Kandula_1/src/schema/wscoor.wsdl
webservices/kandula/branches/Kandula_1/src/schema/wscoor.xsd
Added: webservices/kandula/branches/Kandula_1/src/conf/endpoints.conf
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/conf/endpoints.conf?rev=359386&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/conf/endpoints.conf (added)
+++ webservices/kandula/branches/Kandula_1/src/conf/endpoints.conf Tue Dec 27 20:17:27 2005
@@ -0,0 +1,10 @@
+# endpoints
+host=localhost
+protocol=http
+port=8081
+ActivationPortTypeRPC=/axis/services/Activation
+RegistrationPortTypeRPC=/axis/services/Registration
+CoordinatorPortType=/axis/services/Coordinator
+ParticipantPortType=/axis/services/Participant
+CompletionInitiatorPortType=/axis/services/CompletionInitiator
+CompletionCoordinatorPortType=/axis/services/CompletionCoordinator
Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/ActivationImpl.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/ActivationImpl.java?rev=359386&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/ActivationImpl.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/ActivationImpl.java Tue Dec 27 20:17:27 2005
@@ -0,0 +1,47 @@
+/*
+ * 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.coordinator;
+
+import java.rmi.RemoteException;
+
+import org.apache.axis.types.URI.MalformedURIException;
+import org.apache.ws.transaction.wscoor.ActivationPortTypeRPC;
+import org.apache.ws.transaction.wscoor.CreateCoordinationContextResponseType;
+import org.apache.ws.transaction.wscoor.CreateCoordinationContextType;
+
+public class ActivationImpl implements ActivationPortTypeRPC {
+
+ public CreateCoordinationContextResponseType createCoordinationContextOperation(
+ CreateCoordinationContextType parameters) throws RemoteException {
+
+ String t = parameters.getCoordinationType().toString();
+ CoordinationContext ctx;
+ try {
+ ctx = CoordinationService.getInstance().createCoordinationContext(t);
+ } catch (MalformedURIException e) {
+ e.printStackTrace();
+ throw new RuntimeException(e);
+ } catch (UnsupportedCoordinationTypeException e) {
+ e.printStackTrace();
+ throw new RuntimeException(e);
+ }
+ 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/ws/transaction/coordinator/ActivationStub.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/ActivationStub.java?rev=359386&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/ActivationStub.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/ActivationStub.java Tue Dec 27 20:17:27 2005
@@ -0,0 +1,53 @@
+/*
+ * 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.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.ws.transaction.utility.Service;
+import org.apache.ws.transaction.utility.TCPSnifferHelper;
+import org.apache.ws.transaction.wscoor.ActivationPortTypeRPCBindingStub;
+import org.apache.ws.transaction.wscoor.CreateCoordinationContextResponseType;
+import org.apache.ws.transaction.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(epr));
+ }
+
+ 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/ws/transaction/coordinator/CoordinationContext.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/CoordinationContext.java?rev=359386&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/CoordinationContext.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/CoordinationContext.java Tue Dec 27 20:17:27 2005
@@ -0,0 +1,139 @@
+/*
+ * 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.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.ws.transaction.wscoor.CoordinationContextType;
+import org.apache.ws.transaction.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/ws/transaction/coordinator/CoordinationService.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/CoordinationService.java?rev=359386&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/CoordinationService.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/CoordinationService.java Tue Dec 27 20:17:27 2005
@@ -0,0 +1,81 @@
+/*
+ * Created on Dec 25, 2005
+ *
+ */
+package org.apache.ws.transaction.coordinator;
+
+import org.apache.axis.message.MessageElement;
+import org.apache.axis.message.addressing.EndpointReference;
+import org.apache.axis.message.addressing.PortType;
+import org.apache.axis.message.addressing.ReferencePropertiesType;
+import org.apache.axis.types.URI.MalformedURIException;
+import org.apache.ws.transaction.coordinator.at.ATCoordinator;
+import org.apache.ws.transaction.coordinator.at.ATCoordinatorImpl;
+import org.apache.ws.transaction.utility.CallbackRegistry;
+import org.apache.ws.transaction.utility.EndpointReferenceFactory;
+
+/**
+ * @author Dasarath Weeratunge
+ *
+ */
+public class CoordinationService {
+ public static PortType ACTIVATION_SERVICE = new PortType(
+ "http://schemas.xmlsoap.org/ws/2004/10/wscoor",
+ "ActivationPortTypeRPC");
+
+ public static PortType COMPLETION_COORDINATOR_SERVICE = new PortType(
+ "http://schemas.xmlsoap.org/ws/2004/10/wsat",
+ "CompletionCoordinatorPortType");
+
+ public static PortType COORDINATOR_SERVICE = new PortType(
+ "http://schemas.xmlsoap.org/ws/2004/10/wsat", "CoordinatorPortType");
+
+ private static CoordinationService instance = new CoordinationService();
+
+ public static PortType REGISTRATION_SERVICE = new PortType(
+ "http://schemas.xmlsoap.org/ws/2004/10/wscoor",
+ "RegistrationPortTypeRPC");
+
+ public static CoordinationService getInstance() {
+ return instance;
+ }
+
+ private CoordinationService() {
+ }
+
+ public CoordinationContext createCoordinationContext(String coordinationType)
+ throws UnsupportedCoordinationTypeException, MalformedURIException {
+ if (!ATCoordinator.COORDINATION_TYPE_ID.equals(coordinationType))
+ throw new UnsupportedCoordinationTypeException();
+ Coordinator c = new ATCoordinatorImpl();
+ CallbackRegistry.getInstance().registerCallback(c.getID(), c);
+ return c.getCoordinationContext();
+ }
+
+ public EndpointReference getActivationService() {
+ return EndpointReferenceFactory.getInstance().getEndpointReference(
+ ACTIVATION_SERVICE, null);
+ }
+
+ public EndpointReference getCompletionCoordinatorService(ATCoordinator c) {
+ ReferencePropertiesType r = new ReferencePropertiesType();
+ r.add(new MessageElement(CallbackRegistry.COORDINATOR_REF, c.getID()));
+ return EndpointReferenceFactory.getInstance().getEndpointReference(
+ COMPLETION_COORDINATOR_SERVICE, r);
+ }
+
+ public EndpointReference getCoordinatorService(ATCoordinator c, String ref) {
+ ReferencePropertiesType r = new ReferencePropertiesType();
+ r.add(new MessageElement(CallbackRegistry.COORDINATOR_REF, c.getID()));
+ r.add(new MessageElement(ATCoordinator.PARTICIPANT_REF, ref));
+ return EndpointReferenceFactory.getInstance().getEndpointReference(
+ COORDINATOR_SERVICE, r);
+ }
+
+ public EndpointReference getRegistrationService(Coordinator c) {
+ ReferencePropertiesType r = new ReferencePropertiesType();
+ r.add(new MessageElement(CallbackRegistry.COORDINATOR_REF, c.getID()));
+ return EndpointReferenceFactory.getInstance().getEndpointReference(
+ REGISTRATION_SERVICE, r);
+ }
+}
\ No newline at end of file
Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/Coordinator.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/Coordinator.java?rev=359386&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/Coordinator.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/Coordinator.java Tue Dec 27 20:17:27 2005
@@ -0,0 +1,17 @@
+/*
+ * Created on Dec 23, 2005
+ *
+ */
+package org.apache.ws.transaction.coordinator;
+
+import org.apache.ws.transaction.wscoor.RegistrationPortTypeRPC;
+
+/**
+ * @author Dasarath Weeratunge
+ *
+ */
+public interface Coordinator extends RegistrationPortTypeRPC {
+ String getID();
+
+ CoordinationContext getCoordinationContext();
+}
\ No newline at end of file
Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/CoordinatorImpl.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/CoordinatorImpl.java?rev=359386&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/CoordinatorImpl.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/CoordinatorImpl.java Tue Dec 27 20:17:27 2005
@@ -0,0 +1,58 @@
+/*
+ * Created on Dec 23, 2005
+ *
+ */
+package org.apache.ws.transaction.coordinator;
+
+import java.rmi.RemoteException;
+
+import org.apache.axis.components.uuid.UUIDGen;
+import org.apache.axis.components.uuid.UUIDGenFactory;
+import org.apache.axis.message.addressing.EndpointReference;
+import org.apache.axis.types.URI.MalformedURIException;
+import org.apache.ws.transaction.wscoor.RegisterResponseType;
+import org.apache.ws.transaction.wscoor.RegisterType;
+
+/**
+ * @author Dasarath Weeratunge
+ *
+ */
+public abstract class CoordinatorImpl implements Coordinator {
+ private String id;
+
+ private CoordinationContext ctx;
+
+ public CoordinatorImpl(String coordinationType) throws MalformedURIException {
+ UUIDGen gen = UUIDGenFactory.getUUIDGen();
+ id = "uuid:" + gen.nextUUID();
+ CoordinationService cs = CoordinationService.getInstance();
+ EndpointReference epr = cs.getRegistrationService(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 RegisterResponseType registerOperation(RegisterType params)
+ throws RemoteException {
+ EndpointReference epr = null;
+ try {
+ epr = register(params.getProtocolIdentifier().toString(),
+ new EndpointReference(params.getParticipantProtocolService()));
+ } catch (InvalidCoordinationProtocolException e) {
+ e.printStackTrace();
+ throw new RemoteException(e.getMessage());
+ }
+ RegisterResponseType r = new RegisterResponseType();
+ r.setCoordinatorProtocolService(epr);
+ return r;
+ }
+}
\ No newline at end of file
Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/InvalidCoordinationProtocolException.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/InvalidCoordinationProtocolException.java?rev=359386&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/InvalidCoordinationProtocolException.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/InvalidCoordinationProtocolException.java Tue Dec 27 20:17:27 2005
@@ -0,0 +1,13 @@
+/*
+ * Created on Dec 23, 2005
+ *
+ */
+package org.apache.ws.transaction.coordinator;
+
+/**
+ * @author Dasarath Weeratunge
+ *
+ */
+public class InvalidCoordinationProtocolException extends Exception {
+
+}
Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/ParticipantService.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/ParticipantService.java?rev=359386&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/ParticipantService.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/ParticipantService.java Tue Dec 27 20:17:27 2005
@@ -0,0 +1,61 @@
+/*
+ * Created on Dec 25, 2005
+ *
+ */
+package org.apache.ws.transaction.coordinator;
+
+import org.apache.axis.components.uuid.UUIDGenFactory;
+import org.apache.axis.message.MessageElement;
+import org.apache.axis.message.addressing.EndpointReference;
+import org.apache.axis.message.addressing.PortType;
+import org.apache.axis.message.addressing.ReferencePropertiesType;
+import org.apache.ws.transaction.utility.CallbackRegistry;
+import org.apache.ws.transaction.utility.EndpointReferenceFactory;
+import org.apache.ws.transaction.wsat.CompletionInitiatorPortType;
+import org.apache.ws.transaction.wsat.ParticipantPortType;
+
+/**
+ * @author Dasarath Weeratunge
+ *
+ */
+public class ParticipantService {
+ public static PortType COMPLETION_INITIATOR_SERVICE = new PortType(
+ "http://schemas.xmlsoap.org/ws/2004/10/wsat",
+ "CompletionInitiatorPortType");
+
+ public static PortType PARTICIPANT_SERVICE = new PortType(
+ "http://schemas.xmlsoap.org/ws/2004/10/wsat", "ParticipantPortType");
+
+ private static ParticipantService instance = new ParticipantService();
+
+ private ParticipantService() {
+ }
+
+ public static ParticipantService getInstance() {
+ return instance;
+ }
+
+ public EndpointReference getCompletionInitiatorService(
+ CompletionInitiatorPortType callback) {
+ String urn = "uuid" + UUIDGenFactory.getUUIDGen().nextUUID();
+ CallbackRegistry.getInstance().registerCallback(urn, callback);
+ ReferencePropertiesType r = new ReferencePropertiesType();
+ r.add(new MessageElement(CallbackRegistry.CALLBACK_REF, urn));
+ return EndpointReferenceFactory.getInstance().getEndpointReference(
+ COMPLETION_INITIATOR_SERVICE, r);
+ }
+
+ public EndpointReference getParticipantService(ParticipantPortType callback) {
+ String urn = "uuid" + UUIDGenFactory.getUUIDGen().nextUUID();
+ CallbackRegistry.getInstance().registerCallback(urn, callback);
+ ReferencePropertiesType r = new ReferencePropertiesType();
+ r.add(new MessageElement(CallbackRegistry.CALLBACK_REF, urn));
+ return EndpointReferenceFactory.getInstance().getEndpointReference(
+ PARTICIPANT_SERVICE, r);
+ }
+
+ public void forget(Object callback) {
+ CallbackRegistry.getInstance().remove(callback);
+ }
+
+}
\ No newline at end of file
Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/RegistrationImpl.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/RegistrationImpl.java?rev=359386&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/RegistrationImpl.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/RegistrationImpl.java Tue Dec 27 20:17:27 2005
@@ -0,0 +1,34 @@
+/*
+ * 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.coordinator;
+
+import java.rmi.RemoteException;
+
+import org.apache.ws.transaction.utility.CallbackRegistry;
+import org.apache.ws.transaction.wscoor.RegisterResponseType;
+import org.apache.ws.transaction.wscoor.RegisterType;
+import org.apache.ws.transaction.wscoor.RegistrationPortTypeRPC;
+
+public class RegistrationImpl implements RegistrationPortTypeRPC {
+
+ public RegisterResponseType registerOperation(RegisterType params)
+ throws RemoteException {
+ Coordinator c = (Coordinator) CallbackRegistry.getInstance().correlateMessage(
+ CallbackRegistry.COORDINATOR_REF, false);
+ return c.registerOperation(params);
+ }
+}
\ No newline at end of file
Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/RegistrationStub.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/RegistrationStub.java?rev=359386&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/RegistrationStub.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/RegistrationStub.java Tue Dec 27 20:17:27 2005
@@ -0,0 +1,53 @@
+/*
+ * 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.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.ws.transaction.utility.Service;
+import org.apache.ws.transaction.utility.TCPSnifferHelper;
+import org.apache.ws.transaction.wscoor.RegisterType;
+import org.apache.ws.transaction.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(epr));
+ }
+
+ 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/ws/transaction/coordinator/UnsupportedCoordinationTypeException.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/UnsupportedCoordinationTypeException.java?rev=359386&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/UnsupportedCoordinationTypeException.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/UnsupportedCoordinationTypeException.java Tue Dec 27 20:17:27 2005
@@ -0,0 +1,13 @@
+/*
+ * Created on Dec 25, 2005
+ *
+ */
+package org.apache.ws.transaction.coordinator;
+
+/**
+ * @author Dasarath Weeratunge
+ *
+ */
+public class UnsupportedCoordinationTypeException extends Exception {
+
+}
Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/AT.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/AT.java?rev=359386&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/AT.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/AT.java Tue Dec 27 20:17:27 2005
@@ -0,0 +1,109 @@
+/*
+ * 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.coordinator.at;
+
+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.wsat.CompletionInitiatorPortType;
+import org.apache.ws.transaction.wsat.Notification;
+
+/**
+ * @author Dasarath Weeratunge
+ */
+public class AT {
+ private CoordinationContext ctx;
+
+ private EndpointReference epr;
+
+ private CompletionInitiatorCallback callback;
+
+ private boolean aborted = false;
+
+ private boolean committed = false;
+
+ public AT(CoordinationContext ctx) throws RemoteException {
+ this.ctx = ctx;
+ callback = new CompletionInitiatorCallback();
+ epr = ctx.register(ATCoordinator.PROTOCOL_ID_COMPLETION,
+ ParticipantService.getInstance().getCompletionInitiatorService(
+ callback));
+ }
+
+ private class CompletionInitiatorCallback implements
+ CompletionInitiatorPortType {
+ public synchronized void committedOperation(Notification parameters)
+ throws RemoteException {
+ committed = true;
+ notify();
+ }
+
+ public synchronized void abortedOperation(Notification parameters)
+ throws RemoteException {
+ aborted = 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 (!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 (!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/coordinator/at/AT2PCStatus.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/AT2PCStatus.java?rev=359386&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/AT2PCStatus.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/AT2PCStatus.java Tue Dec 27 20:17:27 2005
@@ -0,0 +1,43 @@
+/*
+ * Created on Dec 23, 2005
+ *
+ */
+package org.apache.ws.transaction.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 COMMITTING = 5;
+
+ public static final int ABORTING = 6;
+
+ public static final int ENDED = 7;
+
+ private static Field[] flds = AT2PCStatus.class.getDeclaredFields();
+
+ public static String getStatusName(int status) {
+ String statusName = null;
+
+ try {
+ for (int i = 0; i < flds.length; i++) {
+ if (flds[i].getInt(null) == status)
+ statusName = flds[i].getName();
+ }
+ } catch (Exception e) {
+ statusName = null;
+ }
+ return statusName;
+ }
+}
\ No newline at end of file
Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/ATCoordinator.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/ATCoordinator.java?rev=359386&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/ATCoordinator.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/ATCoordinator.java Tue Dec 27 20:17:27 2005
@@ -0,0 +1,38 @@
+/*
+ * 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.coordinator.at;
+
+import javax.xml.namespace.QName;
+
+import org.apache.ws.transaction.coordinator.Coordinator;
+import org.apache.ws.transaction.wsat.CompletionCoordinatorPortType;
+import org.apache.ws.transaction.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/ws/transaction/coordinator/at/ATCoordinatorImpl.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/ATCoordinatorImpl.java?rev=359386&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/ATCoordinatorImpl.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/ATCoordinatorImpl.java Tue Dec 27 20:17:27 2005
@@ -0,0 +1,404 @@
+/*
+ * Created on Dec 23, 2005
+ *
+ */
+package org.apache.ws.transaction.coordinator.at;
+
+import java.rmi.RemoteException;
+import java.util.ArrayList;
+import java.util.Collections;
+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 org.apache.axis.MessageContext;
+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.Constants;
+import org.apache.axis.message.addressing.EndpointReference;
+import org.apache.axis.types.URI.MalformedURIException;
+import org.apache.ws.transaction.coordinator.CoordinationService;
+import org.apache.ws.transaction.coordinator.CoordinatorImpl;
+import org.apache.ws.transaction.coordinator.InvalidCoordinationProtocolException;
+import org.apache.ws.transaction.wsat.Notification;
+
+/**
+ * @author Dasarath Weeratunge
+ *
+ */
+public class ATCoordinatorImpl extends CoordinatorImpl implements ATCoordinator {
+
+ int status = AT2PCStatus.NONE;
+
+ private static final int VOLATILE_2PC = 0;
+
+ private static final int DURABLE_2PC = 1;
+
+ Map participants2PC[] = new Map[2];
+
+ Set prepared = Collections.synchronizedSet(new HashSet());
+
+ List participantsComp = Collections.synchronizedList(new ArrayList());
+
+ public static final int MAX_ITERS = 3;
+
+ public static final int ITER_DELAY = 15 * 1000;
+
+ public static final int RESPONSE_DELAY = 3 * 1000;
+
+ public ATCoordinatorImpl() throws MalformedURIException {
+ super(COORDINATION_TYPE_ID);
+ status = AT2PCStatus.ACTIVE;
+ for (int i = 0; i < 2; i++)
+ participants2PC[i] = Collections.synchronizedMap(new HashMap());
+ }
+
+ public synchronized EndpointReference register(String prot,
+ EndpointReference pps) throws InvalidCoordinationProtocolException {
+ if (!(status == AT2PCStatus.ACTIVE || status == AT2PCStatus.PREPARING_VOLATILE))
+ throw new IllegalStateException();
+ CoordinationService cs = CoordinationService.getInstance();
+ String ref = null;
+ EndpointReference epr = null;
+ if (prot.equals(PROTOCOL_ID_COMPLETION)) {
+ if (pps != null)
+ participantsComp.add(pps);
+ epr = cs.getCompletionCoordinatorService(this);
+ } else {
+ if (pps == null)
+ throw new IllegalArgumentException();
+ UUIDGen gen = UUIDGenFactory.getUUIDGen();
+ ref = "uuid:" + gen.nextUUID();
+ if (prot.equals(PROTOCOL_ID_VOLATILE_2PC))
+ participants2PC[VOLATILE_2PC].put(ref, pps);
+ else if (prot.equals(PROTOCOL_ID_DURABLE_2PC))
+ participants2PC[DURABLE_2PC].put(ref, pps);
+ else
+ throw new InvalidCoordinationProtocolException();
+ epr = cs.getCoordinatorService(this, ref);
+ }
+ return epr;
+ }
+
+ public void forget2PC(String ref) {
+ if (participants2PC[VOLATILE_2PC].remove(ref) == null)
+ participants2PC[DURABLE_2PC].remove(ref);
+ }
+
+ 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.ENDED:
+ }
+ }
+
+ public void aborted(String ref) {
+ switch (status) {
+ case AT2PCStatus.ACTIVE:
+ case AT2PCStatus.PREPARING_VOLATILE:
+ case AT2PCStatus.PREPARING_DURABLE:
+ forget2PC(ref);
+ rollback();
+ return;
+
+ case AT2PCStatus.COMMITTING:
+ throw new IllegalStateException();
+
+ case AT2PCStatus.ABORTING:
+ forget2PC(ref);
+ return;
+
+ case AT2PCStatus.ENDED:
+ return;
+ }
+ }
+
+ public void readOnly(String ref) {
+ switch (status) {
+ case AT2PCStatus.ACTIVE:
+ case AT2PCStatus.PREPARING_VOLATILE:
+ case AT2PCStatus.PREPARING_DURABLE:
+ forget2PC(ref);
+ return;
+
+ case AT2PCStatus.COMMITTING:
+ throw new IllegalStateException();
+
+ case AT2PCStatus.ABORTING:
+ forget2PC(ref);
+ return;
+
+ case AT2PCStatus.ENDED:
+ return;
+ }
+ }
+
+ public void replay(String ref) {
+ switch (status) {
+ case AT2PCStatus.ACTIVE:
+ case AT2PCStatus.PREPARING_VOLATILE:
+ case AT2PCStatus.PREPARING_DURABLE:
+ rollback();
+ return;
+
+ case AT2PCStatus.COMMITTING:
+ EndpointReference epr = get2PCEndpointReference(ref);
+ try {
+ new ParticipantStub(epr).commitOperation(null);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return;
+
+ case AT2PCStatus.ABORTING:
+ epr = get2PCEndpointReference(ref);
+ try {
+ new ParticipantStub(epr).rollbackOperation(null);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return;
+
+ case AT2PCStatus.ENDED:
+ return;
+ }
+ }
+
+ public void prepared(String ref) {
+ switch (status) {
+ case AT2PCStatus.ACTIVE:
+ rollback();
+ throw new IllegalStateException();
+
+ case AT2PCStatus.PREPARING_VOLATILE:
+ case AT2PCStatus.PREPARING_DURABLE:
+ prepared.add(ref);
+ return;
+
+ case AT2PCStatus.COMMITTING:
+ EndpointReference epr = get2PCEndpointReference(ref);
+ try {
+ new ParticipantStub(epr).commitOperation(null);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return;
+
+ case AT2PCStatus.ABORTING:
+ epr = get2PCEndpointReference(ref);
+ try {
+ new ParticipantStub(epr).rollbackOperation(null);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ forget2PC(ref);
+ return;
+
+ case AT2PCStatus.ENDED:
+ return;
+ }
+ }
+
+ public void committed(String ref) {
+ switch (status) {
+ case AT2PCStatus.ACTIVE:
+ case AT2PCStatus.PREPARING_VOLATILE:
+ case AT2PCStatus.PREPARING_DURABLE:
+ rollback();
+ throw new IllegalStateException();
+
+ case AT2PCStatus.COMMITTING:
+ forget2PC(ref);
+ return;
+
+ case AT2PCStatus.ABORTING:
+ throw new IllegalStateException();
+
+ case AT2PCStatus.ENDED:
+ return;
+ }
+ }
+
+ private EndpointReference get2PCEndpointReference(String ref) {
+ EndpointReference epr = (EndpointReference) participants2PC[VOLATILE_2PC].get(ref);
+ if (epr == null)
+ epr = (EndpointReference) participants2PC[DURABLE_2PC].get(ref);
+ return epr;
+ }
+
+ private boolean prepare(int prot) {
+ int iters = 0;
+ int status_old = status;
+
+ while (iters < MAX_ITERS) {
+ if (iters++ > 0)
+ pause(ITER_DELAY - RESPONSE_DELAY);
+
+ Iterator iter = participants2PC[prot].values().iterator();
+ while (iter.hasNext()) {
+ if (status == AT2PCStatus.ABORTING)
+ return false;
+ try {
+ new ParticipantStub((EndpointReference) iter.next()).prepareOperation(null);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ pause(RESPONSE_DELAY);
+
+ if (prepared.containsAll(participants2PC[prot].keySet()))
+ return status == status_old;
+ }
+
+ return false;
+ }
+
+ private boolean prepare() {
+ status = AT2PCStatus.PREPARING_VOLATILE;
+ if (!prepare(VOLATILE_2PC))
+ return false;
+
+ status = AT2PCStatus.PREPARING_DURABLE;
+ return prepare(DURABLE_2PC);
+ }
+
+ 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.ENDED:
+ return;
+ }
+
+ if (!prepare()) {
+ rollback();
+ return;
+ }
+
+ status = AT2PCStatus.COMMITTING;
+ terminate();
+ }
+
+ private void pause(long millis) {
+ try {
+ wait(millis);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private void terminate() {
+ int iters = 0;
+ while (iters < MAX_ITERS
+ && !(participants2PC[VOLATILE_2PC].isEmpty() && participants2PC[DURABLE_2PC].isEmpty())) {
+ if (iters++ > 0)
+ pause(ITER_DELAY - RESPONSE_DELAY);
+
+ for (int prot = VOLATILE_2PC; prot == VOLATILE_2PC
+ || prot == DURABLE_2PC; prot = prot == VOLATILE_2PC ? DURABLE_2PC
+ : -1) {
+ Iterator iter = participants2PC[prot].values().iterator();
+ while (iter.hasNext())
+ try {
+ ParticipantStub p = new ParticipantStub(
+ (EndpointReference) iter.next());
+ if (status == AT2PCStatus.ABORTING)
+ p.rollbackOperation(null);
+ else
+ p.commitOperation(null);
+ } catch (Exception e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+
+ }
+
+ pause(RESPONSE_DELAY);
+ }
+
+ if (participants2PC[VOLATILE_2PC].isEmpty()
+ && participants2PC[DURABLE_2PC].isEmpty()) {
+ Iterator iter = participantsComp.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) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ status = AT2PCStatus.ENDED;
+ }
+
+ 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 synchronized String getParticipantRef() {
+ AddressingHeaders header = (AddressingHeaders) MessageContext.getCurrentContext().getProperty(
+ Constants.ENV_ADDRESSING_REQUEST_HEADERS);
+ MessageElement e = header.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();
+ }
+}
\ No newline at end of file
Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/ATManager.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/ATManager.java?rev=359386&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/ATManager.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/ATManager.java Tue Dec 27 20:17:27 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.coordinator.at;
+
+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;
+
+public class ATManager {
+ private static ATManager instance = new ATManager();
+
+ private static ThreadLocal threadInfo = new ThreadLocal();
+
+ public static ATManager getInstance() {
+ return instance;
+ }
+
+ private ATManager() {
+ }
+
+ 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 AT(ctx));
+ } catch (RemoteException e) {
+ throw e;
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void commit() throws RemoteException {
+ AT tx = getTransaction();
+ if (tx == null)
+ throw new IllegalStateException();
+ forget();
+ tx.commit();
+ }
+
+ public void rollback() throws RemoteException {
+ AT tx = getTransaction();
+ if (tx == null)
+ throw new IllegalStateException();
+ forget();
+ tx.rollback();
+ }
+
+ public AT suspend() {
+ AT tx = getTransaction();
+ forget();
+ return tx;
+ }
+
+ public void resume(AT tx) {
+ if (threadInfo.get() != null)
+ throw new IllegalStateException();
+ else
+ threadInfo.set(tx);
+ }
+
+ public void forget() {
+ threadInfo.set(null);
+ }
+
+ public AT getTransaction() {
+ return (AT) threadInfo.get();
+ }
+}
\ No newline at end of file
Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/ATOutHandler.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/ATOutHandler.java?rev=359386&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/ATOutHandler.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/ATOutHandler.java Tue Dec 27 20:17:27 2005
@@ -0,0 +1,47 @@
+/*
+ * 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.coordinator.at;
+
+import javax.xml.soap.SOAPHeader;
+
+import org.apache.axis.AxisFault;
+import org.apache.axis.MessageContext;
+import org.apache.axis.handlers.BasicHandler;
+import org.apache.ws.transaction.coordinator.at.AT;
+import org.apache.ws.transaction.coordinator.at.ATManager;
+
+
+
+/**
+ * @author Dasarath Weeratunge
+ */
+public class ATOutHandler extends BasicHandler {
+ ATManager tm= ATManager.getInstance();
+
+ public void invoke(MessageContext msgContext) throws AxisFault {
+ AT tx= tm.getTransaction();
+ if (tx != null) {
+ try {
+ SOAPHeader header= msgContext.getCurrentMessage().getSOAPEnvelope().getHeader();
+ tx.getCoordinationContex().toSOAPHeaderElement(header);
+ }
+ catch (Exception e) {
+ throw AxisFault.makeFault(e);
+ }
+ }
+ }
+}
Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/CompletionCoordinatorImpl.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/CompletionCoordinatorImpl.java?rev=359386&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/CompletionCoordinatorImpl.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/CompletionCoordinatorImpl.java Tue Dec 27 20:17:27 2005
@@ -0,0 +1,31 @@
+/*
+ * Created on Dec 23, 2005
+ *
+ */
+package org.apache.ws.transaction.coordinator.at;
+
+import java.rmi.RemoteException;
+
+import org.apache.ws.transaction.utility.CallbackRegistry;
+import org.apache.ws.transaction.wsat.CompletionCoordinatorPortType;
+import org.apache.ws.transaction.wsat.Notification;
+
+/**
+ * @author Dasarath Weeratunge
+ *
+ */
+public class CompletionCoordinatorImpl implements CompletionCoordinatorPortType {
+
+ public void commitOperation(Notification params) throws RemoteException {
+ ATCoordinator c = (ATCoordinator) CallbackRegistry.getInstance().correlateMessage(
+ CallbackRegistry.COORDINATOR_REF, false);
+ c.commitOperation(params);
+ }
+
+ public void rollbackOperation(Notification params) throws RemoteException {
+ ATCoordinator c = (ATCoordinator) CallbackRegistry.getInstance().correlateMessage(
+ CallbackRegistry.COORDINATOR_REF, false);
+ c.rollbackOperation(params);
+ }
+
+}
\ No newline at end of file
Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/CompletionCoordinatorStub.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/CompletionCoordinatorStub.java?rev=359386&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/CompletionCoordinatorStub.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/CompletionCoordinatorStub.java Tue Dec 27 20:17:27 2005
@@ -0,0 +1,40 @@
+/*
+ * 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.coordinator.at;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.apache.axis.AxisFault;
+import org.apache.ws.transaction.utility.Service;
+import org.apache.ws.transaction.utility.TCPSnifferHelper;
+import org.apache.ws.transaction.wsat.CompletionCoordinatorBindingStub;
+
+/**
+ * @author Dasarath Weeratunge
+ *
+ * Created on Jun 14, 2004
+ */
+public class CompletionCoordinatorStub extends CompletionCoordinatorBindingStub {
+
+ public CompletionCoordinatorStub(
+ org.apache.axis.message.addressing.EndpointReference epr)
+ throws AxisFault, MalformedURLException {
+ super(new URL(TCPSnifferHelper.redirect(epr.getAddress().toString())),
+ new Service(epr));
+ }
+}
\ No newline at end of file
Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/CompletionInitiatorImpl.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/CompletionInitiatorImpl.java?rev=359386&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/CompletionInitiatorImpl.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/CompletionInitiatorImpl.java Tue Dec 27 20:17:27 2005
@@ -0,0 +1,24 @@
+package org.apache.ws.transaction.coordinator.at;
+
+import org.apache.ws.transaction.utility.CallbackRegistry;
+import org.apache.ws.transaction.wsat.CompletionInitiatorPortType;
+
+public class CompletionInitiatorImpl implements CompletionInitiatorPortType {
+ public void committedOperation(
+ org.apache.ws.transaction.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.ws.transaction.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/ws/transaction/coordinator/at/CompletionInitiatorStub.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/CompletionInitiatorStub.java?rev=359386&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/CompletionInitiatorStub.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/CompletionInitiatorStub.java Tue Dec 27 20:17:27 2005
@@ -0,0 +1,41 @@
+/*
+ * 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.coordinator.at;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.apache.axis.AxisFault;
+import org.apache.ws.transaction.utility.Service;
+import org.apache.ws.transaction.utility.TCPSnifferHelper;
+import org.apache.ws.transaction.wsat.CompletionInitiatorBindingStub;
+
+/**
+ * @author Dasarath Weeratunge
+ *
+ * Created on Jun 14, 2004
+ */
+public class CompletionInitiatorStub extends CompletionInitiatorBindingStub {
+
+ public CompletionInitiatorStub(
+ org.apache.axis.message.addressing.EndpointReference epr)
+ throws AxisFault, MalformedURLException {
+ super(new URL(TCPSnifferHelper.redirect(epr.getAddress().toString())),
+ new Service(epr));
+ }
+
+}
\ No newline at end of file
Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/CoordinatorImpl.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/CoordinatorImpl.java?rev=359386&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/CoordinatorImpl.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/CoordinatorImpl.java Tue Dec 27 20:17:27 2005
@@ -0,0 +1,48 @@
+/*
+ * Created on Dec 23, 2005
+ *
+ */
+package org.apache.ws.transaction.coordinator.at;
+
+import java.rmi.RemoteException;
+
+import org.apache.ws.transaction.utility.CallbackRegistry;
+import org.apache.ws.transaction.wsat.CoordinatorPortType;
+import org.apache.ws.transaction.wsat.Notification;
+
+/**
+ * @author Dasarath Weeratunge
+ *
+ */
+public class CoordinatorImpl implements CoordinatorPortType {
+
+ public void preparedOperation(Notification params) throws RemoteException {
+ ATCoordinator c = (ATCoordinator) CallbackRegistry.getInstance().correlateMessage(
+ CallbackRegistry.COORDINATOR_REF, false);
+ c.preparedOperation(params);
+ }
+
+ public void abortedOperation(Notification params) throws RemoteException {
+ ATCoordinator c = (ATCoordinator) CallbackRegistry.getInstance().correlateMessage(
+ CallbackRegistry.COORDINATOR_REF, false);
+ c.abortedOperation(params);
+ }
+
+ public void readOnlyOperation(Notification params) throws RemoteException {
+ ATCoordinator c = (ATCoordinator) CallbackRegistry.getInstance().correlateMessage(
+ CallbackRegistry.COORDINATOR_REF, false);
+ c.readOnlyOperation(params);
+ }
+
+ public void committedOperation(Notification params) throws RemoteException {
+ ATCoordinator c = (ATCoordinator) CallbackRegistry.getInstance().correlateMessage(
+ CallbackRegistry.COORDINATOR_REF, false);
+ c.committedOperation(params);
+ }
+
+ public void replayOperation(Notification params) throws RemoteException {
+ ATCoordinator c = (ATCoordinator) CallbackRegistry.getInstance().correlateMessage(
+ CallbackRegistry.COORDINATOR_REF, false);
+ c.replayOperation(params);
+ }
+}
\ No newline at end of file
Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/CoordinatorStub.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/CoordinatorStub.java?rev=359386&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/CoordinatorStub.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/CoordinatorStub.java Tue Dec 27 20:17:27 2005
@@ -0,0 +1,41 @@
+/*
+ * 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.coordinator.at;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.apache.axis.AxisFault;
+import org.apache.ws.transaction.utility.Service;
+import org.apache.ws.transaction.utility.TCPSnifferHelper;
+import org.apache.ws.transaction.wsat.CoordinatorBindingStub;
+
+/**
+ * @author Dasarath Weeratunge
+ *
+ * Created on Jun 14, 2004
+ */
+public class CoordinatorStub extends CoordinatorBindingStub {
+
+ public CoordinatorStub(
+ org.apache.axis.message.addressing.EndpointReference epr)
+ throws AxisFault, MalformedURLException {
+ super(new URL(TCPSnifferHelper.redirect(epr.getAddress().toString())),
+ new Service(epr));
+ }
+
+}
\ No newline at end of file
Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/ParticipantImpl.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/ParticipantImpl.java?rev=359386&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/ParticipantImpl.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/ParticipantImpl.java Tue Dec 27 20:17:27 2005
@@ -0,0 +1,42 @@
+/*
+ * Created on Dec 25, 2005
+ *
+ */
+package org.apache.ws.transaction.coordinator.at;
+
+import java.rmi.RemoteException;
+
+import org.apache.ws.transaction.utility.CallbackRegistry;
+import org.apache.ws.transaction.wsat.Notification;
+import org.apache.ws.transaction.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/ws/transaction/coordinator/at/ParticipantStub.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/ParticipantStub.java?rev=359386&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/ParticipantStub.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/coordinator/at/ParticipantStub.java Tue Dec 27 20:17:27 2005
@@ -0,0 +1,41 @@
+/*
+ * 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.coordinator.at;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.apache.axis.AxisFault;
+import org.apache.ws.transaction.utility.Service;
+import org.apache.ws.transaction.utility.TCPSnifferHelper;
+import org.apache.ws.transaction.wsat.ParticipantBindingStub;
+
+/**
+ * @author Dasarath Weeratunge
+ *
+ * Created on Jun 14, 2004
+ */
+public class ParticipantStub extends ParticipantBindingStub {
+
+ public ParticipantStub(
+ org.apache.axis.message.addressing.EndpointReference epr)
+ throws AxisFault, MalformedURLException {
+ super(new URL(TCPSnifferHelper.redirect(epr.getAddress().toString())),
+ new Service(epr));
+ }
+
+}
\ No newline at end of file
Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/j2ee/Bridge.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/j2ee/Bridge.java?rev=359386&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/j2ee/Bridge.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/j2ee/Bridge.java Tue Dec 27 20:17:27 2005
@@ -0,0 +1,87 @@
+/*
+ * Created on Dec 26, 2005
+ *
+ */
+package org.apache.ws.transaction.j2ee;
+
+import java.rmi.RemoteException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+import javax.transaction.xa.XAException;
+
+import org.apache.geronimo.transaction.manager.TransactionManagerImpl;
+import org.apache.ws.transaction.coordinator.CoordinationContext;
+import org.apache.ws.transaction.wscoor.Expires;
+
+/**
+ * @author Dasarath Weeratunge
+ *
+ */
+public class Bridge {
+
+ private static Bridge instance = new Bridge();
+
+ private static final int TIMEOUT = 60 * 60;
+
+ public static Bridge getInstance() {
+ return instance;
+ }
+
+ private Map inM = new HashMap();
+
+ TransactionManagerImpl tm;
+
+ private Bridge() {
+ try {
+ tm = new TransactionManagerImpl(TIMEOUT, null, null);
+ } catch (XAException e) {
+ e.printStackTrace();
+ throw new RuntimeException(e);
+ }
+ }
+
+ public TransactionManager getTM() {
+ return tm;
+ }
+
+ public synchronized Transaction mediate(CoordinationContext ctx)
+ throws RemoteException {
+ String id = ctx.getIdentifier().toString();
+ Transaction tx = (Transaction) inM.get(id);
+ if (tx != null)
+ return tx;
+ Expires expires = ctx.getExpires();
+ long timeout = 0;
+ if (expires != null)
+ timeout = expires.get_value().longValue();
+
+ try {
+ tm.begin(timeout);
+ tx = tm.suspend();
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new RuntimeException(e);
+ }
+
+ new Mediator(tx, ctx);
+
+ inM.put(id, tx);
+ return tx;
+ }
+
+ public synchronized CoordinationContext mediate(Transaction tx) {
+ return null;
+
+ }
+
+ public void forget(String id) {
+ inM.remove(id);
+ }
+
+ public boolean isMapped(String id) {
+ return inM.containsKey(id);
+ }
+}
\ No newline at end of file
Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/j2ee/Mediator.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/j2ee/Mediator.java?rev=359386&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/j2ee/Mediator.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/j2ee/Mediator.java Tue Dec 27 20:17:27 2005
@@ -0,0 +1,206 @@
+/*
+ * Created on Dec 27, 2005
+ *
+ */
+package org.apache.ws.transaction.j2ee;
+
+import java.rmi.RemoteException;
+
+import javax.transaction.Status;
+import javax.transaction.Transaction;
+import javax.transaction.xa.XAException;
+import javax.transaction.xa.XAResource;
+import javax.transaction.xa.Xid;
+
+import org.apache.axis.message.addressing.EndpointReference;
+import org.apache.geronimo.transaction.manager.NamedXAResource;
+import org.apache.geronimo.transaction.manager.TransactionManagerImpl;
+import org.apache.ws.transaction.coordinator.CoordinationContext;
+import org.apache.ws.transaction.coordinator.ParticipantService;
+import org.apache.ws.transaction.coordinator.at.ATCoordinator;
+import org.apache.ws.transaction.coordinator.at.CoordinatorStub;
+import org.apache.ws.transaction.wsat.Notification;
+import org.apache.ws.transaction.wsat.ParticipantPortType;
+
+/**
+ * @author Dasarath Weeratunge
+ *
+ */
+public class Mediator implements ParticipantPortType, NamedXAResource {
+
+ private int timeout = Integer.MAX_VALUE;
+
+ private String id;
+
+ private Transaction tx;
+
+ private EndpointReference c;
+
+ private Bridge bridge = Bridge.getInstance();
+
+ private TransactionManagerImpl tm = (TransactionManagerImpl) bridge.getTM();
+
+ public Mediator(Transaction tx, CoordinationContext ctx)
+ throws RemoteException {
+ id = ctx.getIdentifier().toString();
+ this.tx = tx;
+ EndpointReference epr = ParticipantService.getInstance().getParticipantService(
+ this);
+ c = ctx.register(ATCoordinator.PROTOCOL_ID_DURABLE_2PC, epr);
+ try {
+ tx.enlistResource(this);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void commit(Xid arg0, boolean arg1) throws XAException {
+ if (bridge.isMapped(id))
+ try {
+ new CoordinatorStub(c).committedOperation(null);
+ } catch (Exception e) {
+ }
+ }
+
+ public void end(Xid arg0, int arg1) throws XAException {
+ }
+
+ public void forget(Xid arg0) throws XAException {
+ }
+
+ public String getName() {
+ return getClass().getName();
+ }
+
+ public int getTransactionTimeout() throws XAException {
+ return timeout;
+ }
+
+ public boolean isSameRM(XAResource arg0) throws XAException {
+ return this == arg0;
+ }
+
+ public int prepare(Xid arg0) throws XAException {
+ if (bridge.isMapped(id)) {
+ try {
+ new CoordinatorStub(c).abortedOperation(null);
+ } catch (Exception e) {
+ }
+ throw new XAException();
+ } else
+ return XAResource.XA_RDONLY;
+ }
+
+ public Xid[] recover(int arg0) throws XAException {
+ return null;
+ }
+
+ public void rollback(Xid arg0) throws XAException {
+ if (bridge.isMapped(id))
+ try {
+ new CoordinatorStub(c).abortedOperation(null);
+ } catch (Exception e) {
+ }
+ }
+
+ public boolean setTransactionTimeout(int arg0) throws XAException {
+ timeout = arg0;
+ return false;
+ }
+
+ public void start(Xid arg0, int arg1) throws XAException {
+ }
+
+ public synchronized void commitOperation(Notification parameters)
+ throws RemoteException {
+ done();
+ try {
+ tm.commit(tx, false);
+ new CoordinatorStub(c).committedOperation(null);
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ throw e;
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new RemoteException(e.getMessage());
+ }
+ }
+
+ private void done() {
+ ParticipantService.getInstance().forget(this);
+ }
+
+ public synchronized void prepareOperation(Notification parameters)
+ throws RemoteException {
+ try {
+ bridge.forget(id);
+ CoordinatorStub p = new CoordinatorStub(c);
+ int status = tx.getStatus();
+ switch (status) {
+ case Status.STATUS_ACTIVE:
+ try {
+ if (tm.prepare(tx) == XAResource.XA_RDONLY) {
+ done();
+ p.readOnlyOperation(null);
+ } else
+ p.preparedOperation(null);
+ return;
+ } catch (XAException e) {
+ done();
+ p.abortedOperation(null);
+ return;
+ }
+
+ case Status.STATUS_COMMITTED:
+ case Status.STATUS_COMMITTING:
+ p.committedOperation(null);
+ return;
+
+ case Status.STATUS_MARKED_ROLLBACK:
+ done();
+ p.abortedOperation(null);
+ tx.rollback();
+ return;
+
+ case Status.STATUS_ROLLEDBACK:
+ case Status.STATUS_ROLLING_BACK:
+ done();
+ p.abortedOperation(null);
+ return;
+
+ case Status.STATUS_PREPARED:
+ p.preparedOperation(null);
+ return;
+
+ case Status.STATUS_PREPARING:
+ return;
+
+ case Status.STATUS_NO_TRANSACTION:
+ case Status.STATUS_UNKNOWN:
+ done();
+ p.abortedOperation(null);
+ return;
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new RemoteException(e.getMessage());
+ }
+ }
+
+ public synchronized void rollbackOperation(Notification parameters)
+ throws RemoteException {
+ bridge.forget(id);
+ done();
+ try {
+ tx.rollback();
+ new CoordinatorStub(c).abortedOperation(null);
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ throw e;
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new RemoteException(e.getMessage());
+ }
+ }
+
+}
\ No newline at end of file
Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/j2ee/TxHandler.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/j2ee/TxHandler.java?rev=359386&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/j2ee/TxHandler.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/j2ee/TxHandler.java Tue Dec 27 20:17:27 2005
@@ -0,0 +1,77 @@
+/*
+ * 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.j2ee;
+
+import java.util.Iterator;
+
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+import javax.xml.soap.SOAPElement;
+import javax.xml.soap.SOAPHeader;
+
+import org.apache.axis.AxisFault;
+import org.apache.axis.MessageContext;
+import org.apache.axis.handlers.BasicHandler;
+import org.apache.ws.transaction.coordinator.CoordinationContext;
+
+public class TxHandler extends BasicHandler {
+ private Bridge bridge = Bridge.getInstance();
+
+ private TransactionManager tm = bridge.getTM();
+
+ static private ThreadLocal threadInfo = new ThreadLocal();
+
+ public void invoke(MessageContext mc) throws AxisFault {
+ try {
+ if (mc.getCurrentMessage() == null)
+ return;
+
+ if (mc.isClient() && !mc.getPastPivot()) {
+// Transaction tx = tm.getTransaction();
+// if (tx == null)
+// return;
+//
+// SOAPHeader header = mc.getCurrentMessage().getSOAPEnvelope().getHeader();
+// CoordinationContext ctx = bridge.mediate(tx);
+// ctx.toSOAPHeaderElement(header);
+ } else {
+ if (mc.getPastPivot()) {
+ if (threadInfo.get() == null)
+ return;
+
+ tm.suspend();
+ threadInfo.set(null);
+ } else {
+ SOAPHeader header = mc.getCurrentMessage().getSOAPEnvelope().getHeader();
+ Iterator iter = header.getChildElements();
+ while (iter.hasNext()) {
+ SOAPElement e = (SOAPElement) iter.next();
+ if (CoordinationContext.is(e)) {
+ CoordinationContext ctx = new CoordinationContext(e);
+ Transaction tx = bridge.mediate(ctx);
+ tm.resume(tx);
+ threadInfo.set(tx);
+ return;
+ }
+ }
+ }
+ }
+ } catch (Exception e) {
+ throw AxisFault.makeFault(e);
+ }
+ }
+}
\ No newline at end of file
Added: webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/utility/CallbackRegistry.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/utility/CallbackRegistry.java?rev=359386&view=auto
==============================================================================
--- webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/utility/CallbackRegistry.java (added)
+++ webservices/kandula/branches/Kandula_1/src/java/org/apache/ws/transaction/utility/CallbackRegistry.java Tue Dec 27 20:17:27 2005
@@ -0,0 +1,64 @@
+/*
+ * Created on Dec 24, 2005
+ *
+ */
+package org.apache.ws.transaction.utility;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+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");
+
+ public static final QName COORDINATOR_REF = new QName(
+ "http://ws.apache.org/kandula", "CoordinatorRef");
+
+ private static final CallbackRegistry instance = new CallbackRegistry();
+
+ private Map callbacks = new HashMap();
+
+ protected CallbackRegistry() {
+ }
+
+ public static CallbackRegistry getInstance() {
+ return instance;
+ }
+
+ public synchronized void registerCallback(String ref, Object callback) {
+ callbacks.put(ref, callback);
+ }
+
+ public synchronized Object correlateMessage(QName q, boolean terminal) {
+ return callbacks.get(getRef(q));
+ }
+
+ private String getRef(QName q) {
+ AddressingHeaders header = (AddressingHeaders) MessageContext.getCurrentContext().getProperty(
+ Constants.ENV_ADDRESSING_REQUEST_HEADERS);
+ return header.getReferenceProperties().get(q).getValue();
+ }
+
+ 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
---------------------------------------------------------------------
To unsubscribe, e-mail: kandula-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: kandula-dev-help@ws.apache.org