JBoss.orgCommunity Documentation

Chapter 6. Example

6.1. The basic example
6.1.1. Example implementation of the interface
6.2. Default settings

This example illustrates the concepts and the implementation details for a simple client/server example using implicit context propagation and indirect context management.

This example only includes a single unit of work within the scope of the transaction. consequently, only a one-phase commit is needed.

The client and server processes are both invoked using the implicit propagation and interposition command-line options.

For the purposes of this worked example, a single method implements the DemoInterface interface. This method is used in the DemoClient program.


This section deals with the pieces needed to implement the example interface.

The example overrides the methods of the Resource implementation class. The DemoResource implementation includes the placement of System.out.println statements at judicious points, to highlight when a particular method is invoked.

Only a single unit of work is included within the scope of the transaction. Therefore, the prepare or commit methods should never be invoked, but the commit_one_phase method should be invoked.


At this stage, the Demo.idl has been processed by the ORB’s idl compiler to generate the necessary client and server package.

Line 14 returns the transactional context for the Current pseudo object. After obtaining a Control object, you can derive the Coordinator object (line 16).

Lines 17 and 19 create a resource for the transaction, and then inform the ORB that the resource is ready to receive incoming method invocations.

Line 20 uses the Coordinator to register a DemoResource object as a participant in the transaction. When the transaction terminates, the resource receives requests to commit or rollback the updates performed as part of the transaction.


First, you need to to initialize the ORB and the POA. Lines 10 through 14 accomplish these tasks.

The servant class DemoImplementation contains the implementation code for the DemoInterface interface. The servant services a particular client request. Line 16 instantiates a servant object for the subsequent servicing of client requests.

Once a servant is instantiated, connect the servant to the POA, so that it can recognize the invocations on it, and pass the invocations to the correct servant. Line 18 performs this task.

Lines 20 through to 21 registers the service through the default naming mechanism. More information about the options available can be found in the ORB Portability Guide.

If this registration is successful, line 23 outputs a sanity check message.

Finally, line 25 places the server process into a state where it can begin to accept requests from client processes.


After the server compiles, you can use the command line options defined below to start a server process. By specifying the usage of a filter on the command line, you can override settings in the TransactionService.properties file.

Note

if you specify the interposition filter, you also imply usage of implicit context propagation.

The client, like the server, requires you to first initialize the ORB and the POA. Lines 14 through 18 accomplish these tasks.

After a server process is started, you can obtain the object reference through the default publication mechanism used to publish it in the server. This is done in lines 20 and 21. Initially the reference is an instance of Object. However, to invoke a method on the servant object, you need to narrow this instance to an instance of the DemoInterface interface. This is shown in line 21.

Once we have a reference to this servant object, we can start a transaction (line 23), perform a unit of work (line 25) and commit the transaction (line 27).


These settings are defaults, and you can override them at run-time by using property variables, or in the properties file in the etc/ directory of the installation.