Adam Bien's Weblog

Headlands Firehose Edition Is Available

The "Firehose" release (v0.0.4) headlands (a JCache based in-memory grid) delivers CacheEntryEvents via WebSockets in JSON-format.

Cache change events can be received in real-time from Java clients:



import javax.websocket.ContainerProvider;
import javax.websocket.DeploymentException;
import javax.websocket.WebSocketContainer;



public class NotificationsReceiver extends Endpoint {

    @Override
    public void onOpen(Session session, EndpointConfig ec) {
        this.session = session;
        this.session.addMessageHandler(new MessageHandler.Whole<String>() {

            @Override
            public void onMessage(String msg) {
            }
        });
    }

}


WebSocketContainer containerProvider = ContainerProvider.getWebSocketContainer();
NotificationsReceiver messagesEndpoint = new NotificationsReceiver();
containerProvider.connectToServer(this.messagesEndpoint, new URI("ws://localhost:8080/headlands/firehose/" + channel));

...or JavaScript:

   this.callback = function(payload){
   
   }

  let socket = new WebSocket(`ws://${this.uri}/headlands/firehose/*`);
   socket.onmessage =  (event) => {
     this.serialize(event.data,this.callback);
   };
   socket.onopen = (event) => {
     console.log("socket connection established",event);
   };

See you at: Building HTML 5 Applications with react.js and Java EE 7 workshops at MUC Airport!


NEW online workshop: WebStandards Igniter (online)

Airport MUC workshops: Java EE 7: Bootstrap, Effective, Architectures, Web, React and Angular, Testing and Microservices

Newsletter: airhacks.news

A book about rethinking Java EE Patterns

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
realworldpatterns.com
Online Workshops
...the last 150 posts
...the last 10 comments
License