1 11 package org.eclipse.jdi.internal.connect; 12 13 import java.io.IOException ; 14 import java.io.InterruptedIOException ; 15 import com.ibm.icu.text.MessageFormat; 16 import java.util.LinkedList ; 17 18 import org.eclipse.jdi.internal.jdwp.JdwpPacket; 19 20 import com.sun.jdi.VMDisconnectedException; 21 import com.sun.jdi.connect.spi.Connection; 22 23 27 public class PacketSendManager extends PacketManager { 28 29 private LinkedList fOutgoingPackets; 30 31 34 public PacketSendManager(Connection connection) { 35 super(connection); 36 fOutgoingPackets = new LinkedList (); 37 } 38 39 40 public void disconnectVM() { 41 super.disconnectVM(); 42 synchronized (fOutgoingPackets) { 43 fOutgoingPackets.notifyAll(); 44 } 45 } 46 47 50 public void run() { 51 while (!VMIsDisconnected()) { 52 try { 53 sendAvailablePackets(); 54 } catch (InterruptedException e) {disconnectVM();} 57 catch (InterruptedIOException e) {disconnectVM(e);} 58 catch (IOException e) {disconnectVM(e);} 59 } 60 } 61 62 65 public void sendPacket(JdwpPacket packet) { 66 if (VMIsDisconnected()) { 67 String message; 68 if (getDisconnectException() == null) { 69 message= ConnectMessages.PacketSendManager_Got_IOException_from_Virtual_Machine_1; 70 } else { 72 String exMessage = getDisconnectException().getMessage(); 73 if (exMessage == null) { 74 message= MessageFormat.format(ConnectMessages.PacketSendManager_Got__0__from_Virtual_Machine_1, new String [] {getDisconnectException().getClass().getName()}); 75 } else { 77 message= MessageFormat.format(ConnectMessages.PacketSendManager_Got__0__from_Virtual_Machine___1__1, new String [] {getDisconnectException().getClass().getName(), exMessage}); 78 } } throw new VMDisconnectedException(message); 81 } 82 83 synchronized(fOutgoingPackets) { 84 fOutgoingPackets.add(packet); 86 fOutgoingPackets.notifyAll(); 88 } 89 } 90 91 94 private void sendAvailablePackets() throws InterruptedException , IOException { 95 LinkedList packetsToSend = new LinkedList (); 96 synchronized (fOutgoingPackets) { 97 while (fOutgoingPackets.size() == 0) { 98 fOutgoingPackets.wait(); 99 } packetsToSend.addAll(fOutgoingPackets); 101 fOutgoingPackets.clear(); 102 } 104 while (packetsToSend.size() > 0) { 106 JdwpPacket packet = (JdwpPacket)packetsToSend.removeFirst(); 108 byte[] bytes = packet.getPacketAsBytes(); 109 getConnection().writePacket(bytes); 110 } 111 } 112 } 113 | Popular Tags |