1 6 7 package SOFA.SOFAnet.Core; 8 9 import SOFA.SOFAnet.Repository.NodeNameList; 10 import SOFA.SOFAnet.Transport.*; 11 import java.lang.Object ; 12 import java.util.*; 13 14 20 class ReturnSharedAcceptanceTester 21 { 22 private final String bundleName; 23 private final NodeNameList clients; 24 private final TransportInterface transport; 25 26 private Object lock; 27 private int counter; 28 private final int num; 29 private int result; 30 31 private class OneNodeTester extends Thread 32 { 33 private String nodeName; 34 private int index; 35 36 OneNodeTester(String nodeName, int index) 37 { 38 this.nodeName = nodeName; 39 this.index = index; 40 } 41 42 public void run() 43 { 44 IOParams ioParams = new IOParams(); 45 ioParams.setBundleName(bundleName); 46 ioParams.setNodeName(nodeName); 47 48 boolean can = false; 49 try 50 { 51 transport.canReturnShared(ioParams); 52 if (ioParams.getErrCode() == 0) can = true; 53 } 54 catch (TransportException e) 55 { 56 can = false; 57 Reporter.warning("Accessing to SOFAnode '" + nodeName + "' failed", e); 58 } 59 60 synchronized (lock) 61 { 62 counter++; 63 if (can) result = index; 64 if (can || counter == num) lock.notify(); 65 } 66 } 67 } 68 69 75 public ReturnSharedAcceptanceTester(String bundleName, NodeNameList clients, TransportInterface transport) 76 { 77 this.bundleName = bundleName; 78 this.clients = clients; 79 this.transport = transport; 80 81 lock = new Object (); 82 counter = 0; 83 num = clients.getList().size(); 84 result = -1; 85 } 86 87 91 public int go() 92 { 93 OneNodeTester[] testers = new OneNodeTester[num]; 94 95 int i = 0; 96 Iterator it = clients.getList().iterator(); 97 while (it.hasNext()) 98 { 99 String nodeName = (String )it.next(); 100 101 testers[i] = new OneNodeTester(nodeName, i); 102 i++; 103 } 104 105 synchronized (lock) 106 { 107 for (i = 0; i < num; i++) testers[i].start(); 108 try 109 { 110 lock.wait(10000); } 112 catch (InterruptedException e) 113 { 114 } 115 116 return result; 117 } 118 } 119 120 } 121 | Popular Tags |