Скачать презентацию Reading C 2 -style Applications Built in c Скачать презентацию Reading C 2 -style Applications Built in c

87edfb82451fb8c85cdbfba25fdbc0a5.ppt

  • Количество слайдов: 38

Reading C 2 -style Applications Built in c 2. fw Eric M. Dashofy edashofy@ics. Reading C 2 -style Applications Built in c 2. fw Eric M. Dashofy edashofy@ics. uci. edu For ICS 52 October 20, 2004

Overview Software architectures n The C 2 architectural style n n n With live Overview Software architectures n The C 2 architectural style n n n With live example The Klax application

Software Architecture: Basic Elements Interfaces Clock Component Connector Bus 1 Interfaces Software Architecture: Basic Elements Interfaces Clock Component Connector Bus 1 Interfaces

Software Architecture: Basic Elements (cont). Clock Bus 1 LCD Driver Configuration Links Software Architecture: Basic Elements (cont). Clock Bus 1 LCD Driver Configuration Links

An Architectural Style n n One definition of an architectural style: An architectural style An Architectural Style n n One definition of an architectural style: An architectural style is a named set of constraints (e. g. , rules) you put on your development n n n Constraints may be topological, behavioral, communication-oriented, you name it This can complicate development because these constraints may be inconvenient or unfamiliar BUT architectural styles elicit beneficial system properties that would be really hard to get otherwise

Examples from building architecture: 1. Name some constraints in each style 2. Name some Examples from building architecture: 1. Name some constraints in each style 2. Name some benefits (-ilities) elicited by each style.

The C 2 Architectural Style n Topological Constraints All components, connectors have two interfaces, The C 2 Architectural Style n Topological Constraints All components, connectors have two interfaces, “top” and “bottom” n Components can be connected to 0 -1 connector on each interface n Connectors can be connected to 0+ components or connectors on each interface n

The C 2 Architectural Style n Communication Constraints n Components & connectors communicate using The C 2 Architectural Style n Communication Constraints n Components & connectors communicate using only independent events or messages • Requests go up (“requests rise”) • Notifications go down • No passing pointers n Components & connectors communicate asynchronously • Can send/receive events at any time • No blocking!

The C 2 Architectural Style n Dependency Constraints n Components may make assumptions about The C 2 Architectural Style n Dependency Constraints n Components may make assumptions about services provided above them • But not who is providing them n n Components may NOT make assumptions about services provided below them Concurrency Constraints n Each component & connector assumes it’s running in its own thread of control

Live Example Data Store GUI Interpreter Alarm GUI Live Example Data Store GUI Interpreter Alarm GUI

Live Example Stores data; emits notifications whenever data changes. GUI Interpreter Data Store Alarm Live Example Stores data; emits notifications whenever data changes. GUI Interpreter Data Store Alarm GUI

Live Example Data Store GUI Interpreter Interprets basic GUI actions & translates them into Live Example Data Store GUI Interpreter Interprets basic GUI actions & translates them into data store operations Alarm GUI

Live Example Rings a bell whenever value of X changes Data Store GUI Interpreter Live Example Rings a bell whenever value of X changes Data Store GUI Interpreter Alarm GUI

Live Example Data Store GUI Interpreter Accept & process user actions Alarm GUI Live Example Data Store GUI Interpreter Accept & process user actions Alarm GUI

Live Example Data Store GUI Interpreter Bus connector – routes messages Alarm GUI Live Example Data Store GUI Interpreter Bus connector – routes messages Alarm GUI

Live Example Data Store GUI Interpreter Alarm GUI Live Example Data Store GUI Interpreter Alarm GUI

What –ilities does C 2 buy us? n What do you think? What –ilities does C 2 buy us? n What do you think?

-ilities bought by C 2 n Flexibility n n n Distributability n n Since -ilities bought by C 2 n Flexibility n n n Distributability n n Since no assumption of shared address space, distributing an app across machines is easy Visibility n n Loose coupling lets you swap out components, interpose components Flexible connectors allow run-time changes Since all messages go through connectors, they are easy to catch and log Parallelizability n One-thread-per-brick means multiprocessor machines are effectively utilized

Event-based vs. OO n Event-based n n n Communication by events Mostly asynchronous Requests Event-based vs. OO n Event-based n n n Communication by events Mostly asynchronous Requests emitted to unknown parties Responses and state changes go to many parties No shared pointers n Object Oriented n n n Communication by procedure calls Mostly synchronous Requests emitted to named party only Responses to caller only, state changes to many Lots of shared pointers

Implementing a C 2 architecture Eventbased World C 2 architecture Implemented by… Application (implemented) Implementing a C 2 architecture Eventbased World C 2 architecture Implemented by… Application (implemented) ? ? ? Objectoriented World How do we bridge this gap? Java/JVM Uses services provided by… Native OS

Implementing a C 2 architecture Eventbased World C 2 architecture Implemented by… Application (implemented) Implementing a C 2 architecture Eventbased World C 2 architecture Implemented by… Application (implemented) Uses services provided by… Architecture Framework Uses services provided by… Objectoriented World Java/JVM Uses services provided by… Native OS

What’s an architecture framework? n An architecture framework is software that helps to bridge What’s an architecture framework? n An architecture framework is software that helps to bridge the gaps between an architectural style and a particular implementation platform.

Example n C 2 World n n n Components Connectors Events Links Many threads Example n C 2 World n n n Components Connectors Events Links Many threads Asynchronous communication n Java World n n n Objects Method calls Parameters References Few threads Synchronous communication

Enter c 2. fw n c 2. fw is an architecture framework for the Enter c 2. fw n c 2. fw is an architecture framework for the C 2 style built in Java, providing: n n n Abstract base classes for components, connectors Reusable connectors (local & network) (Pluggable) topology management (Pluggable) message queuing policies (Pluggable) threading policies Essentially, c 2. fw does the hard work, components and connectors simply implement behaviors.

What does a message look like? In c 2. fw, a message can be What does a message look like? In c 2. fw, a message can be any serializable (e. g. no pointers) object n Named. Property. Messages (or subclasses) are popular though n Have a String name n Plus a set of name-value pairs n • e. g. {“description”, “Rectangle 1”} • e. g. {“width”, 123} • e. g. {“color”, java. awt. Color. BLACK}

“Reading” a c 2. fw application Basic format n Lifecycle methods: n init(), begin(), “Reading” a c 2. fw application Basic format n Lifecycle methods: n init(), begin(), end(), destroy() n start(), stop(), suspend(), resume() n n Handling messages n n void handle(Message m) Sending messages n send. To. All(Message m, Interface i)

Your basic c 2. fw component… package edu. uci. ics. mypackage; import c 2. Your basic c 2. fw component… package edu. uci. ics. mypackage; import c 2. fw. *; //import c 2. fw package import c 2. legacy. *; //import support for 2 -interface //C 2 components

Your basic c 2. fw component… package edu. uci. ics. mypackage; import c 2. Your basic c 2. fw component… package edu. uci. ics. mypackage; import c 2. fw. *; //import c 2. fw package import c 2. legacy. *; //import support for 2 -interface //C 2 components public class My. C 2 Component extends Abstract. C 2 Brick{ } Implements lots of boilerplate functionality from the base c 2. fw. Brick interface; declares a top interface top. Iface and a bottom interface bottom. Iface.

A boilerplate c 2. fw component… package edu. uci. ics. mypackage; import c 2. A boilerplate c 2. fw component… package edu. uci. ics. mypackage; import c 2. fw. *; //import c 2. fw package import c 2. legacy. *; //import support for 2 -interface //C 2 components public class My. C 2 Component extends Abstract. C 2 Brick{ public My. C 2 Component(Identifier id){ super(id); } } Each component or connector has a unique identifier.

A boilerplate c 2. fw component… package edu. uci. ics. mypackage; import c 2. A boilerplate c 2. fw component… package edu. uci. ics. mypackage; import c 2. fw. *; //import c 2. fw package import c 2. legacy. *; //import support for 2 -interface //C 2 components public class My. C 2 Component extends Abstract. C 2 Brick{ public My. C 2 Component(Identifier id){ super(id); } public void begin(){ //called automatically by fw. //send out initial events } }

Lifecycle Methods public void init(){ //called when component/connector is created //but component not guaranteed Lifecycle Methods public void init(){ //called when component/connector is created //but component not guaranteed to be hooked up } public void begin(){ //called when component/connector is hooked up //in the architecture, should send initial messages } public void end(){ //called when component/connector is about to be //unhooked, should send final messages } public void destroy(){ //called when component/connector is about to be //destroyed }

A boilerplate c 2. fw component… package edu. uci. ics. mypackage; import c 2. A boilerplate c 2. fw component… package edu. uci. ics. mypackage; import c 2. fw. *; //import c 2. fw package import c 2. legacy. *; //import support for 2 -interface //C 2 components public class My. C 2 Component extends Abstract. C 2 Brick{ public My. C 2 Component(Identifier id){ super(id); } public void begin(){ //called automatically by fw. //send out initial events } public void handle(Message m){ //handle message } }

Implementing handle() //handle() method for our hypothetical alarm component //Called automatically when component receives Implementing handle() //handle() method for our hypothetical alarm component //Called automatically when component receives a message //Should ring bell whenever value of ‘X’ changes public void handle(Message m){ //handle message }

Implementing handle() //handle() method for our hypothetical alarm component public void handle(Message m){ //handle Implementing handle() //handle() method for our hypothetical alarm component public void handle(Message m){ //handle message if(m instanceof Named. Property. Message){ Named. Property. Message npm = (Named. Property. Message)m; } }

Implementing handle() //handle() method for our hypothetical alarm component public void handle(Message m){ //handle Implementing handle() //handle() method for our hypothetical alarm component public void handle(Message m){ //handle message if(m instanceof Named. Property. Message){ Named. Property. Message npm = (Named. Property. Message)m; String name = npm. get. Name(); if((name != null) && (name. equals(“value. Changed”)){ } } }

Implementing handle() //handle() method for our hypothetical alarm component public void handle(Message m){ //handle Implementing handle() //handle() method for our hypothetical alarm component public void handle(Message m){ //handle message if(m instanceof Named. Property. Message){ Named. Property. Message npm = (Named. Property. Message)m; String name = npm. get. Name(); if((name != null) && (name. equals(“value. Changed”)){ String var. Name = (String)npm. get. Parameter(“var. Name”); if((var. Name != null) && (var. Name. equals(“x”)){ } }

Implementing handle() //handle() method for our hypothetical alarm component public void handle(Message m){ //handle Implementing handle() //handle() method for our hypothetical alarm component public void handle(Message m){ //handle message if(m instanceof Named. Property. Message){ Named. Property. Message npm = (Named. Property. Message)m; String name = npm. get. Name(); if((name != null) && (name. equals(“value. Changed”)){ String var. Name = (String)npm. get. Parameter(“var. Name”); if((var. Name != null) && (var. Name. equals(“x”)){ ring. Bell(); Named. Property. Message rnpm = new Named. Property. Message(“Alarm. Fired”); rnpm. add. Property(“time”, System. current. Time. Millis()); send. To. All(rnpm, bottom. Iface); } }

Implementing handle() If we care, we could have checked what interface that message came Implementing handle() If we care, we could have checked what interface that message came in on: if(m. get. Destination(). get. Interface. Identifier(). equals( Abstract. C 2 Brick. TOP_INTERFACE_ID)){ //it’s a notification }