Download presentation
Presentation is loading. Please wait.
1
George Blank University Lecturer
2
CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 12, Distributed Computing Ajay Bajaj, Kunal Mehta, Arun Marioli, Dhairya Shah
3
J2EE Sun offers Java in several different editions. The two most common versions are the standard edition (J2SE) and the enterprise edition (J2EE). There is also a micro edition. In general, the standard edition is for stand-alone applications while the enterprise edition is for computing over a network. Actually, as we have seen, most of what you need for web applets is in J2SE. J2EE adds web servers, database connectivity, remote method invocation and enterprise java beans.
4
The J2EE SDK There is a lot of software included in the J2EE SDK, including NetBeans, the Sun Application Server, and Apache Tomcat Web Server. All of this is currently provided without charge, in a package that compares favorably with development environments that cost thousands of dollars. Around 1990, I paid $20,000 for a single user copy of the Bachman Analyst, a front end case tool that did not do much more than a few diagrams.
5
Distributed Multi-tiered Applications The J2EE platform uses a multi-tiered distributed application model for both enterprise applications Application logic is divided into “components” according to function, and the various application components that make up a J2EE application are installed on different machines depending on the tier in the multi-tiered J2EE environment to which the application component belongs
6
Distributed Java Technologies There are many different ways to create a distributed application with Java. We have already looked at Applets, Servlets, JDBC, and JNLP. In this presentation, we will briefly look at Java Sockets, Remote Method Invocation, and Enterprise Java Beans.
7
Socket Example Sockets simply open a connection between two network hosts to pass information between them. We will look at a simple Java program to implement a socket connection. The example program implements a client, EchoClient, that connects to the Echo server. The Echo server simply receives data from its client and echoes it back. The Echo server is a service built into most operating systems.
8
Socket Basics Open a socket. Open an input stream and output stream to the socket. Read from and write to the stream according to the server's protocol. Close the streams. Close the socket. Only step 3 differs from client to client, depending on the server.
9
Echo Client description EchoClient creates a socket and gets a connection to the Echo server. It reads input from the user on the standard input stream, and then forwards that text to the Echo server by writing the text to the socket. The server echoes the input back through the socket to the client. The client program reads and displays the data passed back to it from the server.
10
Echo Client code import java.io.*; import java.net.*; public class EchoClient { public static void main(String[] args) throws IOException { Socket echoSocket = null; PrintWriter out = null; BufferedReader in = null; try { echoSocket = new Socket("taranis", 7); out = new PrintWriter(echoSocket.getOutputStream(), true); in = new BufferedReader(new InputStreamReader( echoSocket.getInputStream())); } catch (UnknownHostException e) { System.err.println("Don't know about host: taranis."); System.exit(1); } catch (IOException e) { System.err.println("Couldn't get I/O for " + "the connection to: taranis."); System.exit(1); }
11
Echo Client code, cont’d BufferedReader stdIn = new BufferedReader( new InputStreamReader(System.in)); String userInput; while ((userInput = stdIn.readLine()) != null) { out.println(userInput); System.out.println("echo: " + in.readLine()); } out.close(); in.close(); stdIn.close(); echoSocket.close(); }
12
Socket Summary This client program is straightforward and simple because the Echo server implements a simple protocol. The client sends text to the server, and the server echoes it back. When your client programs are talking to a more complicated server such as an HTTP server, your client program will also be more complicated.
13
Java Remote Method Invocation Java RMI is a distributed object model for the Java platform. RMI extends the Java object model beyond a single virtual machine address space. RMI uses object serialization to convert object graphs to byte streams for transport.
14
Remote Method Invocation RMI provides the means to invoke methods remotely. RMI allows for applications to communicate and execute across multiple systems on a network. RMI is supported by the java.rmi, java.rmi.server, and java.rmi.registry Enhanced security of Java 2 requires a security policy implementation.
15
Parts in a RMI System Interface definitions for remote services Implementations of the remote services Stub and Skeleton files A server to host the remote services An RMI Naming service that allows clients to find the remote services A class file provider (an HTTP or FTP server)
16
RMI process Java ClientJava Server Client StubServer Skeleton Client Method Called Method Network transportNetwork Transport argumentsresults Network Not needed In Java 2
17
RMI Server, Client, and Registry The server process registers the remote object X with the registry using the Naming.bind() method. The client calls Naming.lookup(), which contacts the registry and obtains a stub object for X. The client then uses the stub as if it is a local object.
18
RMI Registry The Registry tracks the addresses of the remote objects exported by applications It is the central management point for RMI Does not actually invoke remote methods Bind() links the object in the registry Rebind() replaces object with a new one
19
Parameter Passing When a remote procedure is executed, the java.rmi runtime encodes the arguments and sends them over the network to a server that decodes them. The server then invokes the method, encodes the results, and sends it back. Finally, the client-side java.rmi runtime decodes the result.
20
Building RMI Applications Define remote interfaces Create classes that implement the interfaces Create stub and skeleton classes for the implementation classes. Create Security Policy
21
Steps Involved Write The HTML and Java Source Files. Compile and Deploy Class Files and HTML Files. Start the Remote Object Registry, Server, and Applet
22
Summary Java RMI is a distributed object model for the Java platform. RMI extends the Java object model beyond a single virtual machine address space. RMI uses object serialization to convert object graphs to byte streams for transport.
23
J2EE Architecture J2EE multi-tiered applications are generally considered to be three-tiered applications because they are distributed over three different locations –client machines –the J2EE server machine –the database or legacy machines at the back end
24
J2EE Architecture Three-tiered applications that run in this way extend the standard two-tiered client and server model by placing a multithreaded application server between the client application and back-end storage
25
J2EE Containers The application server maintains control and provides services through an interface or framework known as a container There are five defined container types in the J2EE specification
26
Server J2EE Containers Three of these are server-side containers: –The server itself, which provides the J2EE runtime environment and the other two containers –An EJB container to manage EJB components –A Web container to manage servlets and JSP pages
27
Client J2EE Containers The other two container types are client-side: –An application container for stand-alone GUIs, console –An applet container, meaning a browser, usually with the Java Plug-in
28
J2EE Components As said earlier, J2EE applications are made up of components A J2EE component is a self-contained functional software unit that is assembled into a J2EE application with its related classes and files and that communicates with other components
29
Components Client components run on the client machine, which correlate to the client containers Web components -servlets and JSP pages EJB Components
30
Packaging Applications and Components Under J2EE, applications and components reside in Java Archive (JAR) files These JARs are named with different extensions to denote their purpose, and the terminology is important
31
Various File types Enterprise Archive (EAR) files represent the application, and contain all other server-side component archives that comprise the application Client interface files and EJB components reside in JAR files Web components reside in Web Archive (WAR) files
32
Deployment Descriptors Deployment descriptors are included in the JARs, along with component-related resources Deployment descriptors are XML documents that describe configuration and other deployment settings (remember that the J2EE application server controls many functional aspects of the services it provides) The statements in the deployment descriptor are declarative instructions to the J2EE container; for example, transactional settings are defined in the deployment descriptor and implemented by the J2EE container
33
EJB Components EJB components are server-side, modular, and reusable, comprising specific units of functionality They are similar to the Java classes we create every day, but are subject to special restrictions and must provide specific interfaces for container and client use and access We should consider using EJB components for applications that require scalability, transactional processing, or availability to multiple client types
34
EJB Components- Major Types Session beans –These may be either stateful or stateless and are primarily used to encapsulate business logic, carry out tasks on behalf of a client, and act as controllers or managers for other beans Entity beans –Entity beans represent persistent objects or business concepts that exist beyond a specific application's lifetime; they are typically stored in a relational database
35
Overview Enterprise JavaBeans is a specification for creating server-side secure, scalable, transactional, multi-user secure enterprise-level applications. These server-side components, called enterprise beans, are distributed objects that are hosted in Enterprise Java Bean containers and provide remote services for clients distributed throughout the network.
36
Java Beans vs. EJB Can be either visible non- visible. Local Invocation Synchronous Invocation Decidedly non-visible remote objects Remote and Local Invocation Synchronous and Asynchronous Invocation Object Pooling Transparent Persistence Supports Transactions Support Relationships between entity EJBs J2EE Security Features
37
Advantages of EJB Simplifies the development of middleware components that are secure, transactional, scalable & portable. Simplifies the process to focus mainly on business logic rather than application development. Overall increase in developer productivity Reduces the time to market for mission critical applications
38
Purpose of EJBs SESSION Beans (verbs of the system): –Model task or workflow –Façade for Entity beans –Maintain conversational state with clients ENTITY Beans (nouns of the system): –Object/Relational (O/R) mapping –Transparent and implicit persistence with transaction support Message Driven Beans: –Asynchronous communication with MOM –Conduit for non-J2EE resources to access Session and Entity Beans via JCA Resource adapters.
39
Three Tier Architecture Using EJBs
40
EJB Container
41
EJB Client Finds EJB container via JNDI. Invokes methods on EJB beans.
42
EJB components
43
Entity EJB CMP (Container Managed Persistence) –Container maintains persistence transparently using JDBC calls BMP (Bean Managed Persistence) –Programmer provides persistence logic –Used to connect to non-JDBC data sources like LDAP, mainframe etc. –Useful for executing stored procedures that return result sets
44
Message Driven EJB Invoked by asynchronously by messages Cannot be invoked with local or remote interfaces @MessageDriven annotation with in class marks the Bean message driven Stateless Transaction aware
45
EJB Security Architecture Client Security: –The Enterprise JavaBean (EJB) server automatically performs the steps necessary to ensure that deployed enterprise bean applications are only available to authorized users. –One of these steps is authenticating clients that request access to EJB homes, beans, and individual methods on the beans.
46
Understanding EJB Security Two security measures that client must pass when you add security to EJB system – Authentication and Authorization. Authentication must be performed before any EJB method is called. Authorization occurs at the beginning of each EJB method call.
47
Some EJB Servers Company Product IBM WebSphere BEA Systems BEA WebLogic Sun Microsystems Sun Application Server OracleOracle Application Server JBoss
48
References (1) SUN EJB Specifications http://java.sun.com/products/ejb/docs.html IBM RedBooks http://www.redbooks.ibm.com/redbooks.nsf/redbooks/ http://www.redbooks.ibm.com/redbooks.nsf/redbooks/ IBM WebSphere Developer Technical Journal http://www.ibm.com/developerworks/websphere/ http://www.ibm.com/developerworks/websphere/ Oracle Technology Network http://www.oracle.com/technology/tech/java/index.html http://www.oracle.com/technology/tech/java/index.html
49
References (2) Java.net http://www.java.net/http://www.java.net/ JavaWorld www.javaworld.com/channel_content/jw-ejbs- index.shtml www.javaworld.com/channel_content/jw-ejbs- index.shtml TheServerSide http://www.theserverside.com/ http://www.theserverside.com/ Richard Monson-Haefel, Enterprise JAVABEANS Tate, Clark, Lee, Lisnkey, BITTER EJB Feghhi, Jalal, Web developer's guide to JavaBeans
50
Reading from and Writing to a Socket in Java Let's look at a simple example that illustrates how a program can establish a connection to a server program using the Socket class and then, how the client can send data to and receive data from the server through the socket.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.