hakke

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

hakke [2015/10/30 16:52]
mroriz [Download]
hakke [2017/07/21 03:08]
Line 1: Line 1:
-{{template>:doctable 
-    | 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 ([[wp>Play_framework|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 [[wp>Java]] / [[wp>Scala]] Web Framework. Hakke enable developers to register [[wp>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. 
- 
-===== Usage  ===== 
-==== Receiving Messages in Hakke ==== 
-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: 
- 
-<code javascript> 
-scriptFunctions["msg_name"] = function(data) { 
- var lat = data.lat; 
- var lng = data.lng; 
- //... 
-} 
-</code> 
- 
-Include this code in a JavaScript file or append in the ''public/javascript/map.js'' file. 
- 
-==== Sending Messages to Hakke ==== 
-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 [[https://code.google.com/p/json-simple/|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. 
- 
-<code java> 
-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); 
-</code> 
-===== Architecture ===== 
-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 [[wp>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. 
- 
-{{:flow_1_.png?400|}} 
- 
- 
-===== Download ===== 
-  - First, download the [[Download|''gateway.jar'']] file. 
-  - Download [[https://maven.apache.org/download.cgi|maven]], a java package manager. 
-  - Hakke depends on contextnet, thus, install  the ''gateway.jar'' file as a package. To do that, run the following command:  
-<code bash> $ mvn install:install-file -DgroupId=cnet.lac -DartifactId=contextnet -Dpackaging=jar -Dversion=2.1 -Dfile=/tmp/contextnet.jar </code> 
-  - Now, download the [[https://www.playframework.com/download|Play Framework (Activator)]]. 
-  - [[https://dl.dropboxusercontent.com/u/288607/endler-ext-hakke-9863397b5f35.zip|Download Hakke]]. 
-  - Unpack Hakke. To run the application, execute the following command: 
-<code bash> $ activator run </code> 
- 
  
  • hakke.txt
  • Last modified: 2017/07/21 03:08
  • (external edit)