CORBA Implementation with Java: A Step-by-Step Guide

CORBA Implementation with Java

Server

Package server

Import java.util.Scanner;
Import org.omg.CORBA.ORB;
Import org.omg.CosNaming.NameComponent;
Import org.omg.CosNaming.NamingContextExt;
Import org.omg.CosNaming.NamingContextExtHelper;
Import org.omg.PortableServer.POA;
Import org.omg.PortableServer.POAHelper

Public static void main(String[] args) {
    Servidor manager = new Server(args);
    gestor.publicarEnNS();
    gestor.start();
}

Public class Server extends Thread

DispensadorCorba dispasc;
ORB orb, POA rootpoa static;
Public Servidor(String args[]) throws Exception {
    // Initialize the ORB
    orb = ORB.init(args, null);
    try {
        // Get object reference and we RootPOA narrow object reference to refer
        POAHelper.narrow POA rootpoa = (orb.resolve_initial_references(“RootPOA”));
        // Activate the handler invocations of the POA
        rootpoa.the_POAManager().activate();
    }
    // instantiate an object
    Pardon DispensadorCorba dispasc = new orCorba(5);
}

DispensadorCorba.java

Package server;
Import interface.*;
Public class Elevator extends DispensadorPOA {
    lifts[], int numAscensores;
    Public DispensadorCorba(int numasc) {
        lift = new Elevator[numasc];
    }

AscensorCorba.java

Public class AscensorCorba extends AscensorCorba {
    Public AscensorPOA(int num) {
        door = new Door();
    }

Puerta.java

Public class Gate implements Serializable {
    Public Door() {}
    Public void open() {}
    Public void close() {}
}
Public int getPiso() {}
Synchronized public void ir(int pisodest) {}
Private void down(int pisodest) {}
Private void raise(int pisodest) {}
For (int i = 0; i < numAscensores; i++) {
    try {
        // instantiate an object
        AscensorCorba lift = new AscensorCorba(i);
        // get the reference to the servant
        org.omg.CORBA.Object ref = Servidor.rootpoa.servant_to_reference(elevator);
        lifts[i] = AscensorHelper.narrow(ref.getAscensor());
    }
}
Public Elevator(int id) {
    return lifts[id];
}
}

Public void publicarEnNS() {
    try {
        // We get to the NamingService
        NamingContextExt root = NamingContextExtHelper.narrow(orb.resolve_initial_references(“NameService”));
        // get the reference the servant
        org.omg.CORBA.Object ref = rootpoa.servant_to_reference(dispasc);
        NameComponent path[] = root.to_name(“dispenser”);
        // join in the object NameService with the name “dispenser”
        root.rebind(path, ref);
    }
}

Public void run() {
    // We stayed pending requests
    orb.run();
}

Client

Package client

Import org.omg.CORBA.*;
Import interface.*;
Import org.omg.CosNaming.*;
Import java.util.Scanner;
Import interfaz.Ascensor

Public static void main(String[] args) {
    ControlRemoto manager = new ControlRemoto(args);
    gestor.controlar();
}

Public class ControlRemoto

Dispenser disp;
Elevator asc;
Public Remotecontrol(String[] args) throws Exception {
    ORB orb = ORB.init(args, null);
    try {
        org.omg.CORBA.Object objRef = orb.resolve_initial_references(“NameService”);
        NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
        String name = “dispenser”;
        disp = DispensadorHelper.narrow(ncRef.resolve_str(name));
    }
}

Public void control() throws Exception {
    asc = getAscensorControlar();
    option = menu();
    asc.ir(pisodest);
}

Private Elevator getAscensorControlar() {
    System.out.println(“Enter the elevator’s control: “);
    return disp.getAscensor(id);
}

Interfaces

Prueba: Java Interface WLSR representing the remote object. It is used to contain references CORBA.Implementa Test Operations and extends the Corba Object class used by the client.

PruebaHolder: To adapt to the way parameter passing out and inout type, which can only pass arguments by value.

PruebaHelper: There have only static methods for a series of such operations específico.En the naming service, when you want to get the reference of a CORBA object if, as developed dor know what we can do is type casting (narrowing).

Narrow(): It is a kind of casting that fits references to objects to ObjetosPrueba.

PruebaOperations: Java interface that contains the definitions of the methods equivalent IDL type mapping Java.Contiene, operations and exceptions.

PruebaPOA (Eskeleton) and PruebaPOATie.java: Implement PruebaOperations and is the class that has to extend the charge of sirviente.Es bring a reference from one object to a servant.

_PruebaStub: These are the intermediaries of the client (makes accessible remote objects and transforms the methods that states in array of bytes).

Language IDL: IDL is language neutral language to define CORBA objects. The IDL definitions, by a compiler, can be transformed into programming language that we use. These transformations are well specified in CORBA. However, it is up to each ORB on which files will be created.

Name Service: As with any distributed system, and using the Name Service, CORBA offers the possibility to find references to objects based on CORBA caracteres.En names consist of the names may have many components and each component name is an identifier and llave.El name, is organized in a naming graph. Each of its nodes, is an object and call him appointed environment. The naming context is an object that has a table which stores the relationship between objects and references.

Servant: It is an entity in a programming language that contains the code that implements the IDL interface operations.

Corba Object Reference: The identity of a CORBA object that uses a client to request operations.

CORBA object:

  • Virtual entity with which we can communicate through an ORB.
  • Materialized or embodied in an implementation. This implementation can be an object of a programming language or other construction, which will call a servant.
  • To the application that has one or more objects we call server.

POA:

  • Your work:
    1. When the ORB receives a message, this delivers the message to the POA that manages the object to which the message is directed (object reference associates a servant).
    2. The POA must know how each embodies servant and CORBA object each time a message arrives you will have to send it to the skeleton of the appropriate servant.
  • POA, one that creates the “illusion” of CORBA objects to clientes.No is only a virtual entity that is embodied in a servant.
  • To determine the true object embodies servant CORBA, POA has a table named “Active Object Map” and this table stores this information.