JOMS (Java Opportunistic Message Service)
is a JMS Provider we have developed in our laboratory. JOMS acts as a middleware between already-existing JMS applications and D-MANETs. The main characteristic of JOMS is that it provides mobile wireless applications, act as JMS clients, with JMS services over D-MANETs.
JNDI : Java Naming and Directory Interface
According to the JMS specification, the use of JNDI service is essential. For this reason, JOMS supports a server-less version of JNDI. JOMS along with its server-less version of JNDI have passed several extremely challenging tests with great success. So we can say that JOMS will open the door to other dimensions of dealing with existing standard middleware.
Keywords
Java Message Service, JMS provider, Message-oriented Middleware, D-MANETs, opportunistic networks, Directory service.
Authors
Main author: Abdulkader BENCHI
Quick Links
Pre-Requirements
Before you start using JOMS, the DoDWAN platform is required to be installed and configured on hosts. For installing DoDWAN, please refer here.
Download
Copyright © 2010-2011 IRISA, Université Européenne de Bretagne. JOMS is a free software, so you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or any later version.
The source code consists of about 10000 lines of code, and here is the link.
Getting started
Once you have downloaded and installed JOMS, you can start testing it using one of the multiples examples provided in the source code. Please notice that these examples are located under jms/basic directory. If you are not familiar with JMS, then JMS tutorial from oracle is a useful guide.
If you feel like you do not have time to read every thing in that tutorial and JMS sounded so much familiar to you, then we suggest you something else. Sit back, relax and give the following example some thought.
JOMS tutorial
Step 1: Import the JMS and JNDI API classes. import javax.jms.*; //The line that we need to change. import javax.naming.*; import casa.joms.jndi.*; import java.util.*; public class HelloWorldMessage{ public static void main(String[] args){ try{ ConnectionFactory myConnFactory; Queue myQueue; Context jndi = new InitialContext(); //Step 2: Lookup a ConnectionFactory administered object. myConnFactory= jndi.lookup("ConnectionFactory"); //Step 3: Create a connection to the Message Queue Service Connection myConn = myConnFactory.createConnection(); //Step 4: Create a session within the connection. Session mySess = myConn.createSession(false, 0); //Step 5: Lookup a Queue Destination administered object. myQueue = (Queue) jndi.lookup("world"); //Step 6: Create a text message. TextMessage myTextMsg = mySess.createTextMessage(); //Sender-side code if (args[0].equalsIgnoreCase("sender")){ //Step 7: Create a message producer. MessageProducer myMsgProducer = mySess.createProducer(myQueue); myTextMsg.setText("Hello World"); System.out.println("Sending: " + myTextMsg.getText()); myMsgProducer.send(myTextMsg); } //Receiver-side code else if (args[0].equalsIgnoreCase("receiver")){ //Step 8: Create a message consumer. MessageConsumer myMsgConsumer = mySess.createConsumer(myQueue); //Step 9: Start the connection created in step 3. myConn.start(); //Step 10: Receive a message from the queue. Message msg = myMsgConsumer.receive(); //Step 11: Retreive the contents of the message. if (msg instanceof TextMessage){ TextMessage txtMsg = (TextMessage) msg; System.out.println("Reading: " + txtMsg.getText()); } } //Step 12: Close the session and connection resources. mySess.close(); myConn.close(); } catch (Exception jmse){ System.out.println("Exception: " + jmse.toString()); jmse.printStackTrace(); } } }
The Console
You want to test JOMS in real conditions but you do not want to burn yourself out writing too many applications. Okay, here is the solution. JOMS offers you with an interactive tools, called Console. This console provides you with the most commonly JMS commands, i.e., destination-object management, Pub/Sub commands and Send/Receiver commands. Furthermore, this console allows you to discover all of the destination objects exist in JNDI namespace. The console’s source code is available at jms/admin directory.
You can check the scenario shown in the following figure: there are four devices, named here A, B, C and D. All of these hosts are configured with JOMS. And now, the following steps describe how to run the Console in the this scenario:
Step 1: Launch the console on A, B, C and D
java -cp joms-1.1-jar-with-dependencies.jar casa.dodwan.jms.admin.AdminToolsTCPConsole
Step 2: Access to the console on A, B, C and D
// The port number could be changed using the configuration file telnet localhost 8600
Congratulation! you can now use it. The following examples demonstrate how to use some of the console commands:
To see the full list of console’s commands on any device, type:
h
To create a topic named “ChatRoom1” on device A, type:
add -t topic -n ChatRoom1
To find all of the destination objects stored in the local namespace on device B, type:
?j
To publish a message named “firstMSG” to “ChatRoom1” with payload “HelloWorld” and message selector “language=English” from the host C to the topic “ChatRoom1”, type:
pub -t ChatRoom1 -id firstMSG -p HelloWorld -ssl language=English
To subscribe to the topic “ChatRoom1” in the host D in order to receive the messages with properties “language=English” or “language=French”, type:
sub -t ChatRoom1 -ssl language=English|French
API specification
Building an effective JOMS application requires you to read JOMS APIs. The documentations and API specification for JOMS are included in the source code, and can also be accessed online here.