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/11 15:44:40 UTC

svn commit: r280134 - in /webservices/kandula/trunk/java/src/org/apache/kandula/coordinator: ./ at/ context/ context/at/

Author: thilina
Date: Sun Sep 11 06:44:15 2005
New Revision: 280134

URL: http://svn.apache.org/viewcvs?rev=280134&view=rev
Log:
replacing the use of string for EPR's with Axis2 adressing EndpointReference class
+ some refactoring

Modified:
    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/ATCoordinator.java
    webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/at/ATCoordinatorImpl.java
    webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/at/ATSubCoordinator.java
    webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/context/ActivityContext.java
    webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/context/ActivityContextImpl.java
    webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/context/ContextFactory.java
    webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/context/Participant.java
    webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/context/at/ATActivityContext.java

Modified: webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/Coordinator.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/Coordinator.java?rev=280134&r1=280133&r2=280134&view=diff
==============================================================================
--- webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/Coordinator.java (original)
+++ webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/Coordinator.java Sun Sep 11 06:44:15 2005
@@ -16,6 +16,7 @@
  */
 package org.apache.kandula.coordinator;
 
+import org.apache.axis2.addressing.EndpointReference;
 import org.apache.kandula.KandulaException;
 import org.apache.kandula.coordinator.context.ActivityContext;
 import org.apache.kandula.typemapping.CoordinationContext;
@@ -66,6 +67,6 @@
      * by a initiator. Registration request will be forwarded to repective
      * protocol coordinators.
      */
-    public abstract String registerParticipant(String protocol,
-            String participantEPR, String id) throws KandulaException;
+    public abstract EndpointReference registerParticipant(String protocol,
+            String id,EndpointReference participantEPR) throws KandulaException;
 }

Modified: webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/CoordinatorImpl.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/CoordinatorImpl.java?rev=280134&r1=280133&r2=280134&view=diff
==============================================================================
--- webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/CoordinatorImpl.java (original)
+++ webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/CoordinatorImpl.java Sun Sep 11 06:44:15 2005
@@ -16,6 +16,7 @@
  */
 package org.apache.kandula.coordinator;
 
+import org.apache.axis2.addressing.EndpointReference;
 import org.apache.kandula.KandulaException;
 import org.apache.kandula.coordinator.at.ATCoordinator;
 import org.apache.kandula.coordinator.at.ATCoordinatorImpl;
@@ -32,7 +33,7 @@
  */
 
 public class CoordinatorImpl implements Coordinator {
-    Store store;
+    private Store store;
 
     public CoordinatorImpl() {
         StorageFactory storageFactory = StorageFactory.getInstance();
@@ -51,12 +52,13 @@
      * initiator,Participants and coordinator
      * @throws KandulaException
      */
-    public ActivityContext createCoordinationContext(String coordinationType, long expires) throws KandulaException {
+    public ActivityContext createCoordinationContext(String coordinationType,
+            long expires) throws KandulaException {
         ContextFactory factory = ContextFactory.getInstance();
-        ActivityContext context = factory
-                .createActivity(coordinationType);
+        ActivityContext context = factory.createActivity(coordinationType);
         context.getCoordinationContext().setExpires(expires);
-        store.putContext(context.getCoordinationContext().getActivityID(), context);
+        store.putContext(context.getCoordinationContext().getActivityID(),
+                context);
         return context;
     }
 
@@ -70,14 +72,15 @@
      * CoordinationContext will be replaced by the RegistrationEPR of this
      * Coordinator.
      */
-    public ActivityContext createCoordinationContext(CoordinationContext coorContext) throws KandulaException{
+    public ActivityContext createCoordinationContext(
+            CoordinationContext coorContext) throws KandulaException {
         ContextFactory factory = ContextFactory.getInstance();
-        ActivityContext context = factory
-                .createActivity(coorContext);
-        store.putContext(context.getCoordinationContext().getActivityID(), context);
+        ActivityContext context = factory.createActivity(coorContext);
+        store.putContext(context.getCoordinationContext().getActivityID(),
+                context);
         return context;
     }
-    
+
     /**
      * @param coordinationProtocol
      * @param participantEPR
@@ -86,10 +89,12 @@
      * 
      * This method provides the functional logic for participants to register
      * for a particular transaction activity which was created by a initiator.
-     * Registration request will be forwarded to repective protocol coordinators.
+     * Registration request will be forwarded to repective protocol
+     * coordinators.
      * @throws KandulaException
      */
-    public String registerParticipant(String id, String protocol, String participantEPR) throws KandulaException {
+    public EndpointReference registerParticipant(String id, String protocol,
+            EndpointReference participantEPR) throws KandulaException {
 
         ActivityContext context = getCoordinationContext(id);
         if (context == null) {
@@ -98,7 +103,7 @@
         }
         //TODO use "switch case" when BA is present
         ATCoordinator atCoordinator = new ATCoordinatorImpl();
-        return atCoordinator.register(context,protocol,participantEPR);
+        return atCoordinator.register(context, protocol, participantEPR);
     }
 
     private ActivityContext getCoordinationContext(String id) {

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=280134&r1=280133&r2=280134&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 Sun Sep 11 06:44:15 2005
@@ -16,6 +16,7 @@
  */
 package org.apache.kandula.coordinator.at;
 
+import org.apache.axis2.addressing.EndpointReference;
 import org.apache.kandula.KandulaException;
 import org.apache.kandula.coordinator.context.ActivityContext;
 
@@ -24,8 +25,8 @@
  */
 public interface ATCoordinator {
 
-    public abstract String register(ActivityContext context, String protocol,
-            String participantEPR) throws KandulaException;
+    public abstract EndpointReference register(ActivityContext context, String protocol,
+            EndpointReference participantEPR) throws KandulaException;
 
     /**
      * @param Activity
@@ -85,6 +86,6 @@
      */
     public abstract int abort(ActivityContext context);
     
-    public String addParticipant(ActivityContext context, String protocol,
-            String participantEPR) throws KandulaException;
+    public EndpointReference addParticipant(ActivityContext context, String protocol,
+            EndpointReference participantEPR) throws KandulaException;
 }

Modified: webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/at/ATCoordinatorImpl.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/at/ATCoordinatorImpl.java?rev=280134&r1=280133&r2=280134&view=diff
==============================================================================
--- webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/at/ATCoordinatorImpl.java (original)
+++ webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/at/ATCoordinatorImpl.java Sun Sep 11 06:44:15 2005
@@ -18,6 +18,7 @@
 
 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;
@@ -31,8 +32,8 @@
  */
 public class ATCoordinatorImpl implements ATCoordinator {
 
-    public String register(ActivityContext context, String protocol,
-            String participantEPR) throws KandulaException {
+    public EndpointReference register(ActivityContext context, String protocol,
+            EndpointReference participantEPR) throws KandulaException {
         context.lock();
         switch (context.getStatus()) {
         case CoordinatorStatus.STATUS_PREPARING_DURABLE:
@@ -52,7 +53,7 @@
             throw new IllegalStateException("Coordinator is in Aborting state");
         case CoordinatorStatus.STATUS_ACTIVE:
         case CoordinatorStatus.STATUS_PREPARING_VOLATILE:
-            return addParticipant(context,participantEPR, protocol);
+            return addParticipant(context,protocol, participantEPR);
         case CoordinatorStatus.STATUS_NONE:
         default:
             context.unlock();
@@ -255,8 +256,8 @@
         return Status.CoordinatorStatus.STATUS_ABORTING;
     }
 
-    public String addParticipant(ActivityContext context, String protocol,
-            String participantEPR) throws KandulaException {
+    public EndpointReference addParticipant(ActivityContext context, String protocol,
+            EndpointReference participantEPR) throws KandulaException {
         ATActivityContext atContext = (ATActivityContext) context;
         if (protocol.equals(Constants.WS_AT_DURABLE2PC))
             return atContext.addParticipant(participantEPR, 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=280134&r1=280133&r2=280134&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 Sun Sep 11 06:44:15 2005
@@ -16,6 +16,7 @@
  */
 package org.apache.kandula.coordinator.at;
 
+import org.apache.axis2.addressing.EndpointReference;
 import org.apache.kandula.Constants;
 import org.apache.kandula.KandulaException;
 import org.apache.kandula.coordinator.context.ActivityContext;
@@ -36,8 +37,8 @@
                 "This activity is a Sub Ordinate activity. Completion Protocol not supported.");
     }
 
-    public String addParticipant(ActivityContext context, String protocol,
-            String participantEPR) throws KandulaException {
+    public EndpointReference addParticipant(ActivityContext context, String protocol,
+            EndpointReference participantEPR) throws KandulaException {
         ATActivityContext atContext = (ATActivityContext) context;
         if (protocol.equals(Constants.WS_AT_DURABLE2PC)) {
             if (!atContext.getSubDurableRegistered()) {

Modified: webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/context/ActivityContext.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/context/ActivityContext.java?rev=280134&r1=280133&r2=280134&view=diff
==============================================================================
--- webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/context/ActivityContext.java (original)
+++ webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/context/ActivityContext.java Sun Sep 11 06:44:15 2005
@@ -18,6 +18,7 @@
 
 import java.util.Iterator;
 
+import org.apache.axis2.addressing.EndpointReference;
 import org.apache.kandula.KandulaException;
 import org.apache.kandula.typemapping.CoordinationContext;
 
@@ -26,7 +27,7 @@
  */
 public interface ActivityContext {
     
-    public abstract String addParticipant(String participantEPR, String protocol) throws KandulaException;
+    public abstract EndpointReference addParticipant(EndpointReference participantEPR, String protocol) throws KandulaException;
     
     public abstract Iterator getRegisteredParticipants(String protocol);
     

Modified: webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/context/ActivityContextImpl.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/context/ActivityContextImpl.java?rev=280134&r1=280133&r2=280134&view=diff
==============================================================================
--- webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/context/ActivityContextImpl.java (original)
+++ webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/context/ActivityContextImpl.java Sun Sep 11 06:44:15 2005
@@ -18,6 +18,7 @@
 
 import java.util.HashMap;
 
+import javax.mail.internet.MimeUtility;
 import javax.xml.namespace.QName;
 
 import org.apache.axis2.addressing.AnyContentType;
@@ -25,6 +26,8 @@
 import org.apache.kandula.Status.CoordinatorStatus;
 import org.apache.kandula.coordinator.CoordinatorUtils;
 import org.apache.kandula.typemapping.CoordinationContext;
+import org.apache.kandula.utility.EndpointReferenceFactory;
+import org.apache.kandula.utility.KandulaUtils;
 
 /**
  * @author <a href="mailto:thilina@opensource.lk"> Thilina Gunarathne </a>
@@ -39,7 +42,7 @@
 
     private boolean locked = false;
 
-    protected CoordinationContext coordinationContext=null;
+    protected CoordinationContext coordinationContext = null;
 
     protected ActivityContextImpl() {
         propertyBag = new HashMap();
@@ -47,11 +50,11 @@
 
     public ActivityContextImpl(String coordinationType) {
         propertyBag = new HashMap();
-        activityID = CoordinatorUtils.getRandomStringOf18Characters();
+        activityID =  KandulaUtils.getRandomStringOf18Characters();
         coordinationContext = CoordinationContext.Factory.newInstance();
         coordinationContext.setActivityID(activityID);
-        EndpointReference registrationEpr = new EndpointReference(
-                "http://localhost:8081/axis/services/RegistrationCoordinator");
+        EndpointReference registrationEpr = EndpointReferenceFactory
+                .getInstance().getRegistrationEndpoint(activityID);
         AnyContentType referenceProp = new AnyContentType();
         referenceProp.addReferenceValue(new QName(
                 "http://webservice.apache.org/~thilina", "myapp", "ID"),

Modified: webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/context/ContextFactory.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/context/ContextFactory.java?rev=280134&r1=280133&r2=280134&view=diff
==============================================================================
--- webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/context/ContextFactory.java (original)
+++ webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/context/ContextFactory.java Sun Sep 11 06:44:15 2005
@@ -25,7 +25,7 @@
  * @author <a href="mailto:thilina@opensource.lk"> Thilina Gunarathne </a>
  */
 public class ContextFactory {
-    static ContextFactory instance = new ContextFactory();
+    private static ContextFactory instance = new ContextFactory();
 
     public static ContextFactory getInstance() {
         return instance;

Modified: webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/context/Participant.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/context/Participant.java?rev=280134&r1=280133&r2=280134&view=diff
==============================================================================
--- webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/context/Participant.java (original)
+++ webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/context/Participant.java Sun Sep 11 06:44:15 2005
@@ -16,6 +16,8 @@
  */
 package org.apache.kandula.coordinator.context;
 
+import org.apache.axis2.addressing.EndpointReference;
+
 /**
  * @author <a href="mailto:thilina@opensource.lk"> Thilina Gunarathne </a>
  * 
@@ -23,7 +25,7 @@
  * of Participants
  */
 public class Participant {
-    private String epr;
+    private EndpointReference epr;
     private String protocol;
     private int status;
        
@@ -32,7 +34,7 @@
      * @param protocol
      * @param activityId
      */
-    public Participant(String epr, String protocol) {
+    public Participant(EndpointReference epr, String protocol) {
         super();
         this.epr = epr;
         this.protocol = protocol;

Modified: webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/context/at/ATActivityContext.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/context/at/ATActivityContext.java?rev=280134&r1=280133&r2=280134&view=diff
==============================================================================
--- webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/context/at/ATActivityContext.java (original)
+++ webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/context/at/ATActivityContext.java Sun Sep 11 06:44:15 2005
@@ -26,6 +26,8 @@
 import org.apache.kandula.coordinator.context.ActivityContextImpl;
 import org.apache.kandula.coordinator.context.Participant;
 import org.apache.kandula.typemapping.CoordinationContext;
+import org.apache.kandula.utility.EndpointReferenceFactory;
+import org.apache.kandula.utility.KandulaUtils;
 import org.apache.axis2.addressing.EndpointReference;
 import org.apache.axis2.om.impl.MIMEOutputUtils;
 /**
@@ -82,7 +84,7 @@
     public ATActivityContext(EndpointReference activationEPR)
     {
         super();
-        this.setProperty(REQUESTER_ID, MIMEOutputUtils.getRandomStringOf18Characters());
+        this.setProperty(REQUESTER_ID, KandulaUtils.getRandomStringOf18Characters());
         this.setProperty(ACTIVATION_EPR, activationEPR);
     }
 
@@ -92,32 +94,41 @@
      * @return Coordinator protocol service.
      * @throws KandulaException
      */
-    public String addParticipant(String participantEPR, String protocol)
+    public EndpointReference addParticipant(EndpointReference participantEPR, String protocol)
             throws KandulaException {
-        if (protocol.equals(Constants.WS_AT_VOLATILE2PC)) {
-            return addVolatileParticipant(participantEPR);
-        } else if (protocol.equals(Constants.WS_AT_DURABLE2PC)) {
-            return addDurableParticipant(participantEPR);
+        if (Constants.WS_AT_VOLATILE2PC.equals(protocol)) {
+            addVolatileParticipant(participantEPR);
+            return EndpointReferenceFactory.getInstance().get2PCEndpoint(this.activityID);
+        } else if (Constants.WS_AT_DURABLE2PC.equals(protocol)) {
+            addDurableParticipant(participantEPR);
+            return EndpointReferenceFactory.getInstance().get2PCEndpoint(this.activityID);
+        }else if  (Constants.WS_AT_COMPLETION.equals(protocol))
+        {
+            //TODO keep track of requesters
+            return EndpointReferenceFactory.getInstance().getCompletionEndpoint(this.activityID);
+        }
+        else
+        {
+            throw new KandulaException("UnSupported Protocol");
         }
-        return "2PC port EPR";
     }
 
-    public String addVolatileParticipant(String participantEPR)
+    public void addVolatileParticipant(EndpointReference participantEPR)
             throws KandulaException {
         if (volatileParticipantsTable.contains(participantEPR))
             throw new KandulaException("wscoor:Already Registered");
         volatileParticipantsTable.put(participantEPR, new Participant(
                 participantEPR, Constants.WS_AT_VOLATILE2PC));
-        return "2PC port";
+       
     }
 
-    public String addDurableParticipant(String participantEPR)
+    public void addDurableParticipant(EndpointReference participantEPR)
             throws KandulaException {
         if (durableParticipantsTable.contains(participantEPR))
             throw new KandulaException("wscoor:Already Registered");
         durableParticipantsTable.put(participantEPR, new Participant(
                 participantEPR, Constants.WS_AT_DURABLE2PC));
-        return "2PC port";
+       
     }
 
     public Iterator getRegisteredParticipants(String protocol) {
@@ -141,11 +152,7 @@
     }
 
     public boolean hasMorePreparing() {
-        if (preparingParticipantsCount > 0) {
-            return true;
-        } else {
-            return false;
-        }
+       return (preparingParticipantsCount > 0); 
     }
 
     public boolean getSubVolatileRegistered() {



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