Chapter 8.  Implementing the Bank Server

In the previous chapter, we discussed the interfaces and data objects for the bank example. In this chapter, we’ll continue with the development cycle by building the servers and discussing the various design options that are available. This chapter is much shorter than the previous two because most of the intellectual heavyweight lifting has already been done. Nonetheless, by the end of this chapter, we will have fully implemented the servers for the bank example.

The Structure of a Server

The server objects you write in RMI are just the tip of the iceberg. When you add the automatically generated code and the pre-existing libraries and runtime, every RMI server has the layered structure at runtime shown in Figure 8-1.

Runtime structure for RMI servers

Figure 8-1. Runtime structure for RMI servers

These components have the following roles:

Actual sockets

These are just instances of Socket and ServerSocket, exactly as discussed in Chapter 1. The number of sockets is explicitly controlled by the RMI runtime and is usually proportional to the number of RMI clients connected to a JVM.

RMI runtime

This listens and receives any data coming in over the socket. Because it knows the wire protocol that RMI uses, the RMI runtime can take the data that comes in from the socket and break it apart into distinct method calls (encapsulated as instances of java.rmi.server.RemoteCall

Get Java RMI now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.