Vertx-sync: What is the right way to use fiberhandlers?

1,045 views
Skip to first unread message

philip...@googlemail.com

unread,
Jun 30, 2016, 3:33:13 AM6/30/16
to vert.x
Hi,

Consider this scenario:

We have two consumers "consumer1" and "consumer2".
Before consumer1 sends a reply to a received message, it sends a message to consumer2 and awaits its result.
For complicated reasons, i need to implement this in the synchronous way using vertx-sync.

However, i do not manage to correctly use instrumentation. At least this is what my java VM tells me....
So maybe i misunderstand how to use fiberhandlers...?

I implemented the following minimal example:

package com.lab.de;

import static io.vertx.ext.sync.Sync.awaitResult;
import static io.vertx.ext.sync.Sync.fiberHandler;


import co.paralleluniverse.fibers.Suspendable;
import io.vertx.core.eventbus.Message;

import io.vertx.core.json.JsonObject;

public class myVerticle extends io.vertx.ext.sync.SyncVerticle {
   
String ADDRESS1 = "myAddress1";
   
String ADDRESS2 = "myAddress2";
   
   
@Override
   
@Suspendable
   
public void start() {
        listenForMessages
();
        vertx
.setTimer(1000, tid -> {sendInitialMessage(); });
   
}

   
private void sendInitialMessage() {
        vertx
.eventBus().send(ADDRESS1, "myRequest");
   
}

   
@Suspendable
   
private void listenForMessages() {
        vertx
.eventBus().consumer(ADDRESS1, fiberHandler((Message<JsonObject> msg) -> {
           
System.out.println("Received Message on " + ADDRESS1);
           
           
Message<String> reply = null;
           
try {
                reply
= awaitResult(h -> vertx.eventBus().send(ADDRESS2, "myMessageContent",h),10*1000);
           
} catch(Exception e) {
               
System.err.println("Did not Receive any reply: " + e.getMessage());
               
return;
           
}
           
System.out.println("received Reply: " + reply.body());
       
}));
       
        vertx
.eventBus().consumer(ADDRESS2, fiberHandler((Message<String> msg) -> {
           
System.out.println("Received Message on " + ADDRESS2);
            msg
.reply("myReplyString");
       
}));
       
   
}

}




When running the code (using io.vertx.core.Starter as the Main class and quasar-core-0.7.3-jdk8.jar as the javaagent), i end up with the following output:



Jun 30, 2016 9:25:08 AM io.vertx.core.Starter
INFO
: Succeeded in deploying verticle
Received Message on myAddress1
WARNING
: Uninstrumented methods (marked '**') or call-sites (marked '!!') detected on the call stack:
    at co
.paralleluniverse.common.util.ExtendedStackTrace.here (ExtendedStackTrace.java:44 bci: 8)
    at co
.paralleluniverse.fibers.Fiber.checkInstrumentation (Fiber.java:1618 bci: 0)
    at co
.paralleluniverse.fibers.Fiber.verifySuspend (Fiber.java:1591 bci: 6)
    at co
.paralleluniverse.fibers.Fiber.verifySuspend (Fiber.java:1586 bci: 3)
    at co
.paralleluniverse.fibers.Fiber.park (Fiber.java:583 bci: 0)
    at co
.paralleluniverse.fibers.Fiber.park (Fiber.java:587 bci: 4)
    at co
.paralleluniverse.fibers.FiberAsync.run(long,java.util.concurrent.TimeUnit) (FiberAsync.java:186 bci: 291)
    at io
.vertx.ext.sync.Sync.awaitResult(java.util.function.Consumer,long) (Sync.java:74 bci: 154)
    at com
.lab.de.myVerticle.lambda$1(io.vertx.core.eventbus.Message) (myVerticle.java:34 bci: 36) **
    at io
.vertx.ext.sync.Sync.lambda$null$19031fba$1 (Sync.java:148 bci: 2) (optimized)
    at co
.paralleluniverse.strands.SuspendableUtils$VoidSuspendableCallable.run (SuspendableUtils.java:44 bci: 4)
    at co
.paralleluniverse.strands.SuspendableUtils$VoidSuspendableCallable.run (SuspendableUtils.java:32 bci: 1)
    at co
.paralleluniverse.fibers.Fiber.run (Fiber.java:1024 bci: 11)
    at co
.paralleluniverse.fibers.Fiber.run1 (Fiber.java:1019 bci: 1)
Did not Receive any reply: Oops. Forgot to instrument a method. Run your program with -Dco.paralleluniverse.fibers.verifyInstrumentation=true to catch the culprit!



What i get from this is that line 34 (which is the call to awaitResult) from the method listenForMessages is not instrumented, right?
And this is what puzzles me. It is called from a fiberHandler (which - according to the API - claims to be @Instrumented and @Suspendable).


So, what did i wrong? Don't i use fiberHandlers the right way?


Best,
Philip


Alexandru Ardelean

unread,
Jul 3, 2016, 4:49:02 AM7/3/16
to vert.x
I am getting the same now. I remember it working fine in 3.1.0, but maybe I am wrong...
I am also interested what am I doing wrong. 

Julien Viet

unread,
Jul 3, 2016, 6:08:49 AM7/3/16
to ve...@googlegroups.com
can one of you make a reproducer ? so someone else can try

 
    at co
.paralleluniverse.common.util.ExtendedStackTrace.here (ExtendedStackTrace.java:44bci: 8)

    at co
.paralleluniverse.fibers.Fiber.checkInstrumentation (Fiber.java:1618 bci: 0)
    at co
.paralleluniverse.fibers.Fiber.verifySuspend (Fiber.java:1591 bci: 6)
    at co
.paralleluniverse.fibers.Fiber.verifySuspend (Fiber.java:1586 bci: 3)
    at co
.paralleluniverse.fibers.Fiber.park (Fiber.java:583 bci: 0)
    at co
.paralleluniverse.fibers.Fiber.park (Fiber.java:587 bci: 4)

    at co
.paralleluniverse.fibers.FiberAsync.run(long,java.util.concurrent.TimeUnit)(FiberAsync.java:186 bci: 291)

    at io
.vertx.ext.sync.Sync.awaitResult(java.util.function.Consumer,long) (Sync.java:74 bci:154)
    at com
.lab.de.myVerticle.lambda$1(io.vertx.core.eventbus.Message) (myVerticle.java:34 bci:36) **
    at io
.vertx.ext.sync.Sync.lambda$null$19031fba$1 (Sync.java:148 bci: 2) (optimized)
    at co
.paralleluniverse.strands.SuspendableUtils$VoidSuspendableCallable.run (SuspendableUtils.java:44 bci: 4)
    at co
.paralleluniverse.strands.SuspendableUtils$VoidSuspendableCallable.run (SuspendableUtils.java:32 bci: 1)
    at co
.paralleluniverse.fibers.Fiber.run (Fiber.java:1024 bci: 11)
    at co
.paralleluniverse.fibers.Fiber.run1 (Fiber.java:1019 bci: 1)
Did not Receive any reply: Oops. Forgot to instrument a method. Run your program with -Dco.paralleluniverse.fibers.verifyInstrumentation=true to catch the culprit!



What i get from this is that line 34 (which is the call to awaitResult) from the method listenForMessages is not instrumented, right?
And this is what puzzles me. It is called from a fiberHandler (which - according to the API - claims to be @Instrumented and @Suspendable).


So, what did i wrong? Don't i use fiberHandlers the right way?


Best,
Philip



-- 
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/0177463f-4ab3-41ec-948d-dc32d2fda092%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

philip...@googlemail.com

unread,
Jul 4, 2016, 3:08:18 AM7/4/16
to vert.x
I've created a project GitHub.

Just do the following to reproduce the error:

git clone https://github.com/wette/fiberHandler-example.git
cd fiberHandler
-example
mvn
package
java
-javaagent:quasar-core-0.7.5-jdk8.jar -jar target/myVerticle-0.0.1-SNAPSHOT-fat.jar



It results in the following output:

$ java -javaagent:quasar-core-0.7.5-jdk8.jar -jar target/myVerticle-0.0.1-SNAPSHOT-fat.jar
Jul 04, 2016 9:06:15 AM io.vertx.core.impl.launcher.commands.VertxIsolatedDeployer

INFO
: Succeeded in deploying verticle
Received Message on myAddress1
Did not Receive any reply: Oops. Forgot to instrument a method. Run your program with -Dco.paralleluniverse.fibers.verifyInstrumentation=true to catch the culprit!

stream liu

unread,
Jul 4, 2016, 4:24:59 AM7/4/16
to ve...@googlegroups.com
Hi
I suspect the reason is that "Jul 04, 2016 3:29:27 PM io.vertx.core.impl.launcher.commands.VertxIsolatedDeployer".
This will make another ClassLoadder to load your jar, do you can try your example without fatjar?

philip...@googlemail.com

unread,
Jul 4, 2016, 4:36:39 AM7/4/16
to vert.x
Running the code using a fat jar has the same effect as running without a fat jar.

I didn't look into this, but io.vertx.core.impl.launcher.commands.VertxIsolatedDeployer seems to be used whenever the verticle is started using the Launcher. When starting the verticle with the Starter there is no output related to io.vertx.core.impl.launcher.commands.VertxIsolatedDeployer.

However, no matter how you start the verticle (with/without fatjar; Launcher/Starter; cluster mode / no cluster mode) the outcome is still the same: It says "Oops. Forgot to instrument a method."

stream liu

unread,
Jul 4, 2016, 5:06:53 AM7/4/16
to ve...@googlegroups.com
I try to make it work on IDE and add a main method.

public static void main(String[] args) {
Vertx vertx = Vertx.vertx();
vertx.deployVerticle(new MyVerticle());
}

you have to add VM options manually to the run option for quasar-core.jar and i get output:

Received Message on myAddress1
Received Message on myAddress2
received Reply: myReplyString
 

philip...@googlemail.com

unread,
Jul 4, 2016, 7:09:30 AM7/4/16
to vert.x
I tried that, too. But i still get the Exception.

Which versions of vert.x, java, and quasar are you using?

For me it is
java version "1.8.0_92"
Java(TM) SE Runtime Environment (build 1.8.0_92-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.92-b14, mixed mode)

Vertex 3.3
quasar-core-0.7.5-jdk8.jar

and i run all of this on Windows 7.

stream liu

unread,
Jul 6, 2016, 3:21:22 AM7/6/16
to ve...@googlegroups.com

vertx3.3.0

quasar 0.7.5-jdk8

java version "1.8.0_91"

Java(TM) SE Runtime Environment (build 1.8.0_91-b14)

Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)

Mac OS


Did you run it on IDEA?

philip...@googlemail.com

unread,
Jul 6, 2016, 4:40:37 AM7/6/16
to vert.x
I did use Eclipse.

stream liu

unread,
Jul 6, 2016, 5:18:44 AM7/6/16
to ve...@googlegroups.com

Well, i think eclipse also could work.

Inline image 2

and run this project with Main method i get output:

Inline image 3

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.

stream liu

unread,
Jul 7, 2016, 5:09:41 AM7/7/16
to ve...@googlegroups.com
Hi philip
i create repo for test your case, and which not deps any IDE, so you can test it just with mvn cmd.

philip...@googlemail.com

unread,
Jul 14, 2016, 3:38:44 AM7/14/16
to vert.x
Hi Liu,

thanks for sharing the code!
I tried that on my Windows machine and it works as expected.

Using your code (actually your pom), I was able to fix my code.
What actually did the trick was using the quasar-maven-plugin to do offline instrumentation (instead of using the java-agent for online instrumentation)

So I added the following to my pom, and it all worked great.

Maybe this issue should be explained more prominent on http://vertx.io/docs/vertx-sync/java/#_instrumentation ?

        <plugin>
           
<groupId>com.vlkan</groupId>
           
<artifactId>quasar-maven-plugin</artifactId>
           
<version>0.7.3</version>
           
<configuration>
               
<check>true</check>
               
<debug>true</debug>
               
<verbose>true</verbose>
           
</configuration>
           
<executions>
               
<execution>
                   
<goals>
                       
<goal>instrument</goal>
                   
</goals>
               
</execution>
           
</executions>
           
<dependencies>
               
<!--
                    override the internal dependency to use the same quasar version as the one used by vert.x sync, it
                    works until they change the API.
                -->

               
<dependency>
                   
<groupId>co.paralleluniverse</groupId>
                   
<artifactId>quasar-core</artifactId>
                   
<version>0.7.5</version>
               
</dependency>
           
</dependencies>
       
</plugin>
Reply all
Reply to author
Forward
0 new messages