diff options
Diffstat (limited to '')
-rw-r--r-- | sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianMemberImpl.java | 122 |
1 files changed, 54 insertions, 68 deletions
diff --git a/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianMemberImpl.java b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianMemberImpl.java index 682a6d8e1b..ec6ecb609c 100644 --- a/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianMemberImpl.java +++ b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianMemberImpl.java @@ -34,6 +34,7 @@ import org.osoa.sca.annotations.Service; @Scope("COMPOSITE") public class GuardianMemberImpl implements GuardianMember { + private int participantState; private Stack<Context> contextList; private BlockingInterface service; private Queue<GlobalException> exceptionQueue; @@ -45,6 +46,7 @@ public class GuardianMemberImpl implements GuardianMember { contextList = new Stack<Context>(); contextList.add(Context.INIT_CONTEXT); exceptionQueue = new LinkedList<GlobalException>(); + participantState = GuardianGroup.NORMAL_PARTICIPANT_STATE; } @Init @@ -78,7 +80,10 @@ public class GuardianMemberImpl implements GuardianMember { contextList.push(context); if (contextList.size() == 2) { - gthrow(new JoinException(), null); + JoinException ex = new JoinException(); + ex.setSignalingContext(context); + ex.setSignalingParticipant(getParticipantIdentifier()); + gthrow(ex, null); } } @@ -93,30 +98,31 @@ public class GuardianMemberImpl implements GuardianMember { //If participantList is null then signal to ALL participants public void gthrow(GlobalExceptionInterface ex, List<String> participantList) { //1)Block the participant until raise an exception - if (!service.isBlocked()) { - service.block(); - if (ex != null) { - //Set the exception's parameters - ex.setSignalingContext(getCurrentContext()); - ex.setSignalingParticipant(getParticipantIdentifier()); + if (!(ex instanceof SuspendException)) { + //Set the exception's parameters + ex.setSignalingContext(getCurrentContext()); + ex.setSignalingParticipant(getParticipantIdentifier()); - guardianGroup.gthrow(ex, participantList); - } + guardianGroup.gthrow(ex, participantList); + } else { + /*if (service instanceof BlockingInterface && !service.isBlocked()) { + service.block(); + }*/ + participantState = GuardianGroup.SUSPENDED_PARTICIPANT_STATE; } - - //*Is here the best place to receive such kind of msg? - // - //2B)When receive exception_msg from GuardianGroup do - // if participant is not suspended then suspend it - // if participant supports interrupts then - // interrupt it, add SuspendException in the exception_queue, and invoke checkExceptionStatus - // else invoke checkExceptionStatus periodically - // - //4)Once ALL required participants are SUSPENDED (suspended point), invoke the defined Recovery Rules - // 4.1) recovery_rules < signaled exceptions + context_list of all participant > target context + exception to raise - // 4.2) raise the resolved exception in each participant -> it goes to the exception_queue + //*Is here the best place to receive such kind of msg? + // + //2B)When receive exception_msg from GuardianGroup do + // if participant is not suspended then suspend it + // if participant supports interrupts then + // interrupt it, add SuspendException in the exception_queue, and invoke checkExceptionStatus + // else invoke checkExceptionStatus periodically + // + //4)Once ALL required participants are SUSPENDED (suspended point), invoke the defined Recovery Rules + // 4.1) recovery_rules < signaled exceptions + context_list of all participant > target context + exception to raise + // 4.2) raise the resolved exception in each participant -> it goes to the exception_queue } @@ -131,62 +137,34 @@ public class GuardianMemberImpl implements GuardianMember { // else if first element on the exception_queue is SuspendException then // the method blocks until the next exception is received. The method raises the first non-SuspendException in the queue + //Blocks until the state be diferent the SUSPENDED_STATE + while (participantState == GuardianGroup.SUSPENDED_PARTICIPANT_STATE) { + try { + Thread.sleep(5000); + } catch (InterruptedException ex) { + Logger.getLogger(GuardianMemberImpl.class.getName()).log(Level.SEVERE, null, ex); + } + } + GlobalException exc; if ((exc = exceptionQueue.peek()) == null) { System.out.println(getParticipantIdentifier() + "#No exception on exception queue"); return; - } else { - while ((exc = exceptionQueue.peek()) instanceof SuspendException) { - try { - Thread.sleep(5000); - } catch (InterruptedException ex) { - Logger.getLogger(GuardianMemberImpl.class.getName()).log(Level.SEVERE, null, ex); - } - exceptionQueue.poll(); - } + } - service.unblock(); - -// if (exc != null) { -// System.out.println("\n" + getParticipantIdentifier() + "#"); -// System.out.println("Exc: " + exc); -// System.out.println("TargetContext: " + exc.getTargetContext().getName()); -// System.out.println("Signaling Participant: " + exc.getSignalingParticipant()); -// System.out.println("Current Context: " + getCurrentContext().getName()); -// System.out.println("Equals: " + exc.getTargetContext().equals(getCurrentContext()) + "\n"); -// } - - //Check if ex.targetContext() matches the participant id - //Eg. ex.targetContext(): Main and participant id: Init.Main.Backup -> should thrown the exception - //Test if the exception should be thrown in the target context - if (exc != null) { - for (Context c : contextList) { - if (exc.getTargetContext().equals(c) && (c.equals(Context.INIT_CONTEXT) || c.getExceptionList().contains(exc.getClass()))) { - System.out.println(getParticipantIdentifier() + "#Returning an exception"); - exceptionQueue.poll(); - throw exc; - } - } + //Check if ex.targetContext() matches the participant id + //Eg. ex.targetContext(): Main and participant id: Init.Main.Backup -> should thrown the exception + //Test if the exception should be thrown in the target context + for (Context c : contextList) { + if (exc.getTargetContext().equals(c) && (c.equals(Context.INIT_CONTEXT) || c.getExceptionList().contains(exc.getClass()))) { + System.out.println(getParticipantIdentifier() + "#Returning an exception"); + exceptionQueue.poll(); + throw exc; } -// String[] contexts = getParticipantIdentifier().split("\\."); -// if (exc != null) { -// for (int i = contexts.length - 1; i > 0; i--) { -// if (exc.getTargetContext().equals(new Context(contexts[i]))) { -// -// //Test if the exception should be thrown in the target context -// -// -// System.out.println(getParticipantIdentifier() + "#Returning an exception"); -// exceptionQueue.poll(); -// throw exc; -// } -// } -// } - - return; } + return; } public String getParticipantIdentifier() { @@ -207,4 +185,12 @@ public class GuardianMemberImpl implements GuardianMember { public void removeService() { this.service = null; } + + public int getParticipantState() { + return participantState; + } + + public void setParticipantState(int state) { + this.participantState = state; + } } |