hakke

This is an old revision of the document!


name=Hakke | version=0.1 | accountable=Marcos Roriz | depdency= [[UDI]]

Hakke

Hakke provides a Gateway between SDDL and Web applications. Specifically, it is a SDDL processing node that routes messages from SDDL to a WebFramework (Play). It can also send message from the Web to the SDDL Core. The processing node contains a entire Web Server and executes the Play Framework, a Java / Scala Web Framework. Hakke enable developers to register JavaScript functions to handle SDDL messages. These functions are triggered when a receiving message match the registered function. By default, Hakke provides a template viewing application, that uses Google Maps, that can be adapted to the developer task.

Hakke can receive and send message from and to the SDDL Core. To receive and process a message Hakke require that developers register a handling function. These functions are added to a global pre-defined array of functions named scriptFunctions in Hakke. Since JavaScript treats functions as first-class citizen, to add a function create a new index in the scriptFunctions variable. The function will receive message from SDDL core that are named msg_name in a JSON format.

For example, to add a function that treats msg_name messages, do:

scriptFunctions["msg_name"] = function(data) {
	var lat = data.lat;
	var lng = data.lng;
	//...
}

Include this code in a JavaScript file or append in the public/javascript/map.js file.

SDDL Core applications can send ApplicationMessages to Hakke. To do that, the content object in the message must be a JSON String. There are numerous JSON libraries for Java, in the following code we will use Simple-JSON. It is very important that the message has a field operation with the name of the handling function (msg_name). The following code shows a sample JSON message.

JSONObject jsonMSG = new JSONObject();
jsonMSG.put("operation","msg_name");
jsonMSG.put("lat", -44);
jsonMSG.put("lng", -13);
jsonMSG.put("num", new Integer(100));
jsonMSG.obj.put("balance", new Double(1000.21));
jsonMSG.obj.put("is_vip", new Boolean(true));
 
ApplicationMessage msg = new ApplicationMessage();
msg.setContentObject(jsonMSG.toString());
msg.setPayloadType(PayloadSerialization.JSON);
 
nodeCon.sendMessage(msg);

Hakke uses the Play Framework. A difference between Play and other Web famework it that, by default, it comes with a Web Server. This feature enables Play, and by extension Hakke, to be self-contained. As a Web Framework Hakke treats and process HTTP request, however we need to receive and send from/to SDDL Core to the Web Browser. Play has the concept of global entities, i.e., entities that will be available throughout all the web server lifecycle. We wrap a SDDL DataReader and DataWriter in a global entity called DDSLink. When the web server is initiated this entity is created.

Whenever Hakke loads the index page it creates a WebSocket between the browser and the webserver. Using this feature, Hakke can push and receive data to and from the browser. The created WebSocket is added to a queue in the global entity DDSLink. Whenever Hakke receive a message from SDDL, the DDSLink will iterate over this queue and push the message to all the registered WebSockets. When a session, for instance, ther user closed the page, the WebSocket is removed from this list.

The browser received the sent message in a pre-defined Hakke JavaScript routine. This routine unwraps the message and parse it as a JSON variable data. After that, it will read the operation field from data to identify the routine thats need to be called. This function is called with the JSON message as argument. The Figure below shows an overall view of Hake communication channels.

  1. First, download the ''gateway.jar'' file.
  2. Download maven, a java package manager.
  3. Hakke depends on contextnet, thus, install the gateway.jar file as a package. To do that, run the following command:
 $ mvn install:install-file -DgroupId=cnet.lac -DartifactId=contextnet -Dpackaging=jar -Dversion=2.1 -Dfile=/tmp/contextnet.jar 
  1. Now, download the Play Framework (Activator).
  2. Unpack Hakke. To run the application, execute the following command:
 $ activator run 
  • hakke.1446231167.txt.gz
  • Last modified: 2017/07/21 02:50
  • (external edit)