Presentation is loading. Please wait.

Presentation is loading. Please wait.

27 September 2007Kaiser: COMS W4156 Fall 20071 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser

Similar presentations


Presentation on theme: "27 September 2007Kaiser: COMS W4156 Fall 20071 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser"— Presentation transcript:

1 27 September 2007Kaiser: COMS W4156 Fall 20071 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu http://york.cs.columbia.edu/classes/cs4156/

2 27 September 2007Kaiser: COMS W4156 Fall 20072.NET and Component Services

3 27 September 2007Kaiser: COMS W4156 Fall 20073 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/) http://www.ecma-international.org/

4 27 September 2007Kaiser: COMS W4156 Fall 20074 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

5 27 September 2007Kaiser: COMS W4156 Fall 20075 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

6 27 September 2007Kaiser: COMS W4156 Fall 20076 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

7 27 September 2007Kaiser: COMS W4156 Fall 20077 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

8 27 September 2007Kaiser: COMS W4156 Fall 20078 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

9 27 September 2007Kaiser: COMS W4156 Fall 20079 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

10 27 September 2007Kaiser: COMS W4156 Fall 200710 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

11 27 September 2007Kaiser: COMS W4156 Fall 200711 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

12 27 September 2007Kaiser: COMS W4156 Fall 200712 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

13 27 September 2007Kaiser: COMS W4156 Fall 200713 Scenario-based System Design ScenarioRequired Packages MinimalKernel C# ProgramKernel, 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

14 27 September 2007Kaiser: COMS W4156 Fall 200714 Categories of Packages Classes grouped into packages Packages grouped into five categories Miscellaneous High Level Programming Abstract OS Interfaces Common Programming Utilities EE Functionality

15 27 September 2007Kaiser: COMS W4156 Fall 200715 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, …

16 27 September 2007Kaiser: COMS W4156 Fall 200716 Common Programming Utilities Classes 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.

17 27 September 2007Kaiser: COMS W4156 Fall 200717 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.*

18 27 September 2007Kaiser: COMS W4156 Fall 200718 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.

19 27 September 2007Kaiser: COMS W4156 Fall 200719 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.*

20 27 September 2007Kaiser: COMS W4156 Fall 200720 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

21 27 September 2007Kaiser: COMS W4156 Fall 200721 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, DotGNUMonoDotGNU

22 27 September 2007Kaiser: COMS W4156 Fall 200722 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]

23 27 September 2007Kaiser: COMS W4156 Fall 200723 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”)

24 27 September 2007Kaiser: COMS W4156 Fall 200724 Common Language Runtime Execution Model CLR VB Source code Compiler C++C# Assembly Operating System Services MSIL Common Language Runtime JIT Compiler Compiler Native code Managed Code Managed Code Managed Code Unmanaged Code CLR Services Ngen

25 27 September 2007Kaiser: COMS W4156 Fall 200725 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)

26 27 September 2007Kaiser: COMS W4156 Fall 200726 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”

27 27 September 2007Kaiser: COMS W4156 Fall 200727 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)

28 27 September 2007Kaiser: COMS W4156 Fall 200728 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

29 27 September 2007Kaiser: COMS W4156 Fall 200729 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

30 27 September 2007Kaiser: COMS W4156 Fall 200730 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)

31 27 September 2007Kaiser: COMS W4156 Fall 200731 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

32 27 September 2007Kaiser: COMS W4156 Fall 200732 So Where’s the Component Services?

33 27 September 2007Kaiser: COMS W4156 Fall 200733 So Where’s the Component Services? COM+ (and Web Services)

34 27 September 2007Kaiser: COMS W4156 Fall 200734 Recall COM+ Services Transactions Role-base security Queued components Loosely coupled events Just-in-time activation Object pooling …

35 27 September 2007Kaiser: COMS W4156 Fall 200735.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)

36 27 September 2007Kaiser: COMS W4156 Fall 200736 Example

37 27 September 2007Kaiser: COMS W4156 Fall 200737 Example Server using 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; } } }

38 27 September 2007Kaiser: COMS W4156 Fall 200738 Example Client using 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); } } }

39 27 September 2007Kaiser: COMS W4156 Fall 200739.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.

40 27 September 2007Kaiser: COMS W4156 Fall 200740 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.

41 27 September 2007Kaiser: COMS W4156 Fall 200741.NET vs. COM+ No IUnknown base interface No reference counting, uses garbage collection (also in practice reference counting often used to avoid race conditions)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)

42 27 September 2007Kaiser: COMS W4156 Fall 200742.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

43 27 September 2007Kaiser: COMS W4156 Fall 200743 IDA #3 Due Next Week! Tuesday 2 October, 10am Assignments posted on course websitecourse website Submit via CourseWorksCourseWorks Individual Development Assignment #3

44 27 September 2007Kaiser: COMS W4156 Fall 200744 Upcoming Deadlines Revised project concept due October 9 th – first iteration beginsRevised project concept First iteration plan due October 16 th First iteration progress report due October 23 rd First iteration demo week October 30 th – November 8 th First iteration final report due November 9 th

45 27 September 2007Kaiser: COMS W4156 Fall 200745 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser Kaiser+4156@cs.columbia.edu http://york.cs.columbia.edu/classes/cs4156/


Download ppt "27 September 2007Kaiser: COMS W4156 Fall 20071 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser"

Similar presentations


Ads by Google