archjava a software architecture tool –components –connections –constraints on how components...

24
ArchJava • A software architecture tool – components – connections – constraints on how components interact • Implementation must conform to architecture

Post on 21-Dec-2015

222 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: ArchJava A software architecture tool –components –connections –constraints on how components interact Implementation must conform to architecture

ArchJava

• A software architecture tool– components– connections– constraints on how components interact

• Implementation must conform to architecture

Page 2: ArchJava A software architecture tool –components –connections –constraints on how components interact Implementation must conform to architecture

References

• ECOOP 2002 paper

• ICSE 2002 paper

• website on ArchJava

• ArchJava reference manual

Page 3: ArchJava A software architecture tool –components –connections –constraints on how components interact Implementation must conform to architecture

Architectural Conformance

• communication integrity– each component in the implemented system

may only communicate directly with the components to which it is connected in the architecture.

Page 4: ArchJava A software architecture tool –components –connections –constraints on how components interact Implementation must conform to architecture

public component class Parser { public port in { provides void setInfo(Token symbol, SymTabEntry e); requires Token nextToken() throws ScanException; } public port out { provides SymTabEntry getInfo(Token t); requires void compile (AST ast);} void parse (String file) { Token tok = in.nextToken(); AST ast = parseFile(tok); out.compile(ast); } AST parseFile(Token lookahead) { … } void setInfo(Token t, SymTabEntry e) {… } SymTabEntry getInfo(Token t) { … } …}

strange that parse does not belong to a port; parse isprovided.

Page 5: ArchJava A software architecture tool –components –connections –constraints on how components interact Implementation must conform to architecture

collaboration Parser { public participant in { provides void setInfo(Token symbol, SymTabEntry e); requires Token nextToken() throws ScanException; } public participant out { provides SymTabEntry getInfo(Token t); requires void compile (AST ast); void parse (String file) { Token tok = in.nextToken(); AST ast = parseFile(tok); out.compile(ast); } AST parseFile(Token lookahead) { … } void setInfo(Token t, SymTabEntry e) {… } SymTabEntry getInfo(Token t) { … } …}

can we do the samewith an aspectual collaboration?

Page 6: ArchJava A software architecture tool –components –connections –constraints on how components interact Implementation must conform to architecture

public component class Compiler { private final Scanner scanner = … ; private final Parser parser = … ; private final CodeGen codegen = … ;

connect scanner.out, parser.in; connect parser.out, codegen.in

public static void main(String args[]) { new Compiler().compile(args); } public void compile(String args[]) { // for each file in args do: … parser.parse(file); … }

Page 7: ArchJava A software architecture tool –components –connections –constraints on how components interact Implementation must conform to architecture

Composite components

• sub component: component instance nested within another component.

• singleton sub components: final

• connections: connect primitive is symmetric– bind each required method to a provided

method with same name and signature– args to connect: components own ports or those

of subcomponents in final fields

Page 8: ArchJava A software architecture tool –components –connections –constraints on how components interact Implementation must conform to architecture

Composite components

• Provided methods can be implemented by forwarding invocations to sub components or to the required methods of another port.

• Alternative connection semantics: write smart connectors.

• Only a component’s parent can invoke its methods directly.

Page 9: ArchJava A software architecture tool –components –connections –constraints on how components interact Implementation must conform to architecture

Dynamic architectures

• create component instances with new.

• typed references to sub components may not escape the scope of their parent.

• Garbage collection when components are no longer reachable through references or connections.

Page 10: ArchJava A software architecture tool –components –connections –constraints on how components interact Implementation must conform to architecture

public component class WebServer { private final Router r = new Router(); connect r.request, create; // may be instantiated at run-time // personality analogy connect pattern Router.workers, Worker.serve; public void run() { r.listen(); } private port create { provides r.workers requestWorkers() { final Worker newWorker = new Worker(); r.workers connection = connect(r.workers, newWorker.serve); return connection; } }}

Page 11: ArchJava A software architecture tool –components –connections –constraints on how components interact Implementation must conform to architecture

public component class Router {

Page 12: ArchJava A software architecture tool –components –connections –constraints on how components interact Implementation must conform to architecture

Limitations of ArchJava

• only Java• inter-component connections must be

implemented through method calls (not events, for example)

• focus on communication integrity• no reasoning about temporal ordering of

architectural events• shared data

Page 13: ArchJava A software architecture tool –components –connections –constraints on how components interact Implementation must conform to architecture

Example: Aphyds

• Developed by EE professor with PhD in CS

Page 14: ArchJava A software architecture tool –components –connections –constraints on how components interact Implementation must conform to architecture

Hypotheses

• Do those hypotheses hold for aspectual collaborations? A port corresponds to a participant.

• In ArchJava: no renaming of methods in connectors

Page 15: ArchJava A software architecture tool –components –connections –constraints on how components interact Implementation must conform to architecture

Hypotheses

• Refactoring an application to expose its architecture is done most efficiently in small increments

• Applications can be translated into ArchJava with a modest amount of effort and without excessive code bloat

Page 16: ArchJava A software architecture tool –components –connections –constraints on how components interact Implementation must conform to architecture

Hypotheses

• Expressing software in ArchJava highlights refactoring opportunities by making communication protocols explicit.

• Note: the name of a port gives a clue about the purpose of the port’s methods.

Page 17: ArchJava A software architecture tool –components –connections –constraints on how components interact Implementation must conform to architecture

Hypotheses

• Using separate ports and connections to distinguish different protocols and describing protocols with separate provided and required port interfaces may ease program understanding tasks.

• Communication integrity in ArchJava encourages local communication and helps to reduce coupling between components.

Page 18: ArchJava A software architecture tool –components –connections –constraints on how components interact Implementation must conform to architecture

Architectural Refactoring during Translation

• ArchJava’s

Page 19: ArchJava A software architecture tool –components –connections –constraints on how components interact Implementation must conform to architecture

Ideas

• Can ArchJava constraints be simulated in AspectJ? Simulate a component class with aspects that check the constraints?

• What are the connections between ports and participants?

• Law of Demeter and default architecture.

Page 20: ArchJava A software architecture tool –components –connections –constraints on how components interact Implementation must conform to architecture

Ports and Participants

• Sounds like ports are a second very useful application of the participant idea. Participants are connected in a graph; ports don’t rely on that.

Page 21: ArchJava A software architecture tool –components –connections –constraints on how components interact Implementation must conform to architecture

Ports and Participants

• ArchJava• has provides/requires• connect: link ports• no renaming• no component merging

• AC• has provides/requires• attach: link participants• renaming of method names• component merging

Page 22: ArchJava A software architecture tool –components –connections –constraints on how components interact Implementation must conform to architecture

component class Flying { port flier { provides void fly(); requires void takeOff(); requires void land(); …}}component class Bat { port flier_infra { provides void takeOff(); provides void land(); … } }component class FlyingBat { private final Flying f = … ; private final Bat b = … ; connect f.flier, b.flier_infra; public void fly() { f.fly();}}

Page 23: ArchJava A software architecture tool –components –connections –constraints on how components interact Implementation must conform to architecture

Topic Switch

Page 24: ArchJava A software architecture tool –components –connections –constraints on how components interact Implementation must conform to architecture

Hygienic Components and Mixins

class AddAttribute<C,Attribute> extends C{

// mixin class that adds a field of type

// Attribute to any class C

private Attribute _a;

void setAttribute(Attribute a) {_a = a;}

Attribute getAttribute() {return _a;}

}

class Point { … }