Today's Objectives - PowerPoint PPT Presentation

1 / 14
About This Presentation
Title:

Today's Objectives

Description:

Transmission Control Protocol assembles the data packets into a continuous ... Iterator iter = coll.iterator(); while (iter.hasNext()) dept = (Dept)iter.next ... – PowerPoint PPT presentation

Number of Views:45
Avg rating:3.0/5.0
Slides: 15
Provided by: jamesg52
Category:
Tags: iter | objectives | today

less

Transcript and Presenter's Notes

Title: Today's Objectives


1
Today's Objectives
  • Overview of RMI
  • Review how EJBs use RMI for communication

2
RMI/CORBA
  • Internet Protocol enables passing data packets
    over the network.
  • Transmission Control Protocol assembles the data
    packets into a continuous stream of data.
  • Also, error checks and re-transmission.
  • Socket, a combination of an IP address and port
    number that identifies a program, provides
    network
  • data stream between two programs.
  • Java Remote Method Protocol is the protocol for
    object communications (remote method invocation
  • and parameter passing).
  • Internet Inter-Orb Protocol is a language
    independent object communications protocol. A
    higher level
  • protocol, GIOP, is used above IIOP for orb
    interoperability.

3
TCP/IP Socket
  • try
  • String ip_address "time_A.timefreq.bldrdoc.gov
    "
  • Socket my_socket new Socket (ip_address, 13)
  • BufferedReader my_input_stream new
    BufferedReader
  • (new InputStreamReader (my_socket.getInputStream
    ()))
  • String str my_input_stream.readLine()
  • while (str ! null)
  • System.out.println(str)
  • str my_input_stream.readLine()
  • catch (IOException e) System.out.println("Error"
    e)

4
RMI/CorbaStub and Skeleton for Dept EJB
Client
Remote Dept EJB
Skel
TCP/IP
5
Stubs and Skeletons
  • Stub
  • Initiates a connection with the remote VM
    containing the remote object
  • Marshals (writes) the parameters to the remote VM
  • Waits for the result of the method invocation
  • Unmarshals (reads) the return value of exception
    returned
  • Skeleton
  • Unmarshals (reads) the parameters of the remote
    method
  • Invokes the method on the actual remote object
    implementation
  • Marshals (writes) the result (return value or
    exception) to the caller.
  • Starting with Java 2 SDK, the actions of the
    stubs and skeletons are incorporated into JRMP
    stubs and skeletons are no longer generated
    separately.

6
Object Factory Pattern
Source Sun Microsystems
7
EJB Components

8
DeptHome Home Interface
  • package GerlachPackage
  • import javax.ejb.EJBHome
  • import java.rmi.RemoteException
  • import javax.ejb.CreateException
  • import javax.ejb.FinderException
  • import java.util.Collection
  • public interface DeptHome extends EJBHome
  • public Dept create() throws RemoteException,
    CreateException
  • Dept create(long deptno) throws
    RemoteException, CreateException
  • public Dept findByPrimaryKey(DeptPK primaryKey)
    throws RemoteException, FinderException
  • public Collection findAll() throws
    RemoteException, FinderException

9
Dept -- Remote Interface
  • package GerlachPackage
  • import javax.ejb.EJBObject
  • import java.rmi.RemoteException
  • public interface Dept extends EJBObject
  • long getDeptno() throws RemoteException
  • void setDeptno(long newDeptno) throws
    RemoteException
  • String getDname() throws RemoteException
  • void setDname(String newDname) throws
    RemoteException
  • String getLoc() throws RemoteException
  • void setLoc(String newLoc) throws
    RemoteException

10
DeptBean Entity Bean
  • package GerlachPackage.impl
  • import javax.ejb.EntityBean
  • import javax.ejb.EntityContext
  • import GerlachPackage.DeptPK
  • public class DeptBean implements EntityBean
  • public EntityContext entityContext
  • public long deptno
  • public String dname
  • public String loc
  • public DeptPK ejbCreate(long deptno)
  • this.deptno deptno
  • return new DeptPK(deptno)
  • public void setDeptno(long newDeptno)

11
Client
  • public class SampleDeptClient1
  • public static void main(String args)
  • SampleDeptClient1 sampleDeptClient1 new
    SampleDeptClient1()
  • try
  • Hashtable env new Hashtable()
  • env.put(Context.INITIAL_CONTEXT_FACTORY,
    "com.evermind.server.rmi.RMIInitialContextFactory"
    )
  • env.put(Context.SECURITY_PRINCIPAL,
    "admin")
  • env.put(Context.SECURITY_CREDENTIALS,
    "corbaisfun")
  • env.put(Context.PROVIDER_URL,
    "ormi//javacr.cudenver.edu23791/jgerlach")
  • Context ctx new InitialContext(env)
  • DeptHome deptHome (DeptHome)ctx.lookup("De
    pt")
  • // The initial context implements the Context
    interface and provides the starting point for
    resolution of names -- JNDI (Java Naming and
    Directory Interface).

12
Client Continued
  • // Retrieve all instances using the findAll()
    method
  • // (CMP Entity beans only)
  • Dept dept
  • Collection coll deptHome.findAll()
  • Iterator iter coll.iterator()
  • while (iter.hasNext())
  • dept (Dept)iter.next()
  • System.out.println("deptno "
    dept.getDeptno())
  • System.out.println("dname "
    dept.getDname())
  • System.out.println("loc "
    dept.getLoc())
  • System.out.println()
  • catch(Throwable ex) ex.printStackTrace()

13
Client Continued
  • // Retrieve and modify single EJB instance
  • dept deptHome.findByPrimaryKey(new DeptPK(10))
  • System.out.println("deptno "
    dept.getDeptno())
  • System.out.println("dname " dept.getDname())
  • System.out.println("loc " dept.getLoc())
  • dept.setLoc("Chicago")

14
Client Continued
  • // Create a new dept EJB
  • dept deptHome.create( 99 )
  • dept.setDname("Systems")
  • dept.setLoc("Denver")
Write a Comment
User Comments (0)
About PowerShow.com