22
Copyright (c) Qusay H. Ma hmoud 1 The Naming Service (Client’s View) A tree-like directory for object references Much like a file system: provides directory structure for files Object references are stored by name Each object reference-name pair is called a name binding Name bindings may be organized under naming contexts (name binding itself) All bindings are stored under initial naming context (the only persistent binding)

Copyright (c) Qusay H. Mahmoud 1 The Naming Service (Client’s View) A tree-like directory for object references Much like a file system: provides directory

Embed Size (px)

Citation preview

Page 1: Copyright (c) Qusay H. Mahmoud 1 The Naming Service (Client’s View) A tree-like directory for object references Much like a file system: provides directory

Copyright (c) Qusay H. Mahmoud1

The Naming Service (Client’s View)

A tree-like directory for object references Much like a file system: provides directory

structure for files Object references are stored by name Each object reference-name pair is called a

name binding Name bindings may be organized under

naming contexts (name binding itself) All bindings are stored under initial naming

context (the only persistent binding)

Page 2: Copyright (c) Qusay H. Mahmoud 1 The Naming Service (Client’s View) A tree-like directory for object references Much like a file system: provides directory

Copyright (c) Qusay H. Mahmoud2

The Naming Service….

Your client’s ORB must know the name and port# of a host running the naming service

The naming service can either be the JavaIDL naming service or any COS-compliant service

To start: tnameserv –ORBInitialPort port#– The default port number is 900

To stop: use relevant OS command (kill, ctrl-c) Namespace is lost if name server halts/restarts

Page 3: Copyright (c) Qusay H. Mahmoud 1 The Naming Service (Client’s View) A tree-like directory for object references Much like a file system: provides directory

Copyright (c) Qusay H. Mahmoud3

The Naming Service (interfaces)

org.omg.CosNaming:– NamingContext: primary interface to naming

service– NameComponent: identify (name/kind) services– BindingInterator: iterating through the contents– Binding: a single entry in the naming service– BindingList: a list of entries in the naming service– BindingType: the type of an entry

Page 4: Copyright (c) Qusay H. Mahmoud 1 The Naming Service (Client’s View) A tree-like directory for object references Much like a file system: provides directory

Copyright (c) Qusay H. Mahmoud4

Naming Service (NamingContext)

Analogous to a directory on a file system Contains a series of named objects An object in a NamingContext may be another

NamingContext (analogous to subdirectory) A reference to the top level NamingContext

can be obtained with the ORB method:resolve_initial_references()

Page 5: Copyright (c) Qusay H. Mahmoud 1 The Naming Service (Client’s View) A tree-like directory for object references Much like a file system: provides directory

Copyright (c) Qusay H. Mahmoud5

Naming Service (NamingContext)

To get a reference to an object stored under NamingContext, use:resolve(NameComponent namePath)

It throws: NotFound, CannotProceed, InvalidName

This method returns org.omg.CORBA.Object Therefore, it must be narrowed to a particular

interface using a helper’s narrow()

Page 6: Copyright (c) Qusay H. Mahmoud 1 The Naming Service (Client’s View) A tree-like directory for object references Much like a file system: provides directory

Copyright (c) Qusay H. Mahmoud6

Browsing the Naming Service

The top level only….import org.omg.CORBA.*;import org.omg.CosNaming.*;public class Browser { ORB orb = ORB.init (args, null); // obtain a reference to the naming service org.omg.CORBA.Object nc = orb.resolve_initial_references ("NameService"); NamingContext namingContext = NamingContextHelper.narrow (nc);

Page 7: Copyright (c) Qusay H. Mahmoud 1 The Naming Service (Client’s View) A tree-like directory for object references Much like a file system: provides directory

Copyright (c) Qusay H. Mahmoud7

Browsing the Naming Service….

BindingListHolder b1 = new BindingListHolder ();

BindingIteratorHolder b2 = new BindingIteratorHolder ();

// get initial content-list

namingContext.list (10, b1, b2);

// print out bindings

Binding[] bindings = b1.value;

if(bindings.length == 0) return;

Page 8: Copyright (c) Qusay H. Mahmoud 1 The Naming Service (Client’s View) A tree-like directory for object references Much like a file system: provides directory

Copyright (c) Qusay H. Mahmoud8

Browsing the Naming Service….

for (int i = 0; i < bindings.length; i++) { Binding binding = bindings[i]; NameComponent[] name = binding.binding_name; BindingType type = binding.binding_type; if (type == BindingType.nobject) { System.out.println (name[0].id + "-" + name[0].kind); } else { // BindingType.ncontext System.out.println (name[0].id + "-" + name[0].kind + "/"); } }

Page 9: Copyright (c) Qusay H. Mahmoud 1 The Naming Service (Client’s View) A tree-like directory for object references Much like a file system: provides directory

Copyright (c) Qusay H. Mahmoud9

CORBA Servers

Implement the IDL interfaces by subclassing the appropriate pregenerated skeleton class

Each class is called a servant The HelloServer Example (Slide 34)

– Initialize the ORB– Create initial objects (servants)– Connect each servant to the ORB– Bind the servants in the naming service– Wait for connections

Page 10: Copyright (c) Qusay H. Mahmoud 1 The Naming Service (Client’s View) A tree-like directory for object references Much like a file system: provides directory

Copyright (c) Qusay H. Mahmoud10

CORBA Servers (ObjectImpl)

When a servant extends the _interfaceObjectImpl, it is actually extending the orb.omg.CORBA.Portable.ObjectImpl class

This class provides a variety of helper methods (including all methods of CORBA Object)

Page 11: Copyright (c) Qusay H. Mahmoud 1 The Naming Service (Client’s View) A tree-like directory for object references Much like a file system: provides directory

Copyright (c) Qusay H. Mahmoud11

Naming Service (Server’s View)

Registering/Unregistering services:bind: register the object under the specified namerebind:identical to bind(), but an AlreadyBound

exception won’t be thrown – existing object replacedunbind:unregister a CORBA object

Creating new naming contexts:bind_new_context, new_context, bind_context

Destroying a naming context:destroy: destroy an empty NamingContext

Page 12: Copyright (c) Qusay H. Mahmoud 1 The Naming Service (Client’s View) A tree-like directory for object references Much like a file system: provides directory

Copyright (c) Qusay H. Mahmoud12

Registering Services

Example: NameClient.java

This will add names to the namespace:– Plans is an object reference– Personal is a naming context that contains two

object references: Calendar and Schedule

Page 13: Copyright (c) Qusay H. Mahmoud 1 The Naming Service (Client’s View) A tree-like directory for object references Much like a file system: provides directory

Copyright (c) Qusay H. Mahmoud13

Clearing the Naming Service

Steps:– Get a reference to initial naming context– Recursively iterate through the sub naming contexts– Call unbind– Call destroy

Page 14: Copyright (c) Qusay H. Mahmoud 1 The Naming Service (Client’s View) A tree-like directory for object references Much like a file system: provides directory

Copyright (c) Qusay H. Mahmoud14

Advanced IDL

IDL supports C/C++ style comments:// This is a comment/* This is another comment */

Also, it supports:– conditionals (#if)– defines (#define)– includes (#include)

idlj requires access to a C preprocessor (cpp)

Page 15: Copyright (c) Qusay H. Mahmoud 1 The Naming Service (Client’s View) A tree-like directory for object references Much like a file system: provides directory

Copyright (c) Qusay H. Mahmoud15

Advanced IDL: Arrays

IDL provides multidimensional fixed-size arrays The array size is fixed at compile time IDL arrays map directly into Java arrays Example:interface Customer { attribute string address[4]; // 1-D array attribute short table[5][7]; // 2-D array}

Page 16: Copyright (c) Qusay H. Mahmoud 1 The Naming Service (Client’s View) A tree-like directory for object references Much like a file system: provides directory

Copyright (c) Qusay H. Mahmoud16

Advanced IDL: Sequences

A sequence is a 1-D array that can be of variable size

Two types:– Bounded sequences

sequence<long, 15>employee;– Unbounded sequences

sequence<long> employee

Page 17: Copyright (c) Qusay H. Mahmoud 1 The Naming Service (Client’s View) A tree-like directory for object references Much like a file system: provides directory

Copyright (c) Qusay H. Mahmoud17

Advanced IDL: Enumerations

The enum data type defines an enumeration– A user-defined data type that can hold one of a fixed

set of values

Example:enum CreditCard { visa, amex, discover };

interface Bank {

void applyForCreditCard(CreditCard cc);

};

Page 18: Copyright (c) Qusay H. Mahmoud 1 The Naming Service (Client’s View) A tree-like directory for object references Much like a file system: provides directory

Copyright (c) Qusay H. Mahmoud18

Enumerations (mapping to Java)

An enum is mapped to a Java class with static variables representing the set of values

Example:public class CreditCard { public static vindl CReditCard visa, amex, discover; public static final int _visa, _amex, _discover; public int value();} To compare (using switch): (unknown.value() ==

_visa)

Page 19: Copyright (c) Qusay H. Mahmoud 1 The Naming Service (Client’s View) A tree-like directory for object references Much like a file system: provides directory

Copyright (c) Qusay H. Mahmoud19

Advanced IDL: Structures

The IDL type struct defines a structure Use a struct to group related data together Example:struct Name { string firstName; string lastName;};interface Customer { attribute Name name; };

Page 20: Copyright (c) Qusay H. Mahmoud 1 The Naming Service (Client’s View) A tree-like directory for object references Much like a file system: provides directory

Copyright (c) Qusay H. Mahmoud20

Structures (mapping to Java)

A struct is mapped to a Java class that provides instance variables for the fields, and a constructor for all values, and a null constructor

Example:public class Name { public String firstName; public String lastname; public Name(); public Name(String firstName, String lastName);}

Page 21: Copyright (c) Qusay H. Mahmoud 1 The Naming Service (Client’s View) A tree-like directory for object references Much like a file system: provides directory

Copyright (c) Qusay H. Mahmoud21

Advanced IDL: typedefs

A typedef is an alias, or another name for an existing data type

Example: typedef long age; interface Customer { age howOld; } Typedefs of simple data types are mapped to

the original (I.e. replaced by the more basic type)

Page 22: Copyright (c) Qusay H. Mahmoud 1 The Naming Service (Client’s View) A tree-like directory for object references Much like a file system: provides directory

Copyright (c) Qusay H. Mahmoud22

Advanced IDL: Constants

1. Within an interface:interface Foo { const long aLong = -32; };

Mapped to: public interface Foo {

public static final int aLong = (int) –32L; };

2. Not within an interface:

const string Message=“hello”; Mapped to: public interface Message {

public static final String Message=“hello”; };