Posts tagged: vert.x

Release day - Merry Christmas

Post to Twitter

Yesterday, we've released JVx 2.4, VaadinUI 1.4, HeadlessUI 1.1 and JVx vert.x 3.0.

Headless UI and JVx vert.x are maintenance updates because of JVx changes. JVx 2.4 is a bugfix release with some new cool features and VaadinUI is a performance tuning and bugfix release.

JVx and VaadinUI are available on Maven central. The other releases are hosted on SourceForge.

What's new in JVx 2.4?

  • Thread safety

    DataBook (MemDataBook, RemoteDataBook) are now Thread safe. It wasn't guaranteed before 2.4.

  • Support for Boolean and Arrays (Oracle)

    JVx' OracleDBAccess supports Boolean DataTypes via JDBC calls and Arrays as well. We wrapped the functionality in our existing API and it makes no difference for you. Arrays are wrapped as List of IBeans.

  • Parameter changed event in WorkScreen

    The WorkScreen class got a new event: eventParameterChanged. It enables notification about parameter changes.

  • New AbstractFactory

    We introduced AbstractFactory and changed all factory implementations. With AbstractFactory, it's possible to set custom factory properties. We use this new feature for vaadin UI. With new Vaadin UI it's possible to use the old Table or the new Grid implementation. Simply set a property for that.

  • API change: IFactory

    The invokeInThread method now returns the Thread instance.

  • FontAwesome support
  • Automatic Record translation

What's new in Vaadin 1.4?

  • Based on vaadin 7.5.7
  • FontIcon support
  • Grid support (experimental)

    Set the factory property: vaadin.component.legacy_table to true (via web.xml as init parameter or as URL parameter).

  • Lazy loading of LinkedCellEditor

    Before 1.4, all LinkedCellEditors were loaded immediate. This was a performance impact. With 1.4 this was changed and data will be loaded, when needed.

  • Performance tuning

    The performance is now about 5 times faster than before. We improved the performance because we reduced our CssExtension and reduced the database calls. You can feel the new performance :)

What's new in JVx vert.x 3.0?

It's based on Vert.x 3 and works with JVx 2.4.
(JVx vert.x is hosted on GitHub)

You can find all changes in the project Changelogs.
Happy coding!

JVx.vert.x update to vert.x 3.0

Post to Twitter

Our JVx connection implementation for vert.x is up-to-date. It's now based on vert.x 3.0. We support http and socket connections - no API changes.

Updating to vert.x 3.0 from 2.2 was not funny because package structure was changed and some APIs as well. Whatever, it's working.

If you're interested in our vert.x implementation, check the github repository because we don't offer binaries.

JVx with vert.x

Post to Twitter

We had our first contact with vert.x in 2012 as we tried to use it for our first RaspberryPi project. We did a simple implementation of our JVx connection interface and used the Vertx net implementation to run our applications without application server on a RasPi. Our implementation was based on vert.x 1.2. We didn't use our implementation since that time. We re-used the project in the last weeks because vert.x is still alive and we changed some things in our connection to support streaming protocols. It was a great test case for our changes.

First of all, we did an update to vert.x 2.1.5. Our implementation is now up-to-date. We also changed the implementation because it wasn't an optimized solution. We removed our internal buffering and used vert.x core classes. We also created verticles to support the core concept of vert.x.

If you're interested, simply check the source code. There are two test cases: TestNetSocketConnection and TestHttpConnection in the test folder.

You could use the solution to run a JVx application on an embedded device :) without a Java application server.

But you should know that this project isn't an official project of SIB Visions, and we don't offer support for it. But we try to answer your questions via Forum.

The project is currently located in the JVx repository, but we'll move it to its own repository in next few weeks.

Power control with RaspberryPi, JVx and Vert.x

Post to Twitter

My idea was to create a programmable timer for some lamps at home. I wanted to control the timer via mobile phone (not only smartphone). I decided to use simple SMS'.

The timer app was not really a challenge and the SMS interface was also very straight forward, so I added a little bit network communication and complexity. The result:

Power control

Power control

My Hardware:

  • Raspberry Pi Model B
  • Cinterion TC65i
  • Standard table lamp
  • Solid State Relay (found here)
  • Laptop as cluster client
  • Mobile Phone :)

My software:

My first question was - Which application server should I use for my Pi? I thought that JBoss or Tomcat would be overhead and I would save resources. I decided for Vert.x and a simple socket server. I wanted to show the integration of Vert.x with JVx and so my server got a JVx application with some business logic for publishing messages.

The server "thing" was clear and for reading SMS' I wrote a simple polling app. The app reads SMS from my hardware via RS232 and forwards received SMS via JVx APIs to my server (with Vert.x' NetClient).
I didn't use the EventBus for sending messages becasue I wanted to show the seamless integration of JVx and Vert.x.

The code for forwarding messages:

MasterConnection macon = new MasterConnection(new NetSocketConnection("10.0.0.39"));
macon.setApplicationName("demo");
macon.setUserName("user");
macon.setPassword("password");
macon.setAliveInterval(-1);
macon.open();

macon.callAction("publishMessage", msg.getOriginator(), msg.getText());

The server application is a standard JVx application (only server-side). It uses a standard XmlSecurityManager without the need for a database. The "business logic" is very simple:

public Vertx getVertx()
{
    return (Vertx)get("vertx");
}

public void publishMessage(String pNr, String pMessage)
{
    System.out.println("publishMessage (" + pMessage + ")");
       
    String sNumber = pNr;

    sNumber = sNumber.substring(0, 5);

    //hide last characters
    for (int i = 5; i < pNr.length(); i++)
    {
        sNumber += "*";
    }
       
    JsonObject jsobj = new JsonObject();
    jsobj.putString("number", sNumber);
    jsobj.putString("message", pMessage);
       
    getVertx().eventBus().publish("sms.received", jsobj);
}

I made some tests with vert.x clustering and decided to implement a (very) simple JavaFX application that shows published SMS'. The application contains following code:

vertx = Vertx.newVertx(25502, "10.0.0.11");

EventBus ebus = vertx.eventBus();
ebus.registerHandler("sms.received", new Handler<Message<JsonObject>>()
{
    public void handle(final Message<JsonObject> pMessage)
    {
        Platform.runLater(new Runnable()
        {
            public void run()
            {
                try
                {
                    mdb.insert(false);
                    mdb.setValues(new String[] {"NUMBER", "MESSAGE"},
                                  new String[] {pMessage.body.getString("number"),
                                                pMessage.body.getString("message")});
                    mdb.saveSelectedRow();
                }
                catch (ModelException me)
                {
                    throw new RuntimeException(me);
                }
            }
        });
    }
});

Finally, I created a short video that shows all in action. It shows three applications on the same laptop. The first is the JavaFX application that shows published SMS. The second is the Power control (includes SMS check), started via PuTTY. The third application is the server instance, started via PuTTY. You can see a table lamp that will be turned on and off with SMS, sent from a smartphone.

Enjoy it :)


Power Control with RaspberryPi

Vert.x + JVx

Post to Twitter

Do you know vert.x?

It's like node.js but written in Java and without JavaScript limitations. It's very powerful and easy to use. I don't describe features of vert.x or tell you how it works. If you want to know more about it, you'll find everything you need on the official site.

How and why do we use vert.x?

We simply tried it out to find out how it works and if an integration with JVx makes sense. We started a simple Research project with some goals:

  • Create a simple http server that will run without an application server, e.g. on a Raspberry Pi
  • Create a simple net/socket server, also for Raspberry Pi
  • Deploy an existing JVx application (e.g. FirstApp) and connect to the new server
  • Integrate the EventBus in an existing JVx application
  • Create a simple JavaScript app (show data in a grid) with jQuery, jQueryUI and vert.x EventBus
  • Use EventBus in Cluster mode (Java IPC)

The documentation of vert.x is great and there are a lot of examples, not what we needed but good for a quick start.

It was easy to create a http and socket server. The only problem was that everything was asynchronous and JVx expected synchronous calls. The HttpConnection of JVx worked without modifications because the JDK solved everything. We didn't use the vert.x http client.

It was a little bit tricky to implement an IConnection for socket communication because the server has to know when a command ends. It only reads a stream and does not know the protocol! We didn't introduce a new protocol, instead we wrote a delimiter after each command. This worked like a charm.

After we had http and socket support, the usage of an existing JVx application was easy. We copied existing files and it worked out-of-the-box. That was as expected ;-)

What about the event bus?

With JVx we have a super fast and simple client/server communication and it's possible to send messages from the client to the server, but the client polls. It's not live!

The event bus offers more power and flexibility. We thought it would be a great benefit for JVx applications or applications written in technologies that are supported from vert.x e.g. JavaScript.

It's already possible to use JVx' REST interface from non Java applications but if you use vert.x it would be cool to use the event bus.

The EventBus support was soo easy because the API is very nice and simple. It's enough to register a handler (like a listener) for a specific address (= string). After the registration you'll receive events from the bus :)

We had some problems with clustering vert.x because we didn't read the (whole) documentation and the information was in a different place as expected. If you use vert.x embedded and start multiple applications with different Vertx instances, be sure to use free cluster (communication) ports (see manual):

-cluster-port If the cluster option has also been specified then this determines which port will be used for cluster communication with other vert.x instances. Default is 25500. If you are running more than one vert.x instance on the same host and want to cluster them, then you'll need to make sure each instance has its own cluster port to avoid port conflicts.

We had to create Vertx instances with a specific port, e.g. 25501, 25502 (for the second and third application):

Vertx vertx = Vertx.newVertx(25501, "10.0.0.11");

Without port and host, the instance is not clustered!

The last goal was a simple JavaScript application. Here is a screenshot:

JVx with Vert.x and JQuery

JVx with Vert.x and JQuery

The application connects with username and password and retrieves data from a database via business logic (standard JVx). We used an existing JVx application and wrote one html page for our JavaScript application. Here is the source code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JVx + vert.x + jQuery</title>
 
<link rel="stylesheet" type="text/css" media="screen" href="css/jquery-ui.custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />

<script src="js/jquery-1.7.2.min.js" type="text/javascript"></script>
<script src="js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script src="http://cdn.sockjs.org/sockjs-0.2.1.min.js"></script>
<script src="js/vertxbus.js"></script>
<script type="text/javascript">
  $.jgrid.no_legacy_api = true;
  $.jgrid.useJSON = true;
</script>
<script type="text/javascript">
jQuery(document).ready(function(){
  $.jgrid.defaults = $.extend($.jgrid.defaults,{loadui:"enable"});

  jQuery("#grid").jqGrid(
  {
    datatype: "local",
    height: 400,

    colNames:['ID','PLZ-ID', 'ZIP', 'STRA-ID', 'Street', 'House #', 'Floor', 'Door #'],
    colModel:[
                {name:'ID', width:60, sorttype:"int"},
                {name:'POST_ID', hidden:true},
                {name:'POST_PLZ', width:50, align:"right", sorttype:"text"},
                {name:'STRA_ID', hidden:true},
                {name:'STRA_NAME', width:200, sorttype:"text"},        
                {name:'HAUSNUMMER', width:50, align:"right", sorttype:"int"},          
                {name:'STIEGE', width:70, align:"right", sorttype:"int"},              
                {name:'TUERNUMMER', width:60, align:"right", sorttype:"int"}
                ],
   
    multiselect: false,
    rowNum: 200,
    forceFit: true,
    loadonce: true,
    caption: "Address data"
});

eb = new vertx.EventBus("http://10.0.0.11:8080/eventbus");

eb.onopen = function()
{
    eb.send('jvx.createSession',
            {application: 'demo', username: 'rene', password: 'rene'},
            function (reply)
    {  
      eb.send('jvx.fetch',
              {sessionId: reply.sessionId, object: 'adrData'},
              function (reply2)
      {
        gdata = reply2.data;

        for(var i = 0; i <= gdata.length; i++)
       {
         jQuery("#grid").jqGrid('addRowData', i + 1, gdata[i]);
       }
     });
   });    
};

});
</script>
</head>
<body>
  <div id="GridPane">
    <table id="grid"></table>
  </div>
</body>
</html>

The authentication is hardcoded, of course. It's not a problem to show a login page, but not necessary for our project.

Summary

We have a great integration of JVx for vert.x and it's now possible to use JVx on remote hosts without application server. Simply use Vert.x as http or socket server. It's very cool to use a Raspberry Pi with JVx without Tomcat, Jetty or JBoss - it saves system resources and is cool :)

It's now possible to use JavaScript, Python, Ruby or Groovy as client technology together with vert.x and JVx. Use the power of JVx for your preferred client technology.

The EventBus is a powerful feature to enrich your rich applications :)

Our integration project is open source and free for everyone!