summaryrefslogtreecommitdiffstats
path: root/sandbox/dougsleite/implementation-guardian
diff options
context:
space:
mode:
authordougsleite <dougsleite@13f79535-47bb-0310-9956-ffa450edef68>2009-10-29 18:45:38 +0000
committerdougsleite <dougsleite@13f79535-47bb-0310-9956-ffa450edef68>2009-10-29 18:45:38 +0000
commitc4800a6c1b96b327f7f964ebf468348624363abf (patch)
tree1f96f5b9b87b6f25fab6602ea4a4dfc042e99aca /sandbox/dougsleite/implementation-guardian
parenta1a3fca873e35c3f7dd4036aa1a734df3b7100e9 (diff)
- Changing the implementation-guardian to work with the policy-guardianException module
- Adding the policy-guardianException module: The guardian member is implemented as policies git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@831060 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sandbox/dougsleite/implementation-guardian')
-rw-r--r--sandbox/dougsleite/implementation-guardian/pom.xml6
-rw-r--r--sandbox/dougsleite/implementation-guardian/src/main/java/org/apache/tuscany/sca/implementation/guardian/GuardianMember.java2
-rw-r--r--sandbox/dougsleite/implementation-guardian/src/main/java/org/apache/tuscany/sca/implementation/guardian/GuardianPrimitives.java2
-rw-r--r--sandbox/dougsleite/implementation-guardian/src/main/java/org/apache/tuscany/sca/implementation/guardian/common/Context.java1
-rw-r--r--sandbox/dougsleite/implementation-guardian/src/main/java/org/apache/tuscany/sca/implementation/guardian/impl/GuardianGroupImpl.java6
-rw-r--r--sandbox/dougsleite/implementation-guardian/src/main/java/org/apache/tuscany/sca/implementation/guardian/impl/GuardianMemberImpl.java177
-rw-r--r--sandbox/dougsleite/implementation-guardian/src/main/java/org/apache/tuscany/sca/implementation/guardian/provider/GuardianGroupInvoker.java6
-rw-r--r--sandbox/dougsleite/implementation-guardian/src/main/resources/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/concurrentExceptions/primaryBackup.composite28
-rw-r--r--sandbox/dougsleite/implementation-guardian/src/main/resources/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/simple/primaryBackup.composite18
-rw-r--r--sandbox/dougsleite/implementation-guardian/src/test/java/definitions.xml28
-rw-r--r--sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/GuardianImplementationTest.java77
-rw-r--r--sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/common/Node.java2
-rw-r--r--sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/common/NodeImpl.java43
-rw-r--r--sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/concurrentExceptions/Launch.java4
-rw-r--r--sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/simple/Launch.java2
-rw-r--r--sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/simple/Launch2.java2
16 files changed, 83 insertions, 321 deletions
diff --git a/sandbox/dougsleite/implementation-guardian/pom.xml b/sandbox/dougsleite/implementation-guardian/pom.xml
index dcd91936e6..3752c6ded5 100644
--- a/sandbox/dougsleite/implementation-guardian/pom.xml
+++ b/sandbox/dougsleite/implementation-guardian/pom.xml
@@ -39,6 +39,12 @@
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-policy-guardianExceptionHandling</artifactId>
+ <version>1.6-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-host-embedded</artifactId>
<version>1.6-SNAPSHOT</version>
</dependency>
diff --git a/sandbox/dougsleite/implementation-guardian/src/main/java/org/apache/tuscany/sca/implementation/guardian/GuardianMember.java b/sandbox/dougsleite/implementation-guardian/src/main/java/org/apache/tuscany/sca/implementation/guardian/GuardianMember.java
index b82bf082b1..ec562b082b 100644
--- a/sandbox/dougsleite/implementation-guardian/src/main/java/org/apache/tuscany/sca/implementation/guardian/GuardianMember.java
+++ b/sandbox/dougsleite/implementation-guardian/src/main/java/org/apache/tuscany/sca/implementation/guardian/GuardianMember.java
@@ -29,8 +29,6 @@ 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/implementation-guardian/src/main/java/org/apache/tuscany/sca/implementation/guardian/GuardianPrimitives.java b/sandbox/dougsleite/implementation-guardian/src/main/java/org/apache/tuscany/sca/implementation/guardian/GuardianPrimitives.java
index c50e855d30..3aa014ee12 100644
--- a/sandbox/dougsleite/implementation-guardian/src/main/java/org/apache/tuscany/sca/implementation/guardian/GuardianPrimitives.java
+++ b/sandbox/dougsleite/implementation-guardian/src/main/java/org/apache/tuscany/sca/implementation/guardian/GuardianPrimitives.java
@@ -29,7 +29,7 @@ public interface GuardianPrimitives {
//Methods to manage contexts
public void enableContext(Context context);
- public void removeContext();
+ public Context removeContext();
//Methods to control the signaling of exceptions
public void gthrow(GlobalExceptionInterface ex, List<String> participantList);
diff --git a/sandbox/dougsleite/implementation-guardian/src/main/java/org/apache/tuscany/sca/implementation/guardian/common/Context.java b/sandbox/dougsleite/implementation-guardian/src/main/java/org/apache/tuscany/sca/implementation/guardian/common/Context.java
index 95c6f3bed6..6eb777b587 100644
--- a/sandbox/dougsleite/implementation-guardian/src/main/java/org/apache/tuscany/sca/implementation/guardian/common/Context.java
+++ b/sandbox/dougsleite/implementation-guardian/src/main/java/org/apache/tuscany/sca/implementation/guardian/common/Context.java
@@ -26,7 +26,6 @@ public class Context {
public static Context CURRENT_CONTEXT = new Context("CURRENT_CONTEXT");
public static Context INIT_CONTEXT = new Context("INIT_CONTEXT");
public static Context GUARDIAN_CONTEXT = new Context("GUARDIAN_CONTEXT");
-
private String name;
private List<Class<? extends GlobalException>> exceptionList;
diff --git a/sandbox/dougsleite/implementation-guardian/src/main/java/org/apache/tuscany/sca/implementation/guardian/impl/GuardianGroupImpl.java b/sandbox/dougsleite/implementation-guardian/src/main/java/org/apache/tuscany/sca/implementation/guardian/impl/GuardianGroupImpl.java
index 5a243560e3..9094fc248d 100644
--- a/sandbox/dougsleite/implementation-guardian/src/main/java/org/apache/tuscany/sca/implementation/guardian/impl/GuardianGroupImpl.java
+++ b/sandbox/dougsleite/implementation-guardian/src/main/java/org/apache/tuscany/sca/implementation/guardian/impl/GuardianGroupImpl.java
@@ -102,18 +102,18 @@ public class GuardianGroupImpl implements GuardianGroup {
public void addGuardianMember(GuardianMember guardianMember) {
guardianList.add(guardianMember);
- guardianMember.setUniqueParticipantID(guardianList.size() - 1);
+ //guardianMember.setUniqueParticipantID(guardianList.size() - 1);
}
public boolean removeGuardianMember(GuardianMember guardianMember) {
- throw new UnsupportedOperationException("Not supported yet.");
+ return guardianList.remove(guardianMember);
}
public void enableContext(Context context) {
throw new UnsupportedOperationException("Not supported yet.");
}
- public void removeContext() {
+ public Context removeContext() {
throw new UnsupportedOperationException("Not supported yet.");
}
diff --git a/sandbox/dougsleite/implementation-guardian/src/main/java/org/apache/tuscany/sca/implementation/guardian/impl/GuardianMemberImpl.java b/sandbox/dougsleite/implementation-guardian/src/main/java/org/apache/tuscany/sca/implementation/guardian/impl/GuardianMemberImpl.java
deleted file mode 100644
index 80b9321e79..0000000000
--- a/sandbox/dougsleite/implementation-guardian/src/main/java/org/apache/tuscany/sca/implementation/guardian/impl/GuardianMemberImpl.java
+++ /dev/null
@@ -1,177 +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.implementation.guardian.impl;
-
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Queue;
-import java.util.Stack;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import org.apache.tuscany.sca.implementation.guardian.common.GlobalExceptionInterface;
-import org.apache.tuscany.sca.implementation.guardian.GuardianGroup;
-import org.apache.tuscany.sca.implementation.guardian.GuardianMember;
-import org.apache.tuscany.sca.implementation.guardian.common.Context;
-import org.apache.tuscany.sca.implementation.guardian.common.GlobalException;
-import org.apache.tuscany.sca.implementation.guardian.common.JoinException;
-import org.apache.tuscany.sca.implementation.guardian.common.SuspendException;
-import org.osoa.sca.annotations.Destroy;
-import org.osoa.sca.annotations.Init;
-import org.osoa.sca.annotations.Reference;
-import org.osoa.sca.annotations.Scope;
-import org.osoa.sca.annotations.Service;
-
-@Service(GuardianMember.class)
-@Scope("COMPOSITE")
-public class GuardianMemberImpl implements GuardianMember {
-
- private int participantState;
- private Stack<Context> contextList;
-
- private Queue<GlobalException> exceptionQueue;
- @Reference(name = "guardian_group", required = true)
- public GuardianGroup guardianGroup;
- private int id;
- //FIXME: Review the usage of this variable
- private boolean exceptionThrown;
-
- public GuardianMemberImpl() {
- contextList = new Stack<Context>();
- contextList.add(Context.INIT_CONTEXT);
- exceptionQueue = new LinkedList<GlobalException>();
- participantState = GuardianGroup.NORMAL_PARTICIPANT_STATE;
- exceptionThrown = false;
- }
-
- @Init
- public void init() {
- guardianGroup.addGuardianMember(this);
- }
-
- @Destroy
- public void destroy() {
- guardianGroup.removeGuardianMember(this);
- }
-
- public void addException(GlobalException ex) {
- exceptionQueue.add(ex);
- }
-
- public Context getCurrentContext() {
- return contextList.peek();
- }
-
-
- public void enableContext(Context context) {
- //Update the context list with the related set of exceptions
- contextList.push(context);
-
- if (contextList.size() == 2) {
- JoinException ex = new JoinException();
- ex.setSignalingContext(context);
- ex.putSignalingParticipant(getParticipantIdentifier());
- gthrow(ex, null);
- }
-
- }
-
- public void removeContext() {
- if (!contextList.isEmpty()) {
- contextList.pop();
- }
- }
-
- //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 (!(ex instanceof SuspendException)) {
- //Set the exception's parameters
- ex.setSignalingContext(getCurrentContext());
- ex.putSignalingParticipant(getParticipantIdentifier());
-
- guardianGroup.gthrow(ex, participantList);
- exceptionThrown = true;
- } else {
- setParticipantState(GuardianGroup.SUSPENDED_PARTICIPANT_STATE);
- }
- }
-
- public boolean propagate(GlobalExceptionInterface ex) {
- //1)Compares the current context with the exception's target context
- return !getCurrentContext().equals(ex.getTargetContext());
- }
-
- public void checkExceptionStatus() throws GlobalException {
-
- //Blocks until the state be diferent the SUSPENDED_STATE
- while (participantState == GuardianGroup.SUSPENDED_PARTICIPANT_STATE && exceptionThrown) {
- System.out.println(getParticipantIdentifier() + ": I am blocked!");
- try {
- Thread.sleep(5000);
- } catch (InterruptedException ex) {
- Logger.getLogger(GuardianMemberImpl.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- exceptionThrown = false;
- System.out.println(getParticipantIdentifier() + ": I am not blocked!");
-
- GlobalException exc;
-
- if ((exc = exceptionQueue.peek()) == null) {
- System.out.println(getParticipantIdentifier() + "#No exception on exception queue");
- return;
- }
-
- //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;
- }
- }
-
- return;
- }
-
- public String getParticipantIdentifier() {
- //1) Return the participant identifier -> context list dot separated
- StringBuffer participantIdentifier = new StringBuffer();
- participantIdentifier.append(this.id);
- for (int i = 0; i < contextList.size(); i++) {
- participantIdentifier.append("." + contextList.get(i).getName());
- }
- return participantIdentifier.toString();
- }
-
- public void setUniqueParticipantID(int id) {
- this.id = id;
- }
-
- public int getParticipantState() {
- return participantState;
- }
-
- public void setParticipantState(int state) {
- this.participantState = state;
- }
-}
diff --git a/sandbox/dougsleite/implementation-guardian/src/main/java/org/apache/tuscany/sca/implementation/guardian/provider/GuardianGroupInvoker.java b/sandbox/dougsleite/implementation-guardian/src/main/java/org/apache/tuscany/sca/implementation/guardian/provider/GuardianGroupInvoker.java
index 8f393ebcb9..987e211a48 100644
--- a/sandbox/dougsleite/implementation-guardian/src/main/java/org/apache/tuscany/sca/implementation/guardian/provider/GuardianGroupInvoker.java
+++ b/sandbox/dougsleite/implementation-guardian/src/main/java/org/apache/tuscany/sca/implementation/guardian/provider/GuardianGroupInvoker.java
@@ -48,7 +48,8 @@ public class GuardianGroupInvoker implements Invoker {
@Override
public Message invoke(Message msg) {
- GuardianMember guardianMember = (GuardianMember) ((Object[]) msg.getBody())[0];
+ //GuardianMember guardianMember = (GuardianMember) ((Object[]) msg.getBody())[0];
+ GuardianMember guardianMember = (GuardianMember) msg.getBody();
this.guardian.addGuardianMember(guardianMember);
return msg;
@@ -65,7 +66,8 @@ public class GuardianGroupInvoker implements Invoker {
@Override
public Message invoke(Message msg) {
- GuardianMember guardianMember = (GuardianMember) ((Object[]) msg.getBody())[0];
+ GuardianMember guardianMember = (GuardianMember) msg.getBody();
+
boolean returnedValue = this.guardian.removeGuardianMember(guardianMember);
msg.setBody(returnedValue);
diff --git a/sandbox/dougsleite/implementation-guardian/src/main/resources/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/concurrentExceptions/primaryBackup.composite b/sandbox/dougsleite/implementation-guardian/src/main/resources/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/concurrentExceptions/primaryBackup.composite
index fcb78e3879..a337d40b70 100644
--- a/sandbox/dougsleite/implementation-guardian/src/main/resources/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/concurrentExceptions/primaryBackup.composite
+++ b/sandbox/dougsleite/implementation-guardian/src/main/resources/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/concurrentExceptions/primaryBackup.composite
@@ -25,48 +25,28 @@
<component name="Participant1">
<implementation.java class="org.apache.tuscany.sca.implementation.guardian.itests.primaryBackup.common.NodeImpl"/>
- <reference name="guardian_member" target="GuardianMember1"/>
+ <reference name="guardian" target="GuardianComponent" requires="tuscany:guardianExceptionHandling"/>
<reference name="nodes" target="Participant2 Participant3 Participant4"/>
</component>
<component name="Participant2">
<implementation.java class="org.apache.tuscany.sca.implementation.guardian.itests.primaryBackup.common.NodeImpl"/>
- <reference name="guardian_member" target="GuardianMember2"/>
+ <reference name="guardian" target="GuardianComponent" requires="tuscany:guardianExceptionHandling"/>
<reference name="nodes" target="Participant1 Participant3 Participant4"/>
</component>
<component name="Participant3">
<implementation.java class="org.apache.tuscany.sca.implementation.guardian.itests.primaryBackup.common.NodeImpl"/>
- <reference name="guardian_member" target="GuardianMember3"/>
+ <reference name="guardian" target="GuardianComponent" requires="tuscany:guardianExceptionHandling"/>
<reference name="nodes" target="Participant1 Participant2 Participant4"/>
</component>
<component name="Participant4">
<implementation.java class="org.apache.tuscany.sca.implementation.guardian.itests.primaryBackup.common.NodeImpl"/>
- <reference name="guardian_member" target="GuardianMember4"/>
+ <reference name="guardian" target="GuardianComponent" requires="tuscany:guardianExceptionHandling"/>
<reference name="nodes" target="Participant1 Participant2 Participant3"/>
</component>
- <component name="GuardianMember1">
- <implementation.java class="org.apache.tuscany.sca.implementation.guardian.impl.GuardianMemberImpl"/>
- <reference name="guardian_group" target="GuardianComponent"/>
- </component>
-
- <component name="GuardianMember2">
- <implementation.java class="org.apache.tuscany.sca.implementation.guardian.impl.GuardianMemberImpl"/>
- <reference name="guardian_group" target="GuardianComponent"/>
- </component>
-
- <component name="GuardianMember3">
- <implementation.java class="org.apache.tuscany.sca.implementation.guardian.impl.GuardianMemberImpl"/>
- <reference name="guardian_group" target="GuardianComponent"/>
- </component>
-
- <component name="GuardianMember4">
- <implementation.java class="org.apache.tuscany.sca.implementation.guardian.impl.GuardianMemberImpl"/>
- <reference name="guardian_group" target="GuardianComponent"/>
- </component>
-
<component name="GuardianComponent">
<tuscany:implementation.guardian>
diff --git a/sandbox/dougsleite/implementation-guardian/src/main/resources/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/simple/primaryBackup.composite b/sandbox/dougsleite/implementation-guardian/src/main/resources/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/simple/primaryBackup.composite
index 85af4efd48..a00847573f 100644
--- a/sandbox/dougsleite/implementation-guardian/src/main/resources/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/simple/primaryBackup.composite
+++ b/sandbox/dougsleite/implementation-guardian/src/main/resources/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/simple/primaryBackup.composite
@@ -23,27 +23,17 @@
name="guardianTest">
<component name="Participant1">
- <implementation.java class="org.apache.tuscany.sca.implementation.guardian.itests.primaryBackup.common.NodeImpl"/>
- <reference name="guardian_member" target="GuardianMember1"/>
+ <implementation.java class="org.apache.tuscany.sca.implementation.guardian.itests.primaryBackup.common.NodeImpl"/>
+ <reference name="guardian" target="GuardianComponent" requires="tuscany:guardianExceptionHandling"/>
<reference name="nodes" target="Participant2"/>
</component>
<component name="Participant2">
- <implementation.java class="org.apache.tuscany.sca.implementation.guardian.itests.primaryBackup.common.NodeImpl"/>
- <reference name="guardian_member" target="GuardianMember2"/>
+ <implementation.java class="org.apache.tuscany.sca.implementation.guardian.itests.primaryBackup.common.NodeImpl"/>
+ <reference name="guardian" target="GuardianComponent" requires="tuscany:guardianExceptionHandling"/>
<reference name="nodes" target="Participant1"/>
</component>
- <component name="GuardianMember1">
- <implementation.java class="org.apache.tuscany.sca.implementation.guardian.impl.GuardianMemberImpl"/>
- <reference name="guardian_group" target="GuardianComponent"/>
- </component>
-
- <component name="GuardianMember2">
- <implementation.java class="org.apache.tuscany.sca.implementation.guardian.impl.GuardianMemberImpl"/>
- <reference name="guardian_group" target="GuardianComponent"/>
- </component>
-
<component name="GuardianComponent">
<tuscany:implementation.guardian>
diff --git a/sandbox/dougsleite/implementation-guardian/src/test/java/definitions.xml b/sandbox/dougsleite/implementation-guardian/src/test/java/definitions.xml
new file mode 100644
index 0000000000..0793e69334
--- /dev/null
+++ b/sandbox/dougsleite/implementation-guardian/src/test/java/definitions.xml
@@ -0,0 +1,28 @@
+<?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.
+-->
+<definitions xmlns="http://www.osoa.org/xmlns/sca/1.0" targetNamespace="http://tuscany.apache.org/xmlns/sca/1.0"
+ xmlns:sca="http://www.osoa.org/xmlns/sca/1.0" xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.0"
+ xmlns:calc="http://calculator">
+
+ <!-- PolicySets -->
+ <policySet name="GuardianExceptionHandlingPolicy" provides="tuscany:guardianExceptionHandling" appliesTo="sca:implementation.java/sca:reference"
+ xmlns="http://www.osoa.org/xmlns/sca/1.0"/>
+
+</definitions> \ No newline at end of file
diff --git a/sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/GuardianImplementationTest.java b/sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/GuardianImplementationTest.java
deleted file mode 100644
index ba4f6230d8..0000000000
--- a/sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/GuardianImplementationTest.java
+++ /dev/null
@@ -1,77 +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.implementation.guardian;
-
-import org.apache.tuscany.sca.implementation.guardian.*;
-import org.apache.tuscany.sca.host.embedded.SCADomain;
-import org.apache.tuscany.sca.implementation.guardian.common.Context;
-import org.apache.tuscany.sca.implementation.guardian.common.GlobalException;
-import org.apache.tuscany.sca.implementation.guardian.impl.GuardianMemberImpl;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-public class GuardianImplementationTest {
-
-// private SCADomain scaDomain;
-// private GuardianGroup guardian;
-//
-// @Before
-// public void init() throws Exception {
-// scaDomain = SCADomain.newInstance("org/apache/tuscany/sca/implementation/guardian/guardianTest.composite");
-// guardian = scaDomain.getService(GuardianGroup.class, "GuardianComponent");
-// }
-//
-// @Test
-// public void enabelContextTest() throws Exception {
-// guardian.enableContext(Context.INIT_CONTEXT);
-// }
-//
-// @After
-// public void destroy() {
-// scaDomain.close();
-// }
- public static void main(String... args) {
-
- SCADomain scaDomain = SCADomain.newInstance("org/apache/tuscany/sca/implementation/guardian/guardianTest.composite");
- GuardianGroup guardian = scaDomain.getService(GuardianGroup.class, "GuardianComponent");
-
- System.out.println("\n#EnableContext invocation");
- guardian.enableContext(Context.INIT_CONTEXT);
-
- System.out.println("\n#RemoveContext invocation");
- guardian.removeContext();
-
- System.out.println("\n#CheckExceptionStatus invocation");
- guardian.checkExceptionStatus();
-
- System.out.println("\n#CheckExceptionStatus invocation");
- boolean value = guardian.propagate(new GlobalException());
- System.out.println("returned value: " + value);
-
- System.out.println("\n#AddGuardianMember invocation");
- guardian.addGuardianMember(new GuardianMemberImpl());
-
- System.out.println("\n#RemoveGuardianMember invocation");
- value = guardian.removeGuardianMember(new GuardianMemberImpl());
- System.out.println("returned value: " + value);
-
- }
-
-}
diff --git a/sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/common/Node.java b/sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/common/Node.java
index 6aa9456816..8890f631d4 100644
--- a/sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/common/Node.java
+++ b/sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/common/Node.java
@@ -34,4 +34,6 @@ public interface Node {
public void kill();
public boolean isDead();
+
+ public void setID(String pID);
}
diff --git a/sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/common/NodeImpl.java b/sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/common/NodeImpl.java
index 37f4f529f0..6004468f73 100644
--- a/sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/common/NodeImpl.java
+++ b/sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/common/NodeImpl.java
@@ -23,6 +23,7 @@ import java.util.List;
import java.util.Queue;
import java.util.logging.Level;
import java.util.logging.Logger;
+import org.apache.tuscany.sca.implementation.guardian.GuardianGroup;
import org.apache.tuscany.sca.implementation.guardian.GuardianMember;
import org.apache.tuscany.sca.implementation.guardian.common.Context;
import org.osoa.sca.annotations.Init;
@@ -42,8 +43,8 @@ public class NodeImpl implements Node, TestInterface {
private int role;
private String pID;
private Queue<String> updates;
- @Reference(name = "guardian_member", required = true)
- public GuardianMember gm;
+ @Reference(name = "guardian", required = true)
+ public GuardianGroup guardianGroup;
@Reference(name = "nodes", required = true)
public List<Node> nodeList;
private boolean forcePSFException;
@@ -73,15 +74,14 @@ public class NodeImpl implements Node, TestInterface {
forceAUFException = false;
}
- @Init
- public void init() {
- pID = gm.getParticipantIdentifier();
+ public void setID(String pID) {
+ this.pID = pID;
}
@OneWay
public void execute() {
isDead = false;
- gm.enableContext(mainContext);
+ guardianGroup.enableContext(mainContext);
role = PRIMARY;
while (true) {
@@ -92,7 +92,7 @@ public class NodeImpl implements Node, TestInterface {
System.out.println(pID + "#Main context: ");
sleep(pID + "#Sleeping at main context...", 4000);
- gm.checkExceptionStatus();
+ guardianGroup.checkExceptionStatus();
if (role == PRIMARY) {
//Config as primary then...
@@ -109,12 +109,13 @@ public class NodeImpl implements Node, TestInterface {
} catch (PrimaryFailedException ex) {
System.out.println(pID + "# Exception captured!: PrimaryFailedException");
- System.out.println(pID + "#Needs propagation?: " + gm.propagate(ex));
+ System.out.println(pID + "#Needs propagation?: " + guardianGroup.propagate(ex));
- if (gm.propagate(ex)) {
+ if (guardianGroup.propagate(ex)) {
//throw ex;
this.kill();
ex.printStackTrace();
+ guardianGroup.removeContext();
return;
}
@@ -122,12 +123,14 @@ public class NodeImpl implements Node, TestInterface {
} catch (BackupFailedException ex) {
System.out.println(pID + "# Exception captured!: BackupFailedException");
- System.out.println(pID + "#Needs propagation?: " + gm.propagate(ex));
+ System.out.println(pID + "#Needs propagation?: " + guardianGroup.propagate(ex));
- if (gm.propagate(ex)) {
+ if (guardianGroup.propagate(ex)) {
//throw ex;
this.kill();
ex.printStackTrace();
+
+ guardianGroup.removeContext();
return;
}
}
@@ -141,14 +144,14 @@ public class NodeImpl implements Node, TestInterface {
while (true) {
- gm.enableContext(primaryContext);
+ guardianGroup.enableContext(primaryContext);
//blockingCheck();
try {
System.out.println(pID + "#Primary context: ");
sleep(pID + "#Sleeping at primary context...", 4000);
- gm.checkExceptionStatus();
+ guardianGroup.checkExceptionStatus();
//Process the request then...
System.out.println(pID + "#Processing the request...");
@@ -173,7 +176,7 @@ public class NodeImpl implements Node, TestInterface {
} catch (PrimaryServiceFailureException ex) {
System.out.println(pID + "# Exception captured!: PrimaryServiceFailureException");
- gm.gthrow(new PrimaryFailedException(), null);
+ guardianGroup.gthrow(new PrimaryFailedException(), null);
} catch (BackupFailedException ex) {
System.out.println(pID + "# Exception captured!: BackupFailedException");
//backupAvailable = false;
@@ -182,7 +185,7 @@ public class NodeImpl implements Node, TestInterface {
System.out.println(pID + "# Exception captured!: BackupJoinedException");
backupAvailable = true;
} finally {
- gm.removeContext();
+ guardianGroup.removeContext();
}
}
}
@@ -206,14 +209,14 @@ public class NodeImpl implements Node, TestInterface {
private void backupService() {
while (true) {
- gm.enableContext(backupContext);
+ guardianGroup.enableContext(backupContext);
//blockingCheck();
try {
System.out.println(pID + "#Backup context: ");
sleep(pID + "#Sleeping at backup service", 4000);
- gm.checkExceptionStatus();
+ guardianGroup.checkExceptionStatus();
applyUpdate();
@@ -223,15 +226,15 @@ public class NodeImpl implements Node, TestInterface {
} catch (ApplyUpdateFailureException ex) {
System.out.println(pID + "# Exception captured!: ApplyUpdateFailureException");
- gm.gthrow(new BackupFailedException(), null);
+ guardianGroup.gthrow(new BackupFailedException(), null);
} finally {
- gm.removeContext();
+ guardianGroup.removeContext();
}
}
}
public String getID() {
- return gm.getParticipantIdentifier();
+ return this.pID;
}
private void sleep(String msg, int millis) {
diff --git a/sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/concurrentExceptions/Launch.java b/sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/concurrentExceptions/Launch.java
index ab0c21dba6..169f8e50d4 100644
--- a/sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/concurrentExceptions/Launch.java
+++ b/sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/concurrentExceptions/Launch.java
@@ -32,24 +32,28 @@ public class Launch {
System.out.println("Starting participat1...");
Node c = scaDomain.getService(Node.class, "Participant1");
+ c.setID("Participant1");
c.execute();
System.in.read();
System.out.println("Starting participant2...");
Node c2 = scaDomain.getService(Node.class, "Participant2");
+ c2.setID("Participant2");
c2.execute();
System.in.read();
System.out.println("Starting participant3...");
Node c3 = scaDomain.getService(Node.class, "Participant3");
+ c3.setID("Participant3");
c3.execute();
System.in.read();
System.out.println("Starting participant4...");
Node c4 = scaDomain.getService(Node.class, "Participant4");
+ c4.setID("Participant4");
c4.execute();
System.in.read();
diff --git a/sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/simple/Launch.java b/sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/simple/Launch.java
index 86df9bc5f9..1206d45db2 100644
--- a/sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/simple/Launch.java
+++ b/sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/simple/Launch.java
@@ -32,12 +32,14 @@ public class Launch {
System.out.println("Starting participat1...");
Node c = scaDomain.getService(Node.class, "Participant1");
+ c.setID("Participant1");
c.execute();
System.in.read();
System.out.println("Starting participant2...");
Node c2 = scaDomain.getService(Node.class, "Participant2");
+ c2.setID("Participant2");
c2.execute();
System.in.read();
diff --git a/sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/simple/Launch2.java b/sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/simple/Launch2.java
index 1c5fd26745..e08251e07a 100644
--- a/sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/simple/Launch2.java
+++ b/sandbox/dougsleite/implementation-guardian/src/test/java/org/apache/tuscany/sca/implementation/guardian/itests/primaryBackup/simple/Launch2.java
@@ -32,12 +32,14 @@ public class Launch2 {
System.out.println("Starting participat1...");
Node c = scaDomain.getService(Node.class, "Participant1");
+ c.setID("Participant1");
c.execute();
System.in.read();
System.out.println("Starting participant2...");
Node c2 = scaDomain.getService(Node.class, "Participant2");
+ c2.setID("Participant2");
c2.execute();
System.in.read();