Skip to content

Commit

Permalink
This commit requires a manual recompile of intrace-agent.jar to get t…
Browse files Browse the repository at this point in the history
…his change: mchr3k/org.intrace#31
  • Loading branch information
eostermueller committed May 17, 2014
1 parent 7d1444c commit 838adcd
Show file tree
Hide file tree
Showing 30 changed files with 718 additions and 61 deletions.
Binary file modified agent-lib/intrace-agent.jar
Binary file not shown.
Binary file removed bin/agent-lib/intrace-agent.jar
Binary file not shown.
8 changes: 4 additions & 4 deletions bin/examplesStart.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ mvn -f $(dirname $0)/../pom.xml \
-Dintrace.test.class=example.FirstTraceExample \
antrun:run 1> out.1 2>&1 &

sleep 2
sleep 5

mvn -f $(dirname $0)/../pom.xml \
-Dintrace.test.class=example.SecondTraceExample \
antrun:run &
antrun:run 1> out.2 2>&1 &

sleep 2
sleep 5

pushd $(dirname $0)/../example.webapp

mvn antrun:run &
mvn antrun:run 1> out.3 2>&1 &
3 changes: 2 additions & 1 deletion bin/runOneTest.sh
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
mvn -Dtest=TestRequestEventCollection test
#mvn -Dtest=TestRequestEventCollection test
mvn -Dtest=org.intrace.client.test.level2.connection.InterfaceTracingTest test
2 changes: 1 addition & 1 deletion example.webapp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
<!--
<jvmarg value="-javaagent:../agent-lib/intrace-agent.jar=[serverport-9125[gzip-true"/>
-->
<jvmarg value="-javaagent:/Users/erikostermueller/Documents/src/jsource/inTrace_compressed/etogit/org.intrace/org.intrace/build/jars/intrace-agent.jar=[serverport-9125[gzip-true[exit-stack-trace-true"/>
<jvmarg value="-javaagent:/Users/erikostermueller/Documents/src/jsource/inTraceInterface/org.intrace-master/org.intrace/build/jars/intrace-agent.jar=[serverport-9125[gzip-true[exit-stack-trace-true[callbackport-33000"/>

</java>
</target>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package example.webapp.servlet;
import java.io.*;
import java.sql.Timestamp;

import javax.servlet.*;
import javax.servlet.http.*;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import example.webapp.dao.interfaces.EventDao;
import example.webapp.entity.Event;
import example.webapp.entity.Location;

public class HelloExecuteQuery extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
//ServletContext sc = (ServletContext) WebApplicationContextUtils.getWebApplicationContext();
WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());

EventDao eventDao = (EventDao) ctx.getBean("eventDao");

int count = eventDao.countAll();

response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>Hello World!</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Hello World!</h1>");
out.println("Event count [" + count + "]");
out.println("</body>");
out.println("</html>");


}

}
9 changes: 9 additions & 0 deletions example.webapp/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
<servlet-name>HelloServlet</servlet-name>
<servlet-class>example.webapp.servlet.HelloWorld</servlet-class>
</servlet>
<servlet>
<servlet-name>HelloExecuteQuery</servlet-name>
<servlet-class>example.webapp.servlet.HelloExecuteQuery</servlet-class>
</servlet>

<servlet>
<servlet-name>applicationContext</servlet-name>
Expand All @@ -27,6 +31,11 @@
<url-pattern>/hello</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>HelloExecuteQuery</servlet-name>
<url-pattern>/helloExecuteQuery</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>applicationContext</servlet-name>
<url-pattern>/</url-pattern>
Expand Down
4 changes: 3 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma
<url>http://maven.apache.org</url>
<build>
<plugins>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
Expand All @@ -24,7 +25,8 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma
<java fork="true" classname="${intrace.test.class}"
classpathref="maven.test.classpath">
<arg value="10" />
<jvmarg value="-javaagent:agent-lib/intrace-agent.jar=[regex-example[gzip-true" />
<!-- <jvmarg value="-javaagent:agent-lib/intrace-agent.jar=[regex-example[gzip-true[verbose-true" /> -->
<jvmarg value="-javaagent:agent-lib/intrace-agent.jar=[verbose-true" />
</java>
</target>
</configuration>
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/example/FirstTraceExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public static void otherMain(String arg) throws Exception
{
while (true)
{
interfaceTest();
Thread.sleep(Long.parseLong(arg));
workMethod("foobar");
}
Expand All @@ -45,9 +46,16 @@ private static void workMethod(String foo)
{
System.setProperty("a", "Odd time");
}
interfaceTest();
}

private static String exceptionMethod()
private static void interfaceTest() {
MyTestInterface mti = new MyFirstTestImplementor();
mti.foo();

}

private static String exceptionMethod()
{
try
{
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/example/MyFirstTestImplementor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package example;

public class MyFirstTestImplementor implements MyTestInterface {

@Override
public void foo() {
// TODO Auto-generated method stub

}

}
6 changes: 6 additions & 0 deletions src/main/java/example/MyTestInterface.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package example;

public interface MyTestInterface {

void foo();
}
33 changes: 31 additions & 2 deletions src/main/java/org/intrace/client/DefaultFactory.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package org.intrace.client;

import org.intrace.client.connection.DefaultCallback;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

import org.intrace.client.connection.DefaultCallback;
import org.intrace.client.connection.DefaultConnection;
import org.intrace.client.connection.DefaultTraceEventWriterImpl;
import org.intrace.client.connection.IConnection;
Expand Down Expand Up @@ -101,6 +105,9 @@ public ITraceWriter getTraceWriter() {

@Override
public IConnection getDormantConnection() {
DefaultConnection d = new DefaultConnection();
System.out.println(" $$$ in factory #################################");
System.out.println(d.toString());
return new DefaultConnection();
}

Expand All @@ -122,6 +129,28 @@ public IRequest getRequest() {
public IConnectionStateCallback getCallback() {
return new DefaultCallback();
}
public static void log(String msg) {
FileWriter fw = null;
try {
File output = new File("/tmp/InTrace.txt");
fw = new FileWriter(output,true);
fw.append(msg);

} catch (Exception e) {
e.printStackTrace();
} finally {
if (fw!=null)
try {
fw.flush();
fw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}


}


}
17 changes: 12 additions & 5 deletions src/main/java/org/intrace/client/connection/ConnectionDetail.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,22 @@ void executeStartupCommands() {
@Override
public String toString() {
StringBuilder sb = new StringBuilder();


sb.append("getConnectState[" + getConnectState() + "]\n");
sb.append("isConnected [" + this.isConnected() + "]\n");
sb.append("getConnCallbacks.size [" + getConnCallbacks().size() + "]");
sb.append("Connection state [" + this.m_connectState + "]\n");
if (m_remoteAddress!=null) {
sb.append(m_remoteAddress.getCanonicalHostName()).append("-->CanonicalHostName\n");
sb.append(m_remoteAddress.getHostAddress()).append("-->HostAddress\n");
sb.append(m_remoteAddress.isLinkLocalAddress()).append("-->isLinkLocal\n");
}

if (getControlThread()!=null)
sb.append("control thread [" + getControlThread().toString() + "]\n");

if (this.getNetworkTraceThread2()!=null)
sb.append("trace thread [" + this.getNetworkTraceThread2().toString() + "]\n");

return sb.toString();
}

Expand Down Expand Up @@ -156,7 +163,8 @@ public void setConfig(Map<String, String> settingsMap) {
*/
@Override
public void disconnect() {
getNetworkTraceThread2().requestDisconnect();
if (getNetworkTraceThread2()!=null)
getNetworkTraceThread2().requestDisconnect();
//throw new UnsupportedOperationException(ClientStrings.HARD_DISSCONNECT_NO_LONGER_SUPPORTED);

//ControlConnectionThread#run is calling the above method, so can't throw the above exception quite yet.
Expand Down Expand Up @@ -223,7 +231,7 @@ public boolean isConnected() {
* Why do we have ConnectionPartOne and ConnectionPartTwo?
* There is a hand off, and it happens right here.
* Once ConnectionPartOne is finished with it's business,
* it invokes this setCocket() method.
* it invokes this setSocket() method.
*/
public void setSocket(Socket socket) {
if (socket != null)
Expand All @@ -233,7 +241,6 @@ public void setSocket(Socket socket) {
m_controlThread = new DebugControlConnectionThread(socket, this);
m_controlThread.start();
executeStartupCommands();
// m_controlThread.sendMessage(AgentConfigConstants.INSTRU_ENABLED+"true");
m_controlThread.sendMessage("getsettings");

m_controlThread.sendMessage("[out-network");
Expand Down
22 changes: 17 additions & 5 deletions src/main/java/org/intrace/client/connection/DefaultCallback.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,28 +45,40 @@ public void setConnectState(ConnectState state) {
}

/**
* Need to learn how to use this. Is it even useful?
* org/intrace/agent/ClassTransformer.java (part of agent code) drives the traffic to this method.
* If you place this line of code in the method:
* <pre>
System.out.println("DefaultCallback.setProgress() [" + progress.toString() + "]");
<pre>
...then you'll get output that looks like this:
<pre>
DefaultCallback.setProgress() [{NUM_PROGRESS_COUNT=2700, NUM_PROGRESS_ID=NUM_PROGRESS_ID, NUM_PROGRESS_TOTAL=2740}]
DefaultCallback.setProgress() [{NUM_PROGRESS_COUNT=2710, NUM_PROGRESS_ID=NUM_PROGRESS_ID, NUM_PROGRESS_TOTAL=2740}]
DefaultCallback.setProgress() [{NUM_PROGRESS_COUNT=2720, NUM_PROGRESS_ID=NUM_PROGRESS_ID, NUM_PROGRESS_TOTAL=2740}]
DefaultCallback.setProgress() [{NUM_PROGRESS_COUNT=2730, NUM_PROGRESS_ID=NUM_PROGRESS_ID, NUM_PROGRESS_TOTAL=2740}]
DefaultCallback.setProgress() [{NUM_PROGRESS_DONE=true, NUM_PROGRESS_ID=NUM_PROGRESS_ID, NUM_PROGRESS_TOTAL=2740, NUM_PROGRESS_COUNT=2740}]
</pre>
*/
@Override
public void setProgress(Map<String, String> progress) {
// TODO Auto-generated method stub


}

/**
* Need to learn how to use this. Is it even useful?
*/
@Override
public void setStatus(Map<String, String> progress) {
// TODO Auto-generated method stub


}
/**
* Need to learn how to use this. Is it even useful?
*/
@Override
public void setConfig(Map<String, String> progress) {
// TODO Auto-generated method stub


}

Expand Down
34 changes: 34 additions & 0 deletions src/main/java/org/intrace/client/connection/DefaultConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,28 @@ public class DefaultConnection implements IConnection {
ConnectionDetail getConnectionDetail() {
return m_connDetail;
}

@Override
public String[] getModifiedClasses() {
String modifiedClassesUnparsed = null;
getConnectionDetail().getControlThread().sendMessage("[listmodifiedclasses");
modifiedClassesUnparsed = getConnectionDetail().getControlThread().getMessage();

if (modifiedClassesUnparsed!=null && modifiedClassesUnparsed.length() >= 2) {
if (modifiedClassesUnparsed.charAt(modifiedClassesUnparsed.length()-1)==']')
modifiedClassesUnparsed = modifiedClassesUnparsed.substring(0, modifiedClassesUnparsed.length()-1);
if (modifiedClassesUnparsed.charAt(0)=='[')
modifiedClassesUnparsed = modifiedClassesUnparsed.substring(1);
}

String[] rc = null;
if ("".equals(modifiedClassesUnparsed.trim()) )
rc = null;
else
rc = modifiedClassesUnparsed.trim().split("\\s*,[,\\s]*");

return rc;
}
@Override
public int getConnCallbackSize() {
return getConnectionDetail().getConnCallbacks().size();
Expand Down Expand Up @@ -176,7 +198,10 @@ public void setHostPort(HostPort hostPort) {
public void disconnect() {
IConnectionList connectionList = DefaultConnectionList.getSingleton();
//IConnection cpt = connectionList.locateConnection(m_hostPort);

try {
this.getConnectionDetail().disconnect();
//this.getNetworkTraceThread2().disconnect();
connectionList.disconnect(this, getMasterCallback());
} catch(DisconnectionException de) {
//Since our goal is to disconnect, no need to do anything with the exception.
Expand Down Expand Up @@ -249,4 +274,13 @@ public void executeStartupCommands() {
public NetworkDataReceiverThread2 getNetworkTraceThread2() {
return getConnectionDetail().getNetworkTraceThread2();
}
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("hash [" + this.hashCode() + "]\n");
sb.append("isConnected [" + isConnected() + "]\n");
sb.append("count of callbacks [" + getConnCallbackSize() + "]");
if (this.getConnectionDetail() !=null)
sb.append("detail [" + this.getConnectionDetail().toString() + "]\n");
return sb.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public int disconnect(IConnection conn, IConnectionStateCallback connectionCallb
if (conn==null) {
throw new RuntimeException("Don't support null connections");
}

int numRemainingCallbacks = conn.removeConnectionStatusCallback(connectionCallback); // disconnect is called downstream, but only if no other callbacks are registered.

if (numRemainingCallbacks > 0) {
Expand Down
Loading

0 comments on commit 838adcd

Please sign in to comment.