User's Guide
Reference Manual
Release Notes
PDF
Top

orber
User's Guide
Version 3.6.14

Expand All
Contract All

Chapters

- The Orber Application
  - Top of chapter
  - Content Overview
  - Brief Description of the User's Guide
- Introduction to Orber
  - Top of chapter
  - Overview
- The Orber Application
  - Top of chapter
  - ORB Kernel and IIOP
  - The Object Request Broker (ORB)
  - Internet Inter-Object Protocol (IIOP)
- Interface Repository
  - Top of chapter
  - Interface Repository(IFR)
- Installing Orber
  - Top of chapter
  - Installation Process
  - Configuration
  - Firewall Configuration
  - Interface Configuration
- OMG IDL to Erlang Mapping
  - Top of chapter
  - OMG IDL to Erlang Mapping - Overview
  - OMG IDL Mapping Elements
  - Getting Started
  - Basic OMG IDL Types
  - Template OMG IDL Types and Complex Declarators
  - Constructed OMG IDL Types
  - Scoped Names and Generated Files
  - Typecode, Identity and Name Access Functions
  - References to Constants
  - References to Objects Defined in OMG IDL
  - Exceptions
  - Access to Attributes
  - Invocations of Operations
  - Implementing the DB Application
  - Reserved Compiler Names and Keywords
  - Type Code Representation
- CosNaming Service
  - Top of chapter
  - Overview of the CosNaming Service
  - The Basic Use-cases of the Naming Service
  - Interoperable Naming Service
- How to use security in Orber
  - Top of chapter
  - Security in Orber
- Orber Examples
  - Top of chapter
  - A Tutorial on How to Create a Simple Service
- Orber Stubs/Skeletons
  - Top of chapter
  - Orber Stubs and Skeletons Description
- CORBA System and User Defined Exceptions
  - Top of chapter
  - System Exceptions
  - User Defined Exceptions
  - Throwing Exceptions
  - Catching Exceptions
- Orber Interceptors
  - Top of chapter
  - Using Interceptors
  - Interceptor Example
- OrberWeb
  - Top of chapter
  - Using OrberWeb
  - Starting OrberWeb
- Debugging
  - Top of chapter
  - Tools and FAQ

# 9 Orber Examples

### 9.1 A Tutorial on How to Create a Simple Service

#### Interface Design

This example uses a very simple stack server. The specification contains two interfaces: the first is the Stack itself and the other is the StackFactory which is used to create new stacks. The specification is in the file stack.idl.

#### Generating Erlang Code

Run the IDL compiler on this file by calling the ic:gen/1 function

    \0111> ic:gen("stack").

This will produce the client stub and server skeleton. Among other files a stack API module named StackModule_Stack.erl will be produced. This will produce among other files a stack API module called StackModule_Stack.erl which contains the client stub and the server skeleton.

#### Implementation of Interface

After generating the API stubs and the server skeletons it is time to implement the servers and if no special options are sent to the IDL compiler the file name should be <global interface name>_impl.erl, in our case StackModule_Stack_impl.erl.

We also have the factory interface which is used to create new stacks and that implementation is in the file StackModule_StackFactory_impl.erl.

To start the factory server one executes the function StackModule_StackFactory:oe_create/0 which in this example is done in the module stack_factory.erl where the started service is also registered in the name service.

#### Writing a Client in Erlang

At last we will write a client to access our service.

#### Writing a Client in Java

To write a Java client for Orber you must have another ORB that uses IIOP for client-server communication and supports a Java language mapping. It must also have support for IDL:CosNaming/NamingContext or IDL:CosNaming/NamingContextExt. If the client ORB support Interoperable Naming Service the Java Client can look like:

Note

If an ORB does not support CosNaming at all the cos_naming.idl file must be compiled and imported.

#### Building the Example

To build the example for access from a Java client you need a Java enabled ORB (e.g. JavaIDL). The example below is based on JDK-1.4.

    fingolfin 127> erl
    Erlang (BEAM) emulator version 5.5.4.3 [async-threads:0] [hipe] [kernel-poll:false]

    Eshell V5.5.4.3  (abort with ^G)
    1> ic:gen(stack).
    Erlang IDL compiler version 4.2.12
    ok
    2> make:all().
    Recompile: StackModule_EmptyStack
    Recompile: StackModule_Stack
    Recompile: StackModule_StackFactory
    Recompile: StackModule_StackFactory_impl
    Recompile: StackModule_Stack_impl
    Recompile: oe_stack
    Recompile: stack_client
    Recompile: stack_factory
    up_to_date
    3>
    BREAK: (a)bort (c)ontinue (p)roc info (i)nfo (l)oaded
           (v)ersion (k)ill (D)b-tables (d)istribution
    a
    fingolfin 128> idlj stack.idl
    fingolfin 129> javac StackModule/*.java
    fingolfin 130> javac *.java
    fingolfin 131> cp StackClient.class StackModule/

#### How to Run Everything

Below is a short transcript on how to run Orber.

    fingolfin 143> erl
    Erlang (BEAM) emulator version 5.5.4.3 [async-threads:0] [hipe] [kernel-poll:false]

    Eshell V5.5.4.3  (abort with ^G)
    1> orber:jump_start([{interceptors, {native, [orber_iiop_tracer_silent]}}]).
    ok
    2> oe_stack:oe_register().
    ok
    3> stack_factory:start().
    ok
    4> stack_client:run().
    1
    1
    7
    4
    ok
    5>

Before testing the Java part of this example generate and compile Java classes for orber/examples/stack.idl as seen in the build example. To run the Java client use the following command:

    fingolfin 38> java StackModule.StackClient "corbaname::localhost:4001#StackFactory"
    1
    1
    7
    4
    Empty stack
    fingolfin 39>