From 698169c4ee4fd2511cabf257ac97a3805930b1fc Mon Sep 17 00:00:00 2001 From: dougsleite Date: Tue, 21 Jul 2009 17:45:18 +0000 Subject: - 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 --- .../itests/primaryBackup/common/NodeImpl.java | 112 +++++++++++++-------- .../itests/primaryBackup/simple/Launch3.java | 63 ------------ 2 files changed, 68 insertions(+), 107 deletions(-) delete mode 100644 sandbox/dougsleite/guardian-model/src/test/java/org/apache/tuscany/sca/guardian/itests/primaryBackup/simple/Launch3.java (limited to 'sandbox/dougsleite/guardian-model/src/test') 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 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(); - } -} -- cgit v1.2.3