september 14, 2010coms w41561 coms w4156: advanced software engineering prof. gail kaiser...

80
September 14, 2010 COMS W4156 1 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser [email protected] http://bank.cs.columbia.edu/ classes/cs4156/

Upload: owen-willis

Post on 04-Jan-2016

223 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 1

COMS W4156: Advanced Software Engineering

Prof. Gail Kaiser

[email protected]

http://bank.cs.columbia.edu/classes/cs4156/

Page 2: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 24, 2009 COMS W4156 2

Topics covered in this lecture

• COM• MTS adds component services• COM+ adds more component services• .NET and Enterprise Services

Page 3: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 3

COM

Page 4: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 4

Component Object Model (COM)

• COM specifies an object (or component) model, and programming and compiler requirements, that enable COM objects to interact with other COM objects

• A COM object is made up of a set of data and the functions that manipulate the data

• A COM object’s data is accessed exclusively through one or more sets of related functions called interfaces

• COM requires that the only way to gain access to the methods of an interface is through a pointer to the interface

• Interfaces defined in Microsoft Interface Definition Language (analogous to CORBA IDL, but NOT the same)

Page 5: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 5

Component Object Model (COM)

• COM is a binary standard—a standard that applies after a program has been translated to binary machine code

• COM methods and interfaces must follow a prescribed in-memory layout

• Objects can be written in different languages, including languages that don’t have “objects”

Page 6: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 6

COM Interfaces• COM allows objects to interact across process and

machine boundaries as easily as within a single process

• Marshalling/demarshalling method parameters and return values across process and machine boundaries handled by operating system (in Windows COM implementation)

• COM enables this by specifying that the only way to manipulate the data associated with an object is through an interface on the object

• “Interface” here refers to an implementation in code of a COM binary-compliant interface that is associated with an object

Page 7: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 7

COM Interface Based on but Different from C++ Interface

• COM uses the word interface in a sense different from that typically used in C++ programming

• A C++ interface refers to all of the functions that a class supports and that clients of an object can call to interact with it

• A COM interface is a pure virtual definition that carries no implementation

• A COM interface refers to a predefined group of related functions that a COM class implements, but a specific interface does not necessarily represent all the functions that the class supports

• Represented as a “vtable” (as in C++)

Page 8: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

13 September 2007 Kaiser: COMS W4156 Fall 2007 8

Vtable Layout

Page 9: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 9

Calling an Interface Method• With appropriate compiler support (inherent in C and

C++), a client can call an interface method through its name, rather than its position in the array

• Because an interface is a type, the compiler - given the names of methods - can check the types of parameters and return values of each interface method call

• In contrast, if a client uses a position-based calling scheme, such type-checking is not available

Page 10: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 10

COM Clients and Servers

• A COM client is whatever code or object gets a pointer to a COM server and uses its services by calling the methods of its interface(s)

• A COM server is any object that provides services to clients

• These services are in the form of COM interface implementations that can be called by any client that is able to get a pointer to one of the interfaces on the server object

Page 11: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

13 September 2007 Kaiser: COMS W4156 Fall 2007 11

Server vs. Client Views

Page 12: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 12

Types of COM Server

• An in-process server resides in a dynamic link library (DLL) and runs in the same address space as the COM client

• A local server resides in its own executable (e.g., *.exe file), in a different process but on the same machine as the COM client

• A remote server runs on a different machine than the client

Page 13: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 13

COM Processes

Page 14: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 14

Same Machine• For clients and servers on the same machine, the

CLSID of the server is all the client ever needs• On each machine, COM maintains a database (using

the system registry on Windows) of all the CLSIDs for the servers installed on the system

• This is a mapping between each CLSID and the location of the DLL or EXE that houses the code for that CLSID

• COM consults this database whenever a client wants to create an instance of a COM class and use its services, so the client never needs to know the absolute location

Page 15: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 15

Different Machines

• For distributed systems, COM provides registry entries that allow a remote server to register itself for use by a local client

• Applications need know only a server's CLSID, because they can rely on the registry to locate the server

• However, COM allows clients to override registry entries and specify server locations

Page 16: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 16

COM vs. DCOM

• COM client applications do not need to be aware of how server objects are packaged, whether they are packaged as in-process objects (in DLLs) or as local or remote objects (in EXEs)

• Distributed COM (DCOM) is not separate—it is just COM with a longer wire

Page 17: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 17

COM Limitations

• Like CORBA: No support for common programming idioms (other than RPC)

• Unlike CORBA: Has one “main” implementation - from Microsoft for Windows, so by definition “compatible”

• Needs component services: distributed transactions, resource pooling, disconnected applications, event publication and subscription, better memory and processor (threads) management, …

Page 18: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 18

COM + MTS

Page 19: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 19

Microsoft Transaction Server (MTS)

• Enables the transactional requirements of each component to be set administratively, so components can be written separately and then grouped together as needed to form a single transaction

Page 20: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 20

What Transactional Requirements?

• Many applications write to some database(s) or other data repository(ies)

• An application that makes more than one change to a database may want to group those changes into a single unit – called a transaction

• The goal is to make sure that either all of those changes take place or that none of them do—a mix of success and failure isn’t possible

Page 21: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 21

What is a Transaction?

• “ACID” properties– Atomicity (all or nothing)– Consistency (no integrity constraints violated)– Isolation (no other computation sees intermediate

states, more formally = serializability)– Durability (persistence = failure recovery)

• Component model frameworks generally only concerned with atomicity and durability

Page 22: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 22

Handling Transactions within One Data Source

• If all the data accessed are contained in a single database, the database itself probably provides transactions

• The programmer need only indicate when a transaction begins and when it ends

• The database will make sure that all data accesses within these boundaries are either committed or rolled back

Page 23: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 23

Handling Transactions Across Multiple Data Sources

• The problem gets harder when an application accesses data contained in more than one database or involves other data resource managers such as a message queue

• It’s probably not possible for the transaction support built into any one of those systems to coordinate the commitment or roll-back of all data accesses

• Need some kind of independent transaction coordinating service

Page 24: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 24

What does the Transaction Coordinating Service do?

• Two-Phase Commit • First phase: transaction coordinator asks every

resource manager (e.g., database) involved in the transaction if it’s prepared to commit

• Second phase:– If every resource manager says yes, then the transaction

coordinator tells each one to commit– If one or more of the resource managers involved in this

transaction is unable or unwilling to commit (or does not respond within a timeout period), the transaction coordinator tells all of them to roll back the transaction

Page 25: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 25

MTS Executive and Distributed Transaction Coordinator (DTC)

• Invisible to a client, client sees just an ordinary COM object exposing some number of interfaces

• Executive intercepts every call the client makes on the objects it controls

• DTC manages the two-phase commit

Page 26: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 26

MTS Application Structure

Page 27: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 27

Two-Phase Commit

• OLE = Object Linking and Embedding

Page 28: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 28

Context Object

• Every object involved in a transaction is associated with a context object

• If a transaction needs to span the functions of multiple different objects, then same context object coordinates the activities of all of those objects

• Allows the transaction semantics to be separated from application code

Page 29: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 29

Automatic Transactions

• In traditional transaction systems, the application code indicates when a transaction begins and ends

• MTS also supports automatic transactions, allowing business logic to remain unaware of when transactions start and end

Page 30: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 30

Transaction Semantics Defined Declaratively

• Transaction semantics declared when components are assembled into an application package

• Each component is assigned a transaction attribute, one of four values:– Required – Requires New – Supported – Not Supported

Page 31: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 31

Transaction Options

• REQUIRED - The component must execute within the context of a transaction, although it does not care where the transaction context originates– If the caller has a transaction (context object), then

the called component will use the existing transaction

– If the caller does not have a transaction, then MTS automatically creates a new transaction context for the component

Page 32: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 32

Transaction Options

• REQUIRES NEW - indicates that the component must always establish its own transaction context

• Regardless of whether or not the calling application has a transaction context, MTS automatically creates a new transaction context object for the component

Page 33: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 33

Transaction Options

• SUPPORTED - indicates that the component does not care whether or not there is a transaction context in place

• NOT SUPPORTED - indicates that the component cannot support a transaction

Page 34: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 34

Commit or Abort

• The component operating on the database can tell the MTS executive when its task is complete– Everything has gone just fine and the transaction is ready

to be committed – the component calls IObjectContext::SetComplete (or just returns)

– Something has gone wrong, perhaps one attempt to access data resulted in an error, and the entire transaction should be rolled back – the component calls IObjectContext::SetAbort (or just crashes, hangs, etc.)

Page 35: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 35

Coordination of Multi-Component Transactions

• Calling SetComplete does not necessarily mean that the transaction will be committed right then

• If this component implements all the work required for an entire transaction, then MTS will perform the commit

Page 36: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 36

Coordination of Multi-Component Transactions

• But this component may be part of a group of components, all of which collectively participate in a single transaction

• Each component will call SetComplete (or terminate) when its work is done, but MTS won’t begin the commit process until all components within the transaction have completed successfully

• The code for the component looks the same in either case

Page 37: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 37

And a few other services…

Page 38: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 38

Just-In-Time (JIT) Activation• Also known as deferred activation• When a client makes a call to an object to create an instance,

COM provides that client a reference to a context object instead of a reference to the object

• Client gets a real reference to the object, and the object is activated, only when client calls a method of that object

• Object deactivated when method returns and reactivated when next method called

• Deactivated object releases all resources, including locks on data stores

• Allows server resources to be used more productively

Page 39: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 39

Object Pooling• Recycling of objects• When a client releases an object that supports object pooling, or

such an object is deactivated, instead of destroying that object completely, COM+MTS recycles it

• When another client requests or reactivates the same kind of object, COM+MTS gives an instance from the pool

• Since these component instances are already loaded in memory (up to maximum size of pool), they are immediately available for use

• If you intend to make only one call at a time on a pooled object, it is a good idea to enable JIT activation without object pooling; if you intend to get a reference and make multiple calls on it, using object pooling without JIT activation may result in better performance.

Page 40: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 40

Connection Pooling

• Opening and closing connections to a database can be time-consuming

• Reuse existing database connections rather than create new ones

• A resource dispenser caches resources such as ODBC (Open DataBase Connectivity) connections to a database, allowing components to efficiently reuse them

Page 41: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 41

Role-Based Security

• “Role” = a logically related group of users that share the same permissions to access a defined subset of an application’s functionalities

• Assign different permissions for different roles on a class, interface or method

• Can set either administratively or via programming• Don’t need to write security-related logic into

components (but can do so if desired)

Page 42: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 42

So How Does MTS Fit With COM?

Page 43: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 43

MTS Extends COM to 3-tier Architecture

Page 44: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 44

Client-Server Architecture

Client Server

Page 45: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 45

2-tier Architecturewith Basic Component Middleware

Client Server

Componentmiddleware

Page 46: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 46

3-Tier Architecturewith Component Services Middleware

Client

Componentservicesmiddleware

Database

Application logic com

ponents

LDA

PD

ocument

Storage

Page 47: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 47

COM+

Page 48: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 48

COM+ Adds More Services

Page 49: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 49

Load Balancing

• Scalability: network traffic and number of clients should not affect performance of an application (e.g., response time, throughput)

• Load balancing distributes client calls across a server cluster transparently to the application

• Components to be load-balanced configured on per-class basis at deployment

Page 50: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 50

COM+ Router

• When a client requests a specific component, it first connects to a load balancing router (itself possibly a cluster)

• Router polls the cluster application servers for timing data (e.g., every 200ms)

• Router chooses a server based on lightest server load and availability

Page 51: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 51

Service Control Manager (SCM)

• Router’s SCM forwards the activation request to the selected server's SCM

• If the instantiation of the object fails, the router moves to the next server in a round-robin list

• Continues until a valid interface pointer is returned to the client

• From this point, all communication occurs directly between the client and the server that handled the request

Page 52: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 52

Microsoft Message Queue Server (MSMQ)

• Client can execute (asynchronous) method calls, even if the server component is offline

• MSMQ records and stores method calls automatically

• Useful for online applications that must be completed – but can be completed “later” (online banking, air reservation system, etc.)

Page 53: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 53

Disconnected Applications

• Increasing use of mobile devices has created a need for applications that service disconnected clients

• In a queued system, these users can continue to work when not connected to the application server, and 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 54: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 54

Component Availability

• In synchronous processing applications, if just one component of a compound activity is not available—perhaps because of server overload or networking problems—the entire process is blocked and cannot complete

• An application using the Queued Components service separates the activity into actions that must be completed now and those that can be completed at a later time

Page 55: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 55

Client/Server Decoupling

Page 56: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 56

Message Reliability

• Message Queuing uses database techniques to help protect data in a robust way

• Built-in support for transactions• In the event of a server failure, Message Queuing

ensures that transactions are rolled back so that messages are not lost and data is not corrupted

Page 57: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 57

Server Scheduling

• An application using queued components is well suited to time-shifted component execution, which defers non-critical work to an off-peak period

• Analogous to traditional batch mode processing• Similar requests can be deferred for contiguous

execution by the server rather than requiring the server to react immediately to a wide variety of requests

Page 58: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 58

COM+ Summary• COM-based services and technologies first

released in Windows 2000• Automatically handles difficult programming

tasks such as resource pooling, disconnected applications, distributed transactions, event notification, etc., often administratively (manually or scripted)

• Also supports .NET developers and applications through .NET’s Enterprise Services

Page 59: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 59

What Is Meant By Administratively?

Page 60: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 60

Page 61: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 14, 2010 COMS W4156 61

Page 62: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 16, 2010 COMS W4156 62

.NET

Page 63: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 16, 2010 COMS W4156 63

What is .NET?

• An object-oriented software development platform, with– peer to peer multi-language interoperability – common intermediate language (CIL)– common language runtime (CLR)– common data representation based on XML

• The C# language is the most comfortable for .NET, but not the only one and not mandatory

Page 64: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 16, 2010 COMS W4156 64

Why do they call it “.NET”?

• “I don't know what they were thinking. They certainly weren't thinking of people using search tools. It's meaningless marketing nonsense.” [Andy McMullan]

Page 65: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 16, 2010 COMS W4156 65

How Does Multi-Language Support Work?

• A compiler from any supported language compiles an application into CIL (also referred to as MS IL – Microsoft Intermediate Language)

• The compiler also generates metadata in XML – information on the types and named entities (classes, methods, fields, etc.) defined and used in the application

• At runtime, the CIL code is Just-in-Time (JIT) compiled into the target platform’s native code

• The CLR uses the metadata to perform runtime checks for type-safety and security (“managed code”)

Page 66: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 16, 2010 COMS W4156 66

Attributes

• Metadata attributes attach some data to a class or method, which can be accessed via reflection, e.g., [serializable]

• Context attributes provide an interception mechanism whereby instance activation and method calls can be pre- and/or post- processed

Page 67: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 16, 2010 COMS W4156 67

Common Language RuntimeExecution Model

CLR

VBSource code

Compiler

C++C#

Assembly AssemblyAssembly

Operating System Services

MSIL

Common Language Runtime JIT Compiler

Compiler Compiler

Native code

ManagedCode

ManagedCode

ManagedCode

UnmanagedCode

CLR Services

Ngen

Page 68: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 16, 2010 COMS W4156 68

What does “managed” mean?

• Managed code: .NET provides several core run-time services to the programs that run within it, e.g., exception handling and security - for these services to work, the code must provide a minimum level of information to the runtime

• Managed data: Data that is allocated and freed by the CLR’s garbage collector

• Managed classes: A C++ class can be marked with the __gc keyword - then memory for instances of the class are managed by the garbage collector and the class can interoperate with classes written in other CLR languages, e.g., inherit from a VB class (also restrictions, e.g., a managed class can only inherit from one base class)

Page 69: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 16, 2010 COMS W4156 69

What is an “assembly”?

• A logical .exe or .dll, can be an application (with a main entry point) or a library

• Consists of one or more files (dlls, exes, html files, etc.), and represents a group of resources, type definitions, implementations of those types, and references to other assemblies

• These resources, types and references are described in a block of data called a manifest - part of the assembly, making it self-describing

• Assemblies often referred to as “components”: CLR in a sense replaces COM

Page 70: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 16, 2010 COMS W4156 70

Private vs. Shared Assemblies

• A private assembly is normally used by a single application, and is stored in the application's directory

• A shared assembly is intended to be used by multiple applications, and is normally stored in the global assembly cache (GAC) but can be stored elsewhere

• Assemblies find each other (outside the GAC) by searching directory paths

Page 71: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 16, 2010 COMS W4156 71

Remoting• When a client creates an

instance of the remote type, the .NET infrastructure creates a proxy object that looks exactly like the remote type to the client.

• The client calls a method on that proxy, and the remoting system receives the call, routes it to the server process, invokes the server object, and returns the return value to the client proxy - which returns the result to the client.

Page 72: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 16, 2010 COMS W4156 72

Remoting

• Send messages along channels, e.g., TCP or HTTP

• Multiple serialization formats, e.g., SOAP (for HTTP) or binary (for TCP, replacing DCOM)

• Distributed garbage collection of objects is managed by “leased based lifetime” – when that time expires the object is disconnected from the .NET runtime remoting infrastructure unless in the interim renewed by a successful call from the client to the object (or explicit renewal by client)

Page 73: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 16, 2010 COMS W4156 73

Remote Invocations

• SingleCall: Each incoming request from a client is serviced by a new object

• Singleton: All incoming requests from clients are processed by a single server object

• Client-activated object: The client receives a reference to the remote object and holds that reference (thus keeping the remote object alive) until it is finished with it

Page 74: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 16, 2010 COMS W4156 74

So Where’s the Component Services?

Page 75: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 16, 2010 COMS W4156 75

.NET Enterprise Services

• Classes in the System.EnterpriseServices namespace wrap COM+ and make it much easier to build COM components

• COM+ services can be used by .NET components derived from the ServicedComponent class using the System.EnterpriseServices namespace

• Must be registered with the COM+ catalog• Can also use COM+ services outside components

Page 76: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 16, 2010 COMS W4156 76

Example

Page 77: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

September 16, 2010 COMS W4156 77

.NET vs. COM/COM+

• No IDL (Interface Definition Language) files, the compiler generates the assembly metadata and dependencies are captured during compilation (in manifests)

• Doesn’t rely on registry, reduces DLL Hell

• COM ~1993, DCOM ~1996, (D)COM + MTS ~1998, COM+ ~2000, .NET ~2002

Page 78: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

Upcoming Assignments

September 14, 2010 COMS W4156 78

Page 79: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

Upcoming Assignments

• Homework #1 due Thursday 16 September, 10am• Homework #2 due Thursday 23 September, 10am• Posted on course website• Submit via CourseWorks

September 14, 2010 COMS W4156 79

Page 80: September 14, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

COMS W4156: Advanced Software Engineering

Prof. Gail [email protected]

http://bank.cs.columbia.edu/classes/cs4156/

September 14, 2010 COMS W4156 80