730 likes | 747 Views
Explore the history and use of communication models such as RPC, RMI, and JavaBeansAPI in enterprise systems development, emphasizing middleware approaches like EJB and CORBA.
E N D
Lecture 23 COMSATS Islamabad Enterprise Systems Development ( CSC447) Muhammad Usman, Assistant Professor
Communication Protocol Models • Remote Procedure Call (RPC) • Since 1980s, pioneered by Sun • Tears of testing with various communication models • Distributed extension of MS COM (DCOM) • Lets COM talk to other platforms • Complex configuration and complicated security model • Remote Method Invocation (RMI) • Communication between methods of Java classes • Drawbacks of RPC/RMI approach? • Platform-specific, procedural and low-level
The JavaBeans API • “A Java Bean is a reusable software component that can be manipulated visually in a builder tool.” • JavaBeans API makes it possible to write component software in Java • Components are self-contained, reusable software units that can be visually composed into composite components, applets, applications, and servlets using visual application builder tools. • JavaBean components are known as Beans.
Components and Software Architecture • Classes vs. components: • class hierarchies + object collaboration = detailed design • components + collaboration = architecture • Class vs. JavaBean: • Class == a brick, a piece of wood, a nail • Javabean = a wall element, a roof, a room • Client application == a building • An architecture does not concentrate on nails and bricks!
Sample Reusable Components Button Beans Slider Bean An application constructed from Beans
JavaBeans made out of Java classes • Beans are classes that can be manipulated in a visual builder tool and composed into apps. • Any Java class that adheres to certain conventions regarding property and event interface definitions can be a JavaBean. • Beans publish their attributes and behaviors through special method signature patterns that are recognized by beans-aware application construction tools.
Builder Tools and Properties • Discover Bean’s Properties • Determine properties’ read/write attributes • Determine property types • Locate property editors • Display property sheet • Alter properties
Beans communicate via events • Message sent from one object to another. • Sender fires event, recipient (listener) handles the event • There may be many listeners. Event source Register listener Fire event Event listener Event object
Enterprise Java Beans (EJB) • A server-side component • Contains the business logic of an application • Application clients execute the business logic by invoking the enterprise bean's methods • Why are EJBs attractive? • Frees application developer from dealing with system level aspects of an application • Allows bean developer to focus solely on the logic of the application.
Middleware approach • Middleware • General-purpose software that manages communication between distributed components (modules, classes, JavaBeans) • Thus it sits in the middle, between distributed components, the glue between components • Reuse benefits? • The developer doesn’t have to write code to communicate across processes or processors • Middleware “broker” handles bindings between components, so that components can be reused in other contexts without changing its code
CORBA • Common Object Request Broker Architecture • Created by Object Management Group (consortium of 700+ companies) • Defines how distributed, heterogeneous objects can interoperate • Location Transparency • Client has no idea where object resides, where it is local or remote • Objects • Gives object-oriented benefits at a higher level • E.g. encapsulation – must access through IDL, polymorphism, inheritance of interfaces, exception handling • Portable • across platforms, languages, networks • Standard
CORBA Architecture • Interface Definition Language (IDL) • Similar to interfaces in Java or C++ abstract classes • Defines protocol to be used between devices • Allows “wrappers” for legacy systems • Application Programming Interface (API) • Ensures consistency for clients and CORBA objects (in theory) • Object Request Broker (ORB) • Middleware establishing client/server relationship • Allows transparent invocation of methods • Intercepts calls, and deals with them • Find an object that can implement the request, pass it the parameters, invoke its method, and return the results • Client remains ignorant of how calls are dealt with
CORBA architecture Client Object Implementation IDL Skeleton Object Adapter Dyn. Inter- face IDL Stub ORB Interface Object Services: naming, events, life cycle, persistence, transactions, concurrency, relationships, externalization, object licensing, properties, object query ORB OS Kernel OS Kernel Network
Communication protocol models • Common Object Request Broker Architecture (CORBA) • CORBA2 adopted in 1994 • A specification of services helpful to build distributed applications • Remote Method Invocation (RMI) • Used for communication between components across a network (for example, in Java) • Simple Object Access Protocol (SOAP) • A protocol specification for invoking methods on different servers, services, components and objects
Web services with SOAP • Emerging standards support web services, all in XML: • UDDI (Universal Description, Discovery and Integration) • - describes a way to publish & discover information (directory) • WSDL (Web Service Definition Language) • - describes services as a set of endpoints operating on messages • SOAP (Simple Object Access Protocol) • - defines the overall message structure of web service request
SOAP uses Internet Protocols • What is SOAP? • An open wire protocol specification that defines a uniform way to access services, objects and servers in various platform • Works with existing Internet infrastructure • Talks to web server via XML text rather than several ports • HTTP as the underlying communication protocol • - Encapsulate messages between objects in HTTP • XML as the data serialization format. • - Client and server exchange data in SOAP-XML messages
SOAP specification • SOAP messages describe information in XML: • Consists of a SOAP envelope and encoding rules • Envelope defines name spaces used in the definition of the enclosed data structures • Encoding rules describe how to serialize data and a convention for making remote procedure calls (RPC)
Tools using SOAP for Web Services • Microsoft SOAP Toolkit 2.0 • Provides necessary components for both client-side and server-side, and other operations for Web Services • Available on web site: http://msdn.microsoft.com/downloads/default.asp? • URL=/code/sample.asp?url=/msdn-files/027/001/580/msdncompositedoc.xml • IBM Apache SOAP • Based on the IBM SOAP4J implementation. • Available on web site: http://xml.apache.org/soap/
Architecture of a Web Transaction Processing System Web Server Database Server ApplicationServer Interacts with client Executes the application Hosts the database Java servletreceives messages and calls program on application server The application might be a transaction program that implements the business rules of the Web service
Web Server • HTTP Interface to Web • Java servlet on Web serverinteracts withclient’s browser using HTTP messages and then initiates programs on the application server
Web Application Server • A Web application server is a set of tools and modules for building and executingtransaction processing systems for the Web • Including the application server tier of the system • Name is confusing becauseapplication server is the name usually given to the middle tier in an transaction processing system
Web Application Servers (continued) • Most Web application servers support the J2EE (Java 2 Enterprise Edition) standards • Or Microsoft .NET • We discuss J2EE • J2EE One language, many platforms • A standard implemented by many vendors • .NET One platform, many languages • A set of products of Microsoft
J2EE • J2EE defines a set ofservices and classes particularly oriented toward transaction-oriented Web services • Java servlets • Enterprise Java beans
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
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
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
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 • 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
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
Components • Client components run on the client machine, which correlate to the client containers • Web components -servlets and JSP pages • EJB Components
Enterprise Java Beans • Java classes that implement the business methods of an enterprise • Execute within an infrastructure of services provided by the Web application server • Supports transactions, persistence, concurrency, authorization, etc. • Implements declarative transaction semantics • The bean programmer can just declare that a particular method is to be a transaction and does not have to specify the begin and commit commands • Bean programmer can focus on business methods of the enterprise rather on details of system implementation
Entity Bean • Represents a persistent business object whose state is stored in the database • An entity bean corresponds to a database table • A bean instance corresponds to a rowin that table.
Example of an Entity Bean • An entity bean called Account, which corresponds to a database table Account • Each instance of that bean corresponds to a row in that table • Account has fields that includeAccountId and Balance • AccountId is the primary key • Every entity bean has a FindByPrimaryKey method that can be used to find the bean based on its primary key • Account has other methods that might include Deposit and Withdraw
Persistence of Entity Beans • Any changes to the bean are persistent in that those changes are propagated to the corresponding database items • This persistence can be managed either manually by the bean itself using standard JDBC statements or automatically by the system (as described later) • The system can also automatically manage the authorization and transactional properties of the bean (as described later)
Session Bean • A session bean represents a client performing interactions within a session using the business methods of the enterprise • A session is a sequence of interactions by a user to accomplish some objective. For example, a session might include selecting items from a catalog and then purchasing them. • The session bean retains its state during all the interactions of the session • Stateless session beans also exist
Example of a Session Bean • ShoppingCart provides the services of adding items to a “shopping cart” and then purchasing the selected items • Methods includeAddItemToShoppingCart and Checkout • ShoppingCart maintains state during all the interactions of a session • It remembers what items are in the shopping cart
Session Beans and Entity Beans • Session beans can call methods in entity beans • The Checkout method of the ShoppingCart session bean calls appropriate methods in the Customer, Order, and Shipping entity beans to record the order in the database
Session Bean Transactions • Session beans can be transactional • The transaction can be managed manually by the bean itself using standard JDBC or JTA (Java Transaction API) calls or automatically by the system (as described below)
Message-Driven Beans • All of the communication so far is synchronous • A session bean calls an entity bean and waits for a reply • Sometimes the sender of a message does not need to wait for a reply • Communication can be asynchronous • Thus increasing throughput • Message-driven beans are provided for this purpose • A message-driven bean is like a session bean in that it implements the business methods of the enterprise • It is called when an asynchronous message is placed on the message queue to which it is associated • Its onMessagemethod is called by the system to process the message
Example of a Message-Driven Bean • When shopping cart Checkout method completes, it sends an asynchronous message to the shipping department to ship the purchased goods • The shipping department maintains a message queue, ShippingMessageQ, and a message driven bean, ShippingMessageQListener, associated with that queue • When a message is placed on the queue, the system selects an instance of the bean to process it and calls that bean’s onMessage method
Structure of an Enterprise Bean • The bean class • Contains the implementations of the business methods of the enterprise • A remote interface (also optionally a local interface) • Used by clients to access the bean class remotely, using RMI (or locally with the local interface) • Acts as a proxy for the bean class • Includes declarations of all the business methods • A home interface (also optionally a local home interface) • Contains methods that control bean’s life cycle • Create, remove • Also finder methods (e.g. FindByPrimaryKey) methods
Structure of an Enterprise Bean (continued) • A deployment descriptor: • Containing declarative metadata for the bean • Describing persistence, transactional, and authorization properties