72
Ladan Tahvildari, PEng Ladan Tahvildari, PEng Assistant Professor Assistant Professor Software Technologies Applied Research (STAR) Group Software Technologies Applied Research (STAR) Group Dept. of Elect. & Comp. Eng. Dept. of Elect. & Comp. Eng. University of Waterloo University of Waterloo ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services

ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

Ladan Tahvildari, PEngLadan Tahvildari, PEngAssistant ProfessorAssistant Professor

Software Technologies Applied Research (STAR) Group Software Technologies Applied Research (STAR) Group

Dept. of Elect. & Comp. Eng.Dept. of Elect. & Comp. Eng.

University of WaterlooUniversity of Waterloo

ECE750-Topic11:Component-Based Software Systems

.NET/J2EE Enterprise Services

Page 2: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 2June 14, 2007

Different O-O Component ModelsO-O has been around for a while now and there are many class-based languages that can represent components

C++SmalltalkEiffel.NET languages (C#, VB.NET)Java classes

There are also a component-models that build on these languages

.NET COM+ (.NET languages)EJB (Java)CORBA CCM (C++, Java, many others)

Page 3: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 3June 14, 2007

Abstract views(platform independent,Written in UML)

Domain-specific Models(Platform specific,Written in UML with extra notation)

Implementations

From Abstractions to ImplementationsAbstract system

architecture

EnterpriseMiddlewareArchitecture

OO:simple

Java: EJB,

JMS, JSP

.NET: COM+,ASP

Safety CriticalArchitecture

C

EmbeddedSystem

Architecture

CORBA

Architectural StylesPipes and Filters2-TieredN-TieredLayeredBlackboardModel View Controller

Page 4: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 4June 14, 2007

DB (Data tier)

Enterprise ServicesThere are a range of middleware platforms that address the concerns of the enterprise: CORBA Services, J2EE and COM+.

All these middleware are based around the principle that an n-tiered style is the structural idiom for building enterprise systems.

COM+ is built to house business-logic components within a middle tier – other middleware must be chosen to develop presentation and data tiers.

COM+ (Business logic tier)

ASP.NET or JSP (Presentation tier)

Page 5: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 5June 14, 2007

.NET vs. Java for the Enterprise

Activation/Passivate (on stateful beans)JIT ActivationJava Server Page (JSP) ASP.NET

Instance PoolingObject Pooling

Can be implemented through JMSQueued Components

Java Message Service (JMS)Loosely Coupled Events

Java Transaction Service (JTS)Transactions

EJBSession Beans (Stateless, Stateful)Entity Beans Message-Driven Beans

COM+ ComponentsJava.NET

Page 6: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 6June 14, 2007

.NET: Enterprise ServicesCOM+ offers a suite of pre-programmed functionalities that solve many performance, scalability, and fault-tolerance requirements of the enterpriseThese are known as enterprise services:

TransactionsJust in time activationLoosely coupled messagingObject poolingQueued components

These services are configured to work with components, making the components safer and more trustworthyThese services let the programmer focus on coding the business logic.

relieving the programmer of “plumbing” work that was previously very costly and difficult

Page 7: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 7June 14, 2007

Component ConfigurationServices can be configured and associated with components in three different ways:

COM+ services can be configured declaratively at design-time. Developers apply service-related attributes at design time and create instances of classes that use those services. An .NET attribute is a piece of metadata that is attached to class declarations to give extra information about the class – a bit like a programmed stereotype:

[WrittenByAttribute(“ProgrammerOne”)]class MyClass { … }

Services can be configured at runtime by calling methods on service-related classes or interfaces. Some services can flow from one object to another. For example, an object configured to require a transaction can extend that transaction to a second object if the second object also supports or requires transactions.

Services can be configured as part of the administration process. The Component Services console is a COM+ catalogue that holds the configuration information that is applied to a class implementation.

Page 8: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 8June 14, 2007

UML2 ExtendedWe will use UML2 to express architectures written for COM+However, UML2 does not have native support for many of the conceptsWe will extend UML2 to provide a specialization for COM+ architectures

Use stereotype <<COM+>> to denote that a component is a COM+ component

Use tagged values to denote other architecturally relevant COM+ data

e.g., {tagName = value2}

Page 9: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 9June 14, 2007

Transactions: ProblemConsider a version of our Holiday reservation system. The system takes a reservation request, and then

checks that the requested plane is free, that the hotel is available and that the credit card is validIf everything is okay, it books the aeroplane, the hotel and charges the card

Problem:What happens if one component crashes? What happens if the card becomes invalid during the processing? What happens if someone else booked the last seat on the plane during the booking processing, but the card was charged already?

Page 10: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 10June 14, 2007

TransactionsTransactions are a means to ensure fault tolerance in a system architectureThe idea is that a group of components are associated with a transactionWhen method is invoked on the group from outside, COM+ saves the state of all components in the groupIf the one of the group fails during the processing that results from the outside method call, then the state of the group is returned to what it was just before the call – this is called “rollback”The concept is very powerful – we can have nested transactions

Transaction

Calls from outside transaction group result in the other components performing processing tasks – if one fails, the group’s state is rolledback to just before the call was made

Page 11: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 11June 14, 2007

Transactional SettingsThe transaction service of COM+ sets (possibly nested) transactions for groups of components by associating a transactional attribute value with every COM+ component

There are four kinds of transactional settings:Required – the component must be run within a transaction – if the component is called from another component that is running within a transaction, then it can join that transaction – otherwise, COM+ will create a new transaction

Supported – if the component is called from another component that is running within a transaction, then it can join that transaction

Requires new – COM+ will always create a new transaction for the component when one of its methods has been invoked

Not supported – the component will not run within a transaction

Page 12: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 12June 14, 2007

Setting a Transactional Attribute in .NET

[Transaction(TransactionOption.Required, Isolation=TransactionIsolationLevel.Serializable, Timeout=10)]

public class TestObjectPooling : ServicedComponent{

// methods// go here

}

Says that this component requires a transaction

Says TestObjectPoolingis a COM+ component

Page 13: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 13June 14, 2007

Transactions in UML2 Specialization

<<COM+>>HotelRes

{transaction = TransactionOption.Supported}

<<COM+>>Holiday Reservation

Session{transaction =

TransactionOption.Requires

<<COM+>>CreditCardBilling

{transaction = TransactionOption.RequiresNew}

<<COM+>>AirRes

{transaction = TransactionOption.Supported}

Use tagged values to represent architecturally relevant COM+ service metadata – the transaction type

Page 14: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 14June 14, 2007

.NET vs. Java for the Enterprise

Activation/Passivate (on stateful beans)JIT ActivationJava Server Page (JSP) ASP.NET

Instance PoolingObject Pooling

Can be implemented through JMSQueued Components

Java Message Service (JMS)Loosely Coupled Events

Java Transaction Service (JTS)Transactions

EJBSession Beans (Stateless, Stateful)Entity Beans Message-Driven Beans

COM+ ComponentsJava.NET

Page 15: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 15June 14, 2007

Problem: Fat and Expensive ComponentsConsider a banking system

Bank clerks from different bank branches use web-based clients to interact with the bank server via (amongst other components) an Information component – this permits clerks to make a wide range of different queries to the server

The component doesn’t contain any data itself – but provides links to a wide range of separate databases used by different parts of the Bank (mortgages, personal loans, personal accounts each have separate databases of different legacies)

These links are very expensive to establish (it takes time to make a connection to a database, particularly the legacy ones)

Problem: If there are 1000 bank clerks running these clients, we will need to create 1000 Information objects – this is a BIG waste, particularly as the number of clients actually using the Information object at any time is about 4

Page 16: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 16June 14, 2007

Object PoolingThe object pooling service enables a set of component instances to be kept active in a pool that is shared by clients of the component.

When a client instantiates a client component, the reference is actually linked to the pool – a new instance is not created.

If a client calls an object of pooled class, the call is delegated to a member of the pool – if all the members of the pool are currently serving calls, then the call is queued until an object becomes available.

You can administratively configure and monitor the pool maintained for a given component, specifying characteristics such as pool size and creation request time-out values.

When the application is running, COM+ manages the pool for you, handling the details of object activation and reuse according to the criteria you have specified.

Page 17: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 17June 14, 2007

Object Pooling: AdvantagesYou can achieve very significant performance and scaling benefits by reusing objects in this manner, particularly when they are written to take full advantage of reuse. With object pooling, you gain the following benefits:

You can speed object use time for each client, factoring out time-consuming initialization and resource acquisition from the actual work that the object performs for clients.

You can share the cost of acquiring expensive resources across all clients.

You can pre-allocate objects when the application starts, before any client requests come in.

You can govern resource use with administrative pool management—for example, by setting an appropriate maximum pool level, you can keep open only as many database connections as you have a license for.

You can administratively configure pooling to take best advantage of available hardware resources—you can easily adjust the pool configuration as available hardware resources change.

Page 18: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 18June 14, 2007

Object Pooling: ConstraintsPooled objects must meet certain requirementsto enable a single object instance to be used by multiple clients.

For example, they can't hold client state or have any thread affinity.

Pooled objects are COM+ components – so can be transactional. This can make things complicated, but COM+ handles it for us.

Page 19: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 19June 14, 2007

Object Pooling Code[ObjectPooling(Enabled=true, MinPoolSize=2, MaxPoolSize=5,

CreationTimeOut=20000)]public class TestObjectPooling : ServicedComponent{

// methods// go herepublic override void Activate(){

// Called when removed from the pool.}public override void Deactivate(){

// Called before deactivating or placing back in pool.}public override bool CanBePooled(){

// Called after Deactivate. Indicate your vote here.return true;

}}

Says TestObjectPoolingis a COM+ component

Says that this object is to use the object pooling service, with a minimum pool of 2 and a maximum of 5

Page 20: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 20June 14, 2007

.NET and UML2 The situation of multiple clients sharing a single server can be represented in standard UML using multiplicitiesHowever, that representation doesn’t convey the platform specific detail with the precision we requireE.g., how do we express a pool of size 5 using multiplicities? If we made Information’s multiplicity 5, this could be interpreted to mean that each client has a reference to 5 Information components – not what we mean at allSo – we use tags again -- using a straightforward mapping of the .NET attribute types to tag names

*1 or 5 or what?!

<<COM+>>ClerkClient

<<COM+>>Information

{ObjectPoolingEnabled=true, ObjectPoolingMinPoolSize=2, ObjectPoolingMaxPoolSize=5}

Page 21: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 21June 14, 2007

.NET vs. Java for the Enterprise

Activation/Passivate (on stateful beans)JIT ActivationJava Server Page (JSP) ASP.NET

Instance PoolingObject Pooling

Can be implemented through JMSQueued Components

Java Message Service (JMS)Loosely Coupled Events

Java Transaction Service (JTS)Transactions

EJBSession Beans (Stateless, Stateful)Entity Beans Message-Driven Beans

COM+ ComponentsJava.NET

Page 22: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 22June 14, 2007

Problem: Skinny and Idle ComponentsConsider the Banking example but with the opposite kind of Information Component

Imagine that the Information Component interacts with only one database

It is very cheap to instantiate (there are no legacy databases, only a very fast one)It is cheap to destroyIt is expensive to have running constantly, as it takes up a lot of memory

Performance would be improved if all the clients were to maintain references to Information components, but for an Information reference to be active only when it is needed, and deactivated the moment it is not needed.

Page 23: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 23June 14, 2007

Just in Time ActivationThe COM+ Just-in-Time (JIT) Activation service allows idle server resources to be used more productively.

When a component is configured as JIT activated, COM+ can deactivate an instance of it while a client still holds an active reference to the object.

The next time the client calls a method on the object, COM+ reactivates the object transparently to the client, just in time.

Page 24: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 24June 14, 2007

.NET and UML2In .NET

[JustInTimeActivation(True)] class myClass : ServicedComponent { … }

In UML 2 Specialization

<<COM+>>ClerkClient

<<COM+>>Information

{JustInTimeActivation = true}

Page 25: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 25June 14, 2007

.NET vs. Java for the Enterprise

Activation/Passivate (on stateful beans)JIT ActivationJava Server Page (JSP) ASP.NET

Instance PoolingObject Pooling

Can be implemented through JMSQueued Components

Java Message Service (JMS)Loosely Coupled Events

Java Transaction Service (JTS)Transactions

EJBSession Beans (Stateless, Stateful)Entity Beans Message-Driven Beans

COM+ ComponentsJava.NET

Page 26: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 26June 14, 2007

Loosely Coupled EventsRecall the publish/subscribe asynchronous style of message passing.

We defined this as a platform neutral abstraction.

The loosely coupled event service of COM+ supports late-bound asynchronous method calls between publishers and subscribers.

Rather than repeatedly polling the server, the system notifies interested parties as information becomes available.

Page 27: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 27June 14, 2007

Publish/Subscribe AbstractionComponents subscribe to events from a publisher componentThe publisher sends events to all subscribing components The subscribers are anonymous to the publisherThe anonymity is ignored at the architectural levelOur own <<publish/subscribe>> stereotype to designate this style of implementation semantics

B

C

A

<<publish/subscribe>>

Page 28: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 28June 14, 2007

Publish/Subscribe in COM+The key to the service is the use of special sink components called Event ClassesThese act purely as sinks and do not contain any implementation of their ownComponents may subscribe to an event sink if they expose the same interface as the event classThe publisher calls methods on an event classCOM+ (not the event class) then delegates these method calls to subscribersThe event class is the means of keeping anonymity – subscribers cannot see the publisher and the publisher does not know its subscribers

Publisher Sink

SubscriberSubscriber

SubscriberSubscriber

Subscriber

Page 29: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 29June 14, 2007

Publish/Subscribe in .NET

:Subscriber :Publisher

Computation

Computation

Computation

:Subscriber

Computation

Notify

Computation

Computation

NotifyNotify

Subscribe

Subscribe

:Sink

Notify

Notify

Page 30: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 30June 14, 2007

Loosely Coupled Events in UML2The EventClass is architecturally significant at this level

It is a COM+ component and will be configured, implemented, and deployed just like any other COM+ component

We make EventClass components explicit, using the {EventClass = true} tagEventClass components expose a provided interface for publisher components to callHowever, EventClass components do not require services to run –delegation of functionality to subscribers is handled by COM+We represent this delegation by use of the <<delegate>> stereotype (Note: previously used only for delegating outer interface functionality of composite components to subcomponents)

<<COM+>>Publisher

<<COM+>>Sink

{EventClass = true}

IMessage

<<COM+>>Subscriber1

<<COM+>>Subscriber2

IMessage

IMessage

<<delegate>>

<<delegate>>

Page 31: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 31June 14, 2007

.NET vs. Java for the Enterprise

Activation/Passivate (on stateful beans)JIT ActivationJava Server Page (JSP) ASP.NET

Instance PoolingObject Pooling

Can be implemented through JMSQueued Components

Java Message Service (JMS)Loosely Coupled Events

Java Transaction Service (JTS)Transactions

EJBSession Beans (Stateless, Stateful)Entity Beans Message-Driven Beans

COM+ ComponentsJava.NET

Page 32: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 32June 14, 2007

An Example: Mobile SalesSalespeople take their PDAs to the field and enter orders on the go.Order processing components on the server

Order Processing System

Server location: Toronto Office

Salesperson location: Kitchener

Salesperson location: Stratford

Salesperson location: Waterloo

Salesperson location: Guelph

ISP

Mobile

Connection

Mobile

Connection

Mobile

Connection

Page 33: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 33June 14, 2007

Problem: Mobile Sales… but wireless connection can fail … and sometimes dialup doesn’t work

What happens? Do they wait for connection to reappear? Or take orders by hand and re-enter later?

It would be nice to take orders, record them and send them to the rest of the system whenever possible

Page 34: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 34June 14, 2007

Queued ComponentsThe COM+ Queued Components service provides an easy way to invoke and execute components asynchronously.

Processing can occur without regard to the availability or accessibility of either the sender or receiver.

The key notion is a queue: a storage area that saves messages for later retrieval. Just like a queue in a bank or supermarket, but with:

messages instead of customersa server component instead of a cashier

Page 35: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 35June 14, 2007

Queued ComponentsThe sender and receiver are not connected directly and communicate only through queues. Queuing provides a way to hold the information until the receiver is ready to obtain it.

This is extremely difficult to program reliable distributed queues that can interact with other enterprise services (e.g., transactions) – Queued components services handles it all very nicely and simply.The requestor sends a message to the server; when the server gets to it, the message is processed. Like e-mail, a messaging system must handle the network details and ensure that the message moves from the client to the server.

Page 36: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 36June 14, 2007

How It worksServer components are either

Ordinary Queued (the service equips them with a queue to buffer incoming messages)

The COM+ Queued Components service is built using the following components:

Recorder (for the client or sender side) Listener (for the server or receiver side) Player (for the server or receiver side)

Page 37: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 37June 14, 2007

How It worksRecorder and Queue

Client calls a queued component. The call is made to the Queued Components recorder, which packages it as part of a message to the server and puts it in a queue. The recorder records all of the client's method calls. The recorder thus acts as a proxy for the server component, delegating calls to the interfaces of the queued componentWhen a connection is available -- the queue is sent to the server (via another COM+ service called Message Queuing)

Page 38: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 38June 14, 2007

How It worksListener

This component listens for queues that are sent to itIt retrieves the queued messages and passes them to the Queued Components player.

PlayerThe player reads client's calls at the server side and then invokes the appropriate server component and makes the same method calls. The method calls are not played back by the player until the client component completes

Failure: Undelivered messages are moved from one queue to another so that they can be retried.

Page 39: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 39June 14, 2007

Solution: Mobile Sales with Queues

Order Processing System

Server location: Toronto Office

Location: Waterloo

Location: Kitchener

Location: Guelph

Queue listener:WaterlooGuelph

Kitchener

Queue Recorder:WaterlooGuelph

Kitchener

Page 40: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 40June 14, 2007

Queued Components: AdvantagesReduced Dependency on Component Availability

An application using the Queued Components service allows the server component to operate independently of the client.

Shorter Component LifetimesServer components can complete more quickly.

Uninterrupted Productivity in Disconnected ApplicationsThe increasing use of laptops, notebooks, and palm computers has created a need for applications that service occasionally disconnected clients or mobile users. In a queued system, these users can continue to work in a disconnected scenario or when not connected to the server, and they can later connect to the databases or servers to process their requests.For example, a salesperson can take orders from customers and later connect to the shipping department to process those orders.

Page 41: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 41June 14, 2007

Queued Components: AdvantagesMessage Reliability

In a real-time processing application, if just one component of the transaction is not available (due to server overload or networking problems), the entire process is blocked and cannot complete.An application using the COM+ Queued Components service separates the transaction into activities that must be completednow and those that can be completed at a later time. Messages can be queued for later processing so that the requesting component is free for other tasks.

Efficient Server Scheduling An application using queued components is well suited to time-shifted component execution, which defers uncritical work to an off-peak period. Concept: Traditional Batch Mode Processing.Similar requests can be deferred for contiguous execution by theserver rather than requiring the server to react immediately to a wide variety of requests.

Page 42: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 42June 14, 2007

Transactions for Queued ComponentsAs COM+ components, queued components are transactional.

When the queued component has the transaction attribute setting of Required or Supported, Queued components accepts delivery of the message only if the client-side transaction commits and the queue is set to be transactional.

When the transaction attribute setting is Requires New, queue can accept the message even if the client-side transaction aborts.

Page 43: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 43June 14, 2007

Programming Queued ComponentsMore complicated than programming other COM+ servicesInteraction with listener, recorder and player components is handled mostly through COM+

//Must be a server application to use queued components [assembly: ApplicationActivation(ActivationOption.Server)] [assembly: ApplicationQueuing(Enabled = true,QueueListenerEnabled = true)]

Server side – server needs to be declared to enable queuing:

Client side – calls to server are made via queued interface exposed by recorder:using System.Runtime.InteropServices;//for the Marshal

class IMyInterface obj;

obj=(IMyInterface)Marshal.BindToMoniker("queue:/new:MyNamespace.MyComponent");

obj.MyMethod( );//call is recorded

Interface must be declared as queued:

[InterfaceQueuing(Enabled = true)] public interface IMyInterface { void MyMethod( ); }

IMPORTANT:

Queued interfaces cannot have return values and accept only input by value not by reference

Page 44: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 44June 14, 2007

Queued Components in UML2We choose not to make the listener, recorder and player components explicit in our architectures (not explicit in the implementation either)Instead:

We designate server components as queued via {QueueListenerEnabled= true} tag attributeQueuable interfaces are defined as normal (class-style) but with {InterfaceQueuing = true} tagThe link from client to server (via queuing through a recorder, listener and player) is abstracted interception of a “component” with stereotype <<COM+Queue>>

exposes the provided interface of the queued server delegates required functionality to the server by means of the <<delegate>> stereotype

Page 45: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 45June 14, 2007

Solution: Mobile SalesWhen the system is in disconnected mode, these orders can be queued up in a message queue.

When salespeople connected back to the network, the orders are retrieved from the message queue and processed by the order processing components on the server.

Page 46: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 46June 14, 2007

.NET vs. Java for the Enterprise

Activation/Passivate (on stateful beans)JIT ActivationJava Server Page (JSP) ASP.NET

Instance PoolingObject Pooling

Can be implemented through JMSQueued Components

Java Message Service (JMS)Loosely Coupled Events

Java Transaction Service (JTS)Transactions

EJBSession Beans (Stateless, Stateful)Entity Beans Message-Driven Beans

COM+ ComponentsJava.NET

Page 47: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 47June 14, 2007

J2EE Application ServerJava 2 Enterprise Edition standardizes interfaces for Application Server components

Page 48: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 48June 14, 2007

EJB Overview

Page 49: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 49June 14, 2007

Types of Enterprise Java BeansSession Beans

StatefulStateless

Entity BeansBean-Managed Persistence (BMP)Container-Managed Persistence (CMP)Enterprise Java Beans Query Language

Message-Driven BeansSession bean with Java Messaging features

Page 50: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 50June 14, 2007

Session BeansFor transient functionsRepresents “conversational” stateTypically one per requestData is non-persistentLifetime is limited by the client’s

once the client exits, the session bean and data are gone

Simple and easy to programLight-weight

Page 51: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 51June 14, 2007

Stateful Session Bean’s Life CycleThe client invoke the create methodThe EJB container :

Instantiates the bean Invokes the setSessionContext Invokes ejbCreate

The bean is ready,. While in the ready stateEJB container may passivate the bean moving it from memory to secondary storage A client may invoke a business method EJB container may activate a bean,moving it back to the ready stage, and then calls the bean's ejbActivate methodA client may invoke the remove method and the container calls the bean's ejbRemove method

Page 52: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 52June 14, 2007

Stateful Session Bean’s Life Cycle

Page 53: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 53June 14, 2007

Stateless Session Bean’s Life CycleThe client invoke the create method

The EJB container :Instantiates the bean Invokes the setSessionContext Invokes ejbCreate

The bean is ready. While in the ready stateA client may invoke a business methodA client may invoke the remove method and the container calls the bean's ejbRemove methodIt’s never passivate

Page 54: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 54June 14, 2007

Stateless Session Bean’s Life Cycle

Page 55: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 55June 14, 2007

Types of Enterprise Java BeansSession Beans

StatefulStateless

Entity BeansBean-Managed Persistence (BMP)Container-Managed Persistence (CMP)Enterprise Java Beans Query Language

Message-Driven BeansSession bean with Java Messaging features

Page 56: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 56June 14, 2007

Entity Bean“Transactional” in behaviorCan be shared among clientsPersistent: data exists permanently after client quitsCorresponds to a row of a relational databaseThe persistence (storing into the database) can be done:

automatically by the “container” (CMP) or explicitly by the bean (BMP)

In BMP, you write the code for database access callsThis may be additional responsibility but it gives control to the bean developer.

Page 57: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 57June 14, 2007

Entity Bean’s Life CycleThe EJB container:

Creates the instanceCalls the setEntityContext

The entity bean moves to a pool of available instances

While in the pool:Instance is not associated with any particular object identity All instances in the pool are identical EJB container may assign an identity to an instance when moving it to the ready stage invoking the ejbActivate method A client may invoke the create method

EJB container calls ejbCreate and ejbPostCreate EJB container may remove the instance invoking unsetEntityContext

While in the ready state: A client may invoke entity bean's business methodsA client may invoke the remove method

EJB container calls the ejbRemove method EJB container may invoke the ejbPassivate method

Page 58: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 58June 14, 2007

Entity Bean’s Life Cycle

Page 59: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 59June 14, 2007

Types of Enterprise Java BeansSession Beans

StatefulStateless

Entity BeansBean-Managed Persistence (BMP)Container-Managed Persistence (CMP)Enterprise Java Beans Query Language

Message-Driven BeansSession bean with Java Messaging features

Page 60: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 60June 14, 2007

Message-Driven BeanA message driven bean is an enterprise bean that allows J2EE applications to process messages asynchronouslyIt acts as a JMS listener, which is similar to an event listener except that it receives messages instead of events.The messages can be sent by any J2EE component:

an application clientanother enterprise beana web componenta non-J2EE system using JMS

Retain no data or conversational state

Page 61: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 61June 14, 2007

Message Driven Bean’s Life CycleEJB container creates a pool of message-driven bean instancesFor each instance, the EJB container instantiates the bean :

It calls the setMessageDrivenContext It calls the instance's ejbCreate

Like a stateless session bean,it’s never passivated, It has only two states:

Nonexistent Ready to receive messages

While in the ready state : EJB container may call onMessage EJB container may call the ejbRemove

Page 62: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 62June 14, 2007

Message Driven Bean’s Life Cycle

Page 63: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 63June 14, 2007

.NET vs. Java for the Enterprise

Activation/Passivate (on stateful beans)JIT ActivationJava Server Page (JSP) ASP.NET

Instance PoolingObject Pooling

Can be implemented through JMSQueued Components

Java Message Service (JMS)Loosely Coupled Events

Java Transaction Service (JTS)Transactions

EJBSession Beans (Stateless, Stateful)Entity Beans Message-Driven Beans

COM+ ComponentsJava.NET

Page 64: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 64June 14, 2007

JTA / JTS – TransactionsThe Java Transaction API (JTA) and the Java Transaction Service (JTS) allow J2EE application servers to take the burden of transaction management from the component developer

Developers can define the transactional properties of Enterprise JavaBeans technology based components during design or deployment using declarative statements in the deployment descriptor

The application server takes over the transaction management responsibilities

Page 65: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 65June 14, 2007

TransactionsIn EJB only addresses persistent data

Application code required to rollback changes in application variables

Either Bean or Container Managed TransactionBean Managed

Explicit use of the Java Transaction API by the Bean

Container ManagedCompletely declarative in deployment descriptorContainer invokes business method in specified scope

Entity Beans must use Container Managed transactionsSession and Message Beans may use Bean Managed

Clients can also establish transactional scope

Page 66: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 66June 14, 2007

Transaction AttributesNotSupported

Method never called within a transactionContainer suspends client context if it exists

RequiredRuns in client’s context if it exists otherwise Container create a new contextUsed for a method that requires transaction, but can participate in a broader unit of work

Example: depositing money in an accountCan be atomic by itself or part of a greater transaction involving other operations

Page 67: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 67June 14, 2007

Transaction AttributesSupports

Uses client’s context if it exists otherwise runs without a contextNeeds to be used with caution

RequiresNewContainer always runs the method in a new transactionUseful for work that commits regardless of results of outer unit of work

MandatoryClient must invoke the method from within a transactionContainer uses this context

NeverClient must not invoke the method from within a transactionContainer does not provide transaction context

Page 68: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 68June 14, 2007

.NET vs. Java for the Enterprise

Activation/Passivate (on stateful beans)JIT ActivationJava Server Page (JSP) ASP.NET

Instance PoolingObject Pooling

Can be implemented through JMSQueued Components

Java Message Service (JMS)Loosely Coupled Events

Java Transaction Service (JTS)Transactions

EJBSession Beans (Stateless, Stateful)Entity Beans Message-Driven Beans

COM+ ComponentsJava.NET

Page 69: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 69June 14, 2007

JMS – Java Message ServiceEnterprise messaging provides a reliable, flexible service for the asynchronous exchange of critical business data and events throughout an enterprise

The JMS API adds to this a common API and provider framework that enables the development of portable, message based applications in the Java programming language

Why should we use JMS?Loosely-Coupled systems

ConnectionlessRemoves dependence on client and server platform / programming language / version

Publish / Subscribe metaphorSend / receive information with many, unknown clients

Integration with other messaging systemsIBM MQ-SeriesMicrosoft Message Queue

Page 70: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 70June 14, 2007

JMS – Java Message Service

JMS Queue

JMS Topic

Page 71: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 71June 14, 2007

EJB ExampleThe OnLine Bank

Services: what the client can do in the system such as see the foreign currency , listed shares or make operations on his hown account.

Accounts: a database containing the accounts of all the clients of the bank with information about credit,debit,access etc.

Security: is a subsystem that receives all the alarm caused from wrong access and performs action about the situation (calls police and stops operation of that client keeping information about him/her)

Virtual Bank

Client

Security Accounts

Services

Page 72: ECE750-Topic11: Component-Based Software Systemsltahvild/courses/ECE750-11-S07/mater… · ECE750-Topic11: Component-Based Software Systems .NET/J2EE Enterprise Services . June 14,

ECE750-Topic 11 72June 14, 2007

EJB Example: The OnLine BankEasy to create an EJB structure:

Client will have a web page at client side to insert values and connect the system

This will be done using JSP (Java Servlet Pages )

Services will be a Stateful Session Beanit will be different for each client connecting the system mantaining data about the client connected.

Accounts will be formed by an Entity Bean for each account in the system with a code-account as primary key.

Security will be a Message Driven Bean and will be called only from container if some operation are abnormal for result or the autentification for the same client fails too much times.