Commercial Systems Bahman
Commercial Systems Bahman
• Bahman
Part A: Java Beans
Part B: Enterprise Java Beans
• John
Corba
OLE
ActiveX
• Andrew
COM
DCOM
COM+
Java Beans & Enterprise Java Beans
Component-Based Design
Bahman Kalali
Computer Systems Group
[email protected]
Spring 2002
Outline (Part A)
Introduction to JavaBeans
A Bean's Public Interface
Bean Properties
Bean Events
Bean Methods
Reflection API
Bean Distribution
Summary
Introduction
Type of Properties
Simple
Boolean
Index
Bound
Constrained
Sample Account Property Balance
Exposing Simple Properties
Naming convention to expose a simple property:
• Listener objects will interrogate the property that is changing and process
accordingly.
Constrained Properties
1) setBalance called
2) Account notifies the VetoableChangeListeners
of pending change request
3) Listeners can optionally throw exception
4) balance is updated if no exception is thrown
Bean Custom Events
• Bound and constrained properties fire events when properties are changed.
• Java Beans can also fire other kind of events (custom events).
• The application developer can wire up to these events without writing code.
Exposing Bean Custom Events
Naming conventions are used
1) OverdrawEvent class
2) OverdrawListener interface
3) code to fire the event
4) code to manage the listener chain
Bean Methods
• To expose a method in the Bean’s public interface, simply make the method
public.
How does a visual Builder tool determines
a Bean’s public interface?
Method name
Return type
Argument list
Access type
Bean Distribution
The JAR utility that comes with the JDK can be used to create JAR
files.
JAR files can contain any type of file, not just Java bytecodes,
image,sound and text.
A Bean's Public Interface composed of:
Properties
Simple
Indexed
Boolean
Bound
Constrained
Events
Signalled by changing properties
Signalled for custom state change
Methods
Default is any public method
Outline (Part B)
Introduction to Enterprise Java Beans
Three-Tiered Architecture
JBoss Application Server
Enterprise Java Beans
Accessing a Business Method
Case Study: Distributed Shoe Web Application
Demonstration of application lifecycle
Summary
23
Introduction
EJB specification defines an architecture for the development
and deployment of transactional, distributed object
applications-based, server-side software components.
Case Study
Shoe Retailer Company
25 Running Montreal Nike 50
ShoeCollection
id name branch brand
quantities
Shoe
24
Three-Tiered Architecture
Client Layer
Presentation Layer
Business Logic Layer
Data Layer
Logical Layers Typical Web
Implementation
Java Beans
Presentation Web Server
Layer
Middle Tier
Business Logic EJB
Application Server
Layer
Web Server
Presentation
JSP/Java Beans Servlet Layer
Application Server
EJB Container
Session Bean Business Logic
Layer
Entity Bean
DB
Enterprise Java Beans (contd.)
JBoss Application Server
Home EJB Container
Interface EJB
Home Object
Remote
Interface
EJB
Client Object Bean Class
3: Request new
Client Code EJB Container
EJB object
1: Retrieve
Home Object
reference Home Object
Home Interface 4: Create EJB object
2: Return Home
Object reference Enterprise Bean
JNDI
EJB Object
Remote Interface
Directory Service
29
Accessing a Business Method (cont’d.)
Handling a client request to a business method.
EJB Container
Home Interface
Client Code
Home Object
4: Return
value to client 3:Method Returns
EJB Object
30
Shoe Distributed Web Application
Web Browser
Client Layer
<<HTTP>>
JspShoeBrowse
JSP Pages
Java Bean
Presentation
Layer
Servlet Container
ShoeCollection
Session Bean
Business Logic
Layer
Shoe
Entity Bean
EJB Container
Hypersonic database
Data Layer
JBoss Application Server
31
Demonstration of application lifecycle
Build
Package
shoe.jar shoe.war
cs854-ApplicationServer cs854-WebServer
shoe
Shoe.class WEB-INF
ShoeHOME.class
ShoeBean.class classes
shoecollection header.html
ShoeCollection.class JspShoeBrowse.class
ShoeCollectionHome.class search.jsp lib
ShoeCollectionBean.class
utils browse.jsp web.xml shoe.jar
ShoeExistsException.class mext.jsp
META-INF
jboss.xml
footer.html
ejb-jar.xml prev.jsp
Deploy
Run
32
Summary
No explicit support exists for EJBs may be transactional and the EJB
transactions in JavaBeans. Servers provide transactional support.
33
CORBA Key Concepts
• Location Transparency
• Objects
• Portable
• Standard
Simplified Architecture
ORB
OS
OSKernel
Kernel OS
OSKernel
Kernel
Network
IDL Interface for Quoter
interface Stock {
double price ();
interface Stock_Factory {
Stock get_stock (in string stock_symbol)
raises (Invalid_Stock_Symbol);
};
Client - Manage ORB in Stock Quoter
In client.cpp:
Client.cpp
#include "QuoterC.h”
Quoter::Stock_Factory_var factory =
Quoter::Stock_Factory::_narrow (factory_object.in ());
In stock_factory_i.cpp
// Access object
class Quoter_Stock_i : public POA_Quoter::Stock
{
public:
Quoter_Stock_i (const char *symbol, const char*full_name,
CORBA::Double price);
private:
std::string symbol_;
std::string full_name_; Stock_i.cpp
CORBA::Double price_;
};
Stock Operations
and Attributes Stock_i.cpp
In stock_i.cpp:
// Access object
class Quoter_Stock_i : public POA_Quoter::Stock
{
public: // some details omitted
char *symbol () throw (CORBA::SystemException);
char *full_name () throw (CORBA::SystemException);
Sub
()
Resp = Window.Confirm "Use the MS Agent?"
If Resp Then
Window.Alert "Loading ActiveX Controls."
Document.WriteLn "<OBJECT ID='Agent' width=0 height=0"
Document.WriteLn "CLASSID='CLSID:F5BE8BD2-7DE6-11D0-91FE-
00C04FD701A5'"
Document.WriteLn " CODEBASE='http://activex.microsoft.com/" & _
"controls/agent/msagent.exe#VERSION=1,5,1,0'>"
Document.WriteLn "<" & Chr(47) & "OBJECT>"
Document.WriteLn "<OBJECT ID='TruVoice' width=0 height=0"
Document.WriteLn " CLASSID='CLSID:B8F2846E-CE36-11D0-AC83-
00C04FD97575'"
Document.WriteLn " CODEBASE='http://activex.microsoft.com/" & _
"controls/agent/cgram.exe#VERSION=1,5,0,0'>"
Document.WriteLn "<" & Chr(47) & "OBJECT>"
End If
End Sub
Commercial Products :
Microsoft COM/DCOM/COM+
Andrew Trevors
Software Architecture Group
[email protected]
Overview
• What is COM / DCOM / COM+?
• COM
– Client/Server Model
– Objects & Interfaces
– COM Servers
– COM Clients
– COM Library
– COM Example
• DCOM
• COM+
What is COM / DCOM / COM+?
(1) “Create
Object” (2) Locate
implementation
COM
Objects & Interfaces
• Interface
– a set of member functions that a client can call to access that object
implementation.
– all interfaces start with an ‘I”, followed by a descriptive label
identifying what services they provide.
– all interfaces have a IID (interface identifier) which uniquely
identifies them.
• Object
– an implementation of one or more interfaces
– If object wishes to allow COM to locate and launch its
implementation then it needs to have a CLSID (class identifier)
– at very least, objects must implement IUnknown interface
• QueryInterface(), AddRef(), Release()
COM Servers
• Servers come in three varieties:
– In-process
• Server loaded into the clients process space
• loaded as a Dynamic Linked Library (DLL)
– Local
• Server that runs as a separate process on the same machine as
the client
• run as an executable (EXE) application
– Remote
• Server that runs as a separate process on another machine
• DLL or EXE
COM Servers
• Servers have four responsibilities
– Allocate a CLSID for each supported class and provide a mapping
between CLSID and server module (registry)
– Implement a class factory object with the IClassFactory interface
(CreateInstance & LockServer) for each CLSID
– Expose the class factory so the COM Library can find it once it is
loaded (CoRegisterClassObject or DllGetClassOjbect)
– Provide for unloading the factory if is serving no objects and no
locks are in place
COM Clients
• Any application which uses COM to instantiate objects
• Object usage involves:
– Using CLSID through COM Library or class factory to get an
interface pointer
• Interface pointer is actually a pointer to a pointer to a table of
function pointers
– Using interface pointer to call member functions or to obtain other
interfaces
– Calling Release() function when done with object.
COM Library
• COM Library provides :
– A small number of API functions that facilitate the creation of COM
applications
• clients (object creation).
• servers (object exposure).
– Implementation locator services
• COM determines, from a class identifier, which server
implements that class and where that server is located
(registry).
– Transparent remote procedure calls when an object is running in a
local or remote server
COM Example
class StockQuote : public IUnknown {
public:
HRESULT QueryInterface( IID & iid, void** ppvObj );
ULONG AddRef();
ULONG Release();
HRESULT getSymbol( char** symbol );
HRESULT getLongName( char** name );
HRESULT getPrice( int* price )
private:
int _price;
char* _symbol;
char* _name
};
COM Example
HRESULT StockQuote::QueryInterface( IID & iid, void** ppvObj ) {
HRESULT retVal = S_OK;
if( IsEqualID( iid, IID_IUnknown )
*ppvObj = ( IUnknown*) this;
else {
*ppvObj = NULL;
retVal = E_NOINTERFACE;
}
return retVal;
}
COM Example
hRes = CoCreateInstance(&CLSID_STOCK, NULL,
CLSCTX_SERVER,
&IID_IUnknown, &pStock);
if (SUCCEEDED(hRes)) {
// do something with pStock
}
else {
// report error
}
DCOM
• Extends COM to support object communication across
networks.
• DCOM protocol, Object RPC, extends DCE RPC
– Uses RPC packets with extra information such as interface pointer
identifiers
– Programmers generally write an IDL and use an IDL compiler
(MIDL) to generate proxies/stubs
• Pinging for garbage collection
DCOM
Client Process
Local Server Process
In-Process
Object
Local
Stub
In-Process Server Object
Client
Application COM
RPC Local Server
Local
Object
Proxy
Remote
Remote Server Process
Object
Proxy
RPC Remote
Stub Object
COM
Remote Server
COM+
• Transactions
– Coordination between COM+ and DTC (Distributed
Transaction Coordinator) to ensure ACID properties.
• Queued Components
– Provides asynchronous component invocation and execution
through the use of Microsoft Message Queuing Service
• Object Pooling
– Automatic service provided by COM+ which allows
components to have instances of itself kept active in a pool
• Stateless
• No thread affinity
• Aggregatable
COM+
• COM+ Events