Tutorial: Introduction to Jellingspot Service Beans
Jellingspot Data Server (JDS) is an application container for the development of java-based server side applications
that utilize Bluetooth™ wireless technology.
JDS works in conjunction individual services running inside of it called Jellingspot Service Beans (JSB).
JSBs handle only the business logic written by the developer, removing any need to worry about Bluetooth APIs, threading, database support and
client connection pooling.
The idea of writing such services is to eliminate a lot of chaff coding, and simply utilize JSBs where most of
the code is directly related to application functionality, with very little “plumbing”. You write the application logic and JDS will do the rest.
This introduction will guide you through the development process with a simple
"Hello World" Bluetooth application.
Getting Started
The best way how to begin is to download the latest JDS development kit. This version contains all the files
needed to build and run Bluetooth applications.
You may request this kit through the developer license request form found
here.
Next, follow the installation instructions for JDS.
Once everything has been installed, and you will actually see the server working, you can
continue with the next steps. Finally, go through the appropriate section (so far there is only the
HelloWorld example in this tutorial, but more may follow) on how to
write a specific type of JSB.
The goal of this tutorial is to show textually and visually how to write
practical Bluetooth applications, describe how it has been constructed using code examples.
Therefore it is recommended that the readers of this tutorial have a Java IDE installed and running so they can look at the code
in detail as well as run the application.
Setting up the tutorial
This document assumes that you have downloaded the JDS_kit.zip and unpacked it into your favorite development directory.
You should see the following structure:
jellingspot_kit/
jdsserver
bin/
conf/
data/
etc/
lib/
log/
services/
tutorial/
serviceexecutor.zip
helloworld/
conf/
data/
lib/
res/
src/
| jellingspot_kit/ | Root directory containing the jdsserver itself, environment for JSB development and sources for this tutorial |
| jdsserver | The complete Jellingspot Data Server with two services included |
| jdsserver/bin | Appropriate Linux script to run the server |
| jdsserver/conf | Contains all the configuration files for the server |
| jdsserver/data | Database repository directory |
| jdsserver/lib | Run-time and libraries needed to run the server |
| jdsserver/log | Contains the logs for the server and database engine |
| jdsserver/services | Deploy directory for services |
| Tutorial | This directory contains sources for this tutorial |
| tutorial/ serviceexecutor.zip | This is the ready to use runtime framework to write and test your JSBs without the server |
| tutorial/helloword | Tutorial source code |
Jellingspot Service Beans (JSBs)
The Jellingspot Data Server provides an API that must be implemented in order to write JSBs. This set of APIs contains three main classes that must be implemented.
These classes will be described later in this chapter.
The following figure shows the common structure of a JSB running in the server:
First "Hello World" application
To keep things simple, we have prepared a service that returns a string to a client upon request.
Later in this chapter we will go step by step through the implementation of this service, showing procedural example code along with accompanying explanations.
Since JDS is an application running on the Linux platform
and most developers are using windows, we have created a little utility called the service executor that
simulates the JDS environment. Therefore, you will be able to write your own services on Windows, and once the service is ready to be deployed, you can just paste
into the JDS_HOME/service directory on your Linux box.
Diagram showing the Helloworld service
Creating the project structure
We created our project structure as follows:
The directories classes and src aren’t anything new, but conf, data and lib are directories coming from our service executor util, where conf contains the definition for the database and data is ready to utilize database support for a service (In the Helloworld service, we will not use it). Last, the lib directory contains all other items we might need in writing a service.
HelloWorld service interface
The first thing we will start with is to define the interface for our HelloWorld service that implements com.midletsoft.jds.service.Service.
Create HelloWorldService interface
The service must implement this interface in order to become part of JDS. The JDS framework communicates to the service through this interface, telling it when it can become available and when it should release all of its allocated resources.
Implementation class for HelloWorldService
Next we need to implement all the methods from the service interface, including those from HelloWorldService.
Implement HelloWorldService interface
Implement Service.setContext() and Service.getContext()
In real services we need to be able to access JDS’s resources like its database (in case we have something to store), or other services (in the case our service
must cooperate with other JSBs), device manager or some other type of paths, environments and so on.
In our simple example we don’t need any of these but we must implement these methods anyway:
Implement Service.start() and Service.stop() methods
Our start/stop method won’t do much now, but for learning purposes we will initialize the myHelloMessage variable and then we will release it:
Implement Service.getConnectionHandlerFactory() and HelloWorldService.sayhello() methods
To be able to receive a request from Bluetooth clients, we need to implement and return ConnectionHandlerFactory. This class creates ConnectionHandler
for handling client connections (more about this class in the next section).
If you plan to develop a Bluetooth application that will receive multiple connections at the same time, the ConnectionHandlerFactory is
the right candidate to pool
these connections. In HelloWorldService we will implement this factory as an inner class to keep things
simple:
Implementation of ConnectionHandler class
ConnectionHandler is responsible for receiving connections, getting in/out-put stream from it, and delegating it to a service.
Our ConnectionHandler expects the client send a 0x01 command (that can mean sayHello command) and once this request is received, the handler takes
care of delegating this request to the service and then answering back to the client. The protocol is made up from the
DataInputStream’s method for
sending types directly, so putting out a protocol using this java I/O classes is really simple.
Implement ConnectionHandler interface
As you can see HelloWorldHandler just keeps the reference to the service and myConnInfo gets information about the remote device:
Implement ConnectionHandler.handle() and close() method
Our method for handling connections is really simple. This method reads the request and sends an answer:
And of course, if something goes wrong, we must be able to close this connection down:
Service deployment descriptor
Before we can even assemble a service together, we must create a deployment descriptor that describes the service. This information is used by JDS to deploy a service and properly publish it onto the Bluetooth network:
Write deployment descriptor
Assembling and testing
To assemble this service together, we will use an Ant script that will create the complete JSB package.
Since this service is pretty simple, we won’t need to utilize the service executor. This little executor util is mainly helpful when our server is
using the embedded database to store data and has some web admin UI to administer this service. In our case we will just deploy the JSB into
the $JDS_HOME/service directory and start the server to see if our simple service deploys.
Deploying
Please see the installation and deployment instructions by clicking here
Copyright Midletsoft, LLC 2001-2005. All rights Reserved.