From dc597c10f1ef39ba5513a7131f809ca9a3d3b6a4 Mon Sep 17 00:00:00 2001 From: dougsleite Date: Tue, 2 Jun 2009 17:55:34 +0000 Subject: git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@781101 13f79535-47bb-0310-9956-ffa450edef68 --- sandbox/dougsleite/guardian-model/pom.xml | 13 + .../org/apache/tuscany/sca/guardian/Context.java | 12 +- .../tuscany/sca/guardian/GlobalException.java | 7 +- .../apache/tuscany/sca/guardian/GuardianGroup.java | 3 + .../tuscany/sca/guardian/GuardianGroupImpl.java | 355 +++++++++++++++++---- .../tuscany/sca/guardian/GuardianMemberImpl.java | 37 ++- .../sca/guardian/InvalidRegularExpression.java | 30 ++ .../guardian/exceptions/BackupFailedException.java | 24 -- .../guardian/exceptions/BackupJoinedException.java | 24 -- .../exceptions/PrimaryExistsException.java | 24 -- .../exceptions/PrimaryFailedException.java | 24 -- .../src/main/resources/server-backup.composite | 1 + .../sca/guardian/itests/BackupFailedException.java | 24 ++ .../sca/guardian/itests/BackupJoinedException.java | 24 ++ .../sca/guardian/itests/GuardianLaunch.java | 31 ++ .../tuscany/sca/guardian/itests/Launch3.java | 51 +++ .../tuscany/sca/guardian/itests/NodeImpl.java | 23 +- .../guardian/itests/PrimaryExistsException.java | 24 ++ .../guardian/itests/PrimaryFailedException.java | 24 ++ 19 files changed, 560 insertions(+), 195 deletions(-) create mode 100644 sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/InvalidRegularExpression.java delete mode 100644 sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/exceptions/BackupFailedException.java delete mode 100644 sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/exceptions/BackupJoinedException.java delete mode 100644 sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/exceptions/PrimaryExistsException.java delete mode 100644 sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/exceptions/PrimaryFailedException.java create mode 100644 sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/BackupFailedException.java create mode 100644 sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/BackupJoinedException.java create mode 100644 sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/GuardianLaunch.java create mode 100644 sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/Launch3.java create mode 100644 sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/PrimaryExistsException.java create mode 100644 sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/PrimaryFailedException.java (limited to 'sandbox/dougsleite') diff --git a/sandbox/dougsleite/guardian-model/pom.xml b/sandbox/dougsleite/guardian-model/pom.xml index 82a1bd5c87..cf7bda80b6 100644 --- a/sandbox/dougsleite/guardian-model/pom.xml +++ b/sandbox/dougsleite/guardian-model/pom.xml @@ -75,6 +75,19 @@ junit 4.5 test + + + + org.apache.axis2 + axis2-jaxws + 1.4.1 + + + + org.apache.axis2 + axis2 + 1.2 + pom 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 index 1b3cd72ead..e803f52ebe 100644 --- 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 @@ -26,27 +26,27 @@ 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 exceptionList; + private List> exceptionList; public Context(String name) { this.name = name; - this.exceptionList = new LinkedList(); + this.exceptionList = new LinkedList>(); } - public Context(String name, List exceptionList) { + public Context(String name, List> exceptionList) { this.name = name; this.exceptionList = exceptionList; } - public void addException(GlobalException ex) { + public void addException(Class ex) { this.exceptionList.add(ex); } - public void setExceptionList(List exceptionList) { + public void setExceptionList(List> exceptionList) { this.exceptionList = exceptionList; } - public List getExceptionList() { + public List> getExceptionList() { return this.exceptionList; } 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 index c500a32701..f80e44ef40 100644 --- 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 @@ -24,6 +24,10 @@ public class GlobalException extends RuntimeException { private Context targetContext; //Assigned by the recovery rules private String signalingParticipant; + public GlobalException(Context targetContext) { + this.targetContext = targetContext; + } + public GlobalException() { super(); } @@ -40,9 +44,6 @@ public class GlobalException extends RuntimeException { super(cause); } - private void init() { - } - /** * @return the signalingContext */ 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 12d7cf478b..b0dbcac4a1 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 @@ -18,6 +18,9 @@ */ package org.apache.tuscany.sca.guardian; +import org.osoa.sca.annotations.Remotable; + +//@Remotable public interface GuardianGroup extends GuardianPrimitives { public void addGuardianMember(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 ee78dadddf..a54ffe71b7 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 @@ -18,28 +18,49 @@ */ 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; import java.util.logging.Logger; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import org.apache.axis2.jaxws.message.util.ResettableReader; +import org.osoa.sca.annotations.Property; 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 guardianMembers; + private List guardianList; + private ResettableReader reader; public GuardianGroupImpl() { - guardianMembers = new LinkedList(); + guardianList = new LinkedList(); + } + + @Property(name = "recovery_rules", required = true) + public void setRecoveryRules(String recoveryRules) { + try { + //FileInputStream fileInputStream = new FileInputStream("src/main/resources/recoveryrules.xml"); + FileInputStream fileInputStream = new FileInputStream("src/main/resources/recoveryrules.xml"); + XMLStreamReader xmlReader = XMLInputFactory.newInstance().createXMLStreamReader(fileInputStream); + reader = new ResettableReader(xmlReader); + } catch (XMLStreamException ex) { + Logger.getLogger(GuardianGroupImpl.class.getName()).log(Level.SEVERE, null, ex); + } catch (FileNotFoundException ex) { + Logger.getLogger(GuardianGroupImpl.class.getName()).log(Level.SEVERE, null, ex); + } } public void addGuardianMember(GuardianMember guardianMember) { - guardianMembers.add(guardianMember); - guardianMember.setUniqueParticipantID(guardianMembers.size() - 1); + guardianList.add(guardianMember); + guardianMember.setUniqueParticipantID(guardianList.size() - 1); } public void enableContext(Context context) { @@ -58,14 +79,14 @@ public class GuardianGroupImpl implements GuardianGroup { //Sends a message representing the exception to the other guardian members if (participantList == null) { - for (GuardianMember g : guardianMembers) { + for (GuardianMember g : guardianList) { if (!g.getParticipantIdentifier().equals(ex.getSignalingParticipant())) { //g.gthrow(ex, participantList); g.gthrow(null, null); } } } else { - for (GuardianMember g : guardianMembers) { + for (GuardianMember g : guardianList) { if (participantList.contains(g.getCurrentContext())) { //g.gthrow(ex, participantList); g.gthrow(null, null); @@ -74,9 +95,9 @@ public class GuardianGroupImpl implements GuardianGroup { } //Check if the participants are blocked - List flags = new ArrayList(guardianMembers.size()); - for (int i = 0; i < guardianMembers.size(); i++) { - if (guardianMembers.get(i).getService().isBlocked()) { + List flags = new ArrayList(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); @@ -93,7 +114,7 @@ public class GuardianGroupImpl implements GuardianGroup { } //3)Once ALL required participants are SUSPENDED (suspended point), invoke the defined Recovery Rules - for (GuardianMember g : guardianMembers) { + for (GuardianMember g : guardianList) { g.addException(new SuspendException()); } // 3.1) recovery_rules < signaled exceptions + context information of all participant > target context + exception to raise @@ -104,66 +125,280 @@ public class GuardianGroupImpl implements GuardianGroup { // g.addException(ex); // } - //HARDCODED - SERVER-BACKUP EXAMPLE - //Rule 1 - if (ex instanceof JoinException) { - if (guardianMembers.size() > 1) { + applyRecoveryRules(ex); - PrimaryExistsException primaryExists = new PrimaryExistsException(); - primaryExists.setTargetContext(new Context("MAIN")); +// //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); +// } +// } +// +// } - 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()); + private void applyRecoveryRules(GlobalException ex) { + + String exceptionClassName; + String targetContextName; + Integer min_participant_joined; + Integer max_participant_joined; + + List gmList; + + try { + + reader.reset(); + + while (reader.hasNext()) { + reader.next(); + // + 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(); + + // + 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(); + + // + 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); + + 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 + for (GuardianMember gm : gmList) { + gm.addException(newException); + } + } + } + } + } + break; + } } } } - } //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); + } 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 getMatchingParticipants(String regularExpression, GlobalException signaledException) { + List 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); } } - } //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); + + } else { + //Create an java regular expression + String re = createJavaRegularExpression(regularExpression); + + for (GuardianMember gm : guardianList) { + if (gm.getParticipantIdentifier().matches(re)) { + matchingParticipants.add(gm); } } + } + + return matchingParticipants; + } + + /* Valid expressions: *, .*, , *., *..*, + * *..*..*, || + * + * Invalid expressions: *.*, **, + * + * Not supported yet: !, ! || , !( || ) + */ + private String createJavaRegularExpression(String regularExpression) throws InvalidRegularExpression { + StringBuffer re = new StringBuffer(); + + String[] splitedByBar = regularExpression.split("\\|\\|"); + String[] splitedByPeriod; + + for (int i = 0; i < splitedByBar.length; i++) { + + splitedByPeriod = splitedByBar[i].split("\\."); + + if (i > 0) { + re.append("|"); + } + re.append("^"); + for (int j = 0; j < splitedByPeriod.length; j++) { + + //* + if (splitedByPeriod[j].equals("*")) { + + //Validate the regular expression + if (j + 1 != splitedByPeriod.length && splitedByPeriod[j + 1].equals("*")) { + throw new InvalidRegularExpression(); + } + + //* + if (splitedByPeriod.length == 1) { + re.append("(\\w+)"); + } //*. + + if (j == 0 && splitedByPeriod.length != 1) { + re.append("(\\w+\\"); + re.append(".)*"); + } //.* + else { + re.append("(\\"); + re.append(".\\w+)*"); + } + } // + else { + +// //Validate the regular expression +// if (splitedByPeriod[j].matches("^(\\*)*$")) { +// throw new RuntimeException("Invalid name for a 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] + ")"); + } + } + } + re.append("$"); } + return re.toString(); } public boolean propagate(GlobalException ex) { @@ -175,6 +410,6 @@ public class GuardianGroupImpl implements GuardianGroup { } public boolean removeGuardianMember(GuardianMember guardianMember) { - return this.guardianMembers.remove(guardianMember); + return this.guardianList.remove(guardianMember); } } 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 5edecf4bcd..220325b1f0 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 @@ -41,6 +41,7 @@ public class GuardianMemberImpl implements GuardianMember { public GuardianMemberImpl() { contextList = new Stack(); + contextList.add(Context.INIT_CONTEXT); exceptionQueue = new LinkedList(); } @@ -74,7 +75,7 @@ public class GuardianMemberImpl implements GuardianMember { //Update the context list with the related set of exceptions contextList.push(context); - if (contextList.size() == 1) { + if (contextList.size() == 2) { gthrow(new JoinException(), null); } @@ -162,23 +163,31 @@ public class GuardianMemberImpl implements GuardianMember { // 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("\\."); + //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 (int i = contexts.length - 1; i > 0; i--) { - if (exc.getTargetContext().equals(new Context(contexts[i]))) { + 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; } } } - -// if (exc != null && exc.getTargetContext().equals(getCurrentContext())) { -// 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; @@ -189,12 +198,10 @@ public class GuardianMemberImpl implements GuardianMember { public String getParticipantIdentifier() { //1) Return the participant identifier -> context list dot separated StringBuffer id = new StringBuffer(); - id.append(this.id + "." + Context.INIT_CONTEXT.getName()); + //id.append(this.id + "." + Context.INIT_CONTEXT.getName()); + id.append(this.id); for (int i = 0; i < contextList.size(); i++) { id.append("." + contextList.get(i).getName()); -// if (i + 1 != contextList.size()) { -// id.append("."); -// } } return id.toString(); } diff --git a/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/InvalidRegularExpression.java b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/InvalidRegularExpression.java new file mode 100644 index 0000000000..30e750941e --- /dev/null +++ b/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/InvalidRegularExpression.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 class InvalidRegularExpression extends RuntimeException { + + public InvalidRegularExpression() { + super(); + } + + public InvalidRegularExpression(String message) { + super(message); + } +} 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 deleted file mode 100644 index c4b2dd7de5..0000000000 --- a/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/exceptions/BackupFailedException.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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 deleted file mode 100644 index 1fffa14663..0000000000 --- a/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/exceptions/BackupJoinedException.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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 deleted file mode 100644 index 6d358c281e..0000000000 --- a/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/exceptions/PrimaryExistsException.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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 deleted file mode 100644 index 7f6b73cd05..0000000000 --- a/sandbox/dougsleite/guardian-model/src/main/java/org/apache/tuscany/sca/guardian/exceptions/PrimaryFailedException.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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 { -} diff --git a/sandbox/dougsleite/guardian-model/src/main/resources/server-backup.composite b/sandbox/dougsleite/guardian-model/src/main/resources/server-backup.composite index e2e27937d6..e57403a791 100644 --- a/sandbox/dougsleite/guardian-model/src/main/resources/server-backup.composite +++ b/sandbox/dougsleite/guardian-model/src/main/resources/server-backup.composite @@ -46,6 +46,7 @@ + src/main/resources/recoveryrules.xml diff --git a/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/BackupFailedException.java b/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/BackupFailedException.java new file mode 100644 index 0000000000..6483018a19 --- /dev/null +++ b/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/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.itests; + +import org.apache.tuscany.sca.guardian.*; + +public class BackupFailedException extends GlobalException { +} diff --git a/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/BackupJoinedException.java b/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/BackupJoinedException.java new file mode 100644 index 0000000000..728db2bbd6 --- /dev/null +++ b/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/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.itests; + +import org.apache.tuscany.sca.guardian.GlobalException; + +public class BackupJoinedException extends GlobalException { +} diff --git a/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/GuardianLaunch.java b/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/GuardianLaunch.java new file mode 100644 index 0000000000..11ede178d0 --- /dev/null +++ b/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/GuardianLaunch.java @@ -0,0 +1,31 @@ +/* + * 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.itests; + +import java.io.IOException; +import org.apache.tuscany.sca.host.embedded.SCADomain; + +public class GuardianLaunch { + + public static void main(String... args) throws IOException { + + SCADomain scaDomain = SCADomain.newInstance("guardiangroup.composite"); + System.in.read(); + } +} diff --git a/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/Launch3.java b/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/Launch3.java new file mode 100644 index 0000000000..271d5051fc --- /dev/null +++ b/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/Launch3.java @@ -0,0 +1,51 @@ +/* + * 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; + +import java.io.IOException; +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("participant1.composite"); + + 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(); + } +} diff --git a/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/NodeImpl.java b/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/NodeImpl.java index 86d2e9bbc6..2500817100 100644 --- a/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/NodeImpl.java +++ b/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/NodeImpl.java @@ -29,10 +29,6 @@ import org.apache.tuscany.sca.guardian.GuardianMember; import org.osoa.sca.annotations.Init; import org.osoa.sca.annotations.Reference; import org.osoa.sca.annotations.Scope; -import org.apache.tuscany.sca.guardian.exceptions.BackupFailedException; -import org.apache.tuscany.sca.guardian.exceptions.BackupJoinedException; -import org.apache.tuscany.sca.guardian.exceptions.PrimaryExistsException; -import org.apache.tuscany.sca.guardian.exceptions.PrimaryFailedException; import org.osoa.sca.annotations.Destroy; import org.osoa.sca.annotations.OneWay; @@ -45,8 +41,6 @@ public class NodeImpl implements Node, TestInterface { private Context mainContext; private Context primaryContext; private Context backupContext; - private List exListMain; - private List exListPrimary; private int role; private boolean isExecuting; private String pID; @@ -59,17 +53,16 @@ public class NodeImpl implements Node, TestInterface { private boolean forceAUFException; public NodeImpl() { - exListMain = new LinkedList(); - exListMain.add(new PrimaryFailedException()); - exListMain.add(new PrimaryExistsException()); - exListPrimary = new LinkedList(); - exListPrimary.add(new BackupFailedException()); - exListPrimary.add(new BackupJoinedException()); - exListPrimary.add(new PrimaryServiceFailureException()); + mainContext = new Context("MAIN"); + mainContext.addException(PrimaryFailedException.class); + mainContext.addException(PrimaryExistsException.class); + + primaryContext = new Context("PRIMARY"); + primaryContext.addException(BackupFailedException.class); + primaryContext.addException(BackupJoinedException.class); + primaryContext.addException(PrimaryServiceFailureException.class); - mainContext = new Context("MAIN", exListMain); - primaryContext = new Context("PRIMARY", exListPrimary); backupContext = new Context("BACKUP", null); updates = new LinkedList(); diff --git a/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/PrimaryExistsException.java b/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/PrimaryExistsException.java new file mode 100644 index 0000000000..75b44eb478 --- /dev/null +++ b/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/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.itests; + +import org.apache.tuscany.sca.guardian.GlobalException; + +public class PrimaryExistsException extends GlobalException { +} diff --git a/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/PrimaryFailedException.java b/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/PrimaryFailedException.java new file mode 100644 index 0000000000..daf013b90d --- /dev/null +++ b/sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/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.itests; + +import org.apache.tuscany.sca.guardian.*; + +public class PrimaryFailedException extends GlobalException { +} -- cgit v1.2.3