Data streaming with Jini

Lets take a simple example of how we can stream data from a Jini Server to a Jini Client. Data Streaming means that we can send huge, unbounded data to a consumer. In this example, we will read from a DataStore and directly send it to the client.

We have the following simple api:

The RemoteDataListener is a remote call-back where the data would be published from the Jini server as it becomes available.

Note that this is a Remote interface as well.

Server Implementation

The server implementation is very simple: its a straight delegation to the Dao.

The Dao just pushes data to the RemoteDataListener as shown below:

Client Implementation

The trick really is in the client implementation. In this example, since the RemoteDataListener  is a Remote listener, it is an exported Jini service which lives on the client. This is an example where the Jini Client and Jini Server swaps roles and the client becomes the server. Just to illustrate our point, we have created a very simple client which just writes the data received on to the console.

Then, we have a simple class with the main method to invoke the streaming service:

Note that just before invoking the streaming service and passing the RemoteDataListener, it is being duly exported as a Jini service and the exported RemoteDataListener is then passed to the streaming service. That is the trick, really.

The SpringContextHelper is a simple class to load up Spring Context and help look up remote services:

Running the example

We have embedded the Reggie in, so simply run the SpringNonSecureRmiServer to start the Reggie and the Jini Server. After the Jini Server starts up, run the SimpleStreamingClient. You would see the following on the console:


The sources can be found here:

There are 3 Maven projects under that:

  1. rm-api
  2. rmi-client
  3. rmi-server

Leave a Reply

Your email address will not be published. Required fields are marked *