Title: Java Naming and Directory Interface JNDI
1Java Naming and Directory Interface (JNDI)
Context jndiContext getInitialContext() Objec
t ref jndiContext.lookup(CabinHomeRemote) Cab
inHomeRemote home (CabinHomeRemote)
PortableRemoteObject.narrow(ref,
CabinHomeRemote.class) CabinRemote cabin_1
home.create(new Integer(1)) cabin_1.setName(Mast
er Suite) cabin_1.setDeckLevel(1)
2Java Naming and Directory Interface (JNDI)
JNDI is a standard Java package that provides a
uniform API for accessing a wide range of
services.
3The Remote Client API (Application Program
Interface)
client
EJB server
EJB server
EJB container
EJB container
4The Remote Client API (Application Program
Interface)
client
EJB server
EJB server
EJB container
EJB container
5The Remote Client API (Application Program
Interface)
Remote Client API
Java RMI-IIOP
Java RMI
CORBA
IDL
6The Remote Client API (Application Program
Interface)
Remote Client API
Java RMI-IIOP
Java RMI
CORBA
IDL
7Java RMI-IIOP return types and parameters
- Return types and parameters
- declared (checked by the compiler)
- actual (checked at runtime).
- primitives (byte, boolean, char, )
- Java serializable types (java.io.Serializable)
- Java RMI remote types (java.rmi.Remote).
8Java RMI-IIOP return types and parameters
remote reference
client
original serializable object
EJB object
bean instance
before a serializable object is passed, one copy
resides on the client
9Java RMI-IIOP return types and parameters
remote reference
client
original serializable object
EJB object
after a serializable object is passed, copies
reside on both the client and the bean instance.
Changes to one copy are not reflected in the
other.
bean instance
10Java RMI-IIOP return types and parameters
client application
bean instance
EJB object
remote reference
A
Pass A to B
B
original remote reference
A
EJB object
bean instance
11Java RMI-IIOP return types and parameters
client application
bean instance
EJB object
remote reference
A
B
original remote reference
A
copy of remote reference
EJB object
bean instance
12Java RMI-IIOP overloading restrictions
Remote_interface_X
void bar(String s)
Remote_interface_Y
void bar(long l)
Remote_interface_Z
void bar(byte b)
13Java RMI-IIOP overloading restrictions
Remote_interface_A
Remote_interface_B
void foo(int i)
void foo(double d)
Remote_interface_C
14Java RMI-IIOP narrow
import javax.rmi.PortableRemoteObject javax.nam
ing.Context jndiContext Object ref
jndiContext.lookup(CabinHomeRemote) CabinHomeRe
mote home (CabinHomeRemote)
PortableRemoteObject.narrow(ref,
CabinHomeRemote.class)
15The remote home interface
16The remote home interface bean metadata
EJBHome.getEJBMetaData()
- remote home interface
- remote interface
- primary key
- entity/session bean.
17The remote home interface creating and finding
beans
package com.titan.cabin import
java.rmi.RemoteException import
javax.ejb.CreateException import
javax.ejb.FinderException public interface
CabinHomeRemote extends javax.ejb.EJBHome
public CabinRemote create(Integer id)
throws CreateException, RemoteException
public CabinRemote findByPrimaryKey(Integer pk)
throws FinderException, RemoteException
18The remote home interface (your own) home methods
but only for entity beans.
19The remote interface
EJB home
20The remote interface primary key
EJBObject.getPrimaryKey()
21The remote interface comparing beans for identity
EJBObject.isIdentical() Object.equal()
22The remote interface remove
EJBObject.remove()
23The remote interface the enterprise bean handle
EJBObject.getHandle() returns javax.ejb.Handle
A Handle is a serializable reference to the
remote EJB object.
javax.ejb.HomeHandle
24The local client API
client
EJB server
EJB server
EJB container
EJB container
25The local client API
client
EJB server
EJB server
EJB container
EJB container
26The local interface
getEJBLocalHome() returns a LocalHome object
getPrimaryKey() returns the primary key
isIdentical() compares two local EJB objects
remove() remove the EJB
27The local home interface
create()
findByPrimaryKey()
remove()
28Deployment descriptor
ltejb-jar xmlns"http//java.sun.com/xml/ns/j
2ee" xmlnsxsi"http//www.w3.org/2001/XMLSch
ema-instance" xsischemaLocation"http//java
.sun.com/xml/ns/j2ee
http//java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd"
version"2.1"gt ltenterprise-beansgt
ltentitygt ltejb-namegtCabinEJBlt/ejb-namegt
lthomegtcom.titan. CabinHomeRemotelt/homegt
ltremotegtcom.titan.CabinRemotelt/remotegt
ltlocal-homegtcom.titan.cabin.CabinHomeLocallt/local-
homegt ltlocalgtcom.titan.cabin.CabinLocallt/loc
algt ltejb-classgtcom.titan.CabinBeanlt/ejb-clas
sgt ltpersistence-typegtContainerlt/persistence-
typegt
29Deployment descriptor
ltejb-jar xmlns"http//java.sun.com/xml/ns/j
2ee" xmlnsxsi"http//www.w3.org/2001/XMLSch
ema-instance" xsischemaLocation"http//java
.sun.com/xml/ns/j2ee
http//java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd"
version"2.1"gt ltenterprise-beansgt
ltentitygt ltejb-namegtCabinEJBlt/ejb-namegt
lthomegtcom.titan. CabinHomeRemotelt/homegt
ltremotegtcom.titan.CabinRemotelt/remotegt
ltlocal-homegtcom.titan.cabin.CabinHomeLocallt/local-
homegt ltlocalgtcom.titan.cabin.CabinLocallt/loc
algt ltejb-classgtcom.titan.CabinBeanlt/ejb-clas
sgt ltpersistence-typegtContainerlt/persistence-
typegt
30Local vs. Remote
Local Remote
faster slower
(to other server without rewriting the code)
31Local vs. Remote
Local Remote
faster slower
not movable movable
object arguments object arguments passed
by reference are copied
(dangerous!!!)