diff options
Diffstat (limited to '')
-rw-r--r-- | sandbox/dougsleite/policy-guardianExceptionHandling/src/main/java/org/apache/tuscany/sca/policy/guardianExceptionHandling/GuardianMemberImpl.java (renamed from sandbox/dougsleite/implementation-guardian/src/main/java/org/apache/tuscany/sca/implementation/guardian/impl/GuardianMemberImpl.java) | 73 |
1 files changed, 41 insertions, 32 deletions
diff --git a/sandbox/dougsleite/implementation-guardian/src/main/java/org/apache/tuscany/sca/implementation/guardian/impl/GuardianMemberImpl.java b/sandbox/dougsleite/policy-guardianExceptionHandling/src/main/java/org/apache/tuscany/sca/policy/guardianExceptionHandling/GuardianMemberImpl.java index 80b9321e79..5e9ae7853c 100644 --- a/sandbox/dougsleite/implementation-guardian/src/main/java/org/apache/tuscany/sca/implementation/guardian/impl/GuardianMemberImpl.java +++ b/sandbox/dougsleite/policy-guardianExceptionHandling/src/main/java/org/apache/tuscany/sca/policy/guardianExceptionHandling/GuardianMemberImpl.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.tuscany.sca.implementation.guardian.impl; +package org.apache.tuscany.sca.policy.guardianExceptionHandling; import java.util.LinkedList; import java.util.List; @@ -31,42 +31,46 @@ import org.apache.tuscany.sca.implementation.guardian.common.Context; import org.apache.tuscany.sca.implementation.guardian.common.GlobalException; import org.apache.tuscany.sca.implementation.guardian.common.JoinException; import org.apache.tuscany.sca.implementation.guardian.common.SuspendException; -import org.osoa.sca.annotations.Destroy; -import org.osoa.sca.annotations.Init; -import org.osoa.sca.annotations.Reference; -import org.osoa.sca.annotations.Scope; -import org.osoa.sca.annotations.Service; - -@Service(GuardianMember.class) -@Scope("COMPOSITE") +import org.apache.tuscany.sca.invocation.Message; + public class GuardianMemberImpl implements GuardianMember { private int participantState; private Stack<Context> contextList; - private Queue<GlobalException> exceptionQueue; - @Reference(name = "guardian_group", required = true) - public GuardianGroup guardianGroup; - private int id; + private String id; + //FIXME: Review the usage of this variable private boolean exceptionThrown; + private Message msg; + private GuardianExceptionHandlingPolicyInterceptor interceptor; - public GuardianMemberImpl() { + protected GuardianMemberImpl(String componentName, Message msg, GuardianExceptionHandlingPolicyInterceptor interceptor) { contextList = new Stack<Context>(); contextList.add(Context.INIT_CONTEXT); exceptionQueue = new LinkedList<GlobalException>(); participantState = GuardianGroup.NORMAL_PARTICIPANT_STATE; exceptionThrown = false; + + this.id = componentName; + this.msg = msg; + this.interceptor = interceptor; + } + + public void setGuardianExceptionHandlingPolicyInterceptor(GuardianExceptionHandlingPolicyInterceptor interceptor) { + this.interceptor = interceptor; + } + + public GuardianExceptionHandlingPolicyInterceptor getGuardianExceptionHandlingPolicyInterceptor() { + return this.interceptor; } - @Init - public void init() { - guardianGroup.addGuardianMember(this); + public void setMessage(Message msg) { + this.msg = msg; } - @Destroy - public void destroy() { - guardianGroup.removeGuardianMember(this); + public Message getMessage() { + return this.msg; } public void addException(GlobalException ex) { @@ -76,25 +80,28 @@ public class GuardianMemberImpl implements GuardianMember { public Context getCurrentContext() { return contextList.peek(); } - public void enableContext(Context context) { //Update the context list with the related set of exceptions - contextList.push(context); - if (contextList.size() == 2) { + if (contextList.size() == 1) { + contextList.push(context); + JoinException ex = new JoinException(); ex.setSignalingContext(context); ex.putSignalingParticipant(getParticipantIdentifier()); gthrow(ex, null); + } else { + contextList.push(context); } } - public void removeContext() { - if (!contextList.isEmpty()) { - contextList.pop(); - } + public Context removeContext() { +// if (contextList.size() > 1) { +// return contextList.pop(); +// } + return contextList.pop(); } //If participantList is null then signal to ALL participants @@ -106,7 +113,13 @@ public class GuardianMemberImpl implements GuardianMember { ex.setSignalingContext(getCurrentContext()); ex.putSignalingParticipant(getParticipantIdentifier()); - guardianGroup.gthrow(ex, participantList); + //Prepare the parameters + Object[] params = {ex, participantList}; + msg.setBody(params); + + interceptor.invokeGuardianGroupOperation("gthrow", msg); + //guardianGroup.gthrow(ex, participantList); + exceptionThrown = true; } else { setParticipantState(GuardianGroup.SUSPENDED_PARTICIPANT_STATE); @@ -163,10 +176,6 @@ public class GuardianMemberImpl implements GuardianMember { return participantIdentifier.toString(); } - public void setUniqueParticipantID(int id) { - this.id = id; - } - public int getParticipantState() { return participantState; } |