You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fx-dev@ws.apache.org by th...@apache.org on 2005/09/13 16:43:04 UTC

svn commit: r280567 - in /webservices/kandula/trunk/java/src/org/apache/kandula/coordinator: Coordinator.java CoordinatorImpl.java Registerable.java at/ATCoordinator.java at/ATCoordinatorImpl.java at/ATSubCoordinator.java

Author: thilina
Date: Tue Sep 13 07:42:45 2005
New Revision: 280567

URL: http://svn.apache.org/viewcvs?rev=280567&view=rev
Log:
Removing unnecessory interfaces

Added:
    webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/Registerable.java
Removed:
    webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/Coordinator.java
    webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/CoordinatorImpl.java
    webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/at/ATCoordinatorImpl.java
Modified:
    webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/at/ATCoordinator.java
    webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/at/ATSubCoordinator.java

Added: webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/Registerable.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/Registerable.java?rev=280567&view=auto
==============================================================================
--- webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/Registerable.java (added)
+++ webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/Registerable.java Tue Sep 13 07:42:45 2005
@@ -0,0 +1,17 @@
+package org.apache.kandula.coordinator;
+
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.kandula.coordinator.context.ActivityContext;
+import org.apache.kandula.KandulaException;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: Thilina
+ * Date: Sep 13, 2005
+ * Time: 8:17:20 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public interface Registerable {
+    public EndpointReference register(ActivityContext context, String protocol,
+                                      EndpointReference participantEPR) throws KandulaException;
+}

Modified: webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/at/ATCoordinator.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/at/ATCoordinator.java?rev=280567&r1=280566&r2=280567&view=diff
==============================================================================
--- webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/at/ATCoordinator.java (original)
+++ webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/at/ATCoordinator.java Tue Sep 13 07:42:45 2005
@@ -16,35 +16,144 @@
  */
 package org.apache.kandula.coordinator.at;
 
+import java.util.Iterator;
+
 import org.apache.axis2.addressing.EndpointReference;
+import org.apache.kandula.Constants;
 import org.apache.kandula.KandulaException;
+import org.apache.kandula.Status;
+import org.apache.kandula.Status.CoordinatorStatus;
+import org.apache.kandula.coordinator.CoordinatorUtils;
+import org.apache.kandula.coordinator.Registerable;
 import org.apache.kandula.coordinator.context.ActivityContext;
+import org.apache.kandula.coordinator.context.at.ATActivityContext;
 
 /**
  * @author <a href="mailto:thilina@opensource.lk"> Thilina Gunarathne </a>
  */
-public interface ATCoordinator {
-
-    public abstract EndpointReference register(ActivityContext context, String protocol,
-            EndpointReference participantEPR) throws KandulaException;
+public class ATCoordinator implements Registerable {
 
-    /**
-     * @param Activity
-     *            Id taken from the Request
-     * @return should be a notification. 
-     * This wraps the Commit operation defined
-     *         in Ws-AtomicTransaction specification.
-     */
-    public abstract String commitOperation(String id)  throws IllegalAccessException ;
+    public EndpointReference register(ActivityContext context, String protocol,
+            EndpointReference participantEPR) throws KandulaException {
+        context.lock();
+        switch (context.getStatus()) {
+        case CoordinatorStatus.STATUS_PREPARING_DURABLE:
+            context.unlock();
+            this.abort(context);
+            throw new IllegalStateException(
+                    "Coordinator is in preparing state - Durable ");
+        case CoordinatorStatus.STATUS_PREPARED_SUCCESS:
+            context.unlock();
+            throw new IllegalStateException(
+                    "Coordinator is in prepared success state");
+        case CoordinatorStatus.STATUS_COMMITTING:
+            context.unlock();
+            throw new IllegalStateException(
+                    "Coordinator is in committing state");
+        case CoordinatorStatus.STATUS_ABORTING:
+            throw new IllegalStateException("Coordinator is in Aborting state");
+        case CoordinatorStatus.STATUS_ACTIVE:
+        case CoordinatorStatus.STATUS_PREPARING_VOLATILE:
+            return addParticipant(context,protocol, participantEPR);
+        case CoordinatorStatus.STATUS_NONE:
+        default:
+            context.unlock();
+            throw new IllegalStateException();
+        }
+    }
 
     /**
      * @param Activity
      *            Id taken from the Request
-     * @return should be a notification.
-     * This wraps the rollback operation defined
+     * @return should be a notification This wraps the Commit operation defined
      *         in Ws-AtomicTransaction specification.
      */
-    public abstract String rollbackOperation(String id)  throws IllegalAccessException ;
+    public String commitOperation(String id) throws IllegalAccessException {
+        ActivityContext context = CoordinatorUtils.getActivityContext(id);
+        // if store throws a Exception capture it
+        if (context == null) {
+            throw new IllegalStateException(
+                    "No Activity Found for this Activity ID");
+        }
+
+        /*
+         * Check for states Do we need to lock the activity
+         */
+        context.lock();
+        switch (context.getStatus()) {
+        case CoordinatorStatus.STATUS_NONE:
+        case CoordinatorStatus.STATUS_ABORTING:
+            context.unlock();
+            return "Aborted";
+        case CoordinatorStatus.STATUS_PREPARING_DURABLE:
+        case CoordinatorStatus.STATUS_PREPARING_VOLATILE:
+        case CoordinatorStatus.STATUS_PREPARED_SUCCESS:
+            //If prepared success Ignore this message
+            context.unlock();
+            return null;
+        case CoordinatorStatus.STATUS_COMMITTING:
+            context.unlock();
+            return "Committed";
+        case Status.CoordinatorStatus.STATUS_ACTIVE:
+            int result;
+            result = volatilePrepare(context);
+
+            if (result == Status.CoordinatorStatus.STATUS_ABORTING) {
+                context.lock();
+                context.setStatus(Status.CoordinatorStatus.STATUS_ABORTING);
+                context.unlock();
+                abort(context);
+            }
+
+            result = commit(context);
+            return null;
+        default:
+            context.unlock();
+            return null;
+        }
+
+    }
+
+    public String rollbackOperation(String id) throws IllegalAccessException {
+        ActivityContext context = CoordinatorUtils.getActivityContext(id);
+        // if store throws a Exception capture it
+        if (context == null) {
+            throw new IllegalStateException(
+                    "No Activity Found for this Activity ID");
+        }
+        /*
+         * Check for states Do we need to lock the activity
+         */
+        context.lock();
+        switch (context.getStatus()) {
+        case CoordinatorStatus.STATUS_NONE:
+        case CoordinatorStatus.STATUS_ABORTING:
+            context.unlock();
+            return "Aborted";
+        case CoordinatorStatus.STATUS_PREPARING_DURABLE:
+        case CoordinatorStatus.STATUS_PREPARING_VOLATILE:
+        case CoordinatorStatus.STATUS_PREPARED_SUCCESS:
+            //If prepared success Ignore this message
+            context.unlock();
+            return null;
+        case CoordinatorStatus.STATUS_COMMITTING:
+            context.unlock();
+            return "Committed";
+        case Status.CoordinatorStatus.STATUS_ACTIVE:
+            context.setStatus(Status.CoordinatorStatus.STATUS_ABORTING);
+            context.unlock();
+            int result = abort(context);
+            //                if (result ==fdsfsfd)
+            //                {
+            //                    throw new Exception
+            //                }
+
+            return null;
+        default:
+            context.unlock();
+            return null;
+        }
+    }
 
     /**
      * @param context
@@ -55,7 +164,22 @@
      *      check if there are any more participants to be responded by checking
      *      the hasMorePreparing() methode of the context.
      */
-    public abstract int volatilePrepare(ActivityContext context);
+    public int volatilePrepare(ActivityContext context) {
+        ATActivityContext atContext = (ATActivityContext) context;
+        Iterator volatilePartipantIterator = atContext
+                .getRegisteredParticipants(Constants.WS_AT_VOLATILE2PC);
+        if (volatilePartipantIterator.hasNext()) {
+            atContext
+                    .setStatus(Status.CoordinatorStatus.STATUS_PREPARING_VOLATILE);
+            atContext.unlock();
+            while (volatilePartipantIterator.hasNext()) {
+                atContext.countPreparing();
+                // participantPortType port
+                // port.prepare
+            }
+        }
+        return atContext.getStatus();
+    }
 
     /**
      * @param context
@@ -66,7 +190,27 @@
      *      check if there are any more participants to be responded by checking
      *      the hasMorePreparing() methode of the context.
      */
-    public abstract int durablePrepare(ActivityContext context);
+    public int durablePrepare(ActivityContext context) {
+        ATActivityContext atContext = (ATActivityContext) context;
+        Iterator durablePartipantIterator = atContext
+                .getRegisteredParticipants(Constants.WS_AT_DURABLE2PC);
+        if (durablePartipantIterator.hasNext()) {
+            // wait till all the Volatile prepare()'s are done
+            while (atContext.hasMorePreparing()) {
+                if (atContext.getStatus() == Status.CoordinatorStatus.STATUS_ABORTING)
+                    return Status.CoordinatorStatus.STATUS_ABORTING;
+            }
+            atContext.lock();
+            atContext
+                    .setStatus(Status.CoordinatorStatus.STATUS_PREPARING_DURABLE);
+            atContext.unlock();
+            while (durablePartipantIterator.hasNext()) {
+                atContext.countPreparing();
+                //port.prepare
+            }
+        }
+        return atContext.getStatus();
+    }
 
     /**
      * @param context
@@ -75,7 +219,23 @@
      *      registered for the Transaction Must check whether all the
      *      participants have replied to the prepare()
      */
-    public abstract int commit(ActivityContext context);
+    public int commit(ActivityContext context) {
+        // check whether all participants are prepared
+        ATActivityContext atContext = (ATActivityContext) context;
+        while (atContext.hasMorePreparing()) {
+            if (atContext.getStatus() == Status.CoordinatorStatus.STATUS_ABORTING)
+                return Status.CoordinatorStatus.STATUS_ABORTING;
+        }
+        atContext.lock();
+        atContext.setStatus(Status.CoordinatorStatus.STATUS_COMMITTING);
+        atContext.unlock();
+        Iterator participants = atContext.getAllParticipants();
+
+        while (participants.hasNext()) {
+            //port.commit(participant)
+        }
+        return Status.CoordinatorStatus.STATUS_COMMITTING;
+    }
 
     /**
      * @param context
@@ -84,8 +244,30 @@
      *      registered for the Transaction Do not have to check whether all the
      *      participants have replied to the prepare()
      */
-    public abstract int abort(ActivityContext context);
-    
+    public int abort(ActivityContext context) {
+        // check whether all participants are prepared
+        context.lock();
+        context.setStatus(Status.CoordinatorStatus.STATUS_ABORTING);
+        context.unlock();
+        Iterator participants = context.getAllParticipants();
+
+        while (participants.hasNext()) {
+            //port.rollback(participant)
+        }
+        return Status.CoordinatorStatus.STATUS_ABORTING;
+    }
+
     public EndpointReference addParticipant(ActivityContext context, String protocol,
-            EndpointReference participantEPR) throws KandulaException;
+            EndpointReference participantEPR) throws KandulaException {
+        ATActivityContext atContext = (ATActivityContext) context;
+        if (protocol.equals(Constants.WS_AT_DURABLE2PC))
+            return atContext.addParticipant(participantEPR, protocol);
+        else if (protocol.equals(Constants.WS_AT_VOLATILE2PC))
+            return atContext.addParticipant(participantEPR, protocol);
+        else if (protocol.equals(Constants.WS_AT_COMPLETION))
+            return atContext.addParticipant(participantEPR, protocol);
+        else
+            throw new KandulaException(new IllegalArgumentException(
+                    "Unsupported Protocol"));
+    }
 }

Modified: webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/at/ATSubCoordinator.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/at/ATSubCoordinator.java?rev=280567&r1=280566&r2=280567&view=diff
==============================================================================
--- webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/at/ATSubCoordinator.java (original)
+++ webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/at/ATSubCoordinator.java Tue Sep 13 07:42:45 2005
@@ -25,7 +25,7 @@
 /**
  * @author <a href="mailto:thilina@opensource.lk"> Thilina Gunarathne </a>
  */
-public class ATSubCoordinator extends ATCoordinatorImpl {
+public class ATSubCoordinator extends ATCoordinator {
 
     public String commitOperation(String id) throws IllegalAccessException {
         throw new IllegalAccessException(



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