RRiBbit Remoting over RMI

This chapter will explain how to set up Remoting over Java RMI. RRiBbit will take complete care of setting up the infrastructure needed for RMI communication. This means that using RMI is the easiest way of using Listeners on other machines. Please note that using RMI Remoting will mean that your transactional context will be broken. This is generally not a problem, because most systems don't need transactions over the network. SOAP, for example, the most widely used communication technology, does not support transactions either.

Server side

Let's start with the the server side. You will need to create an instance of RmiRequestProcessorImpl. When you create an instance, it will automatically start to listen to requests in a separate thread. You may want to keep a reference to it, in order to shut it down when the application terminates, with the shutdown() method. Note that an RmiRequestProcessorImpl is not actually an implementation of RequestProcessor, because RequestProcessor is not a Remote interface. This is not a problem though, since an RmiRequestProcessorImpl receives its requests via RMI and not via a Java interface. An RmiRequestProcessorImpl needs the following arguments:

  • portnumber: The portnumber to listen on.

  • listenerObjectRetriever: The ListenerObjectRetriever that is used by this RmiRequestProcessorImpl.

  • listenerObjectExecutor: The ListenerObjectExecutor that is used by this RmiRequestProcessorImpl.

If you want to use SSL, then the RmiRequestProcessorImpl also provides constructors for that. You will have to pass a keystore, its password and a truststore. See this page for a comprehensive guide on SSL in Java. You will need the section titled "Creating a Keystore to Use with JSSE" to create the files that RRiBbit needs. Note that you don't actually have to set up anything yourself. Just pass the files and the password and RRiBbit will take care of everything!

Client side

Okay, so the server side is set up, now it's time to wire up the client side! You will need an RmiRequestDispatcher. This is actually an implementation of RequestDispatcher, so you can pass it directly to the RequestResponseBus. The RmiRequestDispatcher needs the following arguments:

  • portnumber: The portnumber to send requests to.

  • hosts: A list of hostnames (ip-addresses or DNS-resolvable hostnames) to send the requests to.

If you want to use SSL, then you have to give the RmiRequestDispatcher the location of the truststore and it will all work automatically!

Note that the RmiRequestDispatcher takes a list of hosts instead of a single one. You can therefore actually pass multiple hosts and RRiBbit will pick one at random each time a request is made. Load-balancing for free! Also, when a certain host does not respond, another one is chosen, so that will give you automatic failover! The number of times that RRiBbit has to retry before giving up can be set with the appropriate setter of RmiRequestDispatcher. If the number of hosts is smaller than the number of retries, RRiBbit will just try some hosts again.

And that's it as far as RMI Remoting is concerned! For other RRiBbit Remoting implementations, please see this page. And before you actually start using RRiBbit, make sure that you check the FAQ!