COMPE 515 ADVANCED JAVA PROGRAMMING FOR THE WEB - PowerPoint PPT Presentation

1 / 34
About This Presentation
Title:

COMPE 515 ADVANCED JAVA PROGRAMMING FOR THE WEB

Description:

Remote Method Invocation using the different ORBs. IDL Language Mapping ... transforms results or errors, and sends them back to the client via the ORBs. On Server ... – PowerPoint PPT presentation

Number of Views:24
Avg rating:3.0/5.0
Slides: 35
Provided by: CEM4
Category:
Tags: advanced | compe | for | java | programming | the | web | orbs

less

Transcript and Presenter's Notes

Title: COMPE 515 ADVANCED JAVA PROGRAMMING FOR THE WEB


1
COMPE 515ADVANCED JAVA PROGRAMMING FOR THE WEB
  • F. Cemile Serçe

2
Corba (Common object REQUEST broker archICTECTURE)
3
Background
  • RMI is a powerful mechanism for distributing and
    processing objects in a platform-independent
    manner, however...
  • it only works with objects that have been created
    using Java

4
Background
  • CORBA, a more generic approach to the development
    of distributed systems
  • allows to work with objects written in a variety
    of programing languages
  • by a client which themselves may be written in a
    variety of programming languages

5
Background
  • CORBA, product of Object Management Group (OMG)
  • not a specific implementation, but a
    specification for creating and using distributed
    objects
  • an individual implementation constitutes an ORB,
    such as
  • VisiBroker
  • Orbix
  • Java IDL

6
ORB
  • The ORB is an abstract entity that acts as the
    middleman in all remote method invocations.
  • The ORB finds a server that can handle a method
    invocation, passes the request to the server,
    receives the response and forwards it to the
    client.
  • The functions handled by an ORB are actually
    implemented in both client and server

7
Background
  • RMI uses Java to define the interfaces for its
    objects, CORBA uses a special language called
    Interface Definition Language (IDL) to define
    those interfaces
  • In order for any ORB to provide access to
    software objects in a particular programming
    language, the ORB has to provide a mapping from
    the IDL to the target language

8
Remote Method Invocation using the same ORB
9
Remote Method Invocation using the different ORBs
10
IDL Language Mapping
  • OMG defines mappings to different languages
  • C, C, Java, Smalltalk, COBOL, Ada, Lisp, PL/1,
    Python, and IDLscript
  • Every ORB has an IDL compiler, creating
  • A STUB and
  • A SKELETON

11
IDL
12
Java IDL
  • Java TM IDL
  • distributed objects.
  • interaction among objects regardless of whether
    they're written in the Java programming language
    or another language such as C, C, COBOL, or
    others

13
ORB
  • To support interaction between objects in
    separate programs, Java IDL provides an Object
    Request Broker, or ORB.
  • The ORB is a class library
  • enables low-level communication between Java IDL
    applications and other CORBA-compliant
    applications

14
Example
  • A simple CORBA distributed application using Java
    IDL
  • "Hello World" program as a distributed
    application
  • The Hello World program has a single operation
    that returns a string to be printed

15
Distributed Objects
  • Any relationship between distributed objects has
    two sides
  • the client (calls a remote interface)
  • the server (provides a remote interface),
  • common to most distributed object standards,
    including RMI, CORBA, etc.
  • both define object-level rather than application
    level interaction

16
IIOP Internet Inter-ORB ProtocolA one-method
distributed object shared between a CORBA client
and server
17
On Client
  • The application includes a reference for the
    remote object
  • The object reference has a stub method,
  • stub is actually wired into the ORB,
  • Stub invokes the ORB's connection, which forwards
    the invocation to the server.

18
On Server
  • the ORB uses skeleton code to translate the
    remote invocation into a method call on the local
    object
  • skeleton
  • translates the call and calls the method being
    invoked
  • transforms results or errors, and sends them back
    to the client via the ORBs.

19
Between ORBs
  • a shared protocol, IIOP (Internet Inter-ORB
    Protocol)
  • IIOP, which is based on the standard TCP/IP
    internet protocol, defines how CORBA-compliant
    ORBs pass information back and forth
  • Like CORBA and IDL, the IIOP standard is defined
    by OMG

20
Hello World Application
  • Define the remote interface
  • Compile the remote interface
  • Implement the server
  • Implement the client
  • Start the applications

21
1. Define the remote interface
  • define the interface using IDL
  • idlj automatically maps from IDL, generating all
    java language stub and skeleton source files
  • WRITING IDL file

22
WRITING IDL
  • Writing Hello.idl
  • create a new directory, named Hello
  • start a text editor and create a file named
    Hello.idl
  • enter the following code
  • module HelloApp
  • interface Hello
  • string sayHello()
  • oneway void shutdown()
  • save the file

23
Understanding IDL
  • Declaring the CORBA IDL Module
  • a namespace that acts as a container for related
    interfaces and declarations.
  • mapped to Java package statement

24
Understanding IDL
  • Declaring the Interface
  • declare the API contract an object has with other
    objects
  • mapped to java interface statement

25
Understanding IDL
  • Declaring the Operations
  • CORBA operations are the behavior that servers
    promise to perform on behalf of clients that
    invoke them
  • Each operation in the IDL generates a
    corresponding method statement in the generated
    Java interface.

26
2. Compile the remote interface
  • idlj
  • reads OMG IDL files and creates the required Java
    files
  • defaults to generating only the client-side
    bindings
  • if you need both, use the -fall option when
    running the idlj compiler

27
2. Compile the remote interface
  • Make sure that the j2sdk/bin directory is in your
    path
  • Go to a command line prompt.
  • Change to the directory containing your Hello.idl
    file.
  • Enter the compiler command
  • idlj -fall Hello.idl
  • .....Generates a number of files......

28
HelloPOA.java
  • HelloPOA.java
  • This abstract class is the stream-based server
    skeleton
  • _HelloStub.java
  • the client stub
  • Hello.java
  • Java version of our IDL interface
  • HelloHelper.java
  • the narrow() method required to cast CORBA object
    references to their proper types
  • HelloHolder.java
  • holds a public instance member of type Hello
  • HelloOperations.java
  • This interface contains the methods sayHello()
    and shutdown()

29
3. Implement the Server
  • Consists of two classes
  • Servant (HelloImpl)
  • implementation of Hello IDL interface
  • subclass of HelloPOA
  • servant provides methods sayHello(),
    shutdown().
  • servant methods are like ordinary java methods
  • Server
  • ??

30
3. Implement the Server
  • Consists of two classes
  • Servant
  • Server
  • Creates and initializes an ORB instance
  • Gets a reference to the root POA and activates
    the POAManager
  • Creates a servant instance (the implementation of
    one CORBA Hello object) and tells the ORB about
    it
  • Gets a CORBA object reference for a naming
    context in which to register the new CORBA object
  • Gets the root naming context
  • Registers the new object in the naming context
    under the name "Hello
  • Waits for invocations of the new object from the
    client

31
Creating HelloImpl
  • public class HelloImpl extends HelloPOA
  • private ORB orb
  • public void setORB(ORB orb_val)
  • orb orb_val
  • // implement sayHello() method
  • public String sayHello()
  • return "\nHello world !!\n"
  • // implement shutdown() method
  • public void shutdown()
  • orb.shutdown(false)

32
Creating HelloServer
33
4. Implement the client
34
5. Start the applications
  • start orbd
  • start orbd -ORBInitialPort 1050 ORBInitialHost
    localhost
  • start the Hello server
  • start java HelloServer -ORBInitialPort 1050
    -ORBInitialHost localhost
  • Run the client application
  • java HelloClient -ORBInitialPort 1050
    -ORBInitialHost localhost
  • The client prints the string from server to the
    command line
Write a Comment
User Comments (0)
About PowerShow.com