This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
[RFA/JDWP] JdwpConnection cleanup
- From: Keith Seitz <keiths at redhat dot com>
- To: GCJ Patches <java-patches at gcc dot gnu dot org>
- Cc: classpath patches <classpath-patches at gnu dot org>
- Date: Mon, 27 Jun 2005 11:17:31 -0700
- Subject: [RFA/JDWP] JdwpConnection cleanup
Hi,
I believe the attached patch addresses concerns over temporary
OutputStream allocations.
The changes in this patch are reflected in
gnu.classpath.jdwp.event.Event submission.
Comments/questions/concerns?
Keith
ChangeLog
* gnu/classpath/jdwp/transport/JdwpConnection.java (sendPacket): Rename
to ...
(send): ... this.
(send): New overloaded method for sending Events.
Index: gnu/classpath/jdwp/transport/JdwpConnection.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/classpath/jdwp/transport/JdwpConnection.java,v
retrieving revision 1.1
diff -u -p -r1.1 JdwpConnection.java
--- gnu/classpath/jdwp/transport/JdwpConnection.java 7 Jun 2005 01:18:02 -0000 1.1
+++ gnu/classpath/jdwp/transport/JdwpConnection.java 27 Jun 2005 18:11:40 -0000
@@ -40,7 +40,10 @@ exception statement from your version. *
package gnu.classpath.jdwp.transport;
import gnu.classpath.jdwp.Jdwp;
+import gnu.classpath.jdwp.event.Event;
+import gnu.classpath.jdwp.event.EventRequest;
+import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
@@ -64,7 +67,8 @@ public class JdwpConnection
extends Thread
{
// The JDWP handshake
- private static final byte[] _HANDSHAKE = {'J', 'D', 'W', 'P', '-', 'H', 'a', 'n', 'd', 's', 'h', 'a', 'k', 'e'};
+ private static final byte[] _HANDSHAKE = {'J', 'D', 'W', 'P', '-', 'H', 'a',
+ 'n', 'd', 's', 'h', 'a', 'k', 'e'};
// Transport method
private ITransport _transport;
@@ -81,6 +85,12 @@ public class JdwpConnection
// Output stream from transprot
private DataOutputStream _outStream;
+ // A buffer used to construct the packet data
+ private ByteArrayOutputStream _bytes;
+
+ // A DataOutputStream for the byte buffer
+ private DataOutputStream _doStream;
+
/**
* Creates a new <code>JdwpConnection</code> instance
*
@@ -91,6 +101,8 @@ public class JdwpConnection
_transport = transport;
_commandQueue = new ArrayList ();
_shutdown = false;
+ _bytes = new ByteArrayOutputStream ();
+ _doStream = new DataOutputStream (_bytes);
}
/**
@@ -241,9 +253,9 @@ public class JdwpConnection
* Send a packet to the debugger
*
* @param pkt a <code>JdwpPacket</code> to send
- * @throws TransportException
+ * @throws IOException
*/
- public void sendPacket (JdwpPacket pkt)
+ public void send (JdwpPacket pkt)
throws IOException
{
byte[] data = pkt.toBytes ();
@@ -251,6 +263,28 @@ public class JdwpConnection
}
/**
+ * Send an event notification to the debugger
+ *
+ * @param request the debugger request that wanted this event
+ * @param event the event
+ * @throws IOException
+ */
+ public void send (EventRequest request, Event event)
+ throws IOException
+ {
+ JdwpPacket pkt;
+
+ synchronized (_bytes)
+ {
+ _bytes.reset ();
+ pkt = event.toPacket (_doStream, request);
+ pkt.setData (_bytes.toByteArray ());
+ }
+
+ send (pkt);
+ }
+
+ /**
* Shutdown the connection
*/
public void shutdown ()