Server-Side Java Mapping Copyright © 2005-2010 ZeroC, Inc. Ice Programming with Java 6. Server-Side Java Mapping.

Slides:



Advertisements
Similar presentations
Message Passing Vs Distributed Objects
Advertisements

Copyright © 2012 Pearson Education, Inc. Chapter 16: Exceptions, Templates, and the Standard Template Library (STL)
Copyright © 2001 Qusay H. Mahmoud RMI – Remote Method Invocation Introduction What is RMI? RMI System Architecture How does RMI work? Distributed Garbage.
Lecture 2: Object Oriented Programming I
Remote Method Invocation
CS 4800 By Brandon Andrews.  Specifications  Goals  Applications  Design Steps  Testing.
Remote Method Invocation Chin-Chih Chang. Java Remote Object Invocation In Java, the object is serialized before being passed as a parameter to an RMI.
Java RMI. What is RMI? RMI is an RPC system for an object based language. Objects provide a natural granularity for the binding of functions. –RMI allows.
Lecture 10: Web Services. Outline Overview of Web Services Create a Web Service with Sun J2EE (JAX-RPC)
Introduction to Remote Method Invocation (RMI)
June 1, 2000 Object Oriented Programming in Java (95-707) Java Language Basics 1 Lecture 3 Object Oriented Programming in Java Language Basics Classes,
Scott Grissom, copyright 2004Ch 3: Java Features Slide 1 Why Java? It is object-oriented provides many ready to use classes platform independent modern.
How Does Remote Method Invocation Work? –Systems that use RMI for communication typically are divided into two categories: clients and servers. A server.
Terms and Rules Professor Evan Korth New York University (All rights reserved)
Netprog RPC Overview1 Distributed Program Design n Communication-Oriented Design –Design protocol first. –Build programs that adhere to the protocol.
Templates. Objectives At the conclusion of this lesson, students should be able to Explain how function templates are used Correctly create a function.
1 Further OO Concepts II – Java Program at run-time Overview l Steps in Executing a Java Program. l Loading l Linking l Initialization l Creation of Objects.
Copyright © 2003 ProsoftTraining. All rights reserved. Distributed Object Computing Using Java and CORBA.
220 FINAL TEST REVIEW SESSION Omar Abdelwahab. INHERITANCE AND POLYMORPHISM Suppose you have a class FunClass with public methods show, tell, and smile.
1 3. Implementing Web Services 1.Create SOAP proxy interfaces and WSDL based service descriptions 2.Register/publish services 3.Stores service descriptions.
Introduction to Ice Copyright © ZeroC, Inc. Ice Programming with Java 1. Introduction to Ice.
Understanding the CORBA Model. What is CORBA?  The Common Object Request Broker Architecture (CORBA) allows distributed applications to interoperate.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
CSCI 6962: Server-side Design and Programming Web Services.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
CSCE 2013L: Lab 1 Overview  Java Basics The JVM Anatomy of a Java Program  Object-Oriented Programming Overview  Example: Payroll.java JDK Tools and.
2000 Jordan Anastasiade. All rights reserved. 1 Class In this lesson you will be learning about: Class. Inheritance. Polymorphism. Nested and.
REVIEW On Friday we explored Client-Server Applications with Sockets. Servers must create a ServerSocket object on a specific Port #. They then can wait.
LAB 1CSIS04021 Briefing on Assignment One & RMI Programming February 13, 2007.
In the name of Allah The Proxy Pattern Elham moazzen.
1 Java RMI G53ACC Chris Greenhalgh. 2 Contents l Java RMI overview l A Java RMI example –Overview –Walk-through l Implementation notes –Argument passing.
Utilities (Part 2) Implementing static features 1.
Chapter 6 Server-side Programming: Java Servlets
Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 RMI.
Client-Side Slice-to-Java Mapping Copyright © ZeroC, Inc. Ice Programming with Java 4. Client-Side Slice-to-Java Mapping.
Java Remote Method Invocation RMI. Idea If objects communicate with each other on one JVM why not do the same on several JVM’s? If objects communicate.
Synchronized and Monitors. synchronized is a Java keyword to denote a block of code which must be executed atomically (uninterrupted). It can be applied.
Chapter 5: Ball Worlds Features 2 classes, constant data fields, constructors, extension through inheritance, graphics.
Update on CORBA Support for Babel RMI Nanbor Wang and Roopa Pundaleeka Tech-X Corporation Boulder, CO Funded by DOE OASCR SBIR.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
CORBA_1/001 Department of Computer Science Southern Illinois University Edwardsville Spring, 2010 Dr. Hiroshi Fujinoki CORBA:
Server-side Programming The combination of –HTML –JavaScript –DOM is sometimes referred to as Dynamic HTML (DHTML) Web pages that include scripting are.
Multithreading in JAVA
Java Remote Method Invocation (RMI) Overview of RMI Java RMI allowed programmer to execute remote function class using the same semantics as local functions.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
Java for C++ Programmers A Brief Tutorial. Overview Classes and Objects Simple Program Constructors Arrays Strings Inheritance and Interfaces Exceptions.
Server-Side C++ Mapping Copyright © ZeroC, Inc. Ice Programming with C++ 6. Server-Side C++ Mapping.
Remote Method Invocation with Java-RMI
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Interfaces F What is an Interface? F Creating an Interface F Implementing an Interface F What is Marker Interface?
Classes, Interfaces and Packages
Object orientation and Packaging in Java Object Orientation and Packaging Introduction: After completing this chapter, you will be able to identify.
Remote Method Invocation RMI architecture stubs and skeletons for remote services RMI server and client in Java Creating an RMI Application step-by- step.
Java RMI. RMI Any object whose methods can be invoked from another Java VM is called a remote object.
Chapter 4 Request and Response. Servlets are controlled by the container.
IDL Models The Inheritance Model: Using the Inheritance Model, you implement the IDL interface using an implementation class that also extends the compiler-generated.
Threads b A thread is a flow of control in a program. b The Java Virtual Machine allows an application to have multiple threads of execution running concurrently.
1 Lecture 15 Remote Method Invocation Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung Institute of Technology.
COMP Inheritance and Polymorphism Yi Hong June 09, 2015.
Netprog Java RMI1 Remote Method Invocation.
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
Modern Programming Tools And Techniques-I
Principles of Software Development
Broker in practice: Middleware
Remote Method Invocation
Programming Models for Distributed Application
null, true, and false are also reserved.
Chapter 9 Carrano Chapter 10 Small Java
Java Remote Method Invocation
Binding 10: Binding Programming C# © 2003 DevelopMentor, Inc.
Presentation transcript:

Server-Side Java Mapping Copyright © ZeroC, Inc. Ice Programming with Java 6. Server-Side Java Mapping

Server-Side Java Mapping Copyright © ZeroC, Inc. 6-1 Lesson Overview This lesson presents: –the mapping from Slice to Java relevant to the server side. –the relevant APIs that are necessary to initialize and finalize the Ice run time –how to implement and register object implementations. By the end of this lesson, you will be able to write a working Ice server.

Server-Side Java Mapping Copyright © ZeroC, Inc. 6-2 Server-Side Java Mapping All of the client-side Java mapping also applies to the server side. Additional server-side functionality you must know about: how to initialize and finalize the server-side run time how to implement servants how to pass parameters and throw exceptions how to create servants and register them with the run time

Server-Side Java Mapping Copyright © ZeroC, Inc. 6-3 Initializing the Ice Run Time public class Server { public static void main(String[] args) { int status = 1; Ice.Communicator ic = null; try { ic = Ice.Util.initialize(args); // server code here... status = 0; } catch (Exception e) { } if (ic) { try { ic.destroy(); } catch (java.lang.Exception ex) } System.exit(status); }

Server-Side Java Mapping Copyright © ZeroC, Inc. 6-4 Server-Side Initialization Servers must create at least one object adapter, activate that adapter, and then wait for the Ice run time to shut down: ic = Ice.Util.initialize(args); Ice.ObjectAdapter adapter = ic.createObjectAdapterWithEndpoints( "MyAdapter", "tcp -p 10000"); // Instantiate and register one or more servants here... adapter.activate(); ic.waitForShutdown(); An object adapter provides one or more endpoints at which the server listens for incoming requests. An adapter has a name that must be unique within its communicator. Adapters must be activated before they start accepting requests. You must call waitForShutdown from the main thread to wait for the server to shut down (or otherwise prevent the main thread from exiting).

Server-Side Java Mapping Copyright © ZeroC, Inc. 6-5 Mapping for Interfaces Interfaces map to skeleton classes with an abstract method for each Slice operation: module M { interface Simple { void op(); }; This generates: package M; public interface _SimpleOperations { void op(Ice.Current current); } public interface Simple extends Ice.Object, _SimpleOperations, _SimpleOperationsNC; public abstract class _SimpleDisp extends Ice.ObjectImpl implements Simple;

Server-Side Java Mapping Copyright © ZeroC, Inc. 6-6 Mapping for Interfaces (1) You must implement all abstract methods that are inherited from the skeleton class. You can add whatever else you need to support your implementation: constructors and finalizers public or private methods public or private data members other base interfaces

Server-Side Java Mapping Copyright © ZeroC, Inc. 6-7 Mapping for Parameters Server-side operation signatures are identical to the client-side operation signatures (except for a trailing parameter): In-parameters are passed by value or by reference. Out-parameters are passed by holder types. Return values are passed by value or by reference. Every operation has a single trailing parameter of type Ice.Current. string op(int a, string b, out float c, out string d); Maps to: String op(int a, String b, Ice.FloatHolder c, Ice.StringHolder d, Ice.Current __current);

Server-Side Java Mapping Copyright © ZeroC, Inc. 6-8 Throwing Exceptions exception GenericError { string reason; }; interface Example { void op() throws GenericError; }; You could implement op as: public void op(Ice.Current c) throws GenericError { throw new GenericError("something failed"); } Do not throw Ice run-time exceptions. You can throw ObjectNotExistException, OperationNotExistException, or FacetNotExistException, which are returned to the client unchanged. But these have specific meaning and should not be used for anything else. If you throw any other run-time exception, the client will get an UnknownLocalException or UnknownException.

Server-Side Java Mapping Copyright © ZeroC, Inc. 6-9 Tie Classes Tie classes are an alternative mechanism for implementing servants. The --tie option for slice2java generates tie classes in addition to the normal server-side code. Tie classes replace inheritance with delegation. This way, your implementation class need not inherit from the skeleton class: Use the tie mapping when your implementation class must inherit from some other application class (and therefore cannot be derived from the skeleton class). _NodeDisp «interface» _NodeOperations «interface» _NodeTieNodeI Skeleton Class Tie Class Implementation Class

Server-Side Java Mapping Copyright © ZeroC, Inc Creating an ObjectAdapter Each server must have at least one object adapter. You create an adapter with: local interface ObjectAdapter; local interface Communicator { ObjectAdapter createObjectAdapter(string name); ObjectAdapter createObjectAdapterWithEndpoints( string name, string endpoints); //... }; The endpoints at which the adapter listens are taken from configuration (first version), or from the supplied argument (second version). Example endpoint specification: tcp -p 10000:udp -p 10000:ssl -p Endpoints have the general form: [-h ] [-p ] [-t timeout] [-z]

Server-Side Java Mapping Copyright © ZeroC, Inc Object Adapter States An object adapter is in one of three possible states: Holding (initial state after creation) The adapter does not read incoming requests off the wire (for TCP and SSL) and throws incoming UDP requests away. Active The adapter processes incoming requests. You can transition freely between the Holding and Active state. Inactive This is the final state, entered when you initiate destruction of the adapter: –Requests in progress are allowed to complete. –New incoming requests are rejected with a ConnectionRefusedException.

Server-Side Java Mapping Copyright © ZeroC, Inc Controlling Adapter State The following operations on the adapter relate to its state: local interface ObjectAdapter { void activate(); void hold(); void deactivate(); void waitForHold(); void waitForDeactivate(); void destroy(); //... }; The operations to change state are non-blocking. If you want to know when a state transition is complete, call waitForHold or waitForDeactivate as appropriate. destroy blocks until deactivation completes. You can re-create an adapter with the same name once destroy completes.

Server-Side Java Mapping Copyright © ZeroC, Inc Object Identity Each Ice object has an associated object identity. Object identity is defined as: struct Identity { string name; string category; }; The name member gives each Ice object a unique name. The category member is primarily used in conjunction with default servants and servant locators. If you do not use these features, the category is usually left as the empty string. The identity must be unique within the object adapter: no two servants that incarnate an Ice object can have the same identity. The combination of name and category must be unique. An identity with an empty name denotes a null proxy.

Server-Side Java Mapping Copyright © ZeroC, Inc Stringified Object Identity Two helper functions on the communicator allow you to convert between identities and strings: interface Communicator { Identity stringToIdentity(String ident); String identityToString(Identity id); //... } Stringified identities have the form /, for example: person/fred If no slash is present, the string is used as the name, with the category assumed to be empty. The object adapter has a getCommunicator method that returns the communicator. You use the communicator to convert between strings and object identities.

Server-Side Java Mapping Copyright © ZeroC, Inc The Active Servant Map (ASM) Each adapter maintains a map that maps object identities to servants: Incoming requests carry the object identity of the Ice object that is the target. The ASM allows the server-side run time to locate the correct servant for the request. Object identities must be unique per ASM.

Server-Side Java Mapping Copyright © ZeroC, Inc Activating Servants To make a servant available to the Ice run time, you must activate it. This adds an identity–servant pair to the ASM: local interface ObjectAdapter { Object* add(Object servant, Identity id); Object* addWithUUID(Object servant); //... }; Both operations return the proxy for the servant, for example: SimplePrx sp = SimplePrxHelper.uncheckedCast( adapter.add(new SimpleI("hello"), adapter.getCommunicator(). stringToIdentity("fred"))); As soon as a servant is added to the ASM, the run time will dispatch requests to it (assuming that the adapter is activated). addWithUUID adds the servant to the ASM with a UUID as the name, and an empty category.

Server-Side Java Mapping Copyright © ZeroC, Inc Creating Proxies You can create a proxy without activating a servant for the proxy: interface ObjectAdapter { //... Object* createProxy(Identity id); }; The returned proxy contains the passed identity and the adapter’s endpoints. Note that the return type is Object* so, typically, you need to downcast the proxy before you can use it.

Server-Side Java Mapping Copyright © ZeroC, Inc The Ice.Application Class Ice.Application is a utility class that makes it easy to initialize and finalize the Ice run time. public abstract class Application { public Application(); public final int main(String appName, String[] args); public final int main(String appName, String[] args, String configFile); public final int main(String appName, String[] args, InitializationData id); public abstract int run(String[] args); public static Communicator communicator(); public static String appName(); //... } You call Application.main from the real main, and implement the body of your client or server in the run method.

Server-Side Java Mapping Copyright © ZeroC, Inc Shutdown Hook Ice.Application provides control of the JVM shutdown hook: package Ice; public enum SignalPolicy { HandleSignals, NoSignalHandling } public abstract class Application { public Application(); public Application(SignalPolicy signalPolicy); //... synchronized public static void destroyOnInterrupt(); synchronized public static void shutdownOnInterrupt(); synchronized public static void defaultInterrupt(); synchronized public static boolean interrupted(); } The default behavior on interrupt is to destroy the communicator, allowing all currently running operation invocations to complete first.

Server-Side Java Mapping Copyright © ZeroC, Inc Compiling and Running a Server To compile a client, you must: compile the Slice-generated source files(s) compile your application code For Linux: $ mkdir classes $ javac -d classes -classpath \ > classes:$ICEJ_HOME/lib/Ice.jar \ > Server.java \ > generated/Demo/*.java To compile and run the server, Ice.jar must be in your CLASSPATH. Note that these commands are the same as for the client side—you need not supply server-specific options or use a server-specific class file or library.