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 th...@apache.org on 2006/02/10 10:11:58 UTC

svn commit: r376602 - in /webservices/kandula/trunk/java/src/org/apache/kandula/context: CoordinationContext.java at/ coordination/ impl/ impl/ATActivityContext.java impl/ATParticipantContext.java impl/SimpleCoordinationContext.java

Author: thilina
Date: Fri Feb 10 01:11:54 2006
New Revision: 376602

URL: http://svn.apache.org/viewcvs?rev=376602&view=rev
Log:
Rearranging packages
Introducing seperate KandulaConfiguration.java to handle configuration
EndpointReferenceFactory.java cleaned

Added:
    webservices/kandula/trunk/java/src/org/apache/kandula/context/CoordinationContext.java
    webservices/kandula/trunk/java/src/org/apache/kandula/context/impl/
    webservices/kandula/trunk/java/src/org/apache/kandula/context/impl/ATActivityContext.java
    webservices/kandula/trunk/java/src/org/apache/kandula/context/impl/ATParticipantContext.java
    webservices/kandula/trunk/java/src/org/apache/kandula/context/impl/SimpleCoordinationContext.java
Removed:
    webservices/kandula/trunk/java/src/org/apache/kandula/context/at/
    webservices/kandula/trunk/java/src/org/apache/kandula/context/coordination/

Added: webservices/kandula/trunk/java/src/org/apache/kandula/context/CoordinationContext.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/trunk/java/src/org/apache/kandula/context/CoordinationContext.java?rev=376602&view=auto
==============================================================================
--- webservices/kandula/trunk/java/src/org/apache/kandula/context/CoordinationContext.java (added)
+++ webservices/kandula/trunk/java/src/org/apache/kandula/context/CoordinationContext.java Fri Feb 10 01:11:54 2006
@@ -0,0 +1,65 @@
+/*
+ * Copyright  2004 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.kandula.context;
+
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.kandula.context.impl.SimpleCoordinationContext;
+import org.apache.ws.commons.om.OMElement;
+
+/**
+ * @author <a href="mailto:thilina@opensource.lk"> Thilina Gunarathne </a>
+ */
+public interface CoordinationContext {
+	public abstract String getActivityID();
+
+	public abstract String getCoordinationType();
+
+	public abstract EndpointReference getRegistrationService();
+
+	public abstract long getExpires();
+
+	public abstract void setActivityID(String value);
+
+	public abstract void setCoordinationType(String value);
+
+	public abstract void setRegistrationService(EndpointReference value);
+
+	public abstract void setExpires(long value);
+
+	public abstract OMElement toOM();
+
+	public abstract Object getCoordinationContextType();
+
+	public static final class Factory {
+		public static CoordinationContext newContext(String activityId,
+				String coordinationType, EndpointReference epr) {
+			return new SimpleCoordinationContext(activityId, coordinationType,
+					epr);
+		}
+
+		public static CoordinationContext newContext(OMElement contextElement) {
+			return new SimpleCoordinationContext(contextElement);
+		}
+
+		//        public static CoordinationContext newInstance(Object contextType) {
+		//            return new XmlBeansTypeCoordinationContext(contextType);
+		//        }
+
+		private Factory() {
+		} // No instance of this class allowed
+	}
+}
\ No newline at end of file

Added: webservices/kandula/trunk/java/src/org/apache/kandula/context/impl/ATActivityContext.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/trunk/java/src/org/apache/kandula/context/impl/ATActivityContext.java?rev=376602&view=auto
==============================================================================
--- webservices/kandula/trunk/java/src/org/apache/kandula/context/impl/ATActivityContext.java (added)
+++ webservices/kandula/trunk/java/src/org/apache/kandula/context/impl/ATActivityContext.java Fri Feb 10 01:11:54 2006
@@ -0,0 +1,212 @@
+/*
+ * Copyright  2004 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.kandula.context.impl;
+
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.LinkedList;
+
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.kandula.Constants;
+import org.apache.kandula.Status;
+import org.apache.kandula.context.AbstractContext;
+import org.apache.kandula.context.CoordinationContext;
+import org.apache.kandula.coordinator.at.ATParticipantInformation;
+import org.apache.kandula.faults.AbstractKandulaException;
+import org.apache.kandula.faults.AlreadyRegisteredException;
+import org.apache.kandula.faults.InvalidProtocolException;
+import org.apache.kandula.utility.EndpointReferenceFactory;
+
+/**
+ * @author <a href="mailto:thilina@opensource.lk"> Thilina Gunarathne </a>
+ */
+public class ATActivityContext extends AbstractContext {
+
+	private int preparingParticipantsCount = 0;
+
+	private boolean subOrdinate = false;
+
+	private Hashtable volatileParticipantsTable;
+
+	private Hashtable durableParticipantsTable;
+
+	//TODO : check whether there can be more than 1 initiator
+	private EndpointReference completionParticipant;
+
+	private boolean subVolatileRegistered = false;
+
+	private boolean subDurableRegistered = false;
+
+	private EndpointReference parentEPR;
+
+	/**
+	 * Used when creating new activities
+	 */
+	public ATActivityContext() {
+		super(Constants.WS_AT);
+		this.setStatus(Status.CoordinatorStatus.STATUS_ACTIVE);
+		volatileParticipantsTable = new Hashtable();
+		durableParticipantsTable = new Hashtable();
+	}
+
+	/**
+	 * @param context
+	 *            To be used when coordinator is used as a sub ordinate to an
+	 *            another cooordinator
+	 */
+	public ATActivityContext(CoordinationContext context) {
+		subOrdinate = true;
+		parentEPR = context.getRegistrationService();
+		//        context.setRegistrationService(EndpointReferenceFactory.getInstance()
+		//                .getRegistrationEndpoint());
+		this.setStatus(Status.CoordinatorStatus.STATUS_ACTIVE);
+		volatileParticipantsTable = new Hashtable();
+		durableParticipantsTable = new Hashtable();
+		setCoordinationContext(context);
+	}
+
+	/**
+	 * @param id
+	 *            To be used when using as the requester
+	 */
+	public ATActivityContext(EndpointReference activationEPR) {
+		super();
+		this.setProperty(REQUESTER_ID, EndpointReferenceFactory
+				.getRandomStringOf18Characters());
+		this.setProperty(ACTIVATION_EPR, activationEPR);
+	}
+
+	/**
+	 * @param participantEPR
+	 * @param protocol
+	 * @return Coordinator protocol service.
+	 * @throws AbstractKandulaException
+	 */
+	public EndpointReference addParticipant(EndpointReference participantEPR,
+			String protocol) throws AbstractKandulaException {
+		String enlistmentID = EndpointReferenceFactory.getRandomStringOf18Characters();
+		if (Constants.WS_AT_VOLATILE2PC.equals(protocol)) {
+			addVolatileParticipant(participantEPR, enlistmentID);
+			return EndpointReferenceFactory.getInstance()
+					.get2PCCoordinatorEndpoint(activityID, enlistmentID);
+		} else if (Constants.WS_AT_DURABLE2PC.equals(protocol)) {
+			addDurableParticipant(participantEPR, enlistmentID);
+			return EndpointReferenceFactory.getInstance()
+					.get2PCCoordinatorEndpoint(activityID, enlistmentID);
+		} else if (Constants.WS_AT_COMPLETION.equals(protocol)) {
+			completionParticipant = participantEPR;
+			return EndpointReferenceFactory.getInstance()
+					.getCompletionEndpoint(this.activityID);
+		} else {
+			throw new InvalidProtocolException();
+		}
+	}
+
+	public void addVolatileParticipant(EndpointReference participantEPR,
+			String enlistmentID) throws AbstractKandulaException {
+		if (volatileParticipantsTable.contains(participantEPR))
+			throw new AlreadyRegisteredException();
+		ATParticipantInformation participant = new ATParticipantInformation(participantEPR,
+				Constants.WS_AT_VOLATILE2PC, enlistmentID);
+		volatileParticipantsTable.put(enlistmentID, participant);
+	}
+
+	public void addDurableParticipant(EndpointReference participantEPR,
+			String enlistmentID) throws AlreadyRegisteredException {
+		if (durableParticipantsTable.contains(participantEPR)) {
+			throw new AlreadyRegisteredException();
+		}
+		ATParticipantInformation participant = new ATParticipantInformation(participantEPR,
+				Constants.WS_AT_DURABLE2PC, enlistmentID);
+		durableParticipantsTable.put(enlistmentID, participant);
+	}
+
+	public Iterator getRegistered2PCParticipants(String protocol) {
+		if (protocol.equals(Constants.WS_AT_VOLATILE2PC)) {
+			return volatileParticipantsTable.values().iterator();
+		} else if (protocol.equals(Constants.WS_AT_DURABLE2PC)) {
+			return durableParticipantsTable.values().iterator();
+		}
+		return null;
+	}
+
+	public Iterator getAll2PCParticipants() {
+		LinkedList list = new LinkedList(volatileParticipantsTable.values());
+		list.addAll(durableParticipantsTable.values());
+		return list.iterator();
+	}
+
+	public ATParticipantInformation getParticipant(String enlistmentId) {
+		if (volatileParticipantsTable.containsKey(enlistmentId)) {
+			return (ATParticipantInformation) volatileParticipantsTable.get(enlistmentId);
+		} else if (durableParticipantsTable.containsKey(enlistmentId)) {
+			return (ATParticipantInformation) durableParticipantsTable.get(enlistmentId);
+		} else {
+			return null;
+		}
+	}
+
+	/**
+	 * @return the completion initiator epr
+	 */
+	public EndpointReference getCompletionParticipant() {
+		return completionParticipant;
+	}
+
+	public void countPreparing() {
+		preparingParticipantsCount++;
+
+	}
+
+	public void decrementPreparing() {
+		preparingParticipantsCount--;
+	}
+
+	public boolean hasMorePreparing() {
+		return (preparingParticipantsCount > 0);
+	}
+
+	public boolean getSubVolatileRegistered() {
+
+		return subVolatileRegistered;
+	}
+
+	public boolean getSubDurableRegistered() {
+		return subDurableRegistered;
+	}
+
+	public void setSubVolatileRegistered(boolean value) {
+		subVolatileRegistered = value;
+	}
+
+	public void setSubDurableRegistered(boolean value) {
+		subDurableRegistered = value;
+	}
+
+	//    public void prepared(Participant participant)
+	//    {
+	//        if (participant.getStatus()==Status.ParticipantStatus.STATUS_ABORTED)
+	//        {
+	//            //throw new
+	//        }
+	//    }
+
+	public String getCoordinationType() {
+		return Constants.WS_AT;
+	}
+
+}
\ No newline at end of file

Added: webservices/kandula/trunk/java/src/org/apache/kandula/context/impl/ATParticipantContext.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/trunk/java/src/org/apache/kandula/context/impl/ATParticipantContext.java?rev=376602&view=auto
==============================================================================
--- webservices/kandula/trunk/java/src/org/apache/kandula/context/impl/ATParticipantContext.java (added)
+++ webservices/kandula/trunk/java/src/org/apache/kandula/context/impl/ATParticipantContext.java Fri Feb 10 01:11:54 2006
@@ -0,0 +1,63 @@
+/*
+ * Copyright  2004 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.kandula.context.impl;
+
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.kandula.Constants;
+import org.apache.kandula.Status;
+import org.apache.kandula.context.AbstractContext;
+import org.apache.kandula.participant.KandulaResource;
+
+/**
+ * @author <a href="mailto:thilina@opensource.lk"> Thilina Gunarathne </a>
+ */
+public class ATParticipantContext extends AbstractContext {
+	KandulaResource resource;
+
+	public ATParticipantContext() {
+		this.setStatus(Status.CoordinatorStatus.STATUS_ACTIVE);
+	}
+
+	/**
+	 * @return Returns the resource.
+	 */
+	public KandulaResource getResource() {
+		return resource;
+	}
+
+	/**
+	 * @param resource
+	 *            The resource to set.
+	 */
+	public void setResource(KandulaResource resource) {
+		this.resource = resource;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see org.apache.kandula.context.AbstractContext#getCoordinationType()
+	 */
+	public String getCoordinationType() {
+		return Constants.WS_AT;
+	}
+
+	public EndpointReference getCoordinationEPR() {
+		return (EndpointReference) getProperty(ATActivityContext.COORDINATION_EPR);
+	}
+
+}
\ No newline at end of file

Added: webservices/kandula/trunk/java/src/org/apache/kandula/context/impl/SimpleCoordinationContext.java
URL: http://svn.apache.org/viewcvs/webservices/kandula/trunk/java/src/org/apache/kandula/context/impl/SimpleCoordinationContext.java?rev=376602&view=auto
==============================================================================
--- webservices/kandula/trunk/java/src/org/apache/kandula/context/impl/SimpleCoordinationContext.java (added)
+++ webservices/kandula/trunk/java/src/org/apache/kandula/context/impl/SimpleCoordinationContext.java Fri Feb 10 01:11:54 2006
@@ -0,0 +1,133 @@
+/*
+ * Copyright  2004 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.kandula.context.impl;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.kandula.Constants;
+import org.apache.kandula.context.CoordinationContext;
+import org.apache.kandula.utility.EndpointReferenceFactory;
+import org.apache.ws.commons.om.OMAbstractFactory;
+import org.apache.ws.commons.om.OMElement;
+import org.apache.ws.commons.om.OMNamespace;
+import org.apache.ws.commons.soap.SOAPFactory;
+
+/**
+ * @author <a href="mailto:thilina@opensource.lk"> Thilina Gunarathne </a>
+ */
+public class SimpleCoordinationContext implements CoordinationContext {
+	private String activityID;
+
+	private String coordinationType;
+
+	private long expires;
+
+	private EndpointReference registrationServiceEpr;
+
+	private OMElement contextElement = null;
+
+	public SimpleCoordinationContext(String activityID,
+			String coordinationType, EndpointReference epr) {
+		this.activityID = activityID;
+		this.coordinationType = coordinationType;
+		this.registrationServiceEpr = epr;
+	}
+
+	public SimpleCoordinationContext(OMElement contextElement) {
+		super();
+		this.contextElement = contextElement;
+		activityID = contextElement.getFirstChildWithName(
+				new QName("Identifier")).getText();
+		coordinationType = contextElement.getFirstChildWithName(
+				new QName("CoordinationType")).getText();
+		OMElement registrationElement = contextElement
+				.getFirstChildWithName(new QName("RegistrationService"));
+		registrationServiceEpr = EndpointReferenceFactory
+				.endpointFromOM(registrationElement);
+	}
+
+	public String getActivityID() {
+		return activityID;
+	}
+
+	public String getCoordinationType() {
+		return coordinationType;
+	}
+
+	public EndpointReference getRegistrationService() {
+		return this.registrationServiceEpr;
+	}
+
+	public long getExpires() {
+		return expires;
+	}
+
+	public void setActivityID(String value) {
+		this.activityID = value;
+
+	}
+
+	public void setCoordinationType(String value) {
+		this.coordinationType = value;
+
+	}
+
+	public void setRegistrationService(EndpointReference epr) {
+		this.registrationServiceEpr = epr;
+	}
+
+	public void setExpires(long value) {
+		this.expires = value;
+	}
+
+	public Object getCoordinationContextType() {
+		return this;
+	}
+
+	public OMElement toOM() {
+		if (contextElement != null) {
+			return contextElement;
+		} else {
+			SOAPFactory factory = OMAbstractFactory.getSOAP12Factory();
+			OMNamespace wsCoor = factory.createOMNamespace(Constants.WS_COOR,
+					"wscoor");
+			OMElement contextElement = factory.createOMElement(
+					"CoordinationContext", wsCoor);
+			if (this.expires != 0) {
+				OMElement expiresElement = factory.createOMElement("Expires",
+						wsCoor);
+				expiresElement.setText(Long.toString(this.expires));
+				contextElement.addChild(expiresElement);
+			}
+			OMElement identifierElement = factory.createOMElement("Identifier",
+					wsCoor);
+			identifierElement.setText(this.activityID);
+			contextElement.addChild(identifierElement);
+			OMElement coorTypeElement = factory.createOMElement(
+					"CoordinationType", wsCoor);
+			coorTypeElement.setText(this.coordinationType);
+			contextElement.addChild(coorTypeElement);
+			OMElement registrationServiceElement = factory.createOMElement(
+					"RegistrationService", wsCoor);
+			EndpointReferenceFactory.endpointToOM(registrationServiceEpr,
+					registrationServiceElement, factory);
+			contextElement.addChild(registrationServiceElement);
+			return contextElement;
+		}
+	}
+}
\ 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