O'Reilly logo

Java RMI by William Grosso

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The Bank Example in CORBA

In order to make this more concrete, we will briefly walk through how to build the bank example using CORBA. However, since this is an RMI book, we will not dwell on the details—if you’re interested, the complete code for this chapter is contained in the com.ora.rmibook.chapter23.corbaaccounts package.

Defining the Interface

The first step is to define the interface using IDL:

#pragma prefix "com.ora.rmibook.chapter23.corbaaccounts"

struct Money  {
	long cents;
};

exception NegativeAmountException{};
exception OverdraftException{};

interface Account{
	Money getBalance(  );
	void makeDeposit(in Money amount)  raises (NegativeAmountException);
	void makeWithdrawal(in Money amount) raises (NegativeAmountException, 
         OverdraftException);
};

There are several things to note here. Perhaps the most important is that this is actually quite readable. We declare a struct, we declare some exceptions, and we define an interface. The IDL for our account servers looks quite a bit like the Java definitions we’ve used up until now.

Tip

This shouldn’t be a surprise. Chapter 5 through Chapter 7, which contained a fair number of design guidelines, weren’t at all RMI-specific. When you add in the fact that both IDL and Java syntax are descended from C, it would be surprising if RMI programmers couldn’t easily understand IDL interfaces.

Generating Stubs and Skeletons

The IDL contains all the information that defines how clients talk to servers. This means that, once we have the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required