What's new? | Help | Directory | Sign in
Google
                
Search
for
Updated Jul 17, 2007 by aviad.infomancers
Labels: Phase-Deploy, Featured
Requirements  
What's required to get the project running

ObjectWeb's ASM

An open source project by an open source consortium.

Java 5 or higher

No reason why not upgrade to Java 5, really. Or 6, for that matter.

So, download it now from here.

Using the -javaagent flag

To make the magic work, you need to specifiy the yielder.jar in your classpath (using the -classpath flag) and specify the jar as an instrumentation agent using the -javaagent flag. So, your application should load like this (supposing you only have the yielder.jar to load:)

java -cp lib/yielder.jar -javaagent:lib/yielder.jar com.mycompany.MyApp

Comment by sujit....@comcast.net, Jan 20, 2008

Hi, great stuff, thanks for doing it and sharing. I was trying to build an iterable Resultset, so using the yielder, my code looks like this:

public Iterable<String> getNames() {
DataSource? ds = new DriverManagerDataSource?(...); Connection conn = ds.getConnection(); PreparedStatement? ps = conn.prepareStatement("select name from mytable"); final ResultSet? rs = ps.executeQuery(); Iterable<String> names = new Yielder<String>() {
public void yieldNextCore() {
try {
while (rs.next()) {
String name = rs.getString(1); log.debug("yield return " + name); yieldReturn(name);
} log.debug("yield break"); yieldBreak();
} catch (SQLException e) {
log.debug("sqlexception:", e);
} finally {
try {rs.close();} catch (SQLException e) {} yieldBreak();
}
}
}; return names;
}

and in another method (this is within a JUnit test), I have:

@Test public void testIteration() throws Exception {
for (String name : getNames()) {
log.debug("name=" + name);
}
}

I have the javaagent setup in my surefire-test-plugin, like so:

<plugin>
<groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.3</version> <configuration>
<trimStackTrace>false</trimStackTrace> <maven.junit.jvmargs>-Xmx2048m -javaagent:/home/sujit/.m2/repository/com/infomancers/collections/yielder/0.2.2/yielder-0.2.2.jar -verbose</maven.junit.jvmargs>
</configuration>
</plugin>

Now when I run the test, I see that the log statements inside the iterable (before yieldReturn and yieldBreak are being shown), but I dont see any of the name= log messages in the calling loop. If I comment out the loop in testIteration and just make a single call to getNames(), then no log messages show up, which is as I expect. So I am doing something wrong on the yieldReturn call.

I am using yielder-0.2.2.jar (the latest on the Google code repository).

If you could point me to what I am doing wrong, I would really appreciate it.

Thanks very much, Sujit


Sign in to add a comment