summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordougsleite <dougsleite@13f79535-47bb-0310-9956-ffa450edef68>2009-07-21 17:45:18 +0000
committerdougsleite <dougsleite@13f79535-47bb-0310-9956-ffa450edef68>2009-07-21 17:45:18 +0000
commit698169c4ee4fd2511cabf257ac97a3805930b1fc (patch)
tree6d0f3dca910c62f41430e3072c207fd20c34bb53
parent8c0b104e0e7c292187dd6ae0cef8c27e879838cc (diff)
- Modifying the module to work with the policy-recoveryrules module
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@796406 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--sandbox/dougsleite/guardian-model/pom.xml11
-rw-r--r--sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/Constants.java60
-rw-r--r--sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianGroup.java3
-rw-r--r--sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianGroupImpl.java736
-rw-r--r--sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianMember.java4
-rw-r--r--sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianMemberAdapter.java34
-rw-r--r--sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianMemberImpl.java122
-rw-r--r--sandbox/dougsleite/guardian-model/src/main/resources/definitions.xml66
-rw-r--r--sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/primaryBackup/common/NodeImpl.java112
-rw-r--r--sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/primaryBackup/simple/Launch3.java63
10 files changed, 564 insertions, 647 deletions
diff --git a/sandbox/dougsleite/guardian-model/pom.xml b/sandbox/dougsleite/guardian-model/pom.xml
index ac4d37db06..66f2bdbf32 100644
--- a/sandbox/dougsleite/guardian-model/pom.xml
+++ b/sandbox/dougsleite/guardian-model/pom.xml
@@ -88,10 +88,12 @@
<artifactId>axis2</artifactId>
<version>1.2</version>
<type>pom</type>
- </dependency>
-
-
-
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-policy-recoveryrules</artifactId>
+ <version>1.6-SNAPSHOT</version>
+ </dependency>
</dependencies>
<build>
@@ -113,3 +115,4 @@
</build>
</project>
+
diff --git a/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/Constants.java b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/Constants.java
new file mode 100644
index 0000000000..0396a65c08
--- /dev/null
+++ b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/Constants.java
@@ -0,0 +1,60 @@
+/*
+ * 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 javax.xml.namespace.QName;
+
+public interface Constants {
+
+ String RECOVERY_RULES = "recovery_rules";
+ QName RECOVERY_RULES_QNAME = new QName(org.apache.tuscany.sca.assembly.xml.Constants.SCA10_NS, RECOVERY_RULES);
+
+ String RULE = "rule";
+ QName RULE_QNAME = new QName(org.apache.tuscany.sca.assembly.xml.Constants.SCA10_NS, RULE);
+
+ String NAME = "name";
+ QName NAME_QNAME = new QName(org.apache.tuscany.sca.assembly.xml.Constants.SCA10_NS, NAME);
+
+ String SIGNALED_EXCEPTION = "signaled_exception";
+ QName SIGNALED_EXCEPTION_QNAME = new QName(org.apache.tuscany.sca.assembly.xml.Constants.SCA10_NS, SIGNALED_EXCEPTION);
+
+ String PARTICIPANT = "participant";
+ QName PARTICIPANT_QNAME = new QName(org.apache.tuscany.sca.assembly.xml.Constants.SCA10_NS, PARTICIPANT);
+
+ String MATCH = "match";
+ QName MATCH_QNAME = new QName(org.apache.tuscany.sca.assembly.xml.Constants.SCA10_NS, MATCH);
+
+ String THROW_EXCEPTION = "throw_exception";
+ QName THROW_EXCEPTION_QNAME = new QName(org.apache.tuscany.sca.assembly.xml.Constants.SCA10_NS, THROW_EXCEPTION);
+
+ String CLASS = "class";
+ QName CLASS_QNAME = new QName(org.apache.tuscany.sca.assembly.xml.Constants.SCA10_NS, CLASS);
+
+ String TARGET_CONTEXT = "target_context";
+ QName TARGET_CONTEXT_QNAME = new QName(org.apache.tuscany.sca.assembly.xml.Constants.SCA10_NS, TARGET_CONTEXT);
+
+ String MIN_PARTICIPANT_JOINED = "min_participant_joined";
+ QName MIN_PARTICIPANT_JOINED_QNAME = new QName(org.apache.tuscany.sca.assembly.xml.Constants.SCA10_NS, MIN_PARTICIPANT_JOINED);
+
+ String MAX_PARTICIPANT_JOINED = "max_participant_joined";
+ QName MAX_PARTICIPANT_JOINED_QNAME = new QName(org.apache.tuscany.sca.assembly.xml.Constants.SCA10_NS, MAX_PARTICIPANT_JOINED);
+
+ String AFFECTED_PARTICIPANTS = "affected_participants";
+ QName AFFECTED_PARTICIPANTS_QNAME = new QName(org.apache.tuscany.sca.assembly.xml.Constants.SCA10_NS, AFFECTED_PARTICIPANTS);
+}
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
index b0dbcac4a1..5119390a14 100644
--- 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
@@ -23,6 +23,9 @@ import org.osoa.sca.annotations.Remotable;
//@Remotable
public interface GuardianGroup extends GuardianPrimitives {
+ public static int NORMAL_PARTICIPANT_STATE = 0;
+ public static int SUSPENDED_PARTICIPANT_STATE = 1;
+
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
index e21016b3f5..1168f7406c 100644
--- 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
@@ -20,7 +20,6 @@ package org.apache.tuscany.sca.guardian;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
-import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Level;
@@ -39,12 +38,16 @@ public class GuardianGroupImpl implements GuardianGroup {
private List<GuardianMember> guardianList;
private ResettableReader reader;
+ private InnerGuardianGroupThread innerThread;
+ private List<GlobalExceptionInterface> concurrentExList;
public GuardianGroupImpl() {
guardianList = new LinkedList<GuardianMember>();
+ concurrentExList = new LinkedList<GlobalExceptionInterface>();
+ innerThread = new InnerGuardianGroupThread();
}
- @Property(name = "recovery_rules", required = true)
+ @Property(name = "recovery_rules", required = false)
public void setRecoveryRules(String recoveryRules) {
try {
FileInputStream fileInputStream = new FileInputStream(recoveryRules);
@@ -71,52 +74,33 @@ public class GuardianGroupImpl implements GuardianGroup {
throw new UnsupportedOperationException("Not supported yet.");
}
- public void gthrow(GlobalExceptionInterface ex, List<String> participantList) {
+ public synchronized void gthrow(GlobalExceptionInterface 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
+ concurrentExList.add(ex);
+
//Sends a message representing the exception to the other guardian members
+ SuspendException suspendEx = new SuspendException();
if (participantList == null) {
for (GuardianMember g : guardianList) {
- if (!g.getParticipantIdentifier().equals(ex.getSignalingParticipant())) {
- //g.gthrow(ex, participantList);
- g.gthrow(null, null);
- }
+ g.gthrow(suspendEx, null);
}
} else {
for (GuardianMember g : guardianList) {
- if (participantList.contains(g.getCurrentContext())) {
- //g.gthrow(ex, participantList);
- g.gthrow(null, null);
+ if (participantList.contains(g.getParticipantIdentifier())) {
+ g.gthrow(suspendEx, null);
+ //g.gthrow(suspendEx,null); -> g is the signler
}
}
}
- //Check if the participants are blocked
- List<Integer> flags = new ArrayList<Integer>(guardianList.size());
- for (int i = 0; i < guardianList.size(); i++) {
- if (guardianList.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 : guardianList) {
- g.addException(new SuspendException());
- }
+// //3)Once ALL required participants are SUSPENDED (suspended point), invoke the defined Recovery Rules
+// for (GuardianMember g : guardianList) {
+// 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
@@ -125,494 +109,346 @@ public class GuardianGroupImpl implements GuardianGroup {
// g.addException(ex);
// }
- applyRecoveryRules(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);
-// }
-// }
-//
-// }
+ if (!innerThread.isRunning) {
+ innerThread.setGlobalException(ex);
+ new Thread(innerThread).start();
+ }
+ }
+ public boolean propagate(GlobalExceptionInterface ex) {
+ throw new UnsupportedOperationException("Not supported yet.");
}
- private void applyRecoveryRules(GlobalExceptionInterface ex) {
- reader.reset();
- ruleTag(ex);
+ public void checkExceptionStatus() {
+ throw new UnsupportedOperationException("Not supported yet.");
}
- private void ruleTag(GlobalExceptionInterface ex) {
- try {
- while (reader.hasNext()) {
- reader.next();
- //<rule name="" signaled_exception="">
- if (reader.isStartElement() && reader.getLocalName().equals("rule")) {
- for (int i = 0; i < reader.getAttributeCount(); i++) {
- //ex == signaled_exception
- if (reader.getAttributeLocalName(i).equals("signaled_exception") && ex.getClass().getName().equals(reader.getAttributeValue(i))) {
- participantExceptionTag(ex);
- break;
- }
- }
- }
- }
- } catch (XMLStreamException exc) {
- Logger.getLogger(GuardianGroupImpl.class.getName()).log(Level.SEVERE, null, ex);
- }
+ public boolean removeGuardianMember(GuardianMember guardianMember) {
+ return this.guardianList.remove(guardianMember);
}
- private void participantExceptionTag(GlobalExceptionInterface ex) {
- List<GuardianMember> gmList;
- try {
- while (reader.hasNext() && !(reader.isEndElement() && reader.getLocalName().equals("rule"))) {
- reader.next();
- //<participant match="<REG_EXP> | SIGNALER">
- if (reader.isStartElement() && reader.getLocalName().equals("participant")) {
- String participantMatch = reader.getAttributeValue(0).trim();
+ private class InnerGuardianGroupThread implements Runnable {
- gmList = getMatchingParticipants(participantMatch, ex);
+ private boolean isRunning;
+ private GlobalExceptionInterface ex = null;
- if (!gmList.isEmpty()) {
- throwExceptionTag(gmList, ex);
- }
- }
- }
- } catch (XMLStreamException exc) {
- Logger.getLogger(GuardianGroupImpl.class.getName()).log(Level.SEVERE, null, exc);
+ public InnerGuardianGroupThread() {
+ isRunning = false;
}
- }
- private void throwExceptionTag(List<GuardianMember> gmList, GlobalExceptionInterface ex) {
+ public void setGlobalException(GlobalExceptionInterface ex) {
+ this.ex = ex;
+ }
- String exceptionClassName;
- String targetContextName;
- Integer min_participant_joined;
- Integer max_participant_joined;
+ public GlobalExceptionInterface getGlobalException() {
+ return ex;
+ }
- try {
+ public void run() {
+ if (ex != null) {
+ isRunning = true;
+ applyRecoveryRules(ex);
- while (reader.hasNext() && !(reader.isEndElement() && reader.getLocalName().equals("participant"))) {
- reader.next();
-
- //<throw_exception class="<Exception>" target_context="<Context>"/>
- if (reader.isStartElement() && reader.getLocalName().equals("throw_exception")) {
-
- exceptionClassName = null;
- targetContextName = null;
- min_participant_joined = null;
- max_participant_joined = null;
- for (int j = 0; j < reader.getAttributeCount(); j++) {
- if (reader.getAttributeLocalName(j).equals("class")) {
- //class value
- exceptionClassName = reader.getAttributeValue(j);
- } else if (reader.getAttributeLocalName(j).equals("target_context")) {
- //target_context value
- targetContextName = reader.getAttributeValue(j);
- } else if (reader.getAttributeLocalName(j).equals("min_participant_joined")) {
- //min_participant_joined value
- min_participant_joined = Integer.parseInt(reader.getAttributeValue(j));
- } else {
- //max_participant_joined value
- max_participant_joined = Integer.parseInt(reader.getAttributeValue(j));
- }
+ for (GuardianMember gm : guardianList) {
+ if (gm.getParticipantState() == SUSPENDED_PARTICIPANT_STATE) {
+ gm.setParticipantState(NORMAL_PARTICIPANT_STATE);
}
+ }
+ }
+ isRunning = false;
+ }
- //Test the min and max joined participants condition
- if (min_participant_joined != null && max_participant_joined != null) {
- if (!(guardianList.size() >= min_participant_joined && guardianList.size() < max_participant_joined)) {
- break;
- }
- } else if (min_participant_joined != null) {
- if (!(guardianList.size() >= min_participant_joined)) {
- break;
- }
- } else if (max_participant_joined != null) {
- if (!(guardianList.size() >= min_participant_joined)) {
- break;
- }
- }
+ public boolean isRunning() {
+ return isRunning;
+ }
- //<affected_participants>
- String affectedParticipants = affectedParticipantsTag();
- int index = -1;
-
- //Verify if the parameter is an index
- try {
- index = Integer.parseInt(affectedParticipants);
- } catch (NumberFormatException nexc) {
- index = -1;
- }
+ private void applyRecoveryRules(GlobalExceptionInterface ex) {
+ reader.reset();
+ ruleTag(ex);
+ }
- Class exceptionClass = Class.forName(exceptionClassName);
- Context targetContext;
- if (targetContextName.toUpperCase().equals(Context.CURRENT_CONTEXT.getName().toUpperCase())) {
- targetContext = Context.CURRENT_CONTEXT;
- } else if (targetContextName.toUpperCase().equals(Context.INIT_CONTEXT.getName().toUpperCase())) {
- targetContext = Context.INIT_CONTEXT;
- } else {
- targetContext = new Context(targetContextName);
- }
- GlobalException newException = (GlobalException) exceptionClass.newInstance();
-
- newException.setTargetContext(targetContext);
- newException.setSignalingContext(ex.getSignalingContext());
- newException.setSignalingParticipant(ex.getSignalingParticipant());
-
- //Add the exception to the participants matched
- if (index != -1) {
- gmList.get(index).addException(newException);
- } else if (affectedParticipants != null && affectedParticipants.length() != 0) {
- if (affectedParticipants.toUpperCase().equals("FIRST")) {
- gmList.get(0).addException(newException);
- } else if (affectedParticipants.toUpperCase().equals("LAST")) {
- gmList.get(gmList.size() - 1).addException(newException);
- } else if (affectedParticipants.toUpperCase().equals("ALL")) {
- for (GuardianMember gm : gmList) {
- gm.addException(newException);
+ private void ruleTag(GlobalExceptionInterface ex) {
+ try {
+ while (reader.hasNext()) {
+ reader.next();
+ //<rule name="" signaled_exception="">
+ if (reader.isStartElement() && reader.getLocalName().equals("rule")) {
+ for (int i = 0; i < reader.getAttributeCount(); i++) {
+ //ex == signaled_exception
+ if (reader.getAttributeLocalName(i).equals("signaled_exception") && ex.getClass().getName().equals(reader.getAttributeValue(i))) {
+ participantExceptionTag(ex);
+ break;
}
}
- } else {
- for (GuardianMember gm : gmList) {
- gm.addException(newException);
- }
}
}
+ } catch (XMLStreamException exc) {
+ Logger.getLogger(GuardianGroupImpl.class.getName()).log(Level.SEVERE, null, ex);
}
- } catch (XMLStreamException ex1) {
- Logger.getLogger(GuardianGroupImpl.class.getName()).log(Level.SEVERE, null, ex1);
- } catch (InstantiationException ex1) {
- Logger.getLogger(GuardianGroupImpl.class.getName()).log(Level.SEVERE, null, ex1);
- } catch (IllegalAccessException ex1) {
- Logger.getLogger(GuardianGroupImpl.class.getName()).log(Level.SEVERE, null, ex1);
- } catch (ClassNotFoundException ex1) {
- Logger.getLogger(GuardianGroupImpl.class.getName()).log(Level.SEVERE, null, ex1);
}
- }
- private String affectedParticipantsTag() {
- String affectedParticipants = null;
- try {
- while (reader.hasNext() && !(reader.isEndElement() && reader.getLocalName().equals("throw_exception"))) {
- reader.next();
- //<affected_participants>
- if (reader.isStartElement() && reader.getLocalName().equals("affected_participants")) {
- affectedParticipants = reader.getElementText();
+ private void participantExceptionTag(GlobalExceptionInterface ex) {
+ List<GuardianMember> gmList;
+ try {
+ while (reader.hasNext() && !(reader.isEndElement() && reader.getLocalName().equals("rule"))) {
+ reader.next();
+ //<participant match="<REG_EXP> | SIGNALER">
+ if (reader.isStartElement() && reader.getLocalName().equals("participant")) {
+ String participantMatch = reader.getAttributeValue(0).trim();
+
+ gmList = getMatchingParticipants(participantMatch, ex);
+
+ if (!gmList.isEmpty()) {
+ throwExceptionTag(gmList, ex);
+ }
+ }
}
+ } catch (XMLStreamException exc) {
+ Logger.getLogger(GuardianGroupImpl.class.getName()).log(Level.SEVERE, null, exc);
}
- } catch (XMLStreamException ex) {
- Logger.getLogger(GuardianGroupImpl.class.getName()).log(Level.SEVERE, null, ex);
}
- return affectedParticipants;
- }
+ private void throwExceptionTag(List<GuardianMember> gmList, GlobalExceptionInterface ex) {
- private void applyRecoveryRulesOriginal(GlobalExceptionInterface ex) {
+ String exceptionClassName;
+ String targetContextName;
+ Integer min_participant_joined;
+ Integer max_participant_joined;
- String exceptionClassName;
- String targetContextName;
- Integer min_participant_joined;
- Integer max_participant_joined;
+ try {
- List<GuardianMember> gmList;
+ while (reader.hasNext() && !(reader.isEndElement() && reader.getLocalName().equals("participant"))) {
+ reader.next();
+
+ //<throw_exception class="<Exception>" target_context="<Context>"/>
+ if (reader.isStartElement() && reader.getLocalName().equals("throw_exception")) {
+
+ exceptionClassName = null;
+ targetContextName = null;
+ min_participant_joined = null;
+ max_participant_joined = null;
+ for (int j = 0; j < reader.getAttributeCount(); j++) {
+ if (reader.getAttributeLocalName(j).equals("class")) {
+ //class value
+ exceptionClassName = reader.getAttributeValue(j);
+ } else if (reader.getAttributeLocalName(j).equals("target_context")) {
+ //target_context value
+ targetContextName = reader.getAttributeValue(j);
+ } else if (reader.getAttributeLocalName(j).equals("min_participant_joined")) {
+ //min_participant_joined value
+ min_participant_joined = Integer.parseInt(reader.getAttributeValue(j));
+ } else {
+ //max_participant_joined value
+ max_participant_joined = Integer.parseInt(reader.getAttributeValue(j));
+ }
+ }
- try {
+ //Test the min and max joined participants condition
+ if (min_participant_joined != null && max_participant_joined != null) {
+ if (!(guardianList.size() >= min_participant_joined && guardianList.size() < max_participant_joined)) {
+ break;
+ }
+ } else if (min_participant_joined != null) {
+ if (!(guardianList.size() >= min_participant_joined)) {
+ break;
+ }
+ } else if (max_participant_joined != null) {
+ if (!(guardianList.size() >= min_participant_joined)) {
+ break;
+ }
+ }
- reader.reset();
+ //<affected_participants>
+ String affectedParticipants = affectedParticipantsTag();
+ int index = -1;
- while (reader.hasNext()) {
- reader.next();
- //<rule name="" signaled_exception="">
- if (reader.isStartElement() && reader.getLocalName().equals("rule")) {
- for (int i = 0; i < reader.getAttributeCount(); i++) {
- //ex == signaled_exception
- if (reader.getAttributeLocalName(i).equals("signaled_exception") &&
- ex.getClass().getName().equals(reader.getAttributeValue(i))) {
-
- while (reader.hasNext() && !(reader.isEndElement() && reader.getLocalName().equals("rule"))) {
- reader.next();
-
- //<participant match="<REG_EXP> | SIGNALER">
- if (reader.isStartElement() && reader.getLocalName().equals("participant")) {
-
- String participant_match = reader.getAttributeValue(0).trim();
-
- while (reader.hasNext() && !(reader.isEndElement() && reader.getLocalName().equals("participant"))) {
- reader.next();
-
- //<throw_exception class="<Exception>" target_context="<Context>"/>
- if (reader.isStartElement() && reader.getLocalName().equals("throw_exception")) {
-
- exceptionClassName = null;
- targetContextName = null;
- min_participant_joined = null;
- max_participant_joined = null;
-
- for (int j = 0; j < reader.getAttributeCount(); j++) {
- if (reader.getAttributeLocalName(j).equals("class")) {
- //class value
- exceptionClassName = reader.getAttributeValue(j);
- } else if (reader.getAttributeLocalName(j).equals("target_context")) {
- //target_context value
- targetContextName = reader.getAttributeValue(j);
- } else if (reader.getAttributeLocalName(j).equals("min_participant_joined")) {
- //min_participant_joined value
- min_participant_joined = Integer.parseInt(reader.getAttributeValue(j));
- } else {
- //max_participant_joined value
- max_participant_joined = Integer.parseInt(reader.getAttributeValue(j));
- }
- }
-
- //Test the min and max joined participants condition
- if (min_participant_joined != null && max_participant_joined != null) {
- if (!(guardianList.size() >= min_participant_joined && guardianList.size() < max_participant_joined)) {
- break;
- }
- } else if (min_participant_joined != null) {
- if (!(guardianList.size() >= min_participant_joined)) {
- break;
- }
- } else if (max_participant_joined != null) {
- if (!(guardianList.size() >= min_participant_joined)) {
- break;
- }
- }
-
- //match value
- gmList = getMatchingParticipants(participant_match, ex);
-
- String affectedParticipants = null;
- int index = -1;
- while (reader.hasNext() && !(reader.isEndElement() && reader.getLocalName().equals("throw_exception"))) {
- reader.next();
-
- //<affected_participants>
- if (reader.isStartElement() && reader.getLocalName().equals("affected_participants")) {
- affectedParticipants = reader.getElementText();
-
- //Verify if the parameter is an index
- try {
- index = Integer.parseInt(affectedParticipants);
- } catch (NumberFormatException nexc) {
- index = -1;
- }
- }
- }
-
- Class exceptionClass = Class.forName(exceptionClassName);
-
- Context targetContext;
- if (targetContextName.toUpperCase().equals(Context.CURRENT_CONTEXT.getName().toUpperCase())) {
- targetContext = Context.CURRENT_CONTEXT;
- } else if (targetContextName.toUpperCase().equals(Context.INIT_CONTEXT.getName().toUpperCase())) {
- targetContext = Context.INIT_CONTEXT;
- } else {
- targetContext = new Context(targetContextName);
- }
-
- GlobalException newException = (GlobalException) exceptionClass.newInstance();
- newException.setTargetContext(targetContext);
-
- //Add the exception to the participants matched
- if (index != -1) {
- gmList.get(index).addException(newException);
- } else if (affectedParticipants != null && affectedParticipants.length() != 0) {
- if (affectedParticipants.toUpperCase().equals("FIRST")) {
- gmList.get(0).addException(newException);
-
- } else if (affectedParticipants.toUpperCase().equals("LAST")) {
- gmList.get(gmList.size() - 1).addException(newException);
- } else if (affectedParticipants.toUpperCase().equals("ALL")) {
- for (GuardianMember gm : gmList) {
- gm.addException(newException);
- }
- }
- } else {
- for (GuardianMember gm : gmList) {
- gm.addException(newException);
- }
- }
- }
- }
+ //Verify if the parameter is an index
+ try {
+ index = Integer.parseInt(affectedParticipants);
+ } catch (NumberFormatException nexc) {
+ index = -1;
+ }
+
+ Class exceptionClass = Class.forName(exceptionClassName);
+ Context targetContext;
+ if (targetContextName.toUpperCase().equals(Context.CURRENT_CONTEXT.getName().toUpperCase())) {
+ targetContext = Context.CURRENT_CONTEXT;
+ } else if (targetContextName.toUpperCase().equals(Context.INIT_CONTEXT.getName().toUpperCase())) {
+ targetContext = Context.INIT_CONTEXT;
+ } else {
+ targetContext = new Context(targetContextName);
+ }
+ GlobalException newException = (GlobalException) exceptionClass.newInstance();
+
+ newException.setTargetContext(targetContext);
+ newException.setSignalingContext(ex.getSignalingContext());
+ newException.setSignalingParticipant(ex.getSignalingParticipant());
+
+// //Time window of 10 seconds
+// try {
+// Thread.sleep(10000);
+// } catch (InterruptedException ex1) {
+// Logger.getLogger(GuardianGroupImpl.class.getName()).log(Level.SEVERE, null, ex1);
+// }
+// //Check concurrent exception existence
+// if (concurrentExList.size() != 1) {
+// applyConcurrentRecoveryRules(concurrentExList);
+// }
+
+ //Add the exception to the participants matched
+ if (index != -1) {
+ gmList.get(index).addException(newException);
+ } else if (affectedParticipants != null && affectedParticipants.length() != 0) {
+ if (affectedParticipants.toUpperCase().equals("FIRST")) {
+ gmList.get(0).addException(newException);
+ } else if (affectedParticipants.toUpperCase().equals("LAST")) {
+ gmList.get(gmList.size() - 1).addException(newException);
+ } else if (affectedParticipants.toUpperCase().equals("ALL")) {
+ for (GuardianMember gm : gmList) {
+ gm.addException(newException);
}
}
- break;
+ } else {
+ for (GuardianMember gm : gmList) {
+ gm.addException(newException);
+ }
}
}
}
+ } catch (XMLStreamException ex1) {
+ Logger.getLogger(GuardianGroupImpl.class.getName()).log(Level.SEVERE, null, ex1);
+ } catch (InstantiationException ex1) {
+ Logger.getLogger(GuardianGroupImpl.class.getName()).log(Level.SEVERE, null, ex1);
+ } catch (IllegalAccessException ex1) {
+ Logger.getLogger(GuardianGroupImpl.class.getName()).log(Level.SEVERE, null, ex1);
+ } catch (ClassNotFoundException ex1) {
+ Logger.getLogger(GuardianGroupImpl.class.getName()).log(Level.SEVERE, null, ex1);
}
- } catch (XMLStreamException ex1) {
- Logger.getLogger(GuardianGroupImpl.class.getName()).log(Level.SEVERE, null, ex1);
- } catch (Exception ex1) {
- Logger.getLogger(GuardianGroupImpl.class.getName()).log(Level.SEVERE, null, ex1);
}
- }
-
- private List<GuardianMember> getMatchingParticipants(String regularExpression, GlobalExceptionInterface signaledException) {
- List<GuardianMember> matchingParticipants = new LinkedList();
- if (regularExpression.toUpperCase().equals("SIGNALER")) {
- for (GuardianMember gm : guardianList) {
- if (gm.getParticipantIdentifier().equals(signaledException.getSignalingParticipant())) {
- matchingParticipants.add(gm);
- break;
+ private String affectedParticipantsTag() {
+ String affectedParticipants = null;
+ try {
+ while (reader.hasNext() && !(reader.isEndElement() && reader.getLocalName().equals("throw_exception"))) {
+ reader.next();
+ //<affected_participants>
+ if (reader.isStartElement() && reader.getLocalName().equals("affected_participants")) {
+ affectedParticipants = reader.getElementText();
+ }
}
+ } catch (XMLStreamException ex) {
+ Logger.getLogger(GuardianGroupImpl.class.getName()).log(Level.SEVERE, null, ex);
}
- } else if (regularExpression.toUpperCase().equals("!SIGNALER")) {
- for (GuardianMember gm : guardianList) {
- if (!gm.getParticipantIdentifier().equals(signaledException.getSignalingParticipant())) {
- matchingParticipants.add(gm);
+
+ return affectedParticipants;
+ }
+
+ private void applyConcurrentRecoveryRules(List<GlobalExceptionInterface> exceptionList) {
+ System.out.println("CONCURRENT RECOVERY RULES!");
+ System.out.println("exceptions: "+exceptionList);
+ exceptionList.clear();
+ }
+
+ private List<GuardianMember> getMatchingParticipants(String regularExpression, GlobalExceptionInterface signaledException) {
+ List<GuardianMember> matchingParticipants = new LinkedList();
+
+ if (regularExpression.toUpperCase().equals("SIGNALER")) {
+ for (GuardianMember gm : guardianList) {
+ if (gm.getParticipantIdentifier().equals(signaledException.getSignalingParticipant())) {
+ matchingParticipants.add(gm);
+ break;
+ }
+ }
+ } else if (regularExpression.toUpperCase().equals("!SIGNALER")) {
+ for (GuardianMember gm : guardianList) {
+ if (!gm.getParticipantIdentifier().equals(signaledException.getSignalingParticipant())) {
+ matchingParticipants.add(gm);
+ }
}
- }
- } else {
- //Create an java regular expression
- String re = createJavaRegularExpression(regularExpression);
+ } else {
+ //Create an java regular expression
+ String re = createJavaRegularExpression(regularExpression);
- for (GuardianMember gm : guardianList) {
- if (gm.getParticipantIdentifier().matches(re)) {
- matchingParticipants.add(gm);
+ for (GuardianMember gm : guardianList) {
+ if (gm.getParticipantIdentifier().matches(re)) {
+ matchingParticipants.add(gm);
+ }
}
}
- }
- return matchingParticipants;
- }
+ return matchingParticipants;
+ }
- /* Valid expressions: *, <Context>.*, <Context>, *.<Context>, *.<Context>.*,
- * *.<Context>.*.<Context>.*, <REG_EXP> || <REG_EXP>
- *
- * Invalid expressions: *.*, **,
- *
- * Not supported yet: !<Context>, !<Context> || <Context>, !(<Context> || <Context>)
- */
- private String createJavaRegularExpression(String regularExpression) throws InvalidRegularExpression {
- StringBuffer re = new StringBuffer();
+ /* Valid expressions: *, <Context>.*, <Context>, *.<Context>, *.<Context>.*,
+ * *.<Context>.*.<Context>.*, <REG_EXP> || <REG_EXP>
+ *
+ * Invalid expressions: *.*, **,
+ *
+ * Not supported yet: !<Context>, !<Context> || <Context>, !(<Context> || <Context>)
+ */
+ private String createJavaRegularExpression(String regularExpression) throws InvalidRegularExpression {
+ StringBuffer re = new StringBuffer();
- String[] splitedByBar = regularExpression.split("\\|\\|");
- String[] splitedByPeriod;
+ String[] splitedByBar = regularExpression.split("\\|\\|");
+ String[] splitedByPeriod;
- for (int i = 0; i < splitedByBar.length; i++) {
+ for (int i = 0; i < splitedByBar.length; i++) {
- splitedByPeriod = splitedByBar[i].split("\\.");
+ splitedByPeriod = splitedByBar[i].split("\\.");
- if (i > 0) {
- re.append("|");
- }
+ if (i > 0) {
+ re.append("|");
+ }
- re.append("^");
- for (int j = 0; j < splitedByPeriod.length; j++) {
+ re.append("^");
+ for (int j = 0; j < splitedByPeriod.length; j++) {
- //*
- if (splitedByPeriod[j].equals("*")) {
+ //*
+ if (splitedByPeriod[j].equals("*")) {
- //Validate the regular expression
- if (j + 1 != splitedByPeriod.length && splitedByPeriod[j + 1].equals("*")) {
- throw new InvalidRegularExpression();
- }
+ //Validate the regular expression
+ if (j + 1 != splitedByPeriod.length && splitedByPeriod[j + 1].equals("*")) {
+ throw new InvalidRegularExpression();
+ }
- //*
- if (splitedByPeriod.length == 1) {
- re.append("(\\w+)");
- } //*.<CONTEXT>
-
- if (j == 0 && splitedByPeriod.length != 1) {
- re.append("(\\w+\\");
- re.append(".)*");
- } //<CONTEXT>.*
+ //*
+ if (splitedByPeriod.length == 1) {
+ re.append("(\\w+)");
+ } //*.<CONTEXT>
+
+ if (j == 0 && splitedByPeriod.length != 1) {
+ re.append("(\\w+\\");
+ re.append(".)*");
+ } //<CONTEXT>.*
+ else {
+ re.append("(\\");
+ re.append(".\\w+)*");
+ }
+ } //<CONTEXT>
else {
- re.append("(\\");
- re.append(".\\w+)*");
- }
- } //<CONTEXT>
- else {
// //Validate the regular expression
// if (splitedByPeriod[j].matches("^(\\*)*$")) {
// throw new RuntimeException("Invalid name for a context");
// }
- //<CONTEXT> || <CONTEXT>.<CONTEXT>.<CONTEXT> || *.<CONTEXT>
- if (splitedByPeriod.length == 1) {
- re.append("(\\w+\\");
- re.append(".)*");
- }
+ //<CONTEXT> || <CONTEXT>.<CONTEXT>.<CONTEXT> || *.<CONTEXT>
+ if (splitedByPeriod.length == 1) {
+ re.append("(\\w+\\");
+ re.append(".)*");
+ }
- if (j == 0 || j - 1 == 0) {
- re.append("(" + splitedByPeriod[j] + ")");
- } else {
- re.append("(\\." + splitedByPeriod[j] + ")");
+ if (j == 0 || j - 1 == 0) {
+ re.append("(" + splitedByPeriod[j] + ")");
+ } else {
+ re.append("(\\." + splitedByPeriod[j] + ")");
+ }
}
}
+ re.append("$");
}
- re.append("$");
+ return re.toString();
}
- return re.toString();
- }
-
- public boolean propagate(GlobalExceptionInterface ex) {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- public void checkExceptionStatus() {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- public boolean removeGuardianMember(GuardianMember guardianMember) {
- return this.guardianList.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
index 460a89ce2d..48dad22bff 100644
--- 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
@@ -33,4 +33,8 @@ public interface GuardianMember extends GuardianPrimitives {
public String getParticipantIdentifier();
public void setUniqueParticipantID(int id);
+
+ public int getParticipantState();
+
+ public void setParticipantState(int state);
}
diff --git a/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianMemberAdapter.java b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianMemberAdapter.java
index 8c0fd92b6e..b6cbfe8ec6 100644
--- a/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianMemberAdapter.java
+++ b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/GuardianMemberAdapter.java
@@ -1,27 +1,25 @@
/*
- * Copyright 2009 douglas.
- *
- * 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.
- * under the License.
+ * 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 javax.xml.bind.annotation.adapters.XmlAdapter;
-/**
- *
- * @author douglas
- */
public class GuardianMemberAdapter extends XmlAdapter<GuardianMemberImpl, GuardianMember> {
@Override
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;
+ }
}
diff --git a/sandbox/dougsleite/guardian-model/src/main/resources/definitions.xml b/sandbox/dougsleite/guardian-model/src/main/resources/definitions.xml
new file mode 100644
index 0000000000..c08d08cdfa
--- /dev/null
+++ b/sandbox/dougsleite/guardian-model/src/main/resources/definitions.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="ASCII"?>
+<!--
+ * 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.
+-->
+<sca:definitions xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ targetNamespace="http://primarybackup"
+ xmlns:sca="http://www.osoa.org/xmlns/sca/1.0"
+ >
+
+ <sca:policySet name="recoveryRulesPolicy"
+ provides="recoveryRules"
+ appliesTo="sca:implementation.java">
+
+ <recovery_rules>
+
+ <rule name="Rule1" signaled_exception="org.apache.tuscany.sca.guardian.JoinException">
+
+ <participant match="SIGNALER">
+ <throw_exception class="org.apache.tuscany.sca.guardian.itests.primaryBackup.common.PrimaryExistsException" target_context="MAIN" min_participant_joined="2"/>
+ </participant>
+
+ <participant match="!SIGNALER">
+ <throw_exception class="org.apache.tuscany.sca.guardian.itests.primaryBackup.common.BackupJoinedException" target_context="PRIMARY" min_participant_joined="2"/>
+ </participant>
+ </rule>
+
+ <rule name="Rule2" signaled_exception="org.apache.tuscany.sca.guardian.itests.primaryBackup.common.PrimaryFailedException">
+
+ <participant match="*.PRIMARY">
+ <throw_exception class="org.apache.tuscany.sca.guardian.itests.primaryBackup.common.PrimaryFailedException" target_context="INIT_CONTEXT"/>
+ </participant>
+
+ <participant match="*.BACKUP">
+ <throw_exception class="org.apache.tuscany.sca.guardian.itests.primaryBackup.common.PrimaryFailedException" target_context="MAIN"/>
+ </participant>
+ </rule>
+
+ <rule name="Rule3" signaled_exception="org.apache.tuscany.sca.guardian.itests.primaryBackup.common.BackupFailedException">
+
+ <participant match="*.PRIMARY">
+ <throw_exception class="org.apache.tuscany.sca.guardian.itests.primaryBackup.common.BackupFailedException" target_context="PRIMARY"/>
+ </participant>
+
+ <participant match="*.BACKUP">
+ <throw_exception class="org.apache.tuscany.sca.guardian.itests.primaryBackup.common.BackupFailedException" target_context="INIT_CONTEXT"/>
+ </participant>
+ </rule>
+
+ </recovery_rules>
+ </sca:policySet>
+</sca:definitions> \ No newline at end of file
diff --git a/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/primaryBackup/common/NodeImpl.java b/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/primaryBackup/common/NodeImpl.java
index 5ff80e3472..00880352b8 100644
--- a/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/primaryBackup/common/NodeImpl.java
+++ b/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/primaryBackup/common/NodeImpl.java
@@ -32,7 +32,8 @@ import org.osoa.sca.annotations.Destroy;
import org.osoa.sca.annotations.OneWay;
@Scope("COMPOSITE")
-public class NodeImpl implements Node, TestInterface {
+//public class NodeImpl implements Node, TestInterface {
+public class NodeImpl implements Node {
private static int PRIMARY = 0;
private static int BACKUP = 1;
@@ -49,6 +50,7 @@ public class NodeImpl implements Node, TestInterface {
public List<Node> nodeList;
private boolean forcePSFException;
private boolean forceAUFException;
+ private int upcount;
public NodeImpl() {
@@ -91,6 +93,9 @@ public class NodeImpl implements Node, TestInterface {
role = PRIMARY;
while (true) {
+
+ //blockingCheck();
+
try {
System.out.println(pID + "#Main context: ");
sleep(pID + "#Sleeping at main context...", 4000);
@@ -142,37 +147,17 @@ public class NodeImpl implements Node, TestInterface {
}
}
- public String getID() {
- return gm.getParticipantIdentifier();
- }
-
- private void sleep(String msg, int millis) {
- try {
- System.out.println(msg);
- Thread.sleep(millis);
- } catch (InterruptedException ex) {
- Logger.getLogger(NodeImpl.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
-
- private boolean isThereBackupAvailable() {
- for (Node n : nodeList) {
- if (!n.isBlocked()) {
- return true;
- }
- }
- return false;
- }
-
private void primaryService() {
boolean backupAvailable = isThereBackupAvailable();
- System.out.println("Backup available?: " + backupAvailable);
- int upcount = 1;
+
+ upcount = 1;
while (true) {
gm.enableContext(primaryContext);
+ //blockingCheck();
+
try {
System.out.println(pID + "#Primary context: ");
sleep(pID + "#Sleeping at primary context...", 4000);
@@ -187,15 +172,14 @@ public class NodeImpl implements Node, TestInterface {
}
if (backupAvailable) {
- for (Node n : nodeList) {
- if (!n.isBlocked()) {
- n.sendUpdate("Update " + upcount);
- }
+
+ if (!updateBackups()) {
+ backupAvailable = isThereBackupAvailable();
}
- upcount++;
+
} else {
System.out.println(pID + "#No backup available to send updates!");
- backupAvailable = isThereBackupAvailable();
+ //backupAvailable = isThereBackupAvailable();
}
//send the reply to the client
System.out.println(pID + "#Sending the reply to the client...");
@@ -216,11 +200,29 @@ public class NodeImpl implements Node, TestInterface {
}
}
+ private boolean updateBackups() {
+ boolean flag = false;
+
+ for (Node n : nodeList) {
+ if (!n.isBlocked()) {
+ n.sendUpdate("Update " + upcount);
+ flag = true;
+ }
+ }
+ if (flag) {
+ upcount++;
+ }
+
+ return flag;
+ }
+
private void backupService() {
while (true) {
gm.enableContext(backupContext);
+ //blockingCheck();
+
try {
System.out.println(pID + "#Backup context: ");
sleep(pID + "#Sleeping at backup service", 4000);
@@ -241,31 +243,53 @@ public class NodeImpl implements Node, TestInterface {
}
}
- //FIXME - It is not working asynchronously
- //@OneWay
+ public String getID() {
+ return gm.getParticipantIdentifier();
+ }
+
+ private void sleep(String msg, int millis) {
+ try {
+ System.out.println(msg);
+ Thread.sleep(millis);
+ } catch (InterruptedException ex) {
+ Logger.getLogger(NodeImpl.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ }
+
+ private boolean isThereBackupAvailable() {
+ for (Node n : nodeList) {
+ if (!n.isBlocked()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
public void block() {
- System.out.println(pID + "#Participant blocked!");
isBlocked = true;
-
-// while (isBlocked) {
-// try {
-// Thread.sleep(5000);
-// } catch (InterruptedException ex) {
-// Logger.getLogger(ComponentImpl.class.getName()).log(Level.SEVERE, null, ex);
-// }
-// }
}
public boolean isBlocked() {
return isBlocked;
}
- //@OneWay
public void unblock() {
- System.out.println(pID + "#Participant unblocked!");
isBlocked = false;
}
+ private void blockingCheck() {
+ System.out.println(pID + "#Participant blocked!");
+ while (isBlocked) {
+ System.out.println("isBlocked: " + isBlocked);
+ try {
+ Thread.sleep(5000);
+ } catch (InterruptedException ex) {
+ Logger.getLogger(NodeImpl.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ }
+ System.out.println(pID + "#Participant unblocked!");
+ }
+
public void sendUpdate(String update) {
System.out.println(pID + "#Receiving updates from primary: " + update);
updates.offer(update);
diff --git a/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/primaryBackup/simple/Launch3.java b/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/primaryBackup/simple/Launch3.java
deleted file mode 100644
index 780a8df464..0000000000
--- a/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/primaryBackup/simple/Launch3.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright 2009 douglas.
- *
- * 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.
- * under the License.
- */
-package org.apache.tuscany.sca.guardian.itests.primaryBackup.simple;
-
-import java.io.IOException;
-import org.apache.tuscany.sca.guardian.GuardianGroup;
-import org.apache.tuscany.sca.guardian.GuardianMember;
-import org.apache.tuscany.sca.guardian.GuardianMemberImpl;
-import org.apache.tuscany.sca.host.embedded.SCADomain;
-
-/**
- *
- * @author douglas
- */
-public class Launch3 {
-
- public static void main(String... args) throws IOException {
- SCADomain scaDomain = SCADomain.newInstance("primarybackup-ws.composite");
-
- System.out.println("Testing...");
- GuardianGroup c = scaDomain.getService(GuardianGroup.class, "GuardianGroupComponent");
-
- GuardianMember gm = new GuardianMemberImpl();
- c.addGuardianMember(gm);
- //c.enableContext(Context.INIT_CONTEXT);
-
- System.in.read();
-
-// System.out.println("Starting participat1...");
-// Node c = scaDomain.getService(Node.class, "Participant1");
-// c.execute();
-//
-// System.in.read();
-//
-// System.out.println("Starting participant2...");
-// Node c2 = scaDomain.getService(Node.class, "Participant2");
-// c2.execute();
-//
-// System.in.read();
-//
-// System.out.println("Forcing exception ocurrence at participant1...");
-// TestInterface t = scaDomain.getService(TestInterface.class, "Participant1");
-// t.forcePrimaryServiceFailureException();
-//
-// System.in.read();
-
- scaDomain.close();
- }
-}