45
27 September 2007 Kaiser: COMS W4156 Fall 2 007 1 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser [email protected] http://york.cs.columbia.edu/clas ses/cs4156/

27 September 2007Kaiser: COMS W4156 Fall 20071 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser [email protected]

Embed Size (px)

Citation preview

Page 1: 27 September 2007Kaiser: COMS W4156 Fall 20071 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

27 September 2007 Kaiser: COMS W4156 Fall 2007 1

COMS W4156: Advanced Software Engineering

Prof. Gail Kaiser

[email protected]

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

Page 2: 27 September 2007Kaiser: COMS W4156 Fall 20071 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

27 September 2007 Kaiser: COMS W4156 Fall 2007 2

.NET and Component Services

Page 3: 27 September 2007Kaiser: COMS W4156 Fall 20071 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

27 September 2007 Kaiser: COMS W4156 Fall 2007 3

What is .NET?

• An object-oriented general purpose software development platform with multi-language interoperability

• Common Language Infrastructure (CLI)– Common Type System– Common Intermediate Language– Common Language Specification– common Virtual Execution Environment– common XML metadata representation

• CLI specification is an ECMA standard (originally European Computer Manufacturers Association, http://www.ecma-international.org/)

Page 4: 27 September 2007Kaiser: COMS W4156 Fall 20071 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

27 September 2007 Kaiser: COMS W4156 Fall 2007 4

Overview of the CLI

• A file format

• A common type system

• An extensible metadata system

• An intermediate language

• Access to the underlying platform

• A factored base class library

Page 5: 27 September 2007Kaiser: COMS W4156 Fall 20071 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

27 September 2007 Kaiser: COMS W4156 Fall 2007 5

File Format

• Based on Common Object File Format (predecessor to ELF on Unix but a variant still used for Windows)

• Code represented as MSIL (Microsoft Intermediate Language) instructions

• Metadata stored in read-only area• Methods include a descriptive header

– Stack frame size– Types of local variables and parameters– Pinned variable information– Exception handler table

Page 6: 27 September 2007Kaiser: COMS W4156 Fall 20071 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

27 September 2007 Kaiser: COMS W4156 Fall 2007 6

Common Type System

• Spans large number of languages• Object-oriented in flavor• Supports procedural and functional

languages, too• Includes value types (“structs”), pointers

and by-reference values• Subset for wide reach

Page 7: 27 September 2007Kaiser: COMS W4156 Fall 20071 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

27 September 2007 Kaiser: COMS W4156 Fall 2007 7

Metadata System

• Self-description for assemblies (components)– Includes referenced assemblies– Allows crypto-strong names– Records version information– Security boundary

• Self-description for types– Name and defining assembly– Member information (fields, methods, etc.)

• Extensible through custom attributes• Stored in file along with code

Page 8: 27 September 2007Kaiser: COMS W4156 Fall 20071 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

27 September 2007 Kaiser: COMS W4156 Fall 2007 8

Intermediate Language

• Simple stack machine model• Typeless opcodes (add, not add.int32)

– Signed and unsigned via opcode, not type– Rich set of conversion operations

• Tail calls, virtual dispatch, call via function pointer, exception handling

• Typed variable argument lists, dynamically typed pointers

• Objects, vectors, strings, integers, floats built-in

Page 9: 27 September 2007Kaiser: COMS W4156 Fall 20071 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

27 September 2007 Kaiser: COMS W4156 Fall 2007 9

Access to Platform

• Metadata describes managed and unmanaged interface

• Marshaling is automatic for many types• Custom marshaling can be specified• Platform-specific transformations are

possible (ANSI <-> Unicode, etc.)• Platform-specific calling conventions can

be specified

Page 10: 27 September 2007Kaiser: COMS W4156 Fall 20071 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

27 September 2007 Kaiser: COMS W4156 Fall 2007 10

Factored Class Library

• Designed for cross-language use

• Factored to allow minimal footprint and minimal hardware requirements (minimal base is always present)

• File format independent of factorization

• Intended to be platform-neutral

• Three layers: kernel, basic language, additional functionality

Page 11: 27 September 2007Kaiser: COMS W4156 Fall 20071 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

27 September 2007 Kaiser: COMS W4156 Fall 2007 11

Methodology• Define Kernel

– Fixes file format– Hand-picked classes and methods

• Define Basic Language– Minimal hardware support required– Most common language features (including those required

for C#)– Depends on classes defined in Kernel

• Package each advanced function separately– Implemented a la carte by runtime vendors– Required a la carte by developers

Page 12: 27 September 2007Kaiser: COMS W4156 Fall 20071 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

27 September 2007 Kaiser: COMS W4156 Fall 2007 12

Languages and Packages

• C#– Requires Kernel, Basic Language and

Extended Numerics

• ECMAScript– Requires above plus Reflection

• ISO C++– Requires Kernel, Basic Language,

Extended Numerics, and NonCLS

Page 13: 27 September 2007Kaiser: COMS W4156 Fall 20071 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

27 September 2007 Kaiser: COMS W4156 Fall 2007 13

Scenario-based System Design

Scenario Required Packages

Minimal Kernel

C# Program Kernel, Basic Language

Ex: Connected C# Application

Kernel, Basic Language, Common DT, Networking

Ex: Connected XML C# Application

Kernel, Basic Language, Common DT, Advanced DT, Networking, XML, IO, Collections

Core ExecutionEngine

Base Language

XML Standard IO

NetworkingCommon Data

Types

Advanced DataTypes

Collections

Core ExecutionEngine

Core ExecutionEngine

Core ExecutionEngine

Base Language

Base LanguageCommon Data

TypesNetworking

Minimal .Net Execution

Example: Advanced C# App

Example: Connected C# App

C# Program Execution

Page 14: 27 September 2007Kaiser: COMS W4156 Fall 20071 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

27 September 2007 Kaiser: COMS W4156 Fall 2007 14

Categories of Packages

• Classes grouped into packages• Packages grouped into five categories

Core Execution Engine

Development Time Classes

Base Language

GlobalizationAdvanced XML RemotingAsynch Support

XML

Standard IO NetworkingSecurity Threading

SerializationRegular

ExpressionsExtended Numerics

Common Data Types

Advanced Data Types

Collections

Non-CLS Support

ReflectionUnmanagedHostingGC

EE Functionality

Not In Buckets

High Level Programming

Common Programming Utilities

Abstract OS Interfaces

Miscellaneous

High Level Programming

Abstract OS Interfaces

Common Programming Utilities

EE Functionality

Page 15: 27 September 2007Kaiser: COMS W4156 Fall 20071 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

27 September 2007 Kaiser: COMS W4156 Fall 2007 15

Abstract OS Interface

Platform-independent operating system functionality

• Networking– System.Net.*

• Security– System.IsolatedStorage, System.Security, …

• Standard I/O– System.Console, System.IO, System.Text, …

• Threading– System.Threading, …

Page 16: 27 September 2007Kaiser: COMS W4156 Fall 20071 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

27 September 2007 Kaiser: COMS W4156 Fall 2007 16

Common Programming UtilitiesClasses that support typical programming patterns • Common Data Types

– System.DateTime, System.Text.StringBuilder, etc.• Advanced Data Types

– System.BitConverter, System.URI, …• Collections

– System.Collections• Extended Numerics

– System.Decimal, System.Double, etc.• Regular Expressions

– System.Text.RegularExpressions.*• Serialization

– System.Runtime.Serialization.*, etc.

Page 17: 27 September 2007Kaiser: COMS W4156 Fall 20071 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

27 September 2007 Kaiser: COMS W4156 Fall 2007 17

High-Level Programming“Advanced” programming patterns • Asynchronous Programming

– System.AsyncCallback, System.IAsyncResult• Globalization

– System.Globalization.*, System.Resources.*, etc.• Remoting

– System.Runtime.Remoting.*• XML

– System.Xml.* (parsing and generation)• Advanced XML

– System.Xml.Xsl.*, System.Xml.XPath.*

Page 18: 27 September 2007Kaiser: COMS W4156 Fall 20071 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

27 September 2007 Kaiser: COMS W4156 Fall 2007 18

Execution Environment Functionality

Revealing underlying operations to programming languages

• GC– System.WeakReference, System.WeakReferenceException

• Hosting– System.OperatingSystem, etc.

• NonCLS– System.ArgIterator, etc.

• Reflection – System.Reflection.*, etc.

• Unmanaged – System.Runtime.InteropServices, etc.

Page 19: 27 September 2007Kaiser: COMS W4156 Fall 20071 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

27 September 2007 Kaiser: COMS W4156 Fall 2007 19

Miscellaneous

Kernel, Basic Language, and support for developers

• Kernel– 1, 2, and 4 byte integers, arrays, string, object, etc.

• Basic Language Support– System.EventHandler, System.IFormattable,

System.Type, etc.

• Development Time– System.Diagnostics.*,

System.Runtime.CompilerServices.*

Page 20: 27 September 2007Kaiser: COMS W4156 Fall 20071 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

27 September 2007 Kaiser: COMS W4156 Fall 2007 20

CLI Summary

• A file format

• A common type system

• An extensible metadata system

• An intermediate language

• Access to the underlying platform

• A factored base class library

Page 21: 27 September 2007Kaiser: COMS W4156 Fall 20071 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

27 September 2007 Kaiser: COMS W4156 Fall 2007 21

Back to: What is .NET?

• Common Language Runtime (CLR) is Microsoft’s implementation of CLI

• Compilers for C#, VB.NET and C++ turn source code into MSIL that runs on CLR

• Extensive Framework Class Libraries, supporting windows GUI development (Windows Forms), database access (ADO.NET), web development (ASP.NET), web services, XML, etc.

• Other implementations of CLI: Mono, DotGNU

Page 22: 27 September 2007Kaiser: COMS W4156 Fall 20071 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

27 September 2007 Kaiser: COMS W4156 Fall 2007 22

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 23: 27 September 2007Kaiser: COMS W4156 Fall 20071 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

27 September 2007 Kaiser: COMS W4156 Fall 2007 23

How do multiple languages interoperate?

• A compiler from any language compiles an application into MSIL (also referred to as CIL – Common 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 24: 27 September 2007Kaiser: COMS W4156 Fall 20071 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

27 September 2007 Kaiser: COMS W4156 Fall 2007 24

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 25: 27 September 2007Kaiser: COMS W4156 Fall 20071 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

27 September 2007 Kaiser: COMS W4156 Fall 2007 25

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 .NET runtime'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 26: 27 September 2007Kaiser: COMS W4156 Fall 20071 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

27 September 2007 Kaiser: COMS W4156 Fall 2007 26

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”

Page 27: 27 September 2007Kaiser: COMS W4156 Fall 20071 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

27 September 2007 Kaiser: COMS W4156 Fall 2007 27

More on Assemblies

• The identity of a type is the assembly that houses it combined with the type name: if assembly A exports a type called T, and assembly B exports a type called T, .NET sees these as two completely different types (separate from .NET namespaces)

• Many of the security restrictions are enforced at the assembly boundary

• Also unit of versioning (version number consists of 4 parts, convention is major.minor.build.revision)

• Produced by compiler (single module) or linker (multiple modules)

Page 28: 27 September 2007Kaiser: COMS W4156 Fall 20071 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

27 September 2007 Kaiser: COMS W4156 Fall 2007 28

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 29: 27 September 2007Kaiser: COMS W4156 Fall 20071 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

27 September 2007 Kaiser: COMS W4156 Fall 2007 29

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

• Analogous to use of Java annotations in EJB 3.0

Page 30: 27 September 2007Kaiser: COMS W4156 Fall 20071 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

27 September 2007 Kaiser: COMS W4156 Fall 2007 30

Remoting

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

• Multiple serialization formats, e.g., SOAP (for HTTP) or binary (for TCP, similar to 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 31: 27 September 2007Kaiser: COMS W4156 Fall 20071 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

27 September 2007 Kaiser: COMS W4156 Fall 2007 31

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: Same as stateful (D)COM, whereby 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 32: 27 September 2007Kaiser: COMS W4156 Fall 20071 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

27 September 2007 Kaiser: COMS W4156 Fall 2007 32

So Where’s the Component Services?

Page 33: 27 September 2007Kaiser: COMS W4156 Fall 20071 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

27 September 2007 Kaiser: COMS W4156 Fall 2007 33

So Where’s the Component Services?

COM+(and Web Services)

Page 34: 27 September 2007Kaiser: COMS W4156 Fall 20071 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

27 September 2007 Kaiser: COMS W4156 Fall 2007 34

Recall COM+ Services

• Transactions

• Role-base security

• Queued components

• Loosely coupled events

• Just-in-time activation

• Object pooling

• …

Page 35: 27 September 2007Kaiser: COMS W4156 Fall 20071 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

27 September 2007 Kaiser: COMS W4156 Fall 2007 35

.NET Serviced 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 (Windows 2003 only)

Page 36: 27 September 2007Kaiser: COMS W4156 Fall 20071 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

27 September 2007 Kaiser: COMS W4156 Fall 2007 36

Example

Page 37: 27 September 2007Kaiser: COMS W4156 Fall 20071 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

27 September 2007 Kaiser: COMS W4156 Fall 2007 37

Example Serverusing System.EnterpriseServices; using System.Runtime.CompilerServices; using System.Reflection; // Supply the COM+ application name. [assembly: ApplicationName("BankComponent")] // Supply a strong-named assembly. [assembly: AssemblyKeyFileAttribute("BankComponent.snk")]namespace BankComponent

{ [Transaction(TransactionOption.Required)] public class Account : ServicedComponent { [AutoComplete]

public bool Post(int accountNum, double amount) { /* Updates the database; no need to call

SetComplete. Calls SetComplete automatically if no exception is generated (which calls SetAbort). */

return false; } } }

Page 38: 27 September 2007Kaiser: COMS W4156 Fall 20071 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

27 September 2007 Kaiser: COMS W4156 Fall 2007 38

Example Clientusing BankComponent;namespace BankComponentConsoleClient{ class Client { public static int Main() { try { Account act = new Account(); // Post money into the account. act.Post(5, 100); return(0); } catch { return(1); } } } }

Page 39: 27 September 2007Kaiser: COMS W4156 Fall 20071 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

27 September 2007 Kaiser: COMS W4156 Fall 2007 39

.NET/COM Interoperability

• Access classic COM components via a “Runtime Callable Wrapper” – converts the COM interfaces to .NET-compatible interfaces, marshals method calls, maintains object’s lifetime, etc.

Page 40: 27 September 2007Kaiser: COMS W4156 Fall 20071 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

27 September 2007 Kaiser: COMS W4156 Fall 2007 40

COM/.NET Interoperability

• A classic COM client can also treat a (registered) .NET assembly as a regular COM server, using a “COM Callable Wrapper” that mimics QueryInterface, AddRef, Release, etc.

Page 41: 27 September 2007Kaiser: COMS W4156 Fall 20071 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

27 September 2007 Kaiser: COMS W4156 Fall 2007 41

.NET vs. COM+

• No IUnknown base interface• No reference counting, uses garbage collection

(also in practice reference counting often used to avoid race conditions)

• No class factories, the .NET runtime resolves to a particular class within an assembly

• No apartments, programmer synchronizes (or uses automatic .NET synchronization domains)

Page 42: 27 September 2007Kaiser: COMS W4156 Fall 20071 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

27 September 2007 Kaiser: COMS W4156 Fall 2007 42

.NET vs. COM+

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

• No GUIDs (globally unique identifiers), instead uses scoping based on namespaces and “strong names” (unique digital signature using an encryption key)

• Evidence-based security (where component came from), in addition to role-based

• Doesn’t rely on registry, reduces DLL Hell• Different distributed computing (remoting) model

Page 43: 27 September 2007Kaiser: COMS W4156 Fall 20071 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

27 September 2007 Kaiser: COMS W4156 Fall 2007 43

IDA #3 Due Next Week!

• Tuesday 2 October, 10am

• Assignments posted on course website

• Submit via CourseWorks

• Individual Development Assignment #3

Page 44: 27 September 2007Kaiser: COMS W4156 Fall 20071 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

27 September 2007 Kaiser: COMS W4156 Fall 2007 44

Upcoming Deadlines

• Revised project concept due October 9th – first iteration begins

• First iteration plan due October 16th • First iteration progress report due October 23rd • First iteration demo week October 30th –

November 8th • First iteration final report due November 9th

Page 45: 27 September 2007Kaiser: COMS W4156 Fall 20071 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu

27 September 2007 Kaiser: COMS W4156 Fall 2007 45

COMS W4156: Advanced Software Engineering

Prof. Gail Kaiser

[email protected]

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