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 2006/07/23 07:41:38 UTC
svn commit: r424676 [1/2] - in
/webservices/kandula/trunk/java/src/org/apache/kandula: ./ context/
context/impl/ coordinator/ coordinator/at/ initiator/ participant/ storage/
utility/ wsat/ wsat/completion/ wsat/twopc/ wscoor/
Author: thilina
Date: Sat Jul 22 22:41:36 2006
New Revision: 424676
URL: http://svn.apache.org/viewvc?rev=424676&view=rev
Log:
Changing the WS-TX Namespace
Allow registration to be delayed till the service impl/ATActivityContext.java
Optimized the durable reistration during volatile prepare.
Added:
webservices/kandula/trunk/java/src/org/apache/kandula/initiator/InitiatorTransaction.java
webservices/kandula/trunk/java/src/org/apache/kandula/participant/ParticipantUtility.java
Removed:
webservices/kandula/trunk/java/src/org/apache/kandula/initiator/ATInitiatorTransaction.java
Modified:
webservices/kandula/trunk/java/src/org/apache/kandula/Constants.java
webservices/kandula/trunk/java/src/org/apache/kandula/Status.java
webservices/kandula/trunk/java/src/org/apache/kandula/context/AbstractContext.java
webservices/kandula/trunk/java/src/org/apache/kandula/context/ContextFactory.java
webservices/kandula/trunk/java/src/org/apache/kandula/context/CoordinationContext.java
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
webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/Coordinator.java
webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/Registerable.java
webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/at/ATCoordinator.java
webservices/kandula/trunk/java/src/org/apache/kandula/initiator/TransactionManager.java
webservices/kandula/trunk/java/src/org/apache/kandula/initiator/TransactionOutHandler.java
webservices/kandula/trunk/java/src/org/apache/kandula/participant/KandulaResource.java
webservices/kandula/trunk/java/src/org/apache/kandula/participant/ParticipantTransactionCoordinator.java
webservices/kandula/trunk/java/src/org/apache/kandula/participant/TransactionInHandler.java
webservices/kandula/trunk/java/src/org/apache/kandula/storage/SimpleStore.java
webservices/kandula/trunk/java/src/org/apache/kandula/utility/KandulaConfiguration.java
webservices/kandula/trunk/java/src/org/apache/kandula/wsat/AbstractATNotifierStub.java
webservices/kandula/trunk/java/src/org/apache/kandula/wsat/completion/CompletionCoordinatorPortTypeRawXMLSkeleton.java
webservices/kandula/trunk/java/src/org/apache/kandula/wsat/completion/CompletionCoordinatorPortTypeRawXMLStub.java
webservices/kandula/trunk/java/src/org/apache/kandula/wsat/completion/CompletionInitiatorPortTypeRawXMLSkeleton.java
webservices/kandula/trunk/java/src/org/apache/kandula/wsat/completion/CompletionInitiatorPortTypeRawXMLStub.java
webservices/kandula/trunk/java/src/org/apache/kandula/wsat/twopc/CoordinatorPortTypeRawXMLSkeleton.java
webservices/kandula/trunk/java/src/org/apache/kandula/wsat/twopc/CoordinatorPortTypeRawXMLStub.java
webservices/kandula/trunk/java/src/org/apache/kandula/wsat/twopc/ParticipantPortTypeRawXMLSkeleton.java
webservices/kandula/trunk/java/src/org/apache/kandula/wsat/twopc/ParticipantPortTypeRawXMLStub.java
webservices/kandula/trunk/java/src/org/apache/kandula/wscoor/ActivationCoordinatorPortTypeRawXMLStub.java
webservices/kandula/trunk/java/src/org/apache/kandula/wscoor/ActivationRequesterPortTypeRawXMLSkeleton.java
webservices/kandula/trunk/java/src/org/apache/kandula/wscoor/RegistrationCoordinatorPortTypeRawXMLStub.java
webservices/kandula/trunk/java/src/org/apache/kandula/wscoor/RegistrationRequesterPortTypeRawXMLSkeleton.java
Modified: webservices/kandula/trunk/java/src/org/apache/kandula/Constants.java
URL: http://svn.apache.org/viewvc/webservices/kandula/trunk/java/src/org/apache/kandula/Constants.java?rev=424676&r1=424675&r2=424676&view=diff
==============================================================================
--- webservices/kandula/trunk/java/src/org/apache/kandula/Constants.java (original)
+++ webservices/kandula/trunk/java/src/org/apache/kandula/Constants.java Sat Jul 22 22:41:36 2006
@@ -22,73 +22,74 @@
* @author <a href="mailto:thilina@opensource.lk"> Thilina Gunarathne </a>
*/
public interface Constants {
-
+
// WS-Coordination URI's
-
- static final String WS_COOR = "http://schemas.xmlsoap.org/ws/2004/10/wscoor";
-
- static final String WS_COOR_CREATE_COORDINATIONCONTEXT = "http://schemas.xmlsoap.org/ws/2004/10/wscoor/CreateCoordinationContext";
-
- static final String WS_COOR_CREATE_COORDINATIONCONTEXT_RESPONSE = "http://schemas.xmlsoap.org/ws/2004/10/wscoor/CreateCoordinationContextResponse";
-
- static final String WS_COOR_REGISTER = "http://schemas.xmlsoap.org/ws/2004/10/wscoor/Register";
-
- static final String WS_COOR_REGISTER_RESPONSE = "http://schemas.xmlsoap.org/ws/2004/10/wscoor/RegisterResponse";
-
+
+ static final String WS_COOR = "http://docs.oasis-open.org/ws-tx/wscoor/2006/03";
+
+ static final String WS_COOR_CREATE_COORDINATIONCONTEXT = WS_COOR+ "/CreateCoordinationContext";
+
+ static final String WS_COOR_CREATE_COORDINATIONCONTEXT_RESPONSE = WS_COOR+ "/CreateCoordinationContextResponse";
+
+ static final String WS_COOR_REGISTER = WS_COOR+ "/Register";
+
+ static final String WS_COOR_REGISTER_RESPONSE = WS_COOR+ "/RegisterResponse";
+
// WS-AT URI's
-
- static final String WS_AT = "http://schemas.xmlsoap.org/ws/2004/10/wsat";
-
- static final String WS_AT_COMPLETION = "http://schemas.xmlsoap.org/ws/2004/10/wsat/Completion";
-
- static final String WS_AT_COMMIT = "http://schemas.xmlsoap.org/ws/2004/10/wsat/Commit";
-
- static final String WS_AT_COMMITTED = "http://schemas.xmlsoap.org/ws/2004/10/wsat/Committed";
-
- static final String WS_AT_ROLLBACK = "http://schemas.xmlsoap.org/ws/2004/10/wsat/Rollback";
-
- static final String WS_AT_ABORTED = "http://schemas.xmlsoap.org/ws/2004/10/wsat/Aborted";
-
- static final String WS_AT_DURABLE2PC = "http://schemas.xmlsoap.org/ws/2004/10/wsat/Durable2PC";
-
- static final String WS_AT_VOLATILE2PC = "http://schemas.xmlsoap.org/ws/2004/10/wsat/Volatile2PC";
-
- static final String WS_AT_PREPARE = "http://schemas.xmlsoap.org/ws/2004/10/wsat/Prepare";
-
- static final String WS_AT_PREPARED = "http://schemas.xmlsoap.org/ws/2004/10/wsat/Prepared";
-
- static final String WS_AT_REPLAY = "http://schemas.xmlsoap.org/ws/2004/10/wsat/Replay";
-
- static final String WS_AT_READONLY = "http://schemas.xmlsoap.org/ws/2004/10/wsat/ReadOnly";
-
+
+ static final String WS_AT = "http://docs.oasis-open.org/ws-tx/wsat/2006/03";
+
+ static final String WS_AT_COMPLETION = WS_AT+ "/Completion";
+
+ static final String WS_AT_COMMIT = WS_AT+ "/Commit";
+
+ static final String WS_AT_COMMITTED = WS_AT+ "/Committed";
+
+ static final String WS_AT_ROLLBACK = WS_AT+ "/Rollback";
+
+ static final String WS_AT_ABORTED = WS_AT+ "/Aborted";
+
+ static final String WS_AT_DURABLE2PC = WS_AT+ "/Durable2PC";
+
+ static final String WS_AT_VOLATILE2PC = WS_AT+ "/Volatile2PC";
+
+ static final String WS_AT_PREPARE = WS_AT+ "/Prepare";
+
+ static final String WS_AT_PREPARED = WS_AT+ "/Prepared";
+
+ static final String WS_AT_REPLAY = WS_AT+ "/Replay";
+
+ static final String WS_AT_READONLY = WS_AT+ "/ReadOnly";
+
static final String SUB_VOLATILE_REGISTERED = "registered for volatile 2PC";
-
+
static final String SUB_DURABLE_REGISTERED = "registered for durable 2PC";
-
+
// WS-BA URI's
-
- static final String WS_BA = "http://schemas.xmlsoap.org/ws/2004/10/wsba";
-
+
+ static final String WS_BA = "http://docs.oasis-open.org/ws-tx/wsba/2006/03";;
+
// Kandula Specific
// Constants----------------------------------------------------------------------------------------------------
static String KANDULA_URI = "http://ws.apache.org/kandula";
-
+
static String KANDULA_RESOURCE = "KandulaResource";
-
+
static String KANDULA_PRE = "kand";
-
+
static String KANDULA_STORE = "KandulaStore";
-
+
// For the coordinator to identify seperate distributed
// activities(transactions)
// Common to all the parties participating in a single distributed tx.
static final QName TRANSACTION_ID_PARAMETER = new QName(KANDULA_URI,
"TransactionID", KANDULA_PRE);
-
- // Used by the Initiator Transaction Manager & participant TM to track the seperate transactions
+
+ // Used by the Initiator Transaction Manager & participant TM to track the
+ // seperate transactions
static final QName REQUESTER_ID_PARAMETER = new QName(KANDULA_URI,
"RequesterID", KANDULA_PRE);
-
+
// For the coordinator to identify each and every registered participant
// whithing a transaction
// This + Tx_ID will be unique for a participant
Modified: webservices/kandula/trunk/java/src/org/apache/kandula/Status.java
URL: http://svn.apache.org/viewvc/webservices/kandula/trunk/java/src/org/apache/kandula/Status.java?rev=424676&r1=424675&r2=424676&view=diff
==============================================================================
--- webservices/kandula/trunk/java/src/org/apache/kandula/Status.java (original)
+++ webservices/kandula/trunk/java/src/org/apache/kandula/Status.java Sat Jul 22 22:41:36 2006
@@ -1,19 +1,19 @@
/*
-* 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.
-*
-*/
+ * 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;
/**
@@ -21,41 +21,41 @@
*/
public abstract interface Status {
interface CoordinatorStatus {
-
+
static final int STATUS_ABORTING = 9;
-
+
static final int STATUS_ACTIVE = 0;
-
+
static final int STATUS_COMMITTING = 8;
-
+
static final int STATUS_NONE = 6;
-
+
static final int STATUS_PREPARED = 14;
-
+
static final int STATUS_PREPARED_SUCCESS = 13;
-
+
static final int STATUS_PREPARING = 10;
-
+
static final int STATUS_PREPARING_DURABLE = 11;
-
+
static final int STATUS_PREPARING_VOLATILE = 12;
-
+
static final int STATUS_READ_ONLY = 23;
-
+
}
-
+
// TODO remove the inner interfaces..
interface ParticipantStatus {
-
+
static final int STATUS_ABORTED = 22;
-
+
static final int STATUS_COMMITED = 24;
-
+
static final int STATUS_DURABLE_PREPARING = 21;
-
+
static final int STATUS_READ_ONLY = 23;
-
+
static final int STATUS_VOLATILE_PREPARING = 20;
-
+
}
-}
\ No newline at end of file
+}
Modified: webservices/kandula/trunk/java/src/org/apache/kandula/context/AbstractContext.java
URL: http://svn.apache.org/viewvc/webservices/kandula/trunk/java/src/org/apache/kandula/context/AbstractContext.java?rev=424676&r1=424675&r2=424676&view=diff
==============================================================================
--- webservices/kandula/trunk/java/src/org/apache/kandula/context/AbstractContext.java (original)
+++ webservices/kandula/trunk/java/src/org/apache/kandula/context/AbstractContext.java Sat Jul 22 22:41:36 2006
@@ -26,53 +26,53 @@
* @author <a href="mailto:thilina@opensource.lk"> Thilina Gunarathne </a>
*/
public abstract class AbstractContext {
-
+
public static String ACTIVATION_EPR = "activationEPR";
-
+
public static String COORDINATION_EPR = "coordinationEPR";
-
+
public static String REQUESTER_ID = "requesterID";
-
+
protected String activityID;
-
+
protected CoordinationContext coordinationContext = null;
-
+
private boolean locked = false;
-
+
private final HashMap propertyBag;
-
+
private int status = Status.CoordinatorStatus.STATUS_NONE;
-
+
protected AbstractContext() {
propertyBag = new HashMap();
}
-
+
public AbstractContext(String coordinationType) {
propertyBag = new HashMap();
activityID = "urn:"
- + EndpointReferenceFactory.getRandomStringOf18Characters();
+ + EndpointReferenceFactory.getRandomStringOf18Characters();
EndpointReference registrationEpr = EndpointReferenceFactory
- .getInstance().getRegistrationEndpoint(activityID);
+ .getInstance().getRegistrationEndpoint(activityID);
coordinationContext = CoordinationContext.Factory.newContext(
activityID, coordinationType, registrationEpr);
}
-
+
public final CoordinationContext getCoordinationContext() {
return coordinationContext;
}
-
+
public abstract String getCoordinationType();
-
+
public abstract String getRegistrationProtocol();
-
+
public final Object getProperty(Object key) {
return propertyBag.get(key);
}
-
+
public final int getStatus() {
return status;
}
-
+
public final synchronized void lock() {
if (locked) {
while (locked) {
@@ -85,30 +85,30 @@
throw new IllegalStateException();
}
}
-
+
locked = true;
}
-
+
public final void setCoordinationContext(CoordinationContext context) {
this.coordinationContext = context;
}
-
+
public final void setProperty(Object key, Object value) {
propertyBag.put(key, value);
-
+
}
-
+
// we can use a publisher-subscriber in the future to notify listeners abt
// state changes.
public final void setStatus(int value) {
status = value;
}
-
+
public final synchronized void unlock() {
if (!locked)
throw new IllegalStateException();
locked = false;
notify();
}
-
-}
\ No newline at end of file
+
+}
Modified: webservices/kandula/trunk/java/src/org/apache/kandula/context/ContextFactory.java
URL: http://svn.apache.org/viewvc/webservices/kandula/trunk/java/src/org/apache/kandula/context/ContextFactory.java?rev=424676&r1=424675&r2=424676&view=diff
==============================================================================
--- webservices/kandula/trunk/java/src/org/apache/kandula/context/ContextFactory.java (original)
+++ webservices/kandula/trunk/java/src/org/apache/kandula/context/ContextFactory.java Sat Jul 22 22:41:36 2006
@@ -16,7 +16,6 @@
*/
package org.apache.kandula.context;
-import org.apache.axis2.addressing.EndpointReference;
import org.apache.kandula.context.impl.ATActivityContext;
import org.apache.kandula.faults.InvalidProtocolException;
@@ -25,13 +24,13 @@
*/
public class ContextFactory {
private static ContextFactory instance = new ContextFactory();
-
+
public static ContextFactory getInstance() {
return instance;
}
-
+
public AbstractContext createActivity(CoordinationContext context)
- throws InvalidProtocolException {
+ throws InvalidProtocolException {
if (org.apache.kandula.Constants.WS_AT.equalsIgnoreCase(context
.getCoordinationType())) {
return new ATActivityContext(context);
@@ -39,30 +38,13 @@
throw new InvalidProtocolException("Unsupported Protocol Type");
}
}
-
+
public AbstractContext createActivity(String protocol)
- throws InvalidProtocolException {
+ throws InvalidProtocolException {
if (org.apache.kandula.Constants.WS_AT.equalsIgnoreCase(protocol)) {
return new ATActivityContext();
} else {
throw new InvalidProtocolException("Unsupported Protocol Type");
}
}
-
- /**
- * To be used by the initaitor TxManager to create the initial context
- *
- * @param protocol
- * @param activationEPR
- * @return
- * @throws InvalidProtocolException
- */
- public AbstractContext createActivity(String protocol,
- EndpointReference activationEPR) throws InvalidProtocolException {
- if (org.apache.kandula.Constants.WS_AT.equalsIgnoreCase(protocol)) {
- return new ATActivityContext(activationEPR);
- } else {
- throw new InvalidProtocolException("Unsupported Protocol Type");
- }
- }
-}
\ No newline at end of file
+}
Modified: webservices/kandula/trunk/java/src/org/apache/kandula/context/CoordinationContext.java
URL: http://svn.apache.org/viewvc/webservices/kandula/trunk/java/src/org/apache/kandula/context/CoordinationContext.java?rev=424676&r1=424675&r2=424676&view=diff
==============================================================================
--- webservices/kandula/trunk/java/src/org/apache/kandula/context/CoordinationContext.java (original)
+++ webservices/kandula/trunk/java/src/org/apache/kandula/context/CoordinationContext.java Sat Jul 22 22:41:36 2006
@@ -28,38 +28,38 @@
public static CoordinationContext newContext(OMElement contextElement) {
return new SimpleCoordinationContext(contextElement);
}
-
+
public static CoordinationContext newContext(String activityId,
String coordinationType, EndpointReference epr) {
return new SimpleCoordinationContext(activityId, coordinationType,
epr);
}
-
+
// public static CoordinationContext newInstance(Object contextType) {
// return new XmlBeansTypeCoordinationContext(contextType);
// }
-
+
private Factory() {
} // No instance of this class allowed
}
-
+
public abstract String getActivityID();
-
+
public abstract Object getCoordinationContextType();
-
+
public abstract String getCoordinationType();
-
+
public abstract long getExpires();
-
+
public abstract EndpointReference getRegistrationService();
-
+
public abstract void setActivityID(String value);
-
+
public abstract void setCoordinationType(String value);
-
+
public abstract void setExpires(long value);
-
+
public abstract void setRegistrationService(EndpointReference value);
-
+
public abstract OMElement toOM();
-}
\ No newline at end of file
+}
Modified: webservices/kandula/trunk/java/src/org/apache/kandula/context/impl/ATActivityContext.java
URL: http://svn.apache.org/viewvc/webservices/kandula/trunk/java/src/org/apache/kandula/context/impl/ATActivityContext.java?rev=424676&r1=424675&r2=424676&view=diff
==============================================================================
--- webservices/kandula/trunk/java/src/org/apache/kandula/context/impl/ATActivityContext.java (original)
+++ webservices/kandula/trunk/java/src/org/apache/kandula/context/impl/ATActivityContext.java Sat Jul 22 22:41:36 2006
@@ -36,26 +36,26 @@
* @author <a href="mailto:thilina@opensource.lk"> Thilina Gunarathne </a>
*/
public class ATActivityContext extends AbstractContext {
-
+
private Method callBackMethod = null;
-
+
// TODO : check whether there can be more than 1 initiator
private EndpointReference completionParticipant;
-
+
private Hashtable durableParticipantsTable;
-
+
private EndpointReference parentEPR;
-
+
private int preparingParticipantsCount = 0;
-
+
private boolean subDurableRegistered = false;
-
+
private boolean subOrdinate = false;
-
+
private boolean subVolatileRegistered = false;
-
+
private Hashtable volatileParticipantsTable;
-
+
/**
* Used when creating new activities
*/
@@ -65,7 +65,7 @@
volatileParticipantsTable = new Hashtable();
durableParticipantsTable = new Hashtable();
}
-
+
/**
* @param context
* To be used when coordinator is used as a sub ordinate to an
@@ -77,32 +77,12 @@
// context.setRegistrationService(EndpointReferenceFactory.getInstance()
// .getRegistrationEndpoint());
this.setStatus(Status.CoordinatorStatus.STATUS_ACTIVE);
+ // TODO do we need the following
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);
- }
-
- 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);
- }
-
+
/**
* @param participantEPR
* @param protocol
@@ -112,25 +92,44 @@
public EndpointReference addParticipant(EndpointReference participantEPR,
String protocol) throws AbstractKandulaException {
String enlistmentID = EndpointReferenceFactory
- .getRandomStringOf18Characters();
+ .getRandomStringOf18Characters();
if (Constants.WS_AT_VOLATILE2PC.equals(protocol)) {
addVolatileParticipant(participantEPR, enlistmentID);
return EndpointReferenceFactory.getInstance()
- .get2PCCoordinatorEndpoint(activityID, enlistmentID);
+ .get2PCCoordinatorEndpoint(activityID, enlistmentID);
} else if (Constants.WS_AT_DURABLE2PC.equals(protocol)) {
addDurableParticipant(participantEPR, enlistmentID);
return EndpointReferenceFactory.getInstance()
- .get2PCCoordinatorEndpoint(activityID, enlistmentID);
+ .get2PCCoordinatorEndpoint(activityID, enlistmentID);
} else if (Constants.WS_AT_COMPLETION.equals(protocol)) {
completionParticipant = participantEPR;
return EndpointReferenceFactory.getInstance()
- .getCompletionEndpoint(this.activityID);
+ .getCompletionEndpoint(this.activityID);
} else {
throw new InvalidProtocolException();
}
}
-
- public void addVolatileParticipant(EndpointReference participantEPR,
+
+ public void removeParticipant(String enlistmentID) {
+ // TODO: what to do if the participant is not found
+ if (durableParticipantsTable.containsKey(enlistmentID)) {
+ durableParticipantsTable.remove(enlistmentID);
+ } else if (volatileParticipantsTable.containsKey(enlistmentID)) {
+ volatileParticipantsTable.remove(enlistmentID);
+ }
+ }
+
+ protected 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);
+ }
+
+ protected void addVolatileParticipant(EndpointReference participantEPR,
String enlistmentID) throws AbstractKandulaException {
if (volatileParticipantsTable.contains(participantEPR))
throw new AlreadyRegisteredException();
@@ -138,61 +137,40 @@
participantEPR, Constants.WS_AT_VOLATILE2PC, enlistmentID);
volatileParticipantsTable.put(enlistmentID, participant);
}
-
- public synchronized void countPreparing() {
- preparingParticipantsCount++;
-
+
+ public int getDurableParticipantCount() {
+ return durableParticipantsTable.size();
}
-
- public synchronized void decrementPreparing() {
- preparingParticipantsCount--;
+
+ public int getVolatileParticipantCount() {
+ return volatileParticipantsTable.size();
}
-
+
public Iterator getAll2PCParticipants() {
LinkedList list = new LinkedList(volatileParticipantsTable.values());
list.addAll(durableParticipantsTable.values());
return list.iterator();
}
-
- /**
- * @return Returns the callBackMethod.
- */
- public Method getCallBackMethod() {
- return callBackMethod;
- }
-
+
/**
* @return the completion initiator epr
*/
public EndpointReference getCompletionParticipant() {
return completionParticipant;
}
-
- public String getCoordinationType() {
- return Constants.WS_AT;
- }
-
- public int getDurableParticipantCount() {
- return durableParticipantsTable.size();
- }
-
- public String getRegistrationProtocol()
- {
- return Constants.WS_AT_COMPLETION;
- }
-
+
public ATParticipantInformation getParticipant(String enlistmentId) {
if (volatileParticipantsTable.containsKey(enlistmentId)) {
return (ATParticipantInformation) volatileParticipantsTable
- .get(enlistmentId);
+ .get(enlistmentId);
} else if (durableParticipantsTable.containsKey(enlistmentId)) {
return (ATParticipantInformation) durableParticipantsTable
- .get(enlistmentId);
+ .get(enlistmentId);
} else {
return null;
}
}
-
+
public Iterator getRegistered2PCParticipants(String protocol) {
if (protocol.equals(Constants.WS_AT_VOLATILE2PC)) {
return volatileParticipantsTable.values().iterator();
@@ -201,46 +179,58 @@
}
return null;
}
-
- public boolean getSubDurableRegistered() {
- return subDurableRegistered;
- }
-
- public boolean getSubVolatileRegistered() {
-
- return subVolatileRegistered;
+
+ public synchronized void incrementPreparingParticipantCount() {
+ preparingParticipantsCount++;
+
}
-
- public int getVolatileParticipantCount() {
- return volatileParticipantsTable.size();
+
+ public synchronized void decrementPreparingParticipantCount() {
+ preparingParticipantsCount--;
}
-
- public synchronized boolean hasMorePreparing() {
- return (preparingParticipantsCount > 0);
+
+ public String getCoordinationType() {
+ return Constants.WS_AT;
}
-
- public void removeParticipant(String enlistmentID) {
- // TODO: what to do if the participant is not found
- if (durableParticipantsTable.containsKey(enlistmentID)) {
- durableParticipantsTable.remove(enlistmentID);
- } else if (volatileParticipantsTable.containsKey(enlistmentID)) {
- volatileParticipantsTable.remove(enlistmentID);
- }
+
+ public String getRegistrationProtocol() {
+ return null;
}
-
+
/**
* @param callBackMethod
- * The callBackMethod to set.
+ * the method to call when all the participats have been
+ * registered.
*/
public void setCallBackMethod(Method callBackMethod) {
this.callBackMethod = callBackMethod;
}
-
+
+ /**
+ * @return Returns the callBackMethod.
+ */
+ public Method getCallBackMethod() {
+ return callBackMethod;
+ }
+
+ public boolean getSubDurableRegistered() {
+ return subDurableRegistered;
+ }
+
+ public boolean getSubVolatileRegistered() {
+
+ return subVolatileRegistered;
+ }
+
+ public synchronized boolean hasMorePreparing() {
+ return (preparingParticipantsCount > 0);
+ }
+
public void setSubDurableRegistered(boolean value) {
subDurableRegistered = value;
}
-
+
public void setSubVolatileRegistered(boolean value) {
subVolatileRegistered = value;
}
-}
\ No newline at end of file
+}
Modified: webservices/kandula/trunk/java/src/org/apache/kandula/context/impl/ATParticipantContext.java
URL: http://svn.apache.org/viewvc/webservices/kandula/trunk/java/src/org/apache/kandula/context/impl/ATParticipantContext.java?rev=424676&r1=424675&r2=424676&view=diff
==============================================================================
--- webservices/kandula/trunk/java/src/org/apache/kandula/context/impl/ATParticipantContext.java (original)
+++ webservices/kandula/trunk/java/src/org/apache/kandula/context/impl/ATParticipantContext.java Sat Jul 22 22:41:36 2006
@@ -21,21 +21,30 @@
import org.apache.kandula.Status;
import org.apache.kandula.context.AbstractContext;
import org.apache.kandula.participant.KandulaResource;
+import org.apache.kandula.utility.EndpointReferenceFactory;
/**
* @author <a href="mailto:thilina@opensource.lk"> Thilina Gunarathne </a>
*/
public class ATParticipantContext extends AbstractContext {
KandulaResource resource;
-
+ String ID;
+ EndpointReference coordinationEPR;
+
public ATParticipantContext() {
this.setStatus(Status.CoordinatorStatus.STATUS_ACTIVE);
+ ID = EndpointReferenceFactory
+ .getRandomStringOf18Characters();
}
-
+
public EndpointReference getCoordinationEPR() {
- return (EndpointReference) getProperty(ATActivityContext.COORDINATION_EPR);
+ return coordinationEPR;
}
+ public void setCoordinationEPR(EndpointReference endpointReference) {
+ this.coordinationEPR = endpointReference;
+ }
+
/*
* (non-Javadoc)
*
@@ -44,16 +53,17 @@
public String getCoordinationType() {
return Constants.WS_AT;
}
-
+
/**
* @return Returns the transaction partcipant resource.
*/
public KandulaResource getResource() {
return resource;
}
-
+
/**
- * @param setting the transaction participant resource
+ * @param setting
+ * the transaction participant resource
*/
public void setResource(KandulaResource resource) {
this.resource = resource;
@@ -62,5 +72,13 @@
public String getRegistrationProtocol() {
return resource.getProtocol();
}
-
-}
\ No newline at end of file
+
+ public String getID() {
+ return ID;
+ }
+
+ public void setID(String id) {
+ ID = id;
+ }
+
+}
Modified: webservices/kandula/trunk/java/src/org/apache/kandula/context/impl/SimpleCoordinationContext.java
URL: http://svn.apache.org/viewvc/webservices/kandula/trunk/java/src/org/apache/kandula/context/impl/SimpleCoordinationContext.java?rev=424676&r1=424675&r2=424676&view=diff
==============================================================================
--- webservices/kandula/trunk/java/src/org/apache/kandula/context/impl/SimpleCoordinationContext.java (original)
+++ webservices/kandula/trunk/java/src/org/apache/kandula/context/impl/SimpleCoordinationContext.java Sat Jul 22 22:41:36 2006
@@ -32,15 +32,15 @@
*/
public class SimpleCoordinationContext implements CoordinationContext {
private String activityID;
-
+
private OMElement contextElement = null;
-
+
private String coordinationType;
-
+
private long expires;
-
+
private EndpointReference registrationServiceEpr;
-
+
public SimpleCoordinationContext(OMElement contextElement) {
super();
this.contextElement = contextElement;
@@ -49,63 +49,63 @@
coordinationType = contextElement.getFirstChildWithName(
new QName("CoordinationType")).getText();
OMElement registrationElement = contextElement
- .getFirstChildWithName(new QName("RegistrationService"));
+ .getFirstChildWithName(new QName("RegistrationService"));
registrationServiceEpr = EndpointReferenceFactory
- .endpointFromOM(registrationElement);
+ .endpointFromOM(registrationElement);
}
-
+
public SimpleCoordinationContext(String activityID,
String coordinationType, EndpointReference epr) {
this.activityID = activityID;
this.coordinationType = coordinationType;
this.registrationServiceEpr = epr;
}
-
+
public String getActivityID() {
return activityID;
}
-
+
public Object getCoordinationContextType() {
return this;
}
-
+
public String getCoordinationType() {
return coordinationType;
}
-
+
public long getExpires() {
return expires;
}
-
+
public EndpointReference getRegistrationService() {
return this.registrationServiceEpr;
}
-
+
public void setActivityID(String value) {
this.activityID = value;
-
+
}
-
+
public void setCoordinationType(String value) {
this.coordinationType = value;
-
+
}
-
+
public void setExpires(long value) {
this.expires = value;
}
-
+
public void setRegistrationService(EndpointReference epr) {
this.registrationServiceEpr = epr;
}
-
+
public OMElement toOM() {
if (contextElement != null) {
return contextElement;
} else {
SOAPFactory factory = OMAbstractFactory.getSOAP12Factory();
OMNamespace wsCoor = factory.createOMNamespace(Constants.WS_COOR,
- "wscoor");
+ "wscoor");
OMElement contextElement = factory.createOMElement(
"CoordinationContext", wsCoor);
if (this.expires != 0) {
@@ -130,4 +130,4 @@
return contextElement;
}
}
-}
\ No newline at end of file
+}
Modified: webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/Coordinator.java
URL: http://svn.apache.org/viewvc/webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/Coordinator.java?rev=424676&r1=424675&r2=424676&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 Sat Jul 22 22:41:36 2006
@@ -37,13 +37,13 @@
}
/**
+ * Participants decided to use this Coordinator as a interposed
+ * sub-coordinator.The newly created CoordinationContext will contain the
+ * same ActivityIdentifier & Protocol type. But the registration EPR of this
+ * coordinator.
+ *
* @param coorContext
- * @return the interposed Coordination Context created <p/>Participants
- * decided to use this Coordinator as a interposed
- * sub-coordinator.The newly created CoordinationContext will
- * contain the same ActivityIdentifier & Protocol type. Registration
- * EPR of the earlier CoordinationContext will be replaced by the
- * RegistrationEPR of this Coordinator.
+ * @return the interposed Coordination Context received <p/>
*/
public AbstractContext createCoordinationContext(
CoordinationContext coorContext) throws AbstractKandulaException {
Modified: webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/Registerable.java
URL: http://svn.apache.org/viewvc/webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/Registerable.java?rev=424676&r1=424675&r2=424676&view=diff
==============================================================================
--- webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/Registerable.java (original)
+++ webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/Registerable.java Sat Jul 22 22:41:36 2006
@@ -29,21 +29,21 @@
public interface Registerable {
public static final class Factory {
public static Registerable newRegisterable(String coordinationType)
- throws InvalidProtocolException {
+ throws InvalidProtocolException {
if (Constants.WS_AT.equals(coordinationType)) {
-
+
return new ATCoordinator();
-
+
} else {
throw new InvalidProtocolException(
- "Unsupported Coordination Type");
+ "Unsupported Coordination Type");
}
}
-
+
private Factory() {
}
}
-
+
public EndpointReference register(AbstractContext context, String protocol,
EndpointReference participantEPR) throws AbstractKandulaException;
}
Modified: webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/at/ATCoordinator.java
URL: http://svn.apache.org/viewvc/webservices/kandula/trunk/java/src/org/apache/kandula/coordinator/at/ATCoordinator.java?rev=424676&r1=424675&r2=424676&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 Sat Jul 22 22:41:36 2006
@@ -38,6 +38,7 @@
/**
* @author <a href="mailto:thilina@opensource.lk"> Thilina Gunarathne </a>
*/
+
public class ATCoordinator implements Registerable {
private Store store;
@@ -48,96 +49,58 @@
}
/**
- * @param context
- * @throws Exception
- * @see This will send the rollback() messages to all the participants
- * registered for the Transaction Do not have to check whether all the
- * participants have replied to the prepare()
+ * Registration Protocol logic for WS-Atomic Trasaction.
+ *
+ * @see org.apache.kandula.coordinator.Registerable#register(org.apache.kandula.context.AbstractContext,
+ * java.lang.String, org.apache.axis2.addressing.EndpointReference)
*/
- private void abortActivity(AbstractContext context)
- throws AbstractKandulaException {
- ParticipantPortTypeRawXMLStub stub = new ParticipantPortTypeRawXMLStub();
+ public EndpointReference register(AbstractContext context, String protocol,
+ EndpointReference participantEPR) throws AbstractKandulaException {
ATActivityContext atContext = (ATActivityContext) context;
atContext.lock();
- atContext.setStatus(Status.CoordinatorStatus.STATUS_ABORTING);
- atContext.unlock();
- Iterator participants = atContext.getAll2PCParticipants();
-
- while (participants.hasNext()) {
- stub.rollbackOperation(((ATParticipantInformation) participants
- .next()).getEpr());
- }
- CompletionInitiatorPortTypeRawXMLStub completionStub = new CompletionInitiatorPortTypeRawXMLStub(
- atContext.getCompletionParticipant());
- completionStub.abortedOperation();
-
- }
-
- public void abortedOperation(String activityID, String enlistmentID)
- throws AbstractKandulaException {
- ATActivityContext atContext = (ATActivityContext) store.get(activityID);
- synchronized (atContext) {
- atContext.lock();
- switch (atContext.getStatus()) {
- case CoordinatorStatus.STATUS_NONE:
- atContext.unlock();
- break;
- case CoordinatorStatus.STATUS_ABORTING:
- atContext.unlock();
- atContext.removeParticipant(enlistmentID);
- break;
- case CoordinatorStatus.STATUS_PREPARING_DURABLE:
- case CoordinatorStatus.STATUS_PREPARING_VOLATILE:
- case Status.CoordinatorStatus.STATUS_ACTIVE:
- atContext.unlock();
- atContext.removeParticipant(enlistmentID);
- abortActivity(atContext);
- break;
- case CoordinatorStatus.STATUS_PREPARED_SUCCESS:
- case CoordinatorStatus.STATUS_COMMITTING:
- // Invalid state
- atContext.unlock();
- break;
- default:
- atContext.unlock();
- break;
+ switch (atContext.getStatus()) {
+ case CoordinatorStatus.STATUS_PREPARING_DURABLE:
+ atContext.unlock();
+ try {
+ this.abortActivity(atContext);
+ } catch (Exception e) {
+ throw new InvalidStateException(e);
}
+ throw new InvalidStateException(
+ "Coordinator is in preparing state - Durable ");
+ case CoordinatorStatus.STATUS_PREPARED_SUCCESS:
+ atContext.unlock();
+ throw new InvalidStateException(
+ "Coordinator is in prepared success state");
+ case CoordinatorStatus.STATUS_COMMITTING:
+ atContext.unlock();
+ throw new InvalidStateException(
+ "Coordinator is in committing state");
+ case CoordinatorStatus.STATUS_ABORTING:
+ atContext.unlock();
+ throw new InvalidStateException("Coordinator is in Aborting state");
+ case CoordinatorStatus.STATUS_ACTIVE:
+ case CoordinatorStatus.STATUS_PREPARING_VOLATILE:
+ EndpointReference epr = atContext.addParticipant(participantEPR,
+ protocol);
+ atContext.unlock();
+ return epr;
+ case CoordinatorStatus.STATUS_NONE:
+ default:
+ atContext.unlock();
+ throw new InvalidStateException();
}
}
/**
- * @param context
- * @throws Exception
- * @see This will send the commit() messages to all the participants
- * registered for the Transaction Must check whether all the
- * participants have replied to the prepare()
- */
- public void commitActivity(AbstractContext context)
- throws AbstractKandulaException {
- // check whether all participants have prepared
- ParticipantPortTypeRawXMLStub stub = new ParticipantPortTypeRawXMLStub();
- ATActivityContext atContext = (ATActivityContext) context;
-
- atContext.lock();
- atContext.setStatus(Status.CoordinatorStatus.STATUS_COMMITTING);
- atContext.unlock();
- Iterator participants = atContext.getAll2PCParticipants();
- while (participants.hasNext()) {
- ATParticipantInformation participant = (ATParticipantInformation) participants
- .next();
- if (!(Status.CoordinatorStatus.STATUS_READ_ONLY == participant
- .getStatus())) {
- stub.commitOperation(participant.getEpr());
- }
- }
- CompletionInitiatorPortTypeRawXMLStub completionStub = new CompletionInitiatorPortTypeRawXMLStub(
- atContext.getCompletionParticipant());
- completionStub.committedOperation();
- }
-
- /**
- * should send be a notification This wraps the Commit operation defined in
- * Ws-AtomicTransaction specification.
+ * Business logic for Commit operation. Completion protocol defined in
+ * Ws-AtomicTransaction specification. Initiates the 2PC protocol.
+ *
+ * Completion participant decides to commit the transaction. First Send
+ * Prepare messages to Volatile participants,then to Durable participants
+ * registered for this transaction. If all votes as prepared or read only
+ * then issue Commit messages to all participants. Abort the transaction if
+ * atleast one participant respond as aborted.
*
* @throws Exception
*/
@@ -175,13 +138,21 @@
stub.committedOperation();
break;
case Status.CoordinatorStatus.STATUS_ACTIVE:
- atContext.setStatus(Status.CoordinatorStatus.STATUS_PREPARING);
- atContext.unlock();
+
if (atContext.getVolatileParticipantCount() > 0) {
+ atContext
+ .setStatus(Status.CoordinatorStatus.STATUS_PREPARING_VOLATILE);
+ atContext.unlock();
volatilePrepare(atContext);
-
} else if (atContext.getDurableParticipantCount() > 0) {
+ atContext
+ .setStatus(Status.CoordinatorStatus.STATUS_PREPARING_DURABLE);
+ atContext.unlock();
durablePrepare(atContext);
+ } else {
+ atContext.setStatus(Status.CoordinatorStatus.STATUS_COMMITTING);
+ atContext.unlock();
+ commitActivity(atContext);
}
break;
@@ -189,16 +160,68 @@
atContext.unlock();
break;
}
-
}
- public void countParticipantOutcome(String activityID, String enlistmentID)
- throws AbstractKandulaException {
- ATActivityContext context = (ATActivityContext) store.get(activityID);
- context.removeParticipant(enlistmentID);
+ /**
+ * Business logic for Rollback operation. Completion protocol defined in
+ * Ws-AtomicTransaction specification.
+ *
+ * Completion participant decides to Rollback (abort) the transaction. Send
+ * Rollback message all participants registered for this transaction.
+ *
+ * @throws Exception
+ */
+ public void rollbackOperation(String id) throws AbstractKandulaException {
+ CompletionInitiatorPortTypeRawXMLStub stub;
+ ATActivityContext atContext = (ATActivityContext) store.get(id);
+
+ // if store throws a Exception capture it
+ if (atContext == null) {
+ throw new IllegalStateException(
+ "No Activity Found for this Activity ID");
+ }
+ /*
+ * Check for states TODO Do we need to lock the activity
+ */
+ atContext.lock();
+ switch (atContext.getStatus()) {
+ case CoordinatorStatus.STATUS_NONE:
+ case CoordinatorStatus.STATUS_ABORTING:
+ atContext.unlock();
+ stub = new CompletionInitiatorPortTypeRawXMLStub(atContext
+ .getCompletionParticipant());
+ stub.abortedOperation();
+ break;
+ case CoordinatorStatus.STATUS_PREPARING_DURABLE:
+ case CoordinatorStatus.STATUS_PREPARING_VOLATILE:
+ case CoordinatorStatus.STATUS_PREPARED_SUCCESS:
+ // If prepared success Ignoring
+ atContext.unlock();
+ break;
+ case CoordinatorStatus.STATUS_COMMITTING:
+ atContext.unlock();
+ stub = new CompletionInitiatorPortTypeRawXMLStub(atContext
+ .getCompletionParticipant());
+ stub.committedOperation();
+ break;
+ case Status.CoordinatorStatus.STATUS_ACTIVE:
+ atContext.setStatus(Status.CoordinatorStatus.STATUS_ABORTING);
+ atContext.unlock();
+ abortActivity(atContext);
+ break;
+ default:
+ atContext.unlock();
+ break;
+ }
}
/**
+ * Business logic for Prepare and ReadOnly operations. Participant responses
+ * for the prepare phase of two Phase Commit protocol defined in
+ * Ws-AtomicTransaction specification.
+ *
+ * Participant guaranties that he can go ahead with the transaction
+ * successfuly or he already finished it succesfuly.
*
* @param activityID
* @param vote
@@ -222,7 +245,7 @@
* conditions at decrement preparing and count preparing
*/
synchronized (context) {
- context.decrementPreparing();
+ context.decrementPreparingParticipantCount();
if (!context.hasMorePreparing()) {
context.lock();
if (!(context.getStatus() == Status.CoordinatorStatus.STATUS_ABORTING)) {
@@ -230,7 +253,6 @@
Method method = context.getCallBackMethod();
try {
method.invoke(this, new Object[] { context });
-
} catch (Exception e) {
throw new KandulaGeneralException(
"Internal Server Error", e);
@@ -244,136 +266,137 @@
}
/**
- * @param context
- * @throws Exception
- * @see This methode issues the oneway prepare() message. Does not wait till
- * partipants responds. Used in 2PC after user commits as well as in
- * subordinate scenerio, when parent issues Durable prepare(). One can
- * check if there are any more participants to be responded by checking
- * the hasMorePreparing() methode of the context.
+ * Business logic for Abort operation. Participant response for the prepare
+ * phase of two Phase Commit protocol defined in Ws-AtomicTransaction
+ * specification.
+ *
+ * Participant aborts the transaction. This cause the whole transactio to be
+ * aborted.
+ *
+ * @param activityID
+ * @param enlistmentID
+ * @throws AbstractKandulaException
*/
- public void durablePrepare(AbstractContext context)
+ public void abortedOperation(String activityID, String enlistmentID)
throws AbstractKandulaException {
- ParticipantPortTypeRawXMLStub stub = new ParticipantPortTypeRawXMLStub();
- ATActivityContext atContext = (ATActivityContext) context;
- Iterator durablePartipantIterator = atContext
- .getRegistered2PCParticipants(Constants.WS_AT_DURABLE2PC);
-
+ ATActivityContext atContext = (ATActivityContext) store.get(activityID);
synchronized (atContext) {
- if (durablePartipantIterator.hasNext()) {
- atContext.lock();
- atContext
- .setStatus(Status.CoordinatorStatus.STATUS_PREPARING_DURABLE);
+ atContext.lock();
+ switch (atContext.getStatus()) {
+ case CoordinatorStatus.STATUS_NONE:
atContext.unlock();
- while (durablePartipantIterator.hasNext()) {
- atContext.countPreparing();
- stub
- .prepareOperation(((ATParticipantInformation) durablePartipantIterator
- .next()).getEpr());
- }
- }
-
- try {
- Method method = ATCoordinator.class.getMethod("commitActivity",
- new Class[] { AbstractContext.class });
- atContext.setCallBackMethod(method);
- } catch (Exception e) {
- throw new KandulaGeneralException(
- "Internal Kandula Server Error ", e);
+ break;
+ case CoordinatorStatus.STATUS_ABORTING:
+ atContext.unlock();
+ atContext.removeParticipant(enlistmentID);
+ break;
+ case CoordinatorStatus.STATUS_PREPARING_DURABLE:
+ case CoordinatorStatus.STATUS_PREPARING_VOLATILE:
+ case Status.CoordinatorStatus.STATUS_ACTIVE:
+ atContext.unlock();
+ atContext.removeParticipant(enlistmentID);
+ abortActivity(atContext);
+ break;
+ case CoordinatorStatus.STATUS_PREPARED_SUCCESS:
+ case CoordinatorStatus.STATUS_COMMITTING:
+ // Invalid state
+ atContext.unlock();
+ break;
+ default:
+ atContext.unlock();
+ break;
}
}
+ }
+ /**
+ * Business logic for commited operation. Participant notifies the
+ * succesfull completion of Commit phase of two Phase Commit protocol
+ * defined in Ws-AtomicTransaction specification.
+ *
+ * Forget the participant, since he is done.
+ *
+ * @param activityID
+ * @param enlistmentID
+ * @throws AbstractKandulaException
+ */
+ public void countParticipantOutcome(String activityID, String enlistmentID)
+ throws AbstractKandulaException {
+ ATActivityContext context = (ATActivityContext) store.get(activityID);
+ context.removeParticipant(enlistmentID);
}
- public EndpointReference register(AbstractContext context, String protocol,
- EndpointReference participantEPR) throws AbstractKandulaException {
+ /**
+ * This will send the rollback() messages to all the participants registered
+ * for the Transaction Do not have to check whether all the participants
+ * have replied to the prepare()
+ *
+ * @param context
+ * @throws Exception
+ */
+ private void abortActivity(AbstractContext context)
+ throws AbstractKandulaException {
+ ParticipantPortTypeRawXMLStub stub = new ParticipantPortTypeRawXMLStub();
ATActivityContext atContext = (ATActivityContext) context;
atContext.lock();
- switch (atContext.getStatus()) {
- case CoordinatorStatus.STATUS_PREPARING_DURABLE:
- atContext.unlock();
- try {
- this.abortActivity(atContext);
- } catch (Exception e) {
- throw new InvalidStateException(e);
- }
- throw new InvalidStateException(
- "Coordinator is in preparing state - Durable ");
- case CoordinatorStatus.STATUS_PREPARED_SUCCESS:
- atContext.unlock();
- throw new InvalidStateException(
- "Coordinator is in prepared success state");
- case CoordinatorStatus.STATUS_COMMITTING:
- atContext.unlock();
- throw new InvalidStateException(
- "Coordinator is in committing state");
- case CoordinatorStatus.STATUS_ABORTING:
- atContext.unlock();
- throw new InvalidStateException("Coordinator is in Aborting state");
- case CoordinatorStatus.STATUS_ACTIVE:
- case CoordinatorStatus.STATUS_PREPARING_VOLATILE:
- atContext.unlock();
- return atContext.addParticipant(participantEPR, protocol);
+ atContext.setStatus(Status.CoordinatorStatus.STATUS_ABORTING);
+ atContext.unlock();
+ Iterator participants = atContext.getAll2PCParticipants();
- case CoordinatorStatus.STATUS_NONE:
- default:
- atContext.unlock();
- throw new InvalidStateException();
+ while (participants.hasNext()) {
+ stub.rollbackOperation(((ATParticipantInformation) participants
+ .next()).getEpr());
}
+ CompletionInitiatorPortTypeRawXMLStub completionStub = new CompletionInitiatorPortTypeRawXMLStub(
+ atContext.getCompletionParticipant());
+ completionStub.abortedOperation();
+
}
- public void rollbackOperation(String id) throws AbstractKandulaException {
- CompletionInitiatorPortTypeRawXMLStub stub;
- ATActivityContext atContext = (ATActivityContext) store.get(id);
+ /**
+ * This will send the commit() messages to all the participants registered
+ * for the Transaction Must check whether all the participants have replied
+ * to the prepare()
+ *
+ * @param context
+ * @throws Exception
+ *
+ */
+ public void commitActivity(AbstractContext context)
+ throws AbstractKandulaException {
+
+ ATActivityContext atContext = (ATActivityContext) context;
- // if store throws a Exception capture it
- if (atContext == null) {
- throw new IllegalStateException(
- "No Activity Found for this Activity ID");
- }
- /*
- * Check for states TODO Do we need to lock the activity
- */
atContext.lock();
- switch (atContext.getStatus()) {
- case CoordinatorStatus.STATUS_NONE:
- case CoordinatorStatus.STATUS_ABORTING:
- atContext.unlock();
- stub = new CompletionInitiatorPortTypeRawXMLStub(atContext
- .getCompletionParticipant());
- stub.abortedOperation();
- break;
- case CoordinatorStatus.STATUS_PREPARING_DURABLE:
- case CoordinatorStatus.STATUS_PREPARING_VOLATILE:
- case CoordinatorStatus.STATUS_PREPARED_SUCCESS:
- // If prepared success Ignoring
- atContext.unlock();
- break;
- case CoordinatorStatus.STATUS_COMMITTING:
- atContext.unlock();
- stub = new CompletionInitiatorPortTypeRawXMLStub(atContext
- .getCompletionParticipant());
- stub.committedOperation();
- break;
- case Status.CoordinatorStatus.STATUS_ACTIVE:
- atContext.setStatus(Status.CoordinatorStatus.STATUS_ABORTING);
- atContext.unlock();
- abortActivity(atContext);
- break;
- default:
- atContext.unlock();
- break;
+ atContext.setStatus(Status.CoordinatorStatus.STATUS_COMMITTING);
+ atContext.unlock();
+ Iterator participants = atContext.getAll2PCParticipants();
+ if (participants.hasNext()) {
+ // check whether all participants have prepared
+ ParticipantPortTypeRawXMLStub stub = new ParticipantPortTypeRawXMLStub();
+ while (participants.hasNext()) {
+ ATParticipantInformation participant = (ATParticipantInformation) participants
+ .next();
+ if (!(Status.CoordinatorStatus.STATUS_READ_ONLY == participant
+ .getStatus())) {
+ stub.commitOperation(participant.getEpr());
+ }
+ }
}
+ CompletionInitiatorPortTypeRawXMLStub completionStub = new CompletionInitiatorPortTypeRawXMLStub(
+ atContext.getCompletionParticipant());
+ completionStub.committedOperation();
}
/**
+ * This method issues the oneway prepare() message. Does not wait till
+ * partipants responds. Used in 2PC after user commits as well as in
+ * subordinate scenerio, when parent issues volatile prepare(). One can
+ * check if there are any more participants to be responded by checking the
+ * hasMorePreparing() methode of the context.
+ *
* @param context
* @throws Exception
- * @see This methode issues the oneway prepare() message. Does not wait till
- * partipants responds. Used in 2PC after user commits as well as in
- * subordinate scenerio, when parent issues volatile prepare(). One can
- * check if there are any more participants to be responded by checking
- * the hasMorePreparing() methode of the context.
*/
public void volatilePrepare(AbstractContext context)
throws AbstractKandulaException {
@@ -383,40 +406,64 @@
.getRegistered2PCParticipants(Constants.WS_AT_VOLATILE2PC);
synchronized (atContext) {
if (volatilePartipantIterator.hasNext()) {
- atContext.lock();
- atContext
- .setStatus(Status.CoordinatorStatus.STATUS_PREPARING_VOLATILE);
- atContext.unlock();
while (volatilePartipantIterator.hasNext()) {
- atContext.countPreparing();
+ atContext.incrementPreparingParticipantCount();
stub
.prepareOperation(((ATParticipantInformation) volatilePartipantIterator
.next()).getEpr());
}
}
- if (atContext.getDurableParticipantCount() > 0) {
- try {
- Method method = ATCoordinator.class.getMethod(
- "durablePrepare",
- new Class[] { AbstractContext.class });
- atContext.setCallBackMethod(method);
- } catch (Exception e) {
- throw new KandulaGeneralException(
- "Internal Kandula Server Error ", e);
- }
- } else {
- try {
- Method method = ATCoordinator.class.getMethod(
- "commitActivity",
- new Class[] { AbstractContext.class });
- atContext.setCallBackMethod(method);
- } catch (Exception e) {
- throw new KandulaGeneralException(
- "Internal Kandula Server Error ", e);
+ }
+
+ try {
+ Method method = ATCoordinator.class.getMethod("durablePrepare",
+ new Class[] { AbstractContext.class });
+ atContext.setCallBackMethod(method);
+ } catch (Exception e) {
+ throw new KandulaGeneralException("Internal Kandula Server Error ",
+ e);
+ }
+ }
+
+ /**
+ * This method issues the oneway prepare() message. Does not wait till
+ * partipants responds. Used in 2PC after user commits as well as in
+ * subordinate scenerio, when parent issues Durable prepare(). One can check
+ * if there are any more participants to be responded by checking the
+ * hasMorePreparing() methode of the context.
+ *
+ * @param context
+ * @throws Exception
+ */
+ public void durablePrepare(AbstractContext context)
+ throws AbstractKandulaException {
+ ParticipantPortTypeRawXMLStub stub = new ParticipantPortTypeRawXMLStub();
+ ATActivityContext atContext = (ATActivityContext) context;
+ Iterator durablePartipantIterator = atContext
+ .getRegistered2PCParticipants(Constants.WS_AT_DURABLE2PC);
+
+ synchronized (atContext) {
+ if (durablePartipantIterator.hasNext()) {
+ atContext.lock();
+ atContext
+ .setStatus(Status.CoordinatorStatus.STATUS_PREPARING_DURABLE);
+ atContext.unlock();
+ while (durablePartipantIterator.hasNext()) {
+ atContext.incrementPreparingParticipantCount();
+ stub
+ .prepareOperation(((ATParticipantInformation) durablePartipantIterator
+ .next()).getEpr());
}
}
- }
+ try {
+ Method method = ATCoordinator.class.getMethod("commitActivity",
+ new Class[] { AbstractContext.class });
+ atContext.setCallBackMethod(method);
+ } catch (Exception e) {
+ throw new KandulaGeneralException(
+ "Internal Kandula Server Error ", e);
+ }
+ }
}
-
-}
\ No newline at end of file
+}
Added: webservices/kandula/trunk/java/src/org/apache/kandula/initiator/InitiatorTransaction.java
URL: http://svn.apache.org/viewvc/webservices/kandula/trunk/java/src/org/apache/kandula/initiator/InitiatorTransaction.java?rev=424676&view=auto
==============================================================================
--- webservices/kandula/trunk/java/src/org/apache/kandula/initiator/InitiatorTransaction.java (added)
+++ webservices/kandula/trunk/java/src/org/apache/kandula/initiator/InitiatorTransaction.java Sat Jul 22 22:41:36 2006
@@ -0,0 +1,105 @@
+/*
+ * 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.initiator;
+
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.kandula.Status;
+import org.apache.kandula.context.CoordinationContext;
+import org.apache.kandula.utility.EndpointReferenceFactory;
+
+/**
+ * @author <a href="mailto:thilina@opensource.lk"> Thilina Gunarathne </a>
+ */
+public class InitiatorTransaction {
+
+ private EndpointReference activationEPR;
+
+ private EndpointReference coordinationEPR;
+
+ private String requesterID;
+
+ private String coordinationType;
+
+ private CoordinationContext coordinationContext;
+
+ private int status = Status.CoordinatorStatus.STATUS_NONE;
+
+ public InitiatorTransaction(String coordinationType,
+ EndpointReference activationEPR) {
+ this.activationEPR = activationEPR;
+ this.coordinationType = coordinationType;
+ requesterID = EndpointReferenceFactory.getRandomStringOf18Characters();
+ }
+
+ /**
+ * @return Returns the coordinationEPR.
+ */
+ public EndpointReference getCoordinationEPR() {
+ return coordinationEPR;
+ }
+
+ /**
+ * @param coordinationEPR
+ * The coordinationEPR to set.
+ */
+ public void setCoordinationEPR(EndpointReference coordinationEPR) {
+ this.coordinationEPR = coordinationEPR;
+ }
+
+ /**
+ * @return Returns the coordinationContext.
+ */
+ public CoordinationContext getCoordinationContext() {
+ return coordinationContext;
+ }
+
+ /**
+ * @param coordinationContext
+ * The coordinationContext to set.
+ */
+ public void setCoordinationContext(CoordinationContext coordinationContext) {
+ this.coordinationContext = coordinationContext;
+ }
+
+ public final int getStatus() {
+ return status;
+ }
+
+ public final void setStatus(int value) {
+ status = value;
+ }
+
+ public String getRequesterID() {
+ return requesterID;
+ }
+
+ public void setRequesterID(String requesterID) {
+ this.requesterID = requesterID;
+ }
+
+ public String getCoordinationType() {
+ return coordinationType;
+ }
+
+ public EndpointReference getActivationEPR() {
+ return activationEPR;
+ }
+
+ public void setActivationEPR(EndpointReference activationEPR) {
+ this.activationEPR = activationEPR;
+ }
+}
\ No newline at end of file
Modified: webservices/kandula/trunk/java/src/org/apache/kandula/initiator/TransactionManager.java
URL: http://svn.apache.org/viewvc/webservices/kandula/trunk/java/src/org/apache/kandula/initiator/TransactionManager.java?rev=424676&r1=424675&r2=424676&view=diff
==============================================================================
--- webservices/kandula/trunk/java/src/org/apache/kandula/initiator/TransactionManager.java (original)
+++ webservices/kandula/trunk/java/src/org/apache/kandula/initiator/TransactionManager.java Sat Jul 22 22:41:36 2006
@@ -16,13 +16,16 @@
*/
package org.apache.kandula.initiator;
+import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.ConfigurationContextFactory;
+import org.apache.axis2.deployment.DeploymentException;
+import org.apache.kandula.Constants;
import org.apache.kandula.Status;
-import org.apache.kandula.context.AbstractContext;
-import org.apache.kandula.context.ContextFactory;
-import org.apache.kandula.context.impl.ATActivityContext;
import org.apache.kandula.faults.AbstractKandulaException;
import org.apache.kandula.faults.InvalidStateException;
+import org.apache.kandula.faults.KandulaGeneralException;
import org.apache.kandula.storage.StorageFactory;
import org.apache.kandula.storage.Store;
import org.apache.kandula.utility.EndpointReferenceFactory;
@@ -39,82 +42,89 @@
private static ThreadLocal threadInfo;
- private String axis2Home, axis2Xml;
+ private ConfigurationContext configurationContext;
public TransactionManager(String coordinationType,
- EndpointReference coordinatorEPR) throws AbstractKandulaException {
+ EndpointReference coordinatorEPR, String axis2Home, String axis2Xml)
+ throws AbstractKandulaException {
+
+ try {
+ configurationContext = ConfigurationContextFactory
+ .createConfigurationContextFromFileSystem(axis2Home,
+ axis2Xml);
+ } catch (DeploymentException e) {
+ throw new KandulaGeneralException(e);
+ } catch (AxisFault e1) {
+ throw new KandulaGeneralException(e1);
+ }
threadInfo = new ThreadLocal();
- AbstractContext context = ContextFactory.getInstance().createActivity(
+ InitiatorTransaction initiatorTransaction = new InitiatorTransaction(
coordinationType, coordinatorEPR);
if (threadInfo.get() != null)
throw new IllegalStateException();
- threadInfo.set(context.getProperty(ATActivityContext.REQUESTER_ID));
+ threadInfo.set(initiatorTransaction.getRequesterID());
Store store = StorageFactory.getInstance().getInitiatorStore();
- store.put(context.getProperty(ATActivityContext.REQUESTER_ID), context);
+ store.put(initiatorTransaction.getRequesterID(), initiatorTransaction);
}
- public void begin(String axis2Home, String axis2Xml) throws Exception {
- begin(axis2Home,axis2Xml,false);
+ public void begin() throws Exception {
+ begin(false);
}
+
/**
* @throws Exception
*/
- public void begin(String axis2Home, String axis2Xml, boolean async) throws Exception {
- this.axis2Home = axis2Home;
- this.axis2Xml = axis2Xml;
- AbstractContext context = getTransaction();
- String id = (String) context
- .getProperty(AbstractContext.REQUESTER_ID);
+ public void begin(boolean async) throws Exception {
+
+ InitiatorTransaction initiatorTransaction = getTransaction();
+ String id = initiatorTransaction.getRequesterID();
ActivationCoordinatorPortTypeRawXMLStub activationCoordinator = new ActivationCoordinatorPortTypeRawXMLStub(
- axis2Home, axis2Xml, (EndpointReference) context
- .getProperty(AbstractContext.ACTIVATION_EPR));
+ configurationContext, initiatorTransaction.getActivationEPR());
activationCoordinator.createCoordinationContextOperation(
- context,async);
- while (async & context.getCoordinationContext() == null) {
+ initiatorTransaction, async);
+ while (async & initiatorTransaction.getCoordinationContext() == null) {
// allow other threads to execute
Thread.sleep(10);
}
RegistrationCoordinatorPortTypeRawXMLStub registrationCoordinator = new RegistrationCoordinatorPortTypeRawXMLStub(
- axis2Home, axis2Xml, context.getCoordinationContext()
- .getRegistrationService());
- //TODO make this unaware of the protocol
+ configurationContext, initiatorTransaction
+ .getCoordinationContext().getRegistrationService());
+ // TODO make this unaware of the protocol
EndpointReference registrationRequeterPortEPR = EndpointReferenceFactory
.getInstance().getCompletionInitiatorEndpoint(id);
- registrationCoordinator.registerOperation( context,registrationRequeterPortEPR,async);
- while (async & context.getProperty(ATActivityContext.COORDINATION_EPR) == null) {
+ registrationCoordinator.registerOperation(Constants.WS_AT_COMPLETION,
+ initiatorTransaction.getRequesterID(),
+ registrationRequeterPortEPR, async);
+ while (async & initiatorTransaction.getCoordinationEPR() == null) {
Thread.sleep(10);
}
}
public void commit() throws Exception {
- AbstractContext context = getTransaction();
- EndpointReference coordinationEPR = (EndpointReference) context
- .getProperty(ATActivityContext.COORDINATION_EPR);
+ InitiatorTransaction initiatorTransaction = getTransaction();
+ EndpointReference coordinationEPR = initiatorTransaction
+ .getCoordinationEPR();
CompletionCoordinatorPortTypeRawXMLStub stub = new CompletionCoordinatorPortTypeRawXMLStub(
- axis2Home, axis2Xml, coordinationEPR);
+ configurationContext, coordinationEPR);
stub.commitOperation();
- while ((context.getStatus() != Status.ParticipantStatus.STATUS_COMMITED)
- & (context.getStatus() != Status.ParticipantStatus.STATUS_ABORTED)) {
+ while ((initiatorTransaction.getStatus() != Status.CoordinatorStatus.STATUS_COMMITTING)
+ & (initiatorTransaction.getStatus() != Status.CoordinatorStatus.STATUS_ABORTING)) {
Thread.sleep(10);
}
- if ((context.getStatus() == Status.ParticipantStatus.STATUS_ABORTED)) {
+ if ((initiatorTransaction.getStatus() == Status.CoordinatorStatus.STATUS_ABORTING)) {
throw new Exception("Aborted");
}
forgetTransaction();
}
public void rollback() throws Exception {
- AbstractContext context = getTransaction();
- EndpointReference coordinationEPR = (EndpointReference) context
- .getProperty(ATActivityContext.COORDINATION_EPR);
+ InitiatorTransaction initiatorTransaction = getTransaction();
+ EndpointReference coordinationEPR = initiatorTransaction
+ .getCoordinationEPR();
CompletionCoordinatorPortTypeRawXMLStub stub = new CompletionCoordinatorPortTypeRawXMLStub(
- axis2Home, axis2Xml, coordinationEPR);
+ configurationContext, coordinationEPR);
stub.rollbackOperation();
- while ((context.getStatus() != Status.ParticipantStatus.STATUS_COMMITED)
- | (context.getStatus() != Status.ParticipantStatus.STATUS_ABORTED)) {
- Thread.sleep(10);
- }
forgetTransaction();
}
@@ -135,18 +145,18 @@
// threadInfo.set(null);
// }
- public static AbstractContext getTransaction()
+ public static InitiatorTransaction getTransaction()
throws AbstractKandulaException {
Object key = threadInfo.get();
- AbstractContext context = (AbstractContext) StorageFactory
+ InitiatorTransaction context = (InitiatorTransaction) StorageFactory
.getInstance().getInitiatorStore().get(key);
if (context == null) {
throw new InvalidStateException("No Activity Found");
}
return context;
}
- public static void forgetTransaction()
- {
+
+ public static void forgetTransaction() {
threadInfo.set(null);
}
-}
\ No newline at end of file
+}
Modified: webservices/kandula/trunk/java/src/org/apache/kandula/initiator/TransactionOutHandler.java
URL: http://svn.apache.org/viewvc/webservices/kandula/trunk/java/src/org/apache/kandula/initiator/TransactionOutHandler.java?rev=424676&r1=424675&r2=424676&view=diff
==============================================================================
--- webservices/kandula/trunk/java/src/org/apache/kandula/initiator/TransactionOutHandler.java (original)
+++ webservices/kandula/trunk/java/src/org/apache/kandula/initiator/TransactionOutHandler.java Sat Jul 22 22:41:36 2006
@@ -21,7 +21,6 @@
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.handlers.AbstractHandler;
import org.apache.kandula.Constants;
-import org.apache.kandula.context.AbstractContext;
import org.apache.kandula.context.CoordinationContext;
import org.apache.kandula.faults.AbstractKandulaException;
@@ -31,16 +30,16 @@
public void invoke(MessageContext msgContext) throws AxisFault {
- AbstractContext context;
+ InitiatorTransaction initiatorTransaction;
try {
String wsaAction = msgContext.getWSAAction();
if ((wsaAction != Constants.WS_COOR_CREATE_COORDINATIONCONTEXT)
&& (wsaAction != Constants.WS_COOR_REGISTER)
&& (wsaAction != Constants.WS_AT_COMMIT)
&& (wsaAction != Constants.WS_AT_ROLLBACK)) {
- context = TransactionManager.getTransaction();
+ initiatorTransaction = TransactionManager.getTransaction();
SOAPHeader soapHeader = msgContext.getEnvelope().getHeader();
- CoordinationContext coorContext = context
+ CoordinationContext coorContext = initiatorTransaction
.getCoordinationContext();
soapHeader.addChild(coorContext.toOM());
}
Modified: webservices/kandula/trunk/java/src/org/apache/kandula/participant/KandulaResource.java
URL: http://svn.apache.org/viewvc/webservices/kandula/trunk/java/src/org/apache/kandula/participant/KandulaResource.java?rev=424676&r1=424675&r2=424676&view=diff
==============================================================================
--- webservices/kandula/trunk/java/src/org/apache/kandula/participant/KandulaResource.java (original)
+++ webservices/kandula/trunk/java/src/org/apache/kandula/participant/KandulaResource.java Sat Jul 22 22:41:36 2006
@@ -27,4 +27,5 @@
public Vote prepare();
public String getProtocol();
+
}
Modified: webservices/kandula/trunk/java/src/org/apache/kandula/participant/ParticipantTransactionCoordinator.java
URL: http://svn.apache.org/viewvc/webservices/kandula/trunk/java/src/org/apache/kandula/participant/ParticipantTransactionCoordinator.java?rev=424676&r1=424675&r2=424676&view=diff
==============================================================================
--- webservices/kandula/trunk/java/src/org/apache/kandula/participant/ParticipantTransactionCoordinator.java (original)
+++ webservices/kandula/trunk/java/src/org/apache/kandula/participant/ParticipantTransactionCoordinator.java Sat Jul 22 22:41:36 2006
@@ -109,10 +109,12 @@
// }
}
- public void rollback(AbstractContext context) throws InvalidStateException {
+ public void rollback(AbstractContext context) throws AbstractKandulaException {
ATParticipantContext atContext = (ATParticipantContext) context;
atContext.getResource().rollback();
-
+ CoordinatorPortTypeRawXMLStub stub = new CoordinatorPortTypeRawXMLStub(
+ atContext.getCoordinationEPR());
+ stub.abortedOperation();
}
}
Added: webservices/kandula/trunk/java/src/org/apache/kandula/participant/ParticipantUtility.java
URL: http://svn.apache.org/viewvc/webservices/kandula/trunk/java/src/org/apache/kandula/participant/ParticipantUtility.java?rev=424676&view=auto
==============================================================================
--- webservices/kandula/trunk/java/src/org/apache/kandula/participant/ParticipantUtility.java (added)
+++ webservices/kandula/trunk/java/src/org/apache/kandula/participant/ParticipantUtility.java Sat Jul 22 22:41:36 2006
@@ -0,0 +1,37 @@
+package org.apache.kandula.participant;
+
+import java.io.IOException;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.kandula.context.impl.ATParticipantContext;
+import org.apache.kandula.faults.AbstractKandulaException;
+import org.apache.kandula.utility.EndpointReferenceFactory;
+import org.apache.kandula.utility.KandulaConfiguration;
+import org.apache.kandula.wscoor.RegistrationCoordinatorPortTypeRawXMLStub;
+
+public class ParticipantUtility {
+ public static void registerParticipant(
+ ATParticipantContext participantContext) throws AxisFault {
+ try {
+ ConfigurationContext axis2ConfigurationContext = KandulaConfiguration
+ .getInstance().getPariticipantAxis2ConfigurationContext();
+ RegistrationCoordinatorPortTypeRawXMLStub stub = new RegistrationCoordinatorPortTypeRawXMLStub(
+ axis2ConfigurationContext, participantContext
+ .getCoordinationContext().getRegistrationService());
+ EndpointReference participantProtocolService = EndpointReferenceFactory
+ .getInstance().get2PCParticipantEndpoint(
+ participantContext.getID());
+ stub.registerOperation(
+ participantContext.getRegistrationProtocol(),
+ participantContext.getID(), participantProtocolService,
+ false);
+ } catch (IOException e) {
+ throw new AxisFault(e);
+ } catch (AbstractKandulaException e) {
+ AxisFault e1 = new AxisFault(e);
+ throw e1;
+ }
+ }
+}
Modified: webservices/kandula/trunk/java/src/org/apache/kandula/participant/TransactionInHandler.java
URL: http://svn.apache.org/viewvc/webservices/kandula/trunk/java/src/org/apache/kandula/participant/TransactionInHandler.java?rev=424676&r1=424675&r2=424676&view=diff
==============================================================================
--- webservices/kandula/trunk/java/src/org/apache/kandula/participant/TransactionInHandler.java (original)
+++ webservices/kandula/trunk/java/src/org/apache/kandula/participant/TransactionInHandler.java Sat Jul 22 22:41:36 2006
@@ -16,27 +16,21 @@
*/
package org.apache.kandula.participant;
-import java.io.IOException;
-
import javax.xml.namespace.QName;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.soap.SOAPHeader;
import org.apache.axis2.AxisFault;
-import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.description.Parameter;
import org.apache.axis2.handlers.AbstractHandler;
import org.apache.kandula.Constants;
import org.apache.kandula.context.AbstractContext;
import org.apache.kandula.context.CoordinationContext;
import org.apache.kandula.context.impl.ATParticipantContext;
import org.apache.kandula.context.impl.SimpleCoordinationContext;
-import org.apache.kandula.faults.AbstractKandulaException;
import org.apache.kandula.storage.StorageFactory;
import org.apache.kandula.storage.Store;
-import org.apache.kandula.utility.EndpointReferenceFactory;
-import org.apache.kandula.utility.KandulaConfiguration;
-import org.apache.kandula.wscoor.RegistrationCoordinatorPortTypeRawXMLStub;
public class TransactionInHandler extends AbstractHandler {
@@ -66,44 +60,23 @@
coordinationElement);
context.setCoordinationContext(coorContext);
- // TODO : See whether we can allow the user to set the resource when
- // the
- // business logic receives the message
- String resourceFile = (String) msgContext.getParameter(
- Constants.KANDULA_RESOURCE).getValue();
- String participantRepository = KandulaConfiguration.getInstance()
- .getParticipantRepository();
- String participantAxis2Xml = KandulaConfiguration.getInstance()
- .getParticipantAxis2Conf();
-
- try {
- resource = (KandulaResource) Class.forName(resourceFile)
- .newInstance();
- } catch (Exception e) {
- throw new AxisFault(e);
- }
- context.setResource(resource);
-
- String id = EndpointReferenceFactory
- .getRandomStringOf18Characters();
Store store = StorageFactory.getInstance().getStore();
- context.setProperty(AbstractContext.REQUESTER_ID, id);
- store.put(id, context);
- // ParticipantTransactionCoordinator txManager = new
- // ParticipantTransactionCoordinator();
- try {
- RegistrationCoordinatorPortTypeRawXMLStub stub = new RegistrationCoordinatorPortTypeRawXMLStub(
- participantRepository, participantAxis2Xml, coorContext
- .getRegistrationService());
- EndpointReference participantProtocolService = EndpointReferenceFactory
- .getInstance().get2PCParticipantEndpoint(id);
- stub.registerOperation(context,
- participantProtocolService,false);
- } catch (IOException e) {
- throw new AxisFault(e);
- } catch (AbstractKandulaException e) {
- AxisFault e1 = new AxisFault(e);
- throw e1;
+ store.put(context.getID(), context);
+ msgContext.setProperty(AbstractContext.REQUESTER_ID,context.getID());
+ Parameter resourceFile = msgContext.getParameter(
+ Constants.KANDULA_RESOURCE);
+
+ //Resource not given. Registration delayed to the business logic
+ if (resourceFile != null) {
+
+ try {
+ resource = (KandulaResource) Class.forName((String)resourceFile.getValue())
+ .newInstance();
+ } catch (Exception e) {
+ throw new AxisFault(e);
+ }
+ context.setResource(resource);
+ ParticipantUtility.registerParticipant(context);
}
}
}
Modified: webservices/kandula/trunk/java/src/org/apache/kandula/storage/SimpleStore.java
URL: http://svn.apache.org/viewvc/webservices/kandula/trunk/java/src/org/apache/kandula/storage/SimpleStore.java?rev=424676&r1=424675&r2=424676&view=diff
==============================================================================
--- webservices/kandula/trunk/java/src/org/apache/kandula/storage/SimpleStore.java (original)
+++ webservices/kandula/trunk/java/src/org/apache/kandula/storage/SimpleStore.java Sat Jul 22 22:41:36 2006
@@ -18,8 +18,6 @@
import java.util.HashMap;
-import org.apache.kandula.context.AbstractContext;
-
/**
* @author <a href="mailto:thilina@opensource.lk"> Thilina Gunarathne </a>
*/
@@ -47,7 +45,7 @@
* @see org.apache.kandula.storage.Store#getContext(java.lang.String)
*/
public Object get(Object id) {
- return (AbstractContext) contextMap.get(id);
+ return contextMap.get(id);
}
/*
Modified: webservices/kandula/trunk/java/src/org/apache/kandula/utility/KandulaConfiguration.java
URL: http://svn.apache.org/viewvc/webservices/kandula/trunk/java/src/org/apache/kandula/utility/KandulaConfiguration.java?rev=424676&r1=424675&r2=424676&view=diff
==============================================================================
--- webservices/kandula/trunk/java/src/org/apache/kandula/utility/KandulaConfiguration.java (original)
+++ webservices/kandula/trunk/java/src/org/apache/kandula/utility/KandulaConfiguration.java Sat Jul 22 22:41:36 2006
@@ -20,6 +20,14 @@
import java.net.InetAddress;
import java.util.Properties;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.ConfigurationContextFactory;
+import org.apache.axis2.deployment.DeploymentException;
+import org.apache.kandula.faults.AbstractKandulaException;
+import org.apache.kandula.faults.KandulaGeneralException;
+import org.apache.kandula.storage.StorageFactory;
+
/**
* @author <a href="mailto:thilina@opensource.lk"> Thilina Gunarathne </a>
*/
@@ -84,9 +92,9 @@
host = properties.getProperty(HOST_PROPERTY);
port = properties.getProperty(PORT_PROPERTY);
participantRepository = properties.getProperty(PARTICIPANT_REPO);
- if (participantRepository == null) {
- participantRepository = ".";
- }
+ // if (participantRepository == null) {
+ // participantRepository = ".";
+ // }
if (properties.getProperty("tcpmon_enable").equals("true")) {
debug = "true";
@@ -94,30 +102,30 @@
participantAxis2Xml = properties
.getProperty(PARTICIPANT_AXIS2_CONF);
- if (participantAxis2Xml == null) {
- participantAxis2Xml = "axis2.xml";
- }
+ // if (participantAxis2Xml == null) {
+ // participantAxis2Xml = "axis2.xml";
+ // }
kandulaListenerRepository = properties
.getProperty(KANDULA_LISTENER_REPO);
- if (kandulaListenerRepository == null) {
- kandulaListenerRepository = ".";
- }
+ // if (kandulaListenerRepository == null) {
+ // kandulaListenerRepository = ".";
+ // }
kandulaListenerAxis2Xml = properties
.getProperty(KANDULA_LISTENER_AXIS2XML);
- if (kandulaListenerAxis2Xml == null) {
- kandulaListenerRepository += "/axis2.xml";
- }
+ // if (kandulaListenerAxis2Xml == null) {
+ // kandulaListenerRepository += "/axis2.xml";
+ // }
coordinatorAxis2Conf = properties.getProperty(COORDINATOR_AXIS2XML);
- if (coordinatorAxis2Conf == null) {
- coordinatorAxis2Conf = "axis2.xml";
- }
+ // if (coordinatorAxis2Conf == null) {
+ // coordinatorAxis2Conf = "axis2.xml";
+ // }
coordinatorRepo = properties.getProperty(COORDINATOR_REPOSITORY);
- if (coordinatorRepo == null) {
- coordinatorAxis2Conf = ".";
- }
+ // if (coordinatorRepo == null) {
+ // coordinatorAxis2Conf = ".";
+ // }
kandulaListenerPort = properties.getProperty(LISTENER_PORT);
if (kandulaListenerPort == null) {
@@ -149,6 +157,24 @@
return instance;
}
+ public ConfigurationContext getPariticipantAxis2ConfigurationContext()
+ throws AbstractKandulaException {
+ try {
+ if (coordinatorAxis2Conf != null && coordinatorAxis2Conf != "")
+
+ return ConfigurationContextFactory
+ .createConfigurationContextFromFileSystem(
+ participantRepository, participantAxis2Xml);
+ else {
+ return StorageFactory.getInstance().getConfigurationContext();
+ }
+ } catch (DeploymentException e) {
+ throw new KandulaGeneralException(e);
+ } catch (AxisFault e1) {
+ throw new KandulaGeneralException(e1);
+ }
+ }
+
public String getParticipantRepository() {
return participantRepository;
}
@@ -157,6 +183,24 @@
return participantAxis2Xml;
}
+ public ConfigurationContext getCoordinatorAxis2ConfigurationContext()
+ throws AbstractKandulaException {
+ try {
+ if (coordinatorAxis2Conf != null && coordinatorAxis2Conf != "")
+
+ return ConfigurationContextFactory
+ .createConfigurationContextFromFileSystem(
+ coordinatorRepo, coordinatorAxis2Conf);
+ else {
+ return StorageFactory.getInstance().getConfigurationContext();
+ }
+ } catch (DeploymentException e) {
+ throw new KandulaGeneralException(e);
+ } catch (AxisFault e1) {
+ throw new KandulaGeneralException(e1);
+ }
+ }
+
public String getCoordinatorRepo() {
return coordinatorRepo;
}
@@ -195,4 +239,4 @@
// instance = new EndpointReferenceFactory();
// return instance;
// }
-}
\ No newline at end of file
+}
Modified: webservices/kandula/trunk/java/src/org/apache/kandula/wsat/AbstractATNotifierStub.java
URL: http://svn.apache.org/viewvc/webservices/kandula/trunk/java/src/org/apache/kandula/wsat/AbstractATNotifierStub.java?rev=424676&r1=424675&r2=424676&view=diff
==============================================================================
--- webservices/kandula/trunk/java/src/org/apache/kandula/wsat/AbstractATNotifierStub.java (original)
+++ webservices/kandula/trunk/java/src/org/apache/kandula/wsat/AbstractATNotifierStub.java Sat Jul 22 22:41:36 2006
@@ -28,11 +28,9 @@
import org.apache.axis2.client.OperationClient;
import org.apache.axis2.client.Options;
import org.apache.axis2.context.ConfigurationContext;
-import org.apache.axis2.context.ConfigurationContextFactory;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.context.ServiceContext;
import org.apache.axis2.context.ServiceGroupContext;
-import org.apache.axis2.deployment.DeploymentException;
import org.apache.axis2.description.AxisOperation;
import org.apache.axis2.description.AxisService;
import org.apache.axis2.description.AxisServiceGroup;
@@ -48,29 +46,32 @@
protected AxisService service;
- protected ConfigurationContext configurationContext;
-
protected ServiceContext serviceContext;
protected EndpointReference toEPR;
- public AbstractATNotifierStub(String axis2Home, String axis2Xml,
- AxisService service) throws AbstractKandulaException {
- // creating the configuration
- this.service = service;
+ // public AbstractATNotifierStub(ConfigurationContext configurationContext,
+ // AxisService service) throws AbstractKandulaException {
+ // this.service = service;
+ // try {
+ // configurationContext.getAxisConfiguration().addService(service);
+ // } catch (AxisFault e1) {
+ // throw new KandulaGeneralException(e1);
+ // }
+ // ServiceGroupContext sgc = new ServiceGroupContext(configurationContext,
+ // (AxisServiceGroup) this.service.getParent());
+ // this.serviceContext = new ServiceContext(service, sgc);
+ // }
+ public AbstractATNotifierStub(ConfigurationContext configurationContext)
+ throws AbstractKandulaException {
+ this.service = new AxisService("annonService" + this.hashCode());
try {
- configurationContext = ConfigurationContextFactory
- .createConfigurationContextFromFileSystem(axis2Home,
- axis2Xml);
configurationContext.getAxisConfiguration().addService(service);
- } catch (DeploymentException e) {
- throw new KandulaGeneralException(e);
} catch (AxisFault e1) {
throw new KandulaGeneralException(e1);
}
- ServiceGroupContext sgc = new ServiceGroupContext(
- this.configurationContext, (AxisServiceGroup) this.service
- .getParent());
+ ServiceGroupContext sgc = new ServiceGroupContext(configurationContext,
+ (AxisServiceGroup) this.service.getParent());
this.serviceContext = new ServiceContext(service, sgc);
}
@@ -109,6 +110,9 @@
options.setTo(this.toEPR);
if (replyToEPR != null) {
options.setReplyTo(replyToEPR);
+ } else {
+ options.setReplyTo(new EndpointReference(
+ "http://www.w3.org/2005/08/addressing/none"));
}
options.setAction(action);
// options.setTranportOut(org.apache.axis2.Constants.TRANSPORT_HTTP);
@@ -133,4 +137,4 @@
throw new KandulaGeneralException(e);
}
}
-}
\ No newline at end of file
+}
Modified: webservices/kandula/trunk/java/src/org/apache/kandula/wsat/completion/CompletionCoordinatorPortTypeRawXMLSkeleton.java
URL: http://svn.apache.org/viewvc/webservices/kandula/trunk/java/src/org/apache/kandula/wsat/completion/CompletionCoordinatorPortTypeRawXMLSkeleton.java?rev=424676&r1=424675&r2=424676&view=diff
==============================================================================
--- webservices/kandula/trunk/java/src/org/apache/kandula/wsat/completion/CompletionCoordinatorPortTypeRawXMLSkeleton.java (original)
+++ webservices/kandula/trunk/java/src/org/apache/kandula/wsat/completion/CompletionCoordinatorPortTypeRawXMLSkeleton.java Sat Jul 22 22:41:36 2006
@@ -40,7 +40,7 @@
* @param requestElement
* @throws AxisFault
*/
- public OMElement commitOperation(OMElement requestElement) throws AxisFault {
+ public void commitOperation(OMElement requestElement) throws AxisFault {
String activityId;
// log.info("Visited Commit operation");
StorageFactory.getInstance().setConfigurationContext(
@@ -49,19 +49,18 @@
WSDLConstants.MESSAGE_LABEL_IN_VALUE).getEnvelope().getHeader();
activityId = header.getFirstChildWithName(
Constants.TRANSACTION_ID_PARAMETER).getText();
- // TODO do we need to check the incoming message
try {
ATCoordinator coordinator = new ATCoordinator();
coordinator.commitOperation(activityId);
} catch (AbstractKandulaException e) {
+ e.printStackTrace();
AxisFault fault = new AxisFault(e);
fault.setFaultCode(e.getFaultCode());
throw fault;
}
- return null;
}
- public OMElement rollbackOperation(OMElement requestElement)
+ public void rollbackOperation(OMElement requestElement)
throws AxisFault {
String activityId;
@@ -80,7 +79,6 @@
fault.setFaultCode(e.getFaultCode());
throw fault;
}
- return null;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: kandula-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: kandula-dev-help@ws.apache.org