How to send results from agent to java application

Hello

I have been working on a java agent using JVMTI. The next thing that I would like to do is instead of having the output sent to stdout, I would like to have it sent to a java application.

I have been going through Sheng Liang抯 book on JNI, and have seen that to call a java method you need a reference to a jobect. This is where I have become stuck.

So far, what I have done is in a java application, I have a native method called initialize. The first thing my java application does is call this. Then, in my native implementation of initialize, I save the reference of the jobject that is passed along. I then use Runtime.getRuntime ?. to execute a bat file that executes java application with my agent. This doesn抰 seem to be working!!!

Are there any other ways I can approach this?

Thanks

Sajid

[847 byte] By [SajidTendulkara] at [2007-10-2 23:06:05]
# 1

A lot of tools use a socket connection between the agent and "tool font-end". In many cases the transport configuration is passed into the agent via the options string - eg: something like a port number. Then the font-end connects to the agent's port. To get this to work means you need to have socket code in the agent. If you are developing a java agent (meaning you are developing it in the Java Language and using java.lang.instrument) then you can use the networking or NIO APIs. If your agent is in native code and using JVMTI then you'll need to do the native socket code yourself.

alan.batemana at 2007-7-14 6:20:05 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 2

I'm not sure exactly what you are trying to do, but jdb, the simple command line debugger included in the JDK, captures the debuggee's output and error streams and writes them to jdb's output stream.If you want to see how it does this, the source code is in the JDK in file

<JDK>/demo/jpda/examples.jar

Look in file

com/sun/tools/example/debug/tty/VMConnection.java

Check out method displayRemoteOutput and its associated methods.

HTH

- jjh

JimHolmlunda at 2007-7-14 6:20:05 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 3

Hello

Thank you for your reply. Yeah, I have heard about how some agents use sockets, and as I am writing a Native agent, I think I will take this approach too. Also, as I have to develop on Windows, I have started to look into how to use WinSock. I don抰 have too much experience with sockets, but I am thinking that non-blocking sockets maybe the way to do things, do you agree?

Thanks

Sajid

SajidTendulkara at 2007-7-14 6:20:05 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...