1 11 package org.eclipse.jdi.internal.event; 12 13 14 import java.io.DataInputStream ; 15 import java.io.IOException ; 16 import java.util.ArrayList ; 17 import java.util.Collection ; 18 import java.util.Iterator ; 19 import java.util.List ; 20 21 import org.eclipse.jdi.internal.MirrorImpl; 22 import org.eclipse.jdi.internal.VirtualMachineImpl; 23 import org.eclipse.jdi.internal.request.EventRequestImpl; 24 25 import com.sun.jdi.InternalException; 26 import com.sun.jdi.ThreadReference; 27 import com.sun.jdi.event.EventIterator; 28 import com.sun.jdi.event.EventSet; 29 import com.sun.jdi.request.EventRequest; 30 31 37 public class EventSetImpl extends MirrorImpl implements EventSet { 38 39 private List fEvents; 40 41 private byte fSuspendPolicy; 42 43 46 private EventSetImpl(VirtualMachineImpl vmImpl) { 47 super("EventSet", vmImpl); } 49 50 53 public EventSetImpl(VirtualMachineImpl vmImpl, EventImpl[] events) { 54 this(vmImpl); 55 fEvents = new ArrayList (events.length); 56 for (int i = 0; i < events.length; i++) 57 fEvents.add(events[i]); 58 } 59 60 63 public EventSetImpl(VirtualMachineImpl vmImpl, EventImpl event) { 64 this(vmImpl); 65 fEvents = new ArrayList (1); 66 fEvents.add(event); 67 } 68 69 72 public EventIterator eventIterator() { 73 return new EventIteratorImpl(fEvents.listIterator()); 74 } 75 76 79 public int suspendPolicy() { 80 switch(fSuspendPolicy) { 81 case EventRequestImpl.SUSPENDPOL_NONE_JDWP: 82 return EventRequest.SUSPEND_NONE; 83 case EventRequestImpl.SUSPENDPOL_EVENT_THREAD_JDWP: 84 return EventRequest.SUSPEND_EVENT_THREAD; 85 case EventRequestImpl.SUSPENDPOL_ALL_JDWP: 86 return EventRequest.SUSPEND_ALL; 87 default: 88 throw new InternalException(EventMessages.EventSetImpl_Invalid_suspend_policy_encountered___1 + fSuspendPolicy); 89 } 90 } 91 92 95 public void resume() { 96 switch(fSuspendPolicy) { 97 case EventRequestImpl.SUSPENDPOL_NONE_JDWP: 98 break; 99 case EventRequestImpl.SUSPENDPOL_EVENT_THREAD_JDWP: 100 resumeThreads(); 101 break; 102 case EventRequestImpl.SUSPENDPOL_ALL_JDWP: 103 virtualMachineImpl().resume(); 104 break; 105 default: 106 throw new InternalException(EventMessages.EventSetImpl_Invalid_suspend_policy_encountered___1 + fSuspendPolicy); 107 } 108 } 109 110 113 private void resumeThreads() { 114 if (fEvents.size() == 1) { 115 ThreadReference ref= ((EventImpl)fEvents.get(0)).thread(); 118 if (ref != null) { 119 ref.resume(); 120 } else { 121 ((EventImpl)fEvents.get(0)).virtualMachine().resume(); 122 } 123 return; 124 } 125 Iterator iter = fEvents.iterator(); 126 List resumedThreads= new ArrayList (fEvents.size()); 127 while (iter.hasNext()) { 128 EventImpl event = (EventImpl)iter.next(); 129 ThreadReference thread= event.thread(); 130 if (thread == null) { 131 event.virtualMachine().resume(); 132 return; 133 } 134 if (!resumedThreads.contains(thread)) { 135 resumedThreads.add(thread); 136 } 137 } 138 Iterator resumeIter= resumedThreads.iterator(); 139 while (resumeIter.hasNext()) { 140 ((ThreadReference)resumeIter.next()).resume(); 141 } 142 } 143 144 147 public static EventSetImpl read(MirrorImpl target, DataInputStream in) throws IOException { 148 VirtualMachineImpl vmImpl = target.virtualMachineImpl(); 149 EventSetImpl eventSet = new EventSetImpl(vmImpl); 150 151 eventSet.fSuspendPolicy = target.readByte("suspendPolicy", EventRequestImpl.suspendPolicyMap(), in); int size = target.readInt("size", in); eventSet.fEvents = new ArrayList (size); 157 158 while (size-- > 0) { 159 EventImpl event = EventImpl.read(target, in); 160 161 if (event == null) 164 continue; 165 166 EventRequestImpl request = (EventRequestImpl)event.request(); 167 168 if (request == null || !request.isGeneratedInside()) 170 eventSet.fEvents.add(event); 171 172 } 173 return eventSet; 174 } 175 176 179 public boolean contains(Object event) { 180 return fEvents.contains(event); 181 } 182 183 186 public boolean containsAll(Collection events) { 187 return fEvents.containsAll(events); 188 } 189 190 193 public boolean equals(Object object) { 194 return object != null && object.getClass().equals(this.getClass()) && fEvents.equals(((EventSetImpl)object).fEvents); 195 } 196 197 200 public int hashCode() { 201 return fEvents.hashCode(); 202 } 203 204 207 public boolean isEmpty() { 208 return fEvents.isEmpty(); 209 } 210 211 214 public Iterator iterator() { 215 return fEvents.iterator(); 216 } 217 218 221 public int size() { 222 return fEvents.size(); 223 } 224 225 228 public Object [] toArray() { 229 return fEvents.toArray(); 230 } 231 232 235 public Object [] toArray(Object [] events) { 236 return fEvents.toArray(events); 237 } 238 239 243 public boolean add(Object arg1) { 244 throw new UnsupportedOperationException (EventMessages.EventSetImpl_EventSets_are_unmodifiable_3); 245 } 246 247 251 public boolean addAll(Collection arg1) { 252 throw new UnsupportedOperationException (EventMessages.EventSetImpl_EventSets_are_unmodifiable_3); 253 } 254 255 259 public void clear() { 260 throw new UnsupportedOperationException (EventMessages.EventSetImpl_EventSets_are_unmodifiable_3); 261 } 262 263 267 public boolean remove(Object arg1) { 268 throw new UnsupportedOperationException (EventMessages.EventSetImpl_EventSets_are_unmodifiable_3); 269 } 270 271 275 public boolean removeAll(Collection arg1) { 276 throw new UnsupportedOperationException (EventMessages.EventSetImpl_EventSets_are_unmodifiable_3); 277 } 278 279 283 public boolean retainAll(Collection arg1) { 284 throw new UnsupportedOperationException (EventMessages.EventSetImpl_EventSets_are_unmodifiable_3); 285 } 286 } 287 | Popular Tags |