1 28 29 30 package org.objectweb.corba.runtime; 31 32 39 public class MultipleORBWorker 40 extends java.lang.Thread 41 implements MainThread 42 { 43 private org.omg.CORBA.ORB [] _orbs; 45 private Object _orbs_mutex; 46 47 public 48 MultipleORBWorker() 49 { 50 _orbs = new org.omg.CORBA.ORB [0]; 51 _orbs_mutex = new Object (); 52 } 53 54 58 private org.omg.CORBA.ORB [] 59 getORBs() 60 { 61 synchronized(_orbs_mutex) { 62 return _orbs; 63 } 64 } 65 66 private void 67 addORB(org.omg.CORBA.ORB orb) 68 { 69 synchronized(_orbs_mutex) { 70 org.omg.CORBA.ORB [] orbs = new org.omg.CORBA.ORB [_orbs.length+1]; 72 System.arraycopy(_orbs, 0, orbs, 0, _orbs.length); 73 orbs[_orbs.length] = orb; 74 75 _orbs = orbs; 77 } 78 } 79 80 private void 81 removeORB(org.omg.CORBA.ORB orb) 82 { 83 synchronized(_orbs_mutex) { 84 org.omg.CORBA.ORB [] orbs = new org.omg.CORBA.ORB [_orbs.length-1]; 86 int j=0; 87 for (int i=0;i<_orbs.length;i++) { 88 if (_orbs[i]!=orb) { 89 orbs[j++] = _orbs[i]; 90 } 91 } 92 93 _orbs = orbs; 95 } 96 } 97 98 102 final public void 103 stopORB(org.omg.CORBA.ORB orb) 104 { 105 removeORB(orb); 106 } 107 108 final public void 109 runORB(org.omg.CORBA.ORB orb) 110 { 111 addORB(orb); 112 } 113 114 final public void 115 startThread() 116 { 117 start(); 119 } 120 121 125 final public void 126 run() 127 { 128 org.omg.CORBA.ORB [] orbs; 129 while (true) { 132 orbs = getORBs(); 133 for (int i=0;i<orbs.length;i++) { 134 if (orbs[i].work_pending()) { 135 orbs[i].perform_work(); 136 } 137 } 138 } 139 } 140 } 141 | Popular Tags |