1 package gov.nasa.jpf; 20 21 25 public class VMListenerMulticaster implements VMListener 26 { 27 VMListener head; 28 VMListener tail; 29 30 public static VMListener add (VMListener oldListener, VMListener newListener) { 31 if (newListener == null) { 32 return oldListener; 33 } 34 if (oldListener == null) { 35 return newListener; 36 } 37 38 return new VMListenerMulticaster(oldListener, newListener); 41 } 42 43 public static VMListener remove (VMListener oldListener, VMListener removeListener){ 44 if (oldListener == removeListener) { 45 return null; 46 } 47 if (oldListener instanceof VMListenerMulticaster){ 48 return ((VMListenerMulticaster)oldListener).remove( removeListener); 49 } 50 51 return oldListener; 52 } 53 54 protected VMListener remove (VMListener listener) { 55 if (listener == head) { 56 return tail; 57 } 58 if (listener == tail){ 59 return head; 60 } 61 62 VMListenerMulticaster h,t; 63 if (head instanceof VMListenerMulticaster) { 64 h = (VMListenerMulticaster)head; 65 if (tail instanceof VMListenerMulticaster){ 66 t = (VMListenerMulticaster)tail; 67 return new VMListenerMulticaster( h.remove(listener),t.remove(listener)); 68 } else { 69 return new VMListenerMulticaster( h.remove(listener), tail); 70 } 71 } else if (tail instanceof VMListenerMulticaster) { 72 t = (VMListenerMulticaster)tail; 73 return new VMListenerMulticaster( head, t.remove(listener)); 74 } 75 76 return this; 77 } 78 79 80 public VMListenerMulticaster (VMListener h, VMListener t) { 81 head = h; 82 tail = t; 83 } 84 85 public void instructionExecuted (VM vm) { 86 head.instructionExecuted(vm); 87 tail.instructionExecuted(vm); 88 } 89 90 public void threadStarted (VM vm) { 91 head.threadStarted(vm); 92 tail.threadStarted(vm); 93 } 94 95 public void threadTerminated (VM vm) { 96 head.threadTerminated(vm); 97 tail.threadTerminated(vm); 98 } 99 100 public void classLoaded (VM vm) { 101 head.classLoaded(vm); 102 tail.classLoaded(vm); 103 } 104 105 public void objectCreated (VM vm) { 106 head.objectCreated(vm); 107 tail.objectCreated(vm); 108 } 109 110 public void objectReleased (VM vm) { 111 head.objectReleased(vm); 112 tail.objectReleased(vm); 113 } 114 115 public void gcBegin (VM vm) { 116 head.gcBegin(vm); 117 tail.gcBegin(vm); 118 } 119 120 public void gcEnd (VM vm) { 121 head.gcEnd(vm); 122 tail.gcEnd(vm); 123 } 124 125 public void exceptionThrown (VM vm) { 126 head.exceptionThrown(vm); 127 tail.exceptionThrown(vm); 128 } 129 130 } 131 132 | Popular Tags |