Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to avoid serialization when using the Vert.x eventbus 'locally' (java, single jvm)?

My case is:

  • single JVM
  • Java only (i don't need to be polyglot)
  • I don't want to pay serialization costs to publish an immutable event on the bus (publishing the reference to the java object would work).

I understand the scope of the vert.x event bus is much broader than my use case.

I had in mind a behaviour similar to akka: when you go distributed you have to provide serialization for your messages, if you stay local references get passed.

Is there anything that would allow me to do that in Vert.x?

like image 728
white-surf-style-five Avatar asked Jul 17 '18 09:07

white-surf-style-five


People also ask

What is Java serialization and how to do it?

Java serialization enables writing Java objects to file system for permanent storage or on network to transfer to other applications. Serialization in Java is achieved with Serializable interface. Java Serializable interface guarantees the ability to serialize the objects.

How do I use the eventbus in VertX?

There are at least two options of using the EventBus in Vertx: I use the Eventbus methods provided by Vertx to call functions residing on another Verticle. The upside here is that I can use Codecs to pass parameters over the Eventbus.

Is Oracle project Amber going to remove Java serialization?

Oracle is planning to eventually remove Java serialization as part of Project Amber. However, this may take a while, and it’s unlikely to be fixed in previous versions. Therefore, it is wise to avoid Java serialization as much as possible.

How to avoid serialization in sub-class of a class?

If we note output, subclass was Serializable (as subclass always inherits all features from its parent class), for avoiding Serialization in sub-class we defined writeObject () method and throwed NotSerializableException() from there. If member of class does not implement Serializable interface - than NotSerializableException is thrown.


1 Answers

Vert.x already has such an optimization. When sending to the same JVM, objects won't get serialized or deserialized.

You can see the actual code here: https://github.com/eclipse/vert.x/blob/master/src/main/java/io/vertx/core/eventbus/impl/EventBusImpl.java#L372

When you implement your MessageCodec, you actually have two methods: decodeFromWire() and transform(). You can implement only transform with the most naive approach:

@Override
public Object transform(Object o) {
   return o;
}
like image 161
Alexey Soshin Avatar answered Oct 02 '22 19:10

Alexey Soshin