Component Based Software Engineering

Download Report

Transcript Component Based Software Engineering

Components and Architecture
The Software Architecture
“The software architecture of a
program or computing system is the
structure or structures of the system,
which comprise software components
[and connectors], the externally visible
properties of those components [and
connectors] and the relationships
among them.”
Building Reliable Component-based Systems
Page 2
Chapter 3 - Architecting ComponentBased Systems
Architecture Design Process

Can be seen as a function that:




Takes a requirement specification as input.
Generates an architectural design as output.
Is not an automated process, necessitating great effort and
creativity from the involved software architects.
Is comprised of three steps:



Functionality-based design.
Assessment of the quality attributes.
Architecture Transformation.
Building Reliable Component-based Systems
Page 3
Chapter 3 - Architecting ComponentBased Systems
General software architecture design
process
Requirement
specification
Functionality-based
architectural design
Requirement
selection
F.R.
(Partial)
requirement
specification
Application
architecture
Architecture
transformation
OK
not OK
Estimate quality
attributes
OK
QA-optimizing
solutions
More
Requirements?
no
Building Reliable Component-based Systems
Page 4
Chapter 3 - Architecting ComponentBased Systems
Yes
Functionality-based Design

The design process starts with functionalitybased design and consists of four steps:




Defining the boundaries and context of the
system.
Identification of archetypes.
Decomposition of the system into its main
components.
The first validation of the architecture by
describing a number of system instances.
Building Reliable Component-based Systems
Page 5
Chapter 3 - Architecting ComponentBased Systems
Assessment of the quality
attributes

The second phase is the assessment of the
quality attributes in which:



Each quality attribute is given an estimate.
If all estimated quality attributes are as good or
better than required, the architectural design
process is finished.
If not the third phase of software architecture
design is entered: architecture transformation
Building Reliable Component-based Systems
Page 6
Chapter 3 - Architecting ComponentBased Systems
Architecture Transformation

Is concerned with selecting design solutions
to improve the quality attributes while
preserving the domain functionality.


The design is again evaluated and the same
process is repeated if necessary.
The transformations (i.e. quality attribute
optimizing solutions) generally improve one or
some quality attributes while they affect others
negatively.
Building Reliable Component-based Systems
Page 7
Chapter 3 - Architecting ComponentBased Systems
Architecture-driven Component
Development


The goal for the embodiment phase of
design is to either build or select
components and connectors that possess
the quality attributes identified during the
architecting phase of development.
Three types of components:



Custom built components
Reusable components
Commercial components
Building Reliable Component-based Systems
Page 8
Chapter 3 - Architecting ComponentBased Systems
Custom Components


Demands both time and money.
Are most likely to pay off in cases of
software that are:




Very unusual
Safety critical
Highly secure
The component assembly will possess
the quality attributes it was designed
around.
Building Reliable Component-based Systems
Page 9
Chapter 3 - Architecting ComponentBased Systems
Pre-existing Components

There are two main classes of preexisting components:



Reusable components
Commercial components
Is a fundamentally different problem
than custom design.

The requirements to use specific
components and component frameworks
drive the architecture.
Building Reliable Component-based Systems
Page 10
Chapter 3 - Architecting ComponentBased Systems
Reusable Components


Can exist on a wide scale of reusableness
within any organization.
They must be adapted;



In most cases it will be necessary to create
adaptors, often referred to as glue code.
Are developed with reuse in mind.
Product line development exemplifies the
use of pre-planned reusable components.
Building Reliable Component-based Systems
Page 11
Chapter 3 - Architecting ComponentBased Systems
Commercial Components


Introduce a large degree of
uncertainty.
Tend to be



Complex
Idiosyncratic
Unstable
Building Reliable Component-based Systems
Page 12
Chapter 3 - Architecting ComponentBased Systems
Component-driven Architecture
Development

Constraints due to the use of pre-existing
components:





Design freedom is limited to component
selection.
Sufficient information about how a component
will behave is not generally provided.
Component properties must be verified.
The framework into which components are to be
plugged influences the architecture and the
process by which the system is designed.
Such components can not be optimized.
Building Reliable Component-based Systems
Page 13
Chapter 3 - Architecting ComponentBased Systems
Component-driven Architecture
Development

It is expected that more reliable
systems will be produced, with greater
speed and at lower expense due to the
restrictions on design freedom.
Building Reliable Component-based Systems
Page 14
Chapter 3 - Architecting ComponentBased Systems
Chapter 4
Component Models and Technology
Building Reliable Component-based Systems
Page 15
Chapter 4 - Component Models and
Technology
Windows purpose : moving integration between
applicative functions to O.S. level
 it needs effective communication mechanisms
between applications


Excel-generated pie chart
embedded in a Word
document displayed in a
PowerPoint presentation
Different applications need to
share data or procedures
A little history: starting with evolution of
Microsoft approach
DCOM
ActiveX
OCX
COM
OLE
DDE
clipboard
DDE (Dynamic Data Exchange)


What if spreadsheet and word processor need to
share data?
Microsoft comes out with Dynamic Data Exchange
(DDE), circa 1989





Lets different Windows programs share data through links
Suppose some spreadsheet data were linked into word
processor
When you changed data in spreadsheet, the new data
would appear in word processor
Limitation: you couldn’t update the data in the word
processor; you had to invoke the spreadsheet to update
the date there
Worse, links were fragile and would break if you moved
data files around in file system


Object Linking and Embedding OLE (circa 1991)
A way for Windows to create documents containing objects from other
programs.

Embedding lets users copy a snapshot of data into word processor and
save it there
• The objects are components (word processor document, spreadsheet,
picture) can be linked together and pass messages to each other
according to a standard protocol, Object Linking and Embedding (OLE).

Components containers can be re-used by many applications to for E.g.
place a chart from Excel and a slide from PowerPoint into a Word
document

But OLE is a platform-specific solution.
OLE Technology (circa 1993)



A set of APIs to create and display a (compound) document
 Now possible to share code as well as data
Component Object Model (COM)
COM now includes OLE as part of a larger concept
 OLE becomes a set of standard COM interfaces
 COM protocols let components connect to origination
program:
 E.g. word processor can tell spreadsheet, “the user just
clicked on the spreadsheet, so start yourself up, look for
data here, and let me know when you’re done.”
 If the user decides to edit the embedded data, Windows
activates the originating application and loads the
embedded document
For example, a desktop system
might include a picture in a
bitmap editor using OLE
Component Object Model



The component object model (COM) provides a
specification for using components produced by various
vendors within a single application running under the
Windows operating system.
COM objects can be created with a variety of programming
languages. Object-oriented languages, such as C++,
provide programming mechanisms that simplify the
implementation of COM objects.
not an object-oriented language but a binary standard
Microsoft COM

COM encompasses:


COM interfaces (implemented as COM objects)
COM Object locations are stored in registry


a set of mechanisms for registering and passing
messages between COM interfaces.
COM interfaces are defined in Microsoft
Interface Description Language (MIDL).
COM components in Registry
Windows has many COM components.
Registered under
“\HKEY_CLASSES_ROOT\CLSID” on the
registry.
OLE Extensions (OCX)

With Windows 95 came a new standard:



OCX (OLE Custom eXtension component)
A piece of code, smaller than application program,
but with its own user interface
Let users bundle OCX controls to form customized
applications (component composition)
OCX Charting and Graphing example
code for Visual Basic
• When installing the ProEssentials
product, the setup program installs
the ProEssentials DLL and OCX
Charting interfaces into the system
directory.
•The setup program also registers
the OCX Charts with the operating
system, which prepares Visual
Basic for inclusion of
ProEssentials components
OCX Charting and Graphing example
code for Visual Basic
the [Components] dialog and
places those items selected
into Visual Basic's ToolBox as
shown.
ActiveX (circa 1996)



Active X, like Java Applets, supports Internet
xistributed computing. ActiveX components
communicate with each other via events.
Writing a program to run in the ActiveX
environment creates a self-sufficient program
that can run anywhere in ActiveX network
This component is known as an ActiveX
control, and is often used to attach a program
to a web page
Distribution option spectrum
Server: Interaction control
Data validation
Services
Database
Server: Services
Database
Client: Presentation
Client: Presentation
Interaction control
Data validation
Server:Database
Client: Presentation
Interaction control
Data validation
Services ActiveX Comp
Increasing cost
Thick
client
and effort
The Thick client option is where the server simply
provides data management and application services are
implemented on the client by using ActiveX component
Three-tier architecture for an
Internet banking system
Chapter 18 Distributed software engineering
31
ActiveX - implementation



An ActiveX control can be created using one of several
languages or development tools, including C++ and Visual
Basic, or with scripting tools such as VBScript.
ActiveX controls originally were Windows only
 Other vendors later provided Mac and Unix/Linux support
for ActiveX
Security issues: ActiveX controls have full file access (no
sandbox)
 Can be signed for authentication
Creating ActiveX Component
No Customization
Creator
End User
Customization
Creator
Developer
Design Time
End User
Run Time
For each component The Component Creator can
enable Customization (where developer can insert code in the design time for
customization) by defining
• Events (handling user interface )  ActiveX component Could be
mapped to internal User Contol events by using RaiseEvent . Eg. Button
Click, Mouse Down
• Properties  Using Get and Let
•mapped to internal UserContol properties. E.g button
Caption
•New Property
• Methods New methods
Example Creating ActiveX Component
Creating ActiveX Component
Example Mapping Events (written by creator)
Creating ActiveX Component
Example Mapping Propriety
Get: just returns the current
string found in the Caption
property of the command button
Let: takes a new string and just
assigns it to the Caption property
of the command button
Using ActiveX Component
Using ActiveX Component
At design
Component
time developer could write the following code to customize the Bitton
nn= Bitton1.Caption ..  This will call the Get sub in to nn
Bitton1.Caption = “ok” …. This will call the Set sub
Private Sub Bitton1_Click ()
Msgbox (“hello world”)
End Sub
Private Sub Bitton1_MouseDown (Button As Integer, Shift As Integer, X As Single, Y)
Msgbox (“I am moving”)
End Sub
Tax Components
Enter
Amount

Result
Enter Tax
%
Show Result
Clear
For this SC what are the events, properties,
methods


For no customization (using it as it is created)
For customization
Tax Components
Enter
Amount

Result
Enter Tax
%
Show Result
Clear
(not customizable) Events such as Show Result , Clear
event are internal
Private Sub Command1_click ()
TextField3.value = TaxTotal()
End Sub
Private Sub Command2_click ()
TextField3.text = “ “
End Sub
Tax Components
Enter
Amount
Result
Enter Tax
%
Show Result

(simple customizable) Mapping property

Properties ResultColor done by creator
Property Get ResultColor ()
ResultColor = TextField.color
End Properity

Property Let ResultColor (cc)
TextField.color = cc
End Properity
Using this Property by simply done by designer
TaxComponent1. ResultColor = “red”
Clear
Tax Components Result
Enter
Amount

Special
Function
Show Result
(advanced customizable) Events such as button click
Private Sub Command3_click ()
RaiseEvent Click
End Sub
Clear
Tax Components Result
Enter
Amount
(advanced customizable)

Properties Such as caption
Property Get caption ()
caption = button3.caption
End Property
Property Let caption ()
button3.caption = tt
End Property
Special
Function
Show Result
Clear
Tax Components Result
Enter
Amount
Special
Function
Show Result
(advanced customizable)
 At design time a designer wants to add new
function AmountAfterTax to button 3
TaxComponent1.Caption = “ Amount After Tax”
Private Sub TaxComponent1_Click()
AmountAfterTax=Textfield1.value*TaxPer/100)
Result = AmountAfterTax
End Sub
Clear
Tax Components
Result
Enter
Amount
233
Show Result
At Run time
Amount
After Tax
Clear
Microsoft Visual Studio (clothes ordering)
Using at Design Time
Order Form
GUI Component
Business
Component
Grid entry table
Order
Number of rows,
columns, header’s
captions, borders, etc
For Customization:
LOGO, Address, Title,
colors, font, etc
For customization:
The JavaBeans API





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.
A Java Bean component may have a visual representation, for example, a
user-interface component, or may be non-visual, for example, a database
connectivity component .
Java Bean components communicate with each other by sending events..
Components have properties which can be set by the programmer to
achieve some customisation.
Enterprise JavaBeans (EJB) is an extension of the Java Bean model that
provides a mechanism for encapsulating a Java Bean component
Features of JavaBeans






Support for introspection

Allows development tools to query a component to determine
member variables, methods, and interfaces
Support for customization

so that when using an application builder a user can customize
the appearance and behavior of a bean
Support for events (when beans want to intercommunicate)

Notification of a change in state

User activities (typing, mouse actions, …)
Support for properties

both for customization and for programmatic use

Properties can be customized at design-time using property editor
Support for Methods

Invoked to execute component code
Support for persistence

so that a bean can be customized in an application builder and
then have its customized state saved away and reloaded later

implement Serializable or Externalizable
e.g. public class Button implements java.io.Serializable { ... }
Background: What Are Beans?
• Java classes that follow certain conventions
– Must have a zero-argument (empty) constructor
– Should have no public instance variables (fields):
use accessor methods instead of allowing direct
access to fields
– Persistent values should be accessed through
methods called getXxx and setXxx
Why You Should Use Accessors,
Not Public Fields
You can put constraints on values
public void setSpeed(double newSpeed) {
if (newSpeed < 0) {
sendErrorMessage(...);
newSpeed = Math.abs(newSpeed);
}
speed = newSpeed;
}
– If users of your class accessed the fields directly, then
they would each be responsible for checking constraints
Visually Manipulated, Builder
Tools (BDK...)
ToolBox
BeanBox
Property Sheet
Method Tracer
Support Multi-tiered
Application Model

Client tier




Web clients,
Applets,
Applications
Web tier
Business tier
EIS-tier
J2EE Architecture
JSP Using Beans: Basic Tasks
• jsp:useBean
<jsp:useBean id="beanName“ class="package.Class" />
e.g
<jsp:useBean id="book1" class="coreservlets.Book" />
• jsp:getProperty
– This element reads and outputs the value of a bean property.
<jsp:getProperty name="beanName“ property="propertyName" />
e.g.
<jsp:getProperty name="book1" property="title" />
is equivalent to the following JSP expression
<%= book1.getTitle() %>
jsp:setProperty
– This element modifies a bean property. It is normally used as follows:
<jsp:setProperty name="beanName“ property="propertyName"
e.g.
<jsp:setProperty name="book1“ property="title“ value="Core Servlets and
JavaServer Pages" />
is equivalent to the following scriptlet
<% book1.setTitle("Core Servlets and JavaServer Pages"); %>
Userinfo javabean example
Component Diagram
Web
Page
UserInfo
Client
EJB Server
Home
Interface
EJB Container
Home
Stub
Home Interface
EJB
Home
Remote
Interface
Remote Interface
EJB Object
EJB
Stub
Bean Class
Any enterprise bean must define two interfaces
1- Home interface – The Home Stubs extends EJBHome which defines a
bean’s “life cycle” methods, eg. create bean, remove bean, find bean, etc.
• Initially A client initiate interacts with its server object via a container interface: the
container calls the bean’s life cycle methods to create bean instance .
Client
EJB Server
Home
Interface
EJB Container
Home
Stub
Home Interface
EJB
Home
Remote
Interface
Remote Interface
EJB Object
EJB
Stub
Bean Class
2- Remote interface
- defines a bean’s external interface
- EJB Stub extend EJBObject (which in turn extends
java.rmi.Remote)
•Clients never interact directly with a bean class, they use EJB stubs (which connect to
“containers” which call the bean class interface using RMI)
Client
EJB Server
Home
Interface
EJB Container
Home
Stub
Home Interface
EJB
Home
Remote
Interface
Remote Interface
EJB Object
EJB
Stub
Bean Class
- Bean Class
The java class that actually implements the bean’s external interface, e.g. the
bean class provides implementations for the bean’s “business methods”
CORBA
•
•


The Common Object Requesting Broker Architecture
(CORBA) is a standard defined by the (Object Management
Group OMG); that enables software components written in
multiple computer languages and running on multiple
computers to work together.
It forms part of a larger model, Object Management
Architecture (OMA) that defines at a high level of abstraction
A CORBA component provides functionality via an interface
defined in the CORBA Interface Definition Language, and
interacts with other components only via that interface.
It is a system software that provides interoperability services
for applications, such as distributed object computing, and
hides some aspects of hardware and operating system
differences in heterogeneous, distributed environment
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
Object Request Broker (ORB)
 Middleware establishing client/server
relationship
 Allows transparent invocation of methods
 Intercepts calls, and deals with them
1- Servant object publish its interfaces using DSI to ORB
2- ORB install locally at client machine all its interfaces {run-time library}, at IDL STUB
3- The {client} calls (using DII) the - 'IDL-stub to perform some task
4- The stub transmits parameters over the network
5- Once the request is reconstructed by 'ORB', it has to interpret it
6. 'ORB‘ will Find an object that can implement the request, pass it the parameters,
invoke its method to the object’s {server- skeleton}
6- the skeleton (server-side interpreter, it need to know the method signature: a. the
method name, and b. the type of input..
7- The proxies and skeletons provide the object-specific information needed
8- the skeleton returns the results to the caller in a reverse manner so that the IDL stub
can read the result and pass it to the client object
Example: CORPA component
1. Facets: Facets are interfaces that a component provides. For instance, the
Stock_Quote interface provides a stock price
2- Receptacles:. Receptacles provide a standard way to specify interfaces required for
the component to function correctly. The Stock_Exchange component uses the SEC
(Securities and Exchange Commission) interface to function correctly.
3- Event sources/sinks: Components can also interact by monitoring asynchronous
events. These loosely coupled interactions, are commonly used in distributed
applications. A component declares its interest to publish or subscribe to events by
specifying event sources and event sinks in its definition (subscribe ). For example, the
Stock_Exchange component can be an event sink that processes Buy_Offers and
Sell_Offers events and it can be an event source that publishes Price_Change events.
The COM Programming Model
A scalable programming model

On the same machine
(component –
component)
 Fast, secure LPC
Client Process
Client
Server Process
COM
Component
What is DCOM?
DCOM extends COM to support communication among
objects on different computers
Com Object Creation
Proxy & Stub
COM server
Three ways in which a client can access COM objects
provided by a server:
• In-Process Server (if COM object has been
previously activated at the client machine)
• Local Object Proxy (if COM object resides at the
client machine)
• Remote Object Proxy (if COM object resides at a
server machine)
How DCOM Works: Example




Client on Windows machine
Server (CustServer) on Solaris
UNIX machine
Client needs to call ChangeAddress
method of the server’s ICustInfo
interface/class
Both client and server are C++
modules
How DCOM Works: Example
Step 1: Client Initiation
COM
Library
CLSID_CustServer
IID_ICustInfo
Client
Call Stack
CoInitialize
CoCreateInstanceEx
Description of Slide:
COM Library - Collection of routines (API) implemented by COM.
Routines typically begin with Co…
Process:
The first thing any COM client or server calls is CoInitialize. To
connect to the server (client side), the client then calls
CoCreateInstanceEx, passing the CLSID of the server it wishes to
call plus all of the desired Interface IDs.
How DCOM Works: Example
Step 2a: Server Activation (Client Side)
COM
Library
SCM
CLSID_CustServer
Class
Table
Registry
IUnknown
Client
Call Stack
CoInitialize
CoCreateInstanceEx
Proxy
Process:
•The CoCreateInstanceEx call is relayed to
the local SCM (Service Control Manager ) ,
• which first checks the Class Table to see if
the requested object is already running.
•If not, it looks in the registry, using the
CLSID_CustServer, to find out whether the
server is local or remote.
•If it is remote, it gets the name of the server
machine to contact.
•A “default” proxy is loaded which exports
the IUnknown interface.
How DCOM Works: Example
Step 2b: Server Activation (Server Side)
COM
Library
SCM
Class
Process:
On the remoteTable
machine,
the SCM repeats the
Registry
process of checking in the Class Table and
Registry. If the object is already running,IUnknown
it
skips to the next step. If not, it finds out the
Client
name
of the executable from the registry, and
Proxy
starts that module.
The
class and the pointer to the ClassFactory
Call Stack
are
entered in the Class Table.
CoInitialize
ACoCreateInstanceEx
“default” stub is loaded into the server’s
process which will facilitate communication to
the client.
SCM
CLSID_CustServer
Class
Table
COM
Library
IUnknown
Registry
ClassFactory
IClassFactory
Server
Stub
Call Stack
CoInitialize
CoRegisterClassObject
How DCOM Works: Example
Step 3: The Class Factory
COM
Library
Class
Table
SCM
SCM
Class
Table
Registry
COM
Library
IID_IUnknown
Registry
IUnknown
ClassFactory
IUnknown
IClassFactory
Server
Client
Process:
Proxy
Once the server has started, the system
calls a
method
on the IClassFactory interface called
Call Stack
CreateInstance.
This method creates a new
CoInitialize
CoCreateInstanceEx
instance
of the CCustInfo class, so that it is
ready to accept later calls.
Stub
CCustInfo
ICustInfo
Call Stack
CoInitialize
CoRegisterClassObject
How DCOM Works: Example
Step 4: Multiple QueryInterface
COM
Library
SCM
SCM
COM
Library
IID_ICustInfo
Class
Table
Class
Table
Registry
IUnknown
Registry
ClassFactory
Process:
IUnknown
Once the server has started and the Class
Factory
has created a new instance for us, the
Client
Proxy
system will call the QueryInterface
function of
the server object for all of the Interface IDs
Call Stack
(IIDs)
supplied in the CoCreateInstanceEx call.
CoInitialize
CoCreateInstanceEx will either return interface
QueryInterface
pointers or errors if the interface requested is
not supported.
IClassFactory
Server
Stub
CCustInfo
ICustInfo
Call Stack
CoInitialize
CoRegisterClassObject
Process:
Once an interface pointer has been located, it
must be “marshalled” over to the client side.
At this time, using the IID as a key to the
registry, the system loads a special pair of
modules to act as proxy and stub for future
calls. And register it
COM
Step 5: Proxy/Stub
loading
COM
Library
SCM
SCM
IID_ICustInfo
Class
Table
IID_ICustInfo
Class
Table
Registry
Library
IUnknown
Registry
ClassFactory
IUnknown
IClassFactory
Server
Client
pCustInfo
Proxy
Stub
CCustInfo
ICustInfo
Call Stack
CoInitialize
CoCreateInstanceEx
Call Stack
ICustInfo_Proxy
ICustInfo
ICustInfo_Stub
CoInitialize
CoRegisterClassObject
How DCOM Works: Example
Step 6: Method Call
Process:
Once a pointer to the ICustInfo interface has been
obtained,
COM
SCM
SCM
the program can call methods as though the server
module is
Library
local. The client simply calls the ChangeAddress method of
the ICustInfo interface (referenced by pCustInfo), passing all
of the necessary parameters.
Class
COM
Library
Class
Table
Table
Registry
Registry
IUnknown
ClassFactory
IUnknown
IClassFactory
Server
Client
Proxy
Stub
CCustInfo
ICustInfo
Call Stack
CoInitialize
CoCreateInstanceEx
pCustInfo->ChangeAddress
Call Stack
ICustInfo_Proxy
ICustInfo
ICustInfo_Stub
CoInitialize
CoRegisterClassObject
Location Transparency



COM Object locations are stored in registry
Applications make calls using the globally
unique CLSID.
Path to COM server, or remote computer to
run DCOM server is not needed by the
application.

Location transparent –server and client can be
anywhere since they share the same network
protocol
Language Neutrality

Various languages can be used to create
components.




VB, Delphi for rapid development
VC++, Java for advanced development
E.g. A component build in VB can be imported to
VC++
Even more languages can be used to use
COM components

Additionally scripting languages like VB Script,
JScript
Connection Management

Low Bandwidth


Header is 28 bytes over DCE-RPC
Keep-Alive Messages bundled for all connections between
Machines
 preferred transport protocol : UDP


COM employs an efficient pinging protocol to
detect if clients are active
COM uses reference counting mechanism to do
garbage collection



Internal component’s reference counter –increments
when client establishes connection with component
Decrements counter –if client releases its connection
If counter reaches zero –component can free itself
Platform Neutrality

DCOM run-time is available for various
platforms



Win32 platforms, Solaris, DEC UNIX, HPUX,
Linux, MVS, VMS, Mac
Cross-Platform Interoperability Standard
Per-Platform binary standard


Unlike java, DCOM can utilize powerful platformspecific services and optimizations
Less abstraction layers prevents additional
overheads
Security by Configuration
4) Fail or allow call
3) Is user
in the list?
2) Authenticate user
1) DCOM obtains
user name
Weaknesses of COM/DCOM


COM/DCOM is hard to use
COM is not robust enough for enterprise
deployments
• COM/DCOM are best supported on Windows 95
and NT platforms
• low cost development tools provide the ability to
build and access COM components for Windows
platforms, for other platforms the prices are
considerably more expensive
Creating a simple COM server
ATL COM AppWizard
New ATL Object
Add New Method
Interface Definition Language
...
[
object,
uuid(79522A15-BA3D-46A5-92D6-DA4BE60646F4),
dual,
helpstring("ISimple Interface"),
pointer_default(unique)
]
interface ISimple : IDispatch
{
[id(1, helpstring("method StringLen")] HRESULT StringLen([in]
BSTR str, [out,retval] long* length);
};
...
Source & Header File
Source:
STDMETHODIMP CSimple::StringLen(BSTR str, long* length)
{
*length = SysStringLen(str);
return S_OK;
}
Header:
...
public:
STDMETHOD(StringLen)(/*[in]*/ BSTR str,
/*[out,retval]*/ long* length);
...
Creating a Simple COM Client
#include <stdio.h>
#import "SimpleCom.exe"
int main(int argc, char* argv[])
{
SIMPLECOMLib::ISimplePtr pSimple;
long len;
CoInitialize(NULL);
pSimple.CreateInstance(__uuidof(SIMPLECOMLib::Simple));
len = pSimple->StringLen("sample");
printf("Length = %d\n", len);
CoUninitialize();
return 0;
}
Exception Handling
try
{
len = pSimple->StringLen("sample");
}
catch (_com_error &e)
{
printf(“%s\n”, e.Description());
}
Registering COM Objects

COM dll



To register: regsvr32 mycom.dll
To un-register: regsvr32 –u mycom.dll
COM exe


To register: mycom.exe /regserver
To un-register: mycom.exe /unregserver
Configure as DCOM
Protocols for DCOM
Comparison
A Service Oriented Architecture
why to buy if it is cheaper to rent

Web service can be used to:



tools: calendar, chat, etc
Information providers: weather, news, flight information
The ultimate aim of the web services programme is to
build a service-oriented architecture (SOA) with the
properties (Web service can be seen as distributed
component taken to extreme):




Access to services is standardised (interfaces defined)
Network nodes make (reusable) services available to other
nodes, independent of physical location (location transparency)
The publishing of information about available services is
standardised (a service directory)
SOA should be independent of implementation technology – e.g.
services can interoperate regardless of implementation
environment or language (Java, C#, . . . )



E.g. Photos can be shared from sites like Flickr to
social network sites like Facebook and MySpace.
Video content can be embedded on sites which are
served by another host.
Advantages





Easier to reuse (no setup is required)
Scalability: adding more services, and users
Fault tolerant
Lower cost
Disadvantage:


Availability (connection is lost, server down, overloading
many request)
Reliability (relatively slow)
SOAP uses Internet Protocols
What is SOAP?
Simple Object Access Protocol (SOAP) is based on XML
protocol, used for information exchange in distributed
systems. SOAP establishes client-server interaction and
regulates operation factors transmission and return
value. To submit any information transmitted from client
to server and vice versa XML is used
Simple Object Access Protocol
(SOAP)


Developed by IBM, Lotus Development Corporation,
Microsoft, DevelopMentor, and Userland Software
SOAP message

Envelope

A structure describes a method call

Body

Request
 Contains a Remote Procedure Call (RPC); request
for another machine to perform a task. It specifies
the method to be invoked and any parameters

Response
 HTTP response document contains results from
other method call
[from What the heck is SOAP anyway by David Platt ]
Service Composition
Application
Servers
2
Hotel
Reservation
System
1
4
3
Holiday
Reservation Service
Front End
Flight
Reservation
System
Service Composition
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/
A Component now Becomes a Service Running
Outside the Consumer Boundaries
Discover/learnability
Consumer
2
3
XML
XML
SOAP
SOAP
Communicate
Policies
1
SOAP
CCI
CCI
CCI
DB
ERP
CRM
Service
Service
Registry
XML
Service
register
Web services with SOAP
Emerging standards support web services, all in
XML:
1- discovery phase - discover What web
Services that sever is hosting
UDDI (Universal Description, Discovery and Integration)
describes a way to publish & (directory)
2- Learning about what interfaces that
service supports:
WSDL (Web Service Definition Language file) describes
services as a set of endpoints operating on message
3- Communication phase – placing a request
for information and receive the responses
•SOAP (Simple Object Access Protocol) defines the
overall message structure of web service request
Example
1- a RoomService web Services project that contain multiple
services, such as ReservationService, RateQuoateService, etc
2- the actual UDDI file RoomService.vsdisco
3- For Discovery the client application request information
http://servername/roomservice/roomservice.vsdisco
4- the Server send back this XML part (document reference that
contain all the services names)
< docRef = “/roomService1.asmx”
5- the Learnability client request the WSDL from a web Service
http://servername/roomservice/roomService1/
ReservationService.asmx?WSDL
Input - Output
Name = “RoomNum”, Type = “int”
Name = “AvailabilityResult”, Type = “Boolean”
Implementation Web Service
Example in C#
ReservationService.asmx
<%@ WebService Language="C#" %>
using System;
using System.Web.Services;
public class ReservationInterface
{
[WebMethod]
public string opCheckAvaliability(int RoomNum)
{
// Implementation here, check database, etc
}
}
Microsoft SOAP toolkit
Another ASP.NET Web Services
example
Links to
Web
service
methods
Link to service
description
129
1
<%@ WebService Language="JScript" Class="NumberService" %>
2
3
// Fig. 23.38: number.asmx
4
// A simple Web Service
5
6
import System;
7
import System.Web.Services;
8
9
10
public class NumberService extends WebService
{
11
// Determines whether all the characters in a String are digits
12
WebMethod public function isNum( number : String ) : Boolean
13
{
14
var digitArray : char[];
15
digitArray = number.ToCharArray();
16
17
for ( var i : int = 0; i < digitArray.Length ; i++ )
18
{
19
if ( !Char.IsDigit( digitArray[ i ] ) )
20
{
return false;
21
}
22
}
23
24
return true;
25
26
} // end isNum
27
28
WebMethod public function Add( a : float, b : float) : float {
return a + b;
29
30
}
31 } // end class NumberService
ASP.NET Web Services
ASP.NET Web Services
Invoking a method of a Web service from a Web browser.
Results of invoking a Web-service method from a Web browser.
Assignment 3

Build your project using one of the
components frameworks



Compositional Forms
we identify two kinds of entities that
are com-posed: components and
frameworks. Given this, there are three
major classes of interactions that arise
in component-based systems:
•
Component–Component
(C–C):

composition that enables interaction
among compo-nents. These interactions
deliver application functionality, and so
the contracts that spec-ify these
interactions might be classified as
application-level contracts.
Framework–
Component (F–C):

• A composition that enables
interactions between a com-ponent
framework and its components. These
interactions enable frameworks to
manage component resources, and so
the contracts that specify these
interactions might be classi-fied as
system-level contracts.
Framework–Framework
(F–F):

A composition that enables
interactions between frame-works.
These interactions enable
composition of components that are
deployed in het-erogeneous
frameworks, and so these contracts
might be classified as interoperation
con-tracts.

..\CBSE-2012-2013[1]\Technical
Concepts of Component-Based
Software Engineering,.pdf