Enterprise Programming for Distributed Applications - PowerPoint PPT Presentation

1 / 37
About This Presentation
Title:

Enterprise Programming for Distributed Applications

Description:

(Resource: JavaMail email) java:comp/env/eis-specific ... as an address book for retrieving the addresses of mail ... JNDI belongs to the javax extension APIs ... – PowerPoint PPT presentation

Number of Views:77
Avg rating:3.0/5.0
Slides: 38
Provided by: pirooz
Category:

less

Transcript and Presenter's Notes

Title: Enterprise Programming for Distributed Applications


1
Enterprise Programming for Distributed
Applications
  • Pirooz Saeidi

2
Java Distributed Programming-The Three-Tier
Architecture
  • Distributed applications are usually divided into
    several tiers. A Three_Tier Architecture
    consists of
  • Presentation Tier
  • Client applications
  • Application Tier
  • Business Objects
  • these objects may be distributed and run in
    several machines N-tier architecture
  • Data Tier
  • XML, Databases, and legacy Systems

In 2-tier client/server model, the business logic
can be found inside clients user interface, or
within servers data store. But in 3-tier model
the business logic is independently managed.
3
Advantage of a three-tier architecture
  • Performance
  • Fault tolerance and integrity
  • Performance by distributing load across several
    machines
  • Object reuse
  • Different presentation tiers can use the same
    business logic
  • Flexibility-easy to maintain and replace
    application components.

Processes can be managed and deployed separately
from the user interface and the database
4
Enterprise Technologies for Distributed Systems
  • The Java 2 Enterprise Edition (J2EE) facilitates
    the development by providing
  • A set of enterprise APIs to help developing
    distributed applications
  • Source java.sun.com/j2ee
  • Examples of J2EE APIs
  • JDBC, RMI, JMS, JNDI, EJB, JavaMail, JSP,
    Servlets, XML, and CORBA
  • Some of which have already been introduced in the
    module.

5
Technologies for the rest of this module
  • We will introduce the following J2EE
    technologies
  • JNDI Java Naming and Directory Service
  • A common interface to different naming services
  • RMI Remote Method Invocation
  • To invoke remote java object methods
  • EJB Enterprise Java Beans
  • This API defines the component architecture for
    multi-tier client/server-systems by Sun.
  • Other Technologies
  • Jini and Javaspaces Create a self-healing and
    discoverable service-based networked
    architecture.
  • In contrast to technologies such as J2EE, .NET,
    and Corba which are based on a static foundation
    Jini is a Service Oriented Architecture and is a
    dynamic system.

6
The Overall picture

Presentation Tier Application Tier Data Tier
Database
HTML
JMS
JDBC
Web Server
RMI
Application
XML server/database
Jini
Legacy systems
JNDI
WML
7
JNDI ServiceJava Naming Directory Interface
  • A naming service is used to locate objects in
    distributed systems and is a dedicated software
    to control a namespace (e.g. database, file
    system..).
  • Allows binding of names to data objects.
  • Names make sense within a naming space (context).
    A context is a set of name-to-object bindings
  • A naming Service allows lookup of name for data
    (resolution).

8
JND API
  • The JNDI API makes it easy to plug lookup
    services from various providers into a program
    written in the Java language.
  • The client and server both need to use the same
    lookup service.
  • The client can look up any informatiom registered
    with the server and establish communication.

9
JNDINaming Service
  • JNDI names are organised hierarchically and
    resource names are organised into subcontexts
    (like file systems and sub-directories).
  • For example, all JDBC resource names must be in
    javacomp/env/jdbc subcontext. The JNDI name for
    the resource of a classList database could be
    javacomp/env/jdbc/classList

10
JNDINaming Service
  • Subcontexts for other resources
  • javacomp/env/jdbc
  • (Resource JDBC database)
  • javacomp/env/jms
  • (Resource JMS messaging system)
  • javacomp/env/mail
  • (Resource JavaMail email)
  • javacomp/env/eis-specific
  • (Resource connector EIS -enterprise information
    system)

11
JNDIExamples of naming Service
  • The most popular naming service is DNS.
  • File-naming systems locate specified files by
    name (e.g. /usr/hom1/student45)
  • RMI and CORBA
  • Operate their own naming services
  • CORBA uses COSNaming service.

12
JNDIDirectory Service
  • A directory service is a specialised naming
    service
  • Stores attributes associated with objects
  • Uses a hierarchical structure and can search for
    objects by named attributes
  • Example
  • Netscape Directory Server, MS Active Directory,
  • A Java mail client program, can use the directory
    as an address book for retrieving the addresses
    of mail recipients.

13
The JNDI Architecture
  • The JNDI architecture consists of an API and a
    service provider interface (SPI).
  • Java applications use the JNDI API to access
    different naming and directory services.
  • The SPI allows different naming and directory
    services to be connected transparently
  • This enables Java applications to access their
    services using the JNDI API services.
  • See next diagram

14
The JNDI Architecture
  • Source www.sun.com/products/jndi

SPI Examples COSNaming, Windows Registry, LDAP,
DNS/RMI/NIS/NDS
15
The JNDI Packages
  • The JNDI is included in the Java 2 SDK, v1.3 and
    later releases.
  • To use the JNDI, we need the JNDI classes and one
    or more service providers.

16
The JNDI Packages
  • The Java 2 SDK, v1.3 includes three service
    providers for the following naming/directory
    services
  • Lightweight Directory Access Protocol (LDAP)
  • is a protocol for querying and modifying
    directory services running over TCP/IP.
  • Common Object Request Broker Architecture
    (CORBA) Common Object Services (COS) name
    service
  • Java Remote Method Invocation (RMI) Registry
  • Other service providers can be downloaded from
    the JNDI website or obtained from other vendors

17
The JNDI Packages
  • The JNDI is divided into five packages
  • javax.naming
  • Set of classes and interfaces for accessing
    naming services
  • javax.naming.directory
  • Main functionality for accessing a directory
    service
  • javax.naming.event
  • Event listener interface for directory and naming
    services. Notified when the bound object is
    changed, or removed.
  • javax.naming.ldap
  • Extensions for LDAP v3. Supports challenge and
    response authentication
  • javax.naming.spi
  • Interfaces to allow interaction with naming or
    directory services. Used by vendors.

18
Basic classes of JNDI
  • JNDI belongs to the javax extension APIs
  • The frequently used classes or interfaces are
    found in javax.naming
  • Simple interactions use a main interface and a
    main class
  • The class InitialContext
  • The interface Context

19
Basic classes of JNDI
  • The class InitialContext
  • Represents the root of the current naming system.
    All naming operations are relative to a context,
    and this is the starting point for resolution of
    names.
  • For example the root folder in a path of a
    file-naming system
  • The interface Context
  • A set of bound objects in current naming system.
  • Provides functionality to lookup and bind
    operations

20
JNDI in Practice- Binding
  • Binding an object into a JNDI-based service
    involves these 6 steps
  • Choose a service. Examples
  • LDAP, COSNaming, etc.
  • Set up parameters for the Initial context
  • Pass them as ltkey, valuegt pairs Hashtable or
    Properties
  • Set up Context.INITIAL_CONTEXT_FACTORYthe
    driver.

21
JNDI in Practice- Binding
  • 4. Set up other parameters
  • Context.PROVIDER_URL location of the naming
    service
  • Context.SECURITY_AUTHENTICATION security level
    to be used depending on security requirements.
  • 5. Create the connection to the Initial Context,
    which is the root of the naming service.
  • 6. Call the bind or rebind method.
  • Bind fails if name already bound.
  • Rebind will overwrite if name already exists

22
JNDI in Practice- Binding
  • An example of bind associating object with
    names

This is the object
Lecture myLec new Lecture ("EPDA",
55) Properties myProp new Properties
() //set properties to connect to naming
service myProp.put (Context.INITIAL_CONTEXT_FACTO
RY, "com.sun.jnidi.registry.RegistryContextFacto
ry") myProp.put(Context.PROVIDER_URL,
"rmi//aServer34543") //using the properties
get a new initial naming context Context ctx
new InitialContext (myProp) ctx.rebind
("EPDA.Lecture", myLect)
Create an empty property list String of ltkey,
valuegt pairs Look it up in java docs
Put (Object key, Object Val) Maps key to val
23
JNDI in Practice- Lookup
  • Looking up an object into a JNDI-based service
    involves these 7 steps
  • Choose the service you are going to search
  • LDAP., COSNaming
  • Set up parameters for the Initial context
  • Pass them as ltkey, valuegt pairs Hashtable or
    Properties
  • Again Set up Context.INITIAL_CONTEXT_FACTORYthe
    driver.

24
JNDI in Practice- Lookup
  • 4. Set up other parameters
  • Context.PROVIDER_URL location of the naming
    service
  • Context.SECURITY_AUTHENTICATION security level
    to be used As before depending on security
    requirements.
  • But unlikely to use higher security if searching.
  • 5. Create the connection to the Initial Context,
    which is the root of the naming service.
  • Call the lookup method.
  • Downcast the returned references.

25
JNDI in Practice- Lookup
  • An example of Lookup
  • Properties myProp new Properties ()
  • //set properties to connect to naming service
  • myProp.put (Context.INITIAL_CONTEXT_FACTORY,
    "com.sun.jnidi.registry.RegistryContextFactory
    ")
  • myProp.put(Context.PROVIDER_URL,
    "rmi//aServer34543")
  • // using the properties get a new initial naming
    context
  • Context ctx new InitialContext (myProp)
  • //lookup the object
  • Object obj ctx.lookup("EPDA.Lecture")
  • Lecture resolvedObj (Lecture) obj

26
JNDI in practice- jndi.properties
  • May ignore setting up the properties explicitly.
  • For example we may want to have configuration
    changed without changing the code.
  • The call to InitialContext looks for a well-known
    property.

27
Changes to Bound Objects
  • The bound objects in JNDI context can be modified
    in one of these forms
  • Destroy the bindings
  • Replace the bindings
  • Rename the bindings

28
Replacing the Bound Object
  • Use rebind ()
  • To replace the old bound object with the new
  • Name remains the same
  • // create the replacement object using rebind
    (..)
  • Lectures coolEPDA new Lectures ()
  • // replace the old bound object, bound
  • // under the name CoolestModule if one exists
  • cxt.rebind (CoolestModule,coolEPDA)

29
Destroying the Bound Objects
  • To remove a bound object with a supplied name,
    use unbind ()

// destroy the bound object // the object name is
getRidofMe if one exists ctx.unbind
(getRidofMe)
30
Renaming a Binding
  • Using the rename () method
  • Can keep the old object
  • A new object is bound to the original name

// create the replacement object Lecture
thisWeeksTopic new Lecture() // rename the
already bound object //under the name
currentTopic to forgottenTopic ctx.rename
(currentTopic, forgottenTopic) //bind the
new object under the old name ctx.bind
(currentTopic, thisWeeksTopic)
31
Creating and Destroying SubContexts
  • Like in file systems and subdirectories we can
    also manage subcontexts

// create new subcontexts to hold
bindings Ctx.createSubcontext (Assignment1) Ct
x.createSubcontext (Assignment2) // or remove
an old subsontext Ctx.destroySubcontext
(oldAssignment)
32
Interaction with the Context Set
  • We can list all objects bound within a Context
    and interact with them.
  • These are facilitated by two methods
  • The list () method
  • Returns all bindings and types, but doesnt
    return the object
  • The listBindings () method
  • Returns all bindings and types
  • and bound objects
  • It is useful when you iterate a set of actions

33
Interacting with the Context SetThe list ( )
method
  • This method can be used to extract details and
    returns an Enumeration of NameClassPair
    references.
  • Details such as
  • Bind name and
  • Classname of bound object
  • See next example

Enumeration interface generates a series of
elements, one at a time. Repeated calls to the
nextElement method return successive elements of
the series.
javax.naming.NameClassPair represents the object
name class pair of a binding
34
Example of Context List Method
Javax.naming Interface for enumerating lists

Methods such as list ()return a Naming Enumeration
// Get the Enumeration NamingEnumeration nE
ctx.list () // print the details of each
entry NameClassPair ncp While (nE.hasMore())
Ncp (NameClassPair) nE.next
() System.out.println (ncp.getClassName()) Sys
tem.out.println (ncp.getName())
This class represents the object name and class
name pair of a binding found in a context.
35
Interacting with the Bound Object SetThe
listBindings ( ) method
  • Useful when you want to interact with the objects
    themselves
  • This method can be used to extract details and
    returns an Enumeration of Binding references.
  • A subclass of NameClassPair
  • Details are
  • Bind name
  • className of object bound
  • Object reference of object bound
  • See next example

36
Example of ListBindings Method

// Get the Enumeration NamingEnumeration nE
ctx.list () // print the details of each
entry Binding b While (nE.hasMore()) b
(Binding) nE.next () System.out.println
(b.getClassName()) System.out.println
(b.getName()) System.out.println
(b.getObject())
37
Summary
  • In this lecture, we listed a number of Enterprise
    Technologies that fit into the 3-tier
    architecture for Distributed Applications.
  • We looked at methods that facilitate storage of
    information for directory services.
  • We then looked at JNDI to see how it allows
    location of remote functionality,
  • as well as how we can use it for distributed
    systems
Write a Comment
User Comments (0)
About PowerShow.com