summaryrefslogtreecommitdiffstats
path: root/sandbox/dougsleite/guardian-model/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'sandbox/dougsleite/guardian-model/src/main/java/org')
-rw-r--r--sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/BlockingInterface.java30
-rw-r--r--sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/Context.java74
-rw-r--r--sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GlobalException.java87
-rw-r--r--sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianGroup.java26
-rw-r--r--sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianGroupImpl.java180
-rw-r--r--sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianMember.java36
-rw-r--r--sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianMemberImpl.java209
-rw-r--r--sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianPrimitives.java37
-rw-r--r--sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/JoinException.java39
-rw-r--r--sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/LeaveException.java38
-rw-r--r--sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/SuspendException.java38
-rw-r--r--sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/UnhandledException.java38
-rw-r--r--sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/exceptions/BackupFailedException.java24
-rw-r--r--sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/exceptions/BackupJoinedException.java24
-rw-r--r--sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/exceptions/PrimaryExistsException.java24
-rw-r--r--sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/exceptions/PrimaryFailedException.java24
16 files changed, 928 insertions, 0 deletions
diff --git a/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/BlockingInterface.java b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/BlockingInterface.java
new file mode 100644
index 0000000000..848c4a874d
--- /dev/null
+++ b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/BlockingInterface.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.tuscany.sca.guardian;
+
+public interface BlockingInterface {
+
+ //@OneWay
+ public void block();
+
+ //@OneWay
+ public void unblock();
+
+ public boolean isBlocked();
+}
diff --git a/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/Context.java b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/Context.java
new file mode 100644
index 0000000000..1b3cd72ead
--- /dev/null
+++ b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/Context.java
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.tuscany.sca.guardian;
+
+import java.util.LinkedList;
+import java.util.List;
+
+public class Context {
+
+ public static Context CURRENT_CONTEXT = new Context("CURRENT_CONTEXT");
+ public static Context INIT_CONTEXT = new Context("INIT_CONTEXT");
+ private String name;
+ private List<GlobalException> exceptionList;
+
+ public Context(String name) {
+ this.name = name;
+ this.exceptionList = new LinkedList<GlobalException>();
+ }
+
+ public Context(String name, List exceptionList) {
+ this.name = name;
+ this.exceptionList = exceptionList;
+ }
+
+ public void addException(GlobalException ex) {
+ this.exceptionList.add(ex);
+ }
+
+ public void setExceptionList(List exceptionList) {
+ this.exceptionList = exceptionList;
+ }
+
+ public List getExceptionList() {
+ return this.exceptionList;
+ }
+
+ /**
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @param name the name to set
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ return (obj instanceof Context &&
+ (((Context) obj).getName().equals(this.getName()) ||
+ this == Context.CURRENT_CONTEXT ||
+ ((Context) obj) == Context.CURRENT_CONTEXT));
+ }
+}
diff --git a/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GlobalException.java b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GlobalException.java
new file mode 100644
index 0000000000..c500a32701
--- /dev/null
+++ b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GlobalException.java
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.tuscany.sca.guardian;
+
+public class GlobalException extends RuntimeException {
+
+ private Context signalingContext;
+ private Context targetContext; //Assigned by the recovery rules
+ private String signalingParticipant;
+
+ public GlobalException() {
+ super();
+ }
+
+ public GlobalException(String message) {
+ super(message);
+ }
+
+ public GlobalException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public GlobalException(Throwable cause) {
+ super(cause);
+ }
+
+ private void init() {
+ }
+
+ /**
+ * @return the signalingContext
+ */
+ public Context getSignalingContext() {
+ return signalingContext;
+ }
+
+ /**
+ * @param signalingContext the signalingContext to set
+ */
+ public void setSignalingContext(Context signalingContext) {
+ this.signalingContext = signalingContext;
+ }
+
+ /**
+ * @return the targetContext
+ */
+ public Context getTargetContext() {
+ return targetContext;
+ }
+
+ /**
+ * @param targetContext the targetContext to set
+ */
+ public void setTargetContext(Context targetContext) {
+ this.targetContext = targetContext;
+ }
+
+ /**
+ * @return the signalingProcess
+ */
+ public String getSignalingParticipant() {
+ return signalingParticipant;
+ }
+
+ /**
+ * @param signalingProcess the signalingProcess to set
+ */
+ public void setSignalingParticipant(String signalingProcess) {
+ this.signalingParticipant = signalingProcess;
+ }
+}
diff --git a/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianGroup.java b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianGroup.java
new file mode 100644
index 0000000000..12d7cf478b
--- /dev/null
+++ b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianGroup.java
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.tuscany.sca.guardian;
+
+public interface GuardianGroup extends GuardianPrimitives {
+
+ public void addGuardianMember(GuardianMember guardianMember);
+
+ public boolean removeGuardianMember(GuardianMember guardianMember);
+}
diff --git a/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianGroupImpl.java b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianGroupImpl.java
new file mode 100644
index 0000000000..ee78dadddf
--- /dev/null
+++ b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianGroupImpl.java
@@ -0,0 +1,180 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.tuscany.sca.guardian;
+
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.osoa.sca.annotations.Scope;
+import org.apache.tuscany.sca.guardian.exceptions.*;
+import org.osoa.sca.annotations.Service;
+
+@Service(GuardianGroup.class)
+@Scope("COMPOSITE")
+public class GuardianGroupImpl implements GuardianGroup {
+
+ List<GuardianMember> guardianMembers;
+
+ public GuardianGroupImpl() {
+ guardianMembers = new LinkedList<GuardianMember>();
+ }
+
+ public void addGuardianMember(GuardianMember guardianMember) {
+ guardianMembers.add(guardianMember);
+ guardianMember.setUniqueParticipantID(guardianMembers.size() - 1);
+ }
+
+ public void enableContext(Context context) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public void removeContext() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public void gthrow(GlobalException ex, List<String> participantList) {
+
+ //1)Ivoked by a GuardianMember instance through the gthrow method
+ //2)Notify all participants about the exception (FIFO atomic broadcast model) - it will cause the suspension of all participants
+ // 2.1)Invoke the gthrow of the guardian members associated with the participants on participantList
+
+ //Sends a message representing the exception to the other guardian members
+ if (participantList == null) {
+ for (GuardianMember g : guardianMembers) {
+ if (!g.getParticipantIdentifier().equals(ex.getSignalingParticipant())) {
+ //g.gthrow(ex, participantList);
+ g.gthrow(null, null);
+ }
+ }
+ } else {
+ for (GuardianMember g : guardianMembers) {
+ if (participantList.contains(g.getCurrentContext())) {
+ //g.gthrow(ex, participantList);
+ g.gthrow(null, null);
+ }
+ }
+ }
+
+ //Check if the participants are blocked
+ List<Integer> flags = new ArrayList<Integer>(guardianMembers.size());
+ for (int i = 0; i < guardianMembers.size(); i++) {
+ if (guardianMembers.get(i).getService().isBlocked()) {
+ flags.add(i, 1);
+ } else {
+ flags.add(i, 0);
+ }
+ }
+
+ //Wait until all participants are blocked
+ while (flags.contains(0)) {
+ try {
+ Thread.sleep(5000);
+ } catch (InterruptedException ex1) {
+ Logger.getLogger(GuardianGroupImpl.class.getName()).log(Level.SEVERE, null, ex1);
+ }
+ }
+
+ //3)Once ALL required participants are SUSPENDED (suspended point), invoke the defined Recovery Rules
+ for (GuardianMember g : guardianMembers) {
+ g.addException(new SuspendException());
+ }
+ // 3.1) recovery_rules < signaled exceptions + context information of all participant > target context + exception to raise
+
+ //Simpleste Recovery Rule: broadcast the exception for all participants - FIXME: hardcoded
+// for (GuardianMemberImpl g : guardianMembers) {
+// ex.setTargetContext(Context.CURRENT_CONTEXT);
+// g.addException(ex);
+// }
+
+ //HARDCODED - SERVER-BACKUP EXAMPLE
+ //Rule 1
+ if (ex instanceof JoinException) {
+ if (guardianMembers.size() > 1) {
+
+ PrimaryExistsException primaryExists = new PrimaryExistsException();
+ primaryExists.setTargetContext(new Context("MAIN"));
+
+ BackupJoinedException backupJoined = new BackupJoinedException();
+ backupJoined.setTargetContext(new Context("PRIMARY"));
+
+ for (GuardianMember g : guardianMembers) {
+ //let p = JoinException.signaler
+ if (g.getParticipantIdentifier().equals(ex.getSignalingParticipant())) {
+ g.addException(primaryExists);
+ System.out.println("adding PrimaryExistsException to " + g.getParticipantIdentifier());
+ } else {
+ g.addException(backupJoined);
+ System.out.println("adding BackupJoinedException to " + g.getParticipantIdentifier());
+ }
+ }
+ }
+ } //Rule 2
+ else if (ex instanceof PrimaryFailedException) {
+
+ PrimaryFailedException primaryFailedInit = new PrimaryFailedException();
+ primaryFailedInit.setTargetContext(Context.INIT_CONTEXT);
+
+ PrimaryFailedException primaryFailedMain = new PrimaryFailedException();
+ primaryFailedMain.setTargetContext(new Context("MAIN"));
+
+ for (GuardianMember g : guardianMembers) {
+ if (g.getCurrentContext().getName().equals("PRIMARY")) {
+ System.out.println("adding PrimaryFailedException to " + g.getParticipantIdentifier());
+ g.addException(primaryFailedInit);
+ } else if (g.getCurrentContext().getName().equals("BACKUP")) {
+ System.out.println("adding PrimaryFailedException to " + g.getParticipantIdentifier());
+ g.addException(primaryFailedMain);
+ }
+ }
+ } //Rule 3
+ else if (ex instanceof BackupFailedException) {
+
+ BackupFailedException backupFailedPrimary = new BackupFailedException();
+ backupFailedPrimary.setTargetContext(new Context("PRIMARY"));
+
+ BackupFailedException backupFailedInit = new BackupFailedException();
+ backupFailedInit.setTargetContext(Context.INIT_CONTEXT);
+
+ for (GuardianMember g : guardianMembers) {
+ if (g.getCurrentContext().getName().equals("PRIMARY")) {
+ System.out.println("adding BackupFailedException to " + g.getParticipantIdentifier());
+ g.addException(backupFailedPrimary);
+ } else if (g.getCurrentContext().getName().equals("BACKUP")) {
+ System.out.println("adding BackupFailedException to " + g.getParticipantIdentifier());
+ g.addException(backupFailedInit);
+ }
+ }
+
+ }
+ }
+
+ public boolean propagate(GlobalException ex) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public void checkExceptionStatus() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public boolean removeGuardianMember(GuardianMember guardianMember) {
+ return this.guardianMembers.remove(guardianMember);
+ }
+}
diff --git a/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianMember.java b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianMember.java
new file mode 100644
index 0000000000..460a89ce2d
--- /dev/null
+++ b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianMember.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.tuscany.sca.guardian;
+
+public interface GuardianMember extends GuardianPrimitives {
+
+ public void addException(GlobalException ex);
+
+ public void setService(BlockingInterface service);
+
+ public void removeService();
+
+ public Context getCurrentContext();
+
+ public BlockingInterface getService();
+
+ public String getParticipantIdentifier();
+
+ public void setUniqueParticipantID(int id);
+}
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
new file mode 100644
index 0000000000..5edecf4bcd
--- /dev/null
+++ b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianMemberImpl.java
@@ -0,0 +1,209 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.tuscany.sca.guardian;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Queue;
+import java.util.Stack;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.osoa.sca.annotations.Init;
+import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Scope;
+import org.osoa.sca.annotations.Destroy;
+
+@Scope("COMPOSITE")
+public class GuardianMemberImpl implements GuardianMember {
+
+ private Stack<Context> contextList;
+ private BlockingInterface service;
+ private Queue<GlobalException> exceptionQueue;
+ @Reference(name = "guardian_group", required = true)
+ public GuardianGroup guardianGroup;
+ private int id;
+
+ public GuardianMemberImpl() {
+ contextList = new Stack<Context>();
+ exceptionQueue = new LinkedList<GlobalException>();
+ }
+
+ @Init
+ public void init() {
+ guardianGroup.addGuardianMember(this);
+ }
+
+ @Destroy
+ public void destroy() {
+ guardianGroup.removeGuardianMember(this);
+ }
+
+ public void addException(GlobalException ex) {
+ exceptionQueue.add(ex);
+ }
+
+ public void setService(BlockingInterface service) {
+ this.service = service;
+ }
+
+ public Context getCurrentContext() {
+ return contextList.peek();
+ }
+
+ public BlockingInterface getService() {
+ return service;
+ }
+
+ public void enableContext(Context context) {
+ //Update the context list with the related set of exceptions
+ contextList.push(context);
+
+ if (contextList.size() == 1) {
+ gthrow(new JoinException(), null);
+ }
+
+ }
+
+ public void removeContext() {
+ if (!contextList.isEmpty()) {
+ contextList.pop();
+ }
+ }
+
+ //Adapt to allow a regular expression
+ //If participantList is null then signal to ALL participants
+ public void gthrow(GlobalException 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());
+
+ guardianGroup.gthrow(ex, participantList);
+ }
+
+ //if (participantList == null || !participantList.contains(getParticipantIdentifier())) {
+// if (getParticipantIdentifier().equals(ex.getSignalingParticipant())) {
+// //2A)Call the gthrow of the GuardianGroup - communicate with other guardian members
+// System.out.println("HERE AT " + getParticipantIdentifier());
+// guardianGroup.gthrow(ex, participantList);
+// }
+
+ }
+
+
+ //*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
+
+ }
+
+ public boolean propagate(GlobalException ex) {
+ //1)Compares the current context with the exception's target context
+ return !getCurrentContext().equals(ex.getTargetContext());
+ }
+
+ public void checkExceptionStatus() throws GlobalException {
+ //1)Chek the exception queue
+ // 1.1) if exception_queue is empty then return
+ // 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
+
+ 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");
+// }
+
+ //FIX-ME: ex.targetContext() matches the participant id -> could use regular expressions
+ //Eg. ex.targetContext(): Main and participant id: Init/Main/Backup -> should throw the exception
+ String[] contexts = getParticipantIdentifier().split("\\.");
+ if (exc != null) {
+ for (int i = contexts.length - 1; i > 0; i--) {
+ if (exc.getTargetContext().equals(new Context(contexts[i]))) {
+ System.out.println(getParticipantIdentifier() + "#Returning an exception");
+ exceptionQueue.poll();
+ throw exc;
+ }
+ }
+ }
+
+// if (exc != null && exc.getTargetContext().equals(getCurrentContext())) {
+// System.out.println(getParticipantIdentifier() + "#Returning an exception");
+// exceptionQueue.poll();
+// throw exc;
+// }
+
+ return;
+ }
+
+ }
+
+ public String getParticipantIdentifier() {
+ //1) Return the participant identifier -> context list dot separated
+ StringBuffer id = new StringBuffer();
+ id.append(this.id + "." + Context.INIT_CONTEXT.getName());
+ for (int i = 0; i < contextList.size(); i++) {
+ id.append("." + contextList.get(i).getName());
+// if (i + 1 != contextList.size()) {
+// id.append(".");
+// }
+ }
+ return id.toString();
+ }
+
+ public void setUniqueParticipantID(int id) {
+ this.id = id;
+ }
+
+ public void removeService() {
+ this.service = null;
+ }
+}
diff --git a/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianPrimitives.java b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianPrimitives.java
new file mode 100644
index 0000000000..a7710f811e
--- /dev/null
+++ b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianPrimitives.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.tuscany.sca.guardian;
+
+import java.util.List;
+
+public interface GuardianPrimitives {
+
+ //Methods to manage contexts
+ public void enableContext(Context context);
+
+ public void removeContext();
+
+ //Methods to control the signaling of exceptions
+ public void gthrow(GlobalException ex, List<String> participantList);
+
+ public boolean propagate(GlobalException ex);
+
+ //Method to check pending global exceptions
+ public void checkExceptionStatus();
+}
diff --git a/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/JoinException.java b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/JoinException.java
new file mode 100644
index 0000000000..b14ebeac2b
--- /dev/null
+++ b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/JoinException.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.tuscany.sca.guardian;
+
+class JoinException extends GlobalException {
+
+ public JoinException() {
+ super();
+ }
+
+ public JoinException(String message) {
+ super(message);
+ }
+
+ public JoinException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public JoinException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/LeaveException.java b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/LeaveException.java
new file mode 100644
index 0000000000..04e892f4bd
--- /dev/null
+++ b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/LeaveException.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.tuscany.sca.guardian;
+
+class LeaveException extends GlobalException {
+
+ public LeaveException() {
+ super();
+ }
+
+ public LeaveException(String message) {
+ super(message);
+ }
+
+ public LeaveException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public LeaveException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/SuspendException.java b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/SuspendException.java
new file mode 100644
index 0000000000..b7ede6d530
--- /dev/null
+++ b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/SuspendException.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.tuscany.sca.guardian;
+
+class SuspendException extends GlobalException {
+
+ public SuspendException() {
+ super();
+ }
+
+ public SuspendException(String message) {
+ super(message);
+ }
+
+ public SuspendException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public SuspendException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/UnhandledException.java b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/UnhandledException.java
new file mode 100644
index 0000000000..81e3844280
--- /dev/null
+++ b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/UnhandledException.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.tuscany.sca.guardian;
+
+public class UnhandledException extends GlobalException {
+
+ public UnhandledException() {
+ super();
+ }
+
+ public UnhandledException(String message) {
+ super(message);
+ }
+
+ public UnhandledException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public UnhandledException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/exceptions/BackupFailedException.java b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/exceptions/BackupFailedException.java
new file mode 100644
index 0000000000..c4b2dd7de5
--- /dev/null
+++ b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/exceptions/BackupFailedException.java
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.tuscany.sca.guardian.exceptions;
+
+import org.apache.tuscany.sca.guardian.*;
+
+public class BackupFailedException extends GlobalException {
+}
diff --git a/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/exceptions/BackupJoinedException.java b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/exceptions/BackupJoinedException.java
new file mode 100644
index 0000000000..1fffa14663
--- /dev/null
+++ b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/exceptions/BackupJoinedException.java
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.tuscany.sca.guardian.exceptions;
+
+import org.apache.tuscany.sca.guardian.GlobalException;
+
+public class BackupJoinedException extends GlobalException {
+}
diff --git a/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/exceptions/PrimaryExistsException.java b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/exceptions/PrimaryExistsException.java
new file mode 100644
index 0000000000..6d358c281e
--- /dev/null
+++ b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/exceptions/PrimaryExistsException.java
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.tuscany.sca.guardian.exceptions;
+
+import org.apache.tuscany.sca.guardian.GlobalException;
+
+public class PrimaryExistsException extends GlobalException {
+}
diff --git a/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/exceptions/PrimaryFailedException.java b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/exceptions/PrimaryFailedException.java
new file mode 100644
index 0000000000..7f6b73cd05
--- /dev/null
+++ b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/exceptions/PrimaryFailedException.java
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.tuscany.sca.guardian.exceptions;
+
+import org.apache.tuscany.sca.guardian.*;
+
+public class PrimaryFailedException extends GlobalException {
+}