SlideShare una empresa de Scribd logo
1 de 57
Implementation Techniques Software Architecture Lecture 16
Objectives ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Objectives ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Recall Pipe-and-Filter ,[object Object],[object Object],[object Object],Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy;  (C)  2008 John Wiley & Sons, Inc. Reprinted with permission.
Framework #1: stdio ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Evaluating stdio ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Framework #2: java.io ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Evaluating java.io ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Recall the C2 Style ,[object Object],[object Object],[object Object],Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy;  (C)  2008 John Wiley & Sons, Inc. Reprinted with permission.
Framework #1: Lightweight C2 Framework ,[object Object],[object Object],[object Object],[object Object],Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy;  (C)  2008 John Wiley & Sons, Inc. Reprinted with permission.
Evaluating Lightweight C2 Framework ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Framework #2: Flexible C2 Framework ,[object Object],[object Object],[object Object],[object Object],Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy;  (C)  2008 John Wiley & Sons, Inc. Reprinted with permission.
Framework #2: Flexible C2 Framework Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy;  (C)  2008 John Wiley & Sons, Inc. Reprinted with permission.
Evaluating Flexible C2 Framework ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Objectives ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Implementing Pipe and Filter Lunar Lander ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy;  (C)  2008 John Wiley & Sons, Inc. Reprinted with permission.
Implementing Pipe and Filter Lunar Lander ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy;  (C)  2008 John Wiley & Sons, Inc. Reprinted with permission.
Implementing Pipe and Filter Lunar Lander ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy;  (C)  2008 John Wiley & Sons, Inc. Reprinted with permission.
GetBurnRate Filter //Import the java.io framework import java.io.*; public class GetBurnRate{ public static void main(String[] args){ //Send welcome message System.out.println(&quot;#Welcome to Lunar Lander&quot;); try{ //Begin reading from System input BufferedReader inputReader =  new BufferedReader(new InputStreamReader(System.in)); //Set initial burn rate to 0  int burnRate = 0; do{ //Prompt user System.out.println(&quot;#Enter burn rate or <0 to quit:&quot;); . . . Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy;  (C)  2008 John Wiley & Sons, Inc. Reprinted with permission.
GetBurnRate Filter //Import the java.io framework import java.io.*; public class GetBurnRate{ public static void main(String[] args){ //Send welcome message System.out.println(&quot;#Welcome to Lunar Lander&quot;); try{ //Begin reading from System input BufferedReader inputReader =  new BufferedReader(new InputStreamReader(System.in)); //Set initial burn rate to 0  int burnRate = 0; do{ //Prompt user System.out.println(&quot;#Enter burn rate or <0 to quit:&quot;); . . . . . . //Read user response try{ String burnRateString = inputReader.readLine(); burnRate = Integer.parseInt(burnRateString); //Send user-supplied burn rate to next filter  System.out.println(&quot;%&quot; + burnRate); } catch(NumberFormatException nfe){ System.out.println(&quot;#Invalid burn rate.&quot;); } }while(burnRate >= 0); inputReader.close(); } catch(IOException ioe){ ioe.printStackTrace(); } } } Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy;  (C)  2008 John Wiley & Sons, Inc. Reprinted with permission.
Implementing Pipe and Filter Lunar Lander ,[object Object],[object Object],[object Object],[object Object],[object Object],Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy;  (C)  2008 John Wiley & Sons, Inc. Reprinted with permission.
CalcBurnRate Filter import java.io.*; public class CalcNewValues{ public static void main(String[] args){ //Initialize values final int GRAVITY = 2; int altitude = 1000; int fuel = 500; int velocity = 70; int time = 0; try{ BufferedReader inputReader = new  BufferedReader(new InputStreamReader(System.in)); //Print initial values System.out.println(&quot;%a&quot; + altitude); System.out.println(&quot;%f&quot; + fuel); System.out.println(&quot;%v&quot; + velocity); System.out.println(&quot;%t&quot; + time); . . . Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy;  (C)  2008 John Wiley & Sons, Inc. Reprinted with permission.
CalcBurnRate Filter import java.io.*; public class CalcNewValues{ public static void main(String[] args){ //Initialize values final int GRAVITY = 2; int altitude = 1000; int fuel = 500; int velocity = 70; int time = 0; try{ BufferedReader inputReader = new  BufferedReader(new InputStreamReader(System.in)); //Print initial values System.out.println(&quot;%a&quot; + altitude); System.out.println(&quot;%f&quot; + fuel); System.out.println(&quot;%v&quot; + velocity); System.out.println(&quot;%t&quot; + time); . . . String inputLine = null; do{ inputLine = inputReader.readLine(); if((inputLine != null) &&  (inputLine.length() > 0)){ if(inputLine.startsWith(&quot;#&quot;)){ //This is a status line of text, and  //should be passed down the pipeline System.out.println(inputLine); } else if(inputLine.startsWith(&quot;%&quot;)){ //This is an input burn rate try{ int burnRate = Integer.parseInt(inputLine.substring(1)); if(altitude <= 0){ System.out.println(&quot;#The game is over.&quot;); } else if(burnRate > fuel){ System.out.println(&quot;#Sorry, you don't&quot; +  &quot;have that much fuel.&quot;); } . . . Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy;  (C)  2008 John Wiley & Sons, Inc. Reprinted with permission.
CalcBurnRate Filter import java.io.*; public class CalcNewValues{ public static void main(String[] args){ //Initialize values final int GRAVITY = 2; int altitude = 1000; int fuel = 500; int velocity = 70; int time = 0; try{ BufferedReader inputReader = new  BufferedReader(new InputStreamReader(System.in)); //Print initial values System.out.println(&quot;%a&quot; + altitude); System.out.println(&quot;%f&quot; + fuel); System.out.println(&quot;%v&quot; + velocity); System.out.println(&quot;%t&quot; + time); . . . String inputLine = null; do{ inputLine = inputReader.readLine(); if((inputLine != null) &&  (inputLine.length() > 0)){ if(inputLine.startsWith(&quot;#&quot;)){ //This is a status line of text, and  //should be passed down the pipeline System.out.println(inputLine); } else if(inputLine.startsWith(&quot;%&quot;)){ //This is an input burn rate try{ int burnRate = Integer.parseInt(inputLine.substring(1)); if(altitude <= 0){ System.out.println(&quot;#The game is over.&quot;); } else if(burnRate > fuel){ System.out.println(&quot;#Sorry, you don't&quot; +  &quot;have that much fuel.&quot;); } . . . else{ //Calculate new application state time = time + 1; altitude = altitude - velocity; velocity = ((velocity + GRAVITY) * 10 - burnRate * 2) / 10; fuel = fuel - burnRate; if(altitude <= 0){ altitude = 0; if(velocity <= 5){ System.out.println(&quot;#You have landed safely.&quot;); } else{ System.out.println(&quot;#You have crashed.&quot;); } } } //Print new values System.out.println(&quot;%a&quot; + altitude); System.out.println(&quot;%f&quot; + fuel); System.out.println(&quot;%v&quot; + velocity); System.out.println(&quot;%t&quot; + time); } catch(NumberFormatException nfe){ } . . . Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy;  (C)  2008 John Wiley & Sons, Inc. Reprinted with permission.
CalcBurnRate Filter import java.io.*; public class CalcNewValues{ public static void main(String[] args){ //Initialize values final int GRAVITY = 2; int altitude = 1000; int fuel = 500; int velocity = 70; int time = 0; try{ BufferedReader inputReader = new  BufferedReader(new InputStreamReader(System.in)); //Print initial values System.out.println(&quot;%a&quot; + altitude); System.out.println(&quot;%f&quot; + fuel); System.out.println(&quot;%v&quot; + velocity); System.out.println(&quot;%t&quot; + time); . . . String inputLine = null; do{ inputLine = inputReader.readLine(); if((inputLine != null) &&  (inputLine.length() > 0)){ if(inputLine.startsWith(&quot;#&quot;)){ //This is a status line of text, and  //should be passed down the pipeline System.out.println(inputLine); } else if(inputLine.startsWith(&quot;%&quot;)){ //This is an input burn rate try{ int burnRate = Integer.parseInt(inputLine.substring(1)); if(altitude <= 0){ System.out.println(&quot;#The game is over.&quot;); } else if(burnRate > fuel){ System.out.println(&quot;#Sorry, you don't&quot; +  &quot;have that much fuel.&quot;); } . . . else{ //Calculate new application state time = time + 1; altitude = altitude - velocity; velocity = ((velocity + GRAVITY) * 10 - burnRate * 2) / 10; fuel = fuel - burnRate; if(altitude <= 0){ altitude = 0; if(velocity <= 5){ System.out.println(&quot;#You have landed safely.&quot;); } else{ System.out.println(&quot;#You have crashed.&quot;); } } } //Print new values System.out.println(&quot;%a&quot; + altitude); System.out.println(&quot;%f&quot; + fuel); System.out.println(&quot;%v&quot; + velocity); System.out.println(&quot;%t&quot; + time); } catch(NumberFormatException nfe){ } . . . } } }while((inputLine != null) && (altitude > 0)); inputReader.close(); } catch(IOException ioe){ ioe.printStackTrace(); } } } Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy;  (C)  2008 John Wiley & Sons, Inc. Reprinted with permission.
Implementing Pipe and Filter Lunar Lander ,[object Object],[object Object],[object Object],Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy;  (C)  2008 John Wiley & Sons, Inc. Reprinted with permission.
DisplayValues Filter import java.io.*; public class DisplayValues{ public static void main(String[] args){ try{ BufferedReader inputReader = new  BufferedReader(new InputStreamReader(System.in)); String inputLine = null; do{ inputLine = inputReader.readLine(); if((inputLine != null) &&  (inputLine.length() > 0)){ if(inputLine.startsWith(&quot;#&quot;)){ //This is a status line of text, and  //should be passed down the pipeline with  //the pound-sign stripped off System.out.println(inputLine.substring(1)); } . . . Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy;  (C)  2008 John Wiley & Sons, Inc. Reprinted with permission.
DisplayValues Filter import java.io.*; public class DisplayValues{ public static void main(String[] args){ try{ BufferedReader inputReader = new  BufferedReader(new InputStreamReader(System.in)); String inputLine = null; do{ inputLine = inputReader.readLine(); if((inputLine != null) &&  (inputLine.length() > 0)){ if(inputLine.startsWith(&quot;#&quot;)){ //This is a status line of text, and  //should be passed down the pipeline with  //the pound-sign stripped off System.out.println(inputLine.substring(1)); } . . . else if(inputLine.startsWith(&quot;%&quot;)){ //This is a value to display if(inputLine.length() > 1){ try{ char valueType = inputLine.charAt(1); int value = Integer.parseInt(inputLine.substring(2)); switch(valueType){ case 'a': System.out.println(&quot;Altitude: &quot; + value); break; case 'f': System.out.println(&quot;Fuel remaining: &quot; + value); break; case 'v': System.out.println(&quot;Current Velocity: “ + value); break; case 't': System.out.println(&quot;Time elapsed: &quot; + value); break; } } catch(NumberFormatException nfe){ } . . . Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy;  (C)  2008 John Wiley & Sons, Inc. Reprinted with permission.
DisplayValues Filter import java.io.*; public class DisplayValues{ public static void main(String[] args){ try{ BufferedReader inputReader = new  BufferedReader(new InputStreamReader(System.in)); String inputLine = null; do{ inputLine = inputReader.readLine(); if((inputLine != null) &&  (inputLine.length() > 0)){ if(inputLine.startsWith(&quot;#&quot;)){ //This is a status line of text, and  //should be passed down the pipeline with  //the pound-sign stripped off System.out.println(inputLine.substring(1)); } . . . else if(inputLine.startsWith(&quot;%&quot;)){ //This is a value to display if(inputLine.length() > 1){ try{ char valueType = inputLine.charAt(1); int value = Integer.parseInt(inputLine.substring(2)); switch(valueType){ case 'a': System.out.println(&quot;Altitude: &quot; + value); break; case 'f': System.out.println(&quot;Fuel remaining: &quot; + value); break; case 'v': System.out.println(&quot;Current Velocity: “ + value); break; case 't': System.out.println(&quot;Time elapsed: &quot; + value); break; } } catch(NumberFormatException nfe){ } . . . } } } }while(inputLine != null); inputReader.close(); } catch(IOException ioe){ ioe.printStackTrace(); } } } Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy;  (C)  2008 John Wiley & Sons, Inc. Reprinted with permission.
Implementing Pipe and Filter Lunar Lander ,[object Object],[object Object],Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy;  (C)  2008 John Wiley & Sons, Inc. Reprinted with permission.
Implementing Pipe and Filter Lunar Lander Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy;  (C)  2008 John Wiley & Sons, Inc. Reprinted with permission.
Implementing Pipe and Filter Lunar Lander
Implementing Pipe and Filter Lunar Lander Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy;  (C)  2008 John Wiley & Sons, Inc. Reprinted with permission.
Implementing Pipe and Filter Lunar Lander
Takeaways ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Implementing Lunar Lander in C2 ,[object Object],[object Object],[object Object],[object Object],[object Object],Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy;  (C)  2008 John Wiley & Sons, Inc. Reprinted with permission.
Implementing Lunar Lander in C2 (cont’d) ,[object Object],[object Object],[object Object],Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy;  (C)  2008 John Wiley & Sons, Inc. Reprinted with permission.
Clock Component import c2.framework.*; public class Clock extends ComponentThread{ public Clock(){ super.create(&quot;clock&quot;, FIFOPort.class); } public void start(){ super.start(); Thread clockThread = new Thread(){ public void run(){ //Repeat while the application runs while(true){ //Wait for five seconds try{ Thread.sleep(5000); } catch(InterruptedException ie){} //Send out a tick notification Notification n = new Notification(&quot;clockTick&quot;); send(n); } } }; Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy;  (C)  2008 John Wiley & Sons, Inc. Reprinted with permission.
Clock Component import c2.framework.*; public class Clock extends ComponentThread{ public Clock(){ super.create(&quot;clock&quot;, FIFOPort.class); } public void start(){ super.start(); Thread clockThread = new Thread(){ public void run(){ //Repeat while the application runs while(true){ //Wait for five seconds try{ Thread.sleep(5000); } catch(InterruptedException ie){} //Send out a tick notification Notification n = new Notification(&quot;clockTick&quot;); send(n); } } }; clockThread.start(); } protected void handle(Notification n){ //This component does not handle notifications } protected void handle(Request r){ //This component does not handle requests } } Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy;  (C)  2008 John Wiley & Sons, Inc. Reprinted with permission.
Implementing Lunar Lander in C2 ,[object Object],[object Object],[object Object],[object Object],[object Object],Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy;  (C)  2008 John Wiley & Sons, Inc. Reprinted with permission.
GameState Component import c2.framework.*; public class GameState extends ComponentThread{ public GameState(){ super.create(&quot;gameState&quot;, FIFOPort.class); } //Internal game state and initial values int altitude = 1000; int fuel = 500; int velocity = 70; int time = 0; int burnRate = 0; boolean landedSafely = false; Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy;  (C)  2008 John Wiley & Sons, Inc. Reprinted with permission.
GameState Component import c2.framework.*; public class GameState extends ComponentThread{ public GameState(){ super.create(&quot;gameState&quot;, FIFOPort.class); } //Internal game state and initial values int altitude = 1000; int fuel = 500; int velocity = 70; int time = 0; int burnRate = 0; boolean landedSafely = false; protected void handle(Request r){ if(r.name().equals(&quot;updateGameState&quot;)){ //Update the internal game state if(r.hasParameter(&quot;altitude&quot;)){ this.altitude = ((Integer)r.getParameter(&quot;altitude&quot;)).intValue(); } if(r.hasParameter(&quot;fuel&quot;)){ this.fuel = ((Integer)r.getParameter(&quot;fuel&quot;)).intValue(); } if(r.hasParameter(&quot;velocity&quot;)){ this.velocity = ((Integer)r.getParameter(&quot;velocity&quot;)).intValue(); } if(r.hasParameter(&quot;time&quot;)){ this.time = ((Integer)r.getParameter(&quot;time&quot;)).intValue(); } if(r.hasParameter(&quot;burnRate&quot;)){ this.burnRate = ((Integer)r.getParameter(&quot;burnRate&quot;)).intValue(); } if(r.hasParameter(&quot;landedSafely&quot;)){ this.landedSafely = ((Boolean)r.getParameter(&quot;landedSafely&quot;)) .booleanValue(); } //Send out the updated game state Notification n = createStateNotification(); send(n); } Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy;  (C)  2008 John Wiley & Sons, Inc. Reprinted with permission.
GameState Component import c2.framework.*; public class GameState extends ComponentThread{ public GameState(){ super.create(&quot;gameState&quot;, FIFOPort.class); } //Internal game state and initial values int altitude = 1000; int fuel = 500; int velocity = 70; int time = 0; int burnRate = 0; boolean landedSafely = false; protected void handle(Request r){ if(r.name().equals(&quot;updateGameState&quot;)){ //Update the internal game state if(r.hasParameter(&quot;altitude&quot;)){ this.altitude = ((Integer)r.getParameter(&quot;altitude&quot;)).intValue(); } if(r.hasParameter(&quot;fuel&quot;)){ this.fuel = ((Integer)r.getParameter(&quot;fuel&quot;)).intValue(); } if(r.hasParameter(&quot;velocity&quot;)){ this.velocity = ((Integer)r.getParameter(&quot;velocity&quot;)).intValue(); } if(r.hasParameter(&quot;time&quot;)){ this.time = ((Integer)r.getParameter(&quot;time&quot;)).intValue(); } if(r.hasParameter(&quot;burnRate&quot;)){ this.burnRate = ((Integer)r.getParameter(&quot;burnRate&quot;)).intValue(); } if(r.hasParameter(&quot;landedSafely&quot;)){ this.landedSafely = ((Boolean)r.getParameter(&quot;landedSafely&quot;)) .booleanValue(); } //Send out the updated game state Notification n = createStateNotification(); send(n); } else if(r.name().equals(&quot;getGameState&quot;)){ //If a component requests the game state //without updating it, send out the state Notification n = createStateNotification(); send(n); } } protected Notification createStateNotification(){ //Create a new notification comprising the //current game state Notification n = new Notification(&quot;gameState&quot;); n.addParameter(&quot;altitude&quot;, altitude); n.addParameter(&quot;fuel&quot;, fuel); n.addParameter(&quot;velocity&quot;, velocity); n.addParameter(&quot;time&quot;, time); n.addParameter(&quot;burnRate&quot;, burnRate); n.addParameter(&quot;landedSafely&quot;, landedSafely); return n; } protected void handle(Notification n){ //This component does not handle notifications } } Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy;  (C)  2008 John Wiley & Sons, Inc. Reprinted with permission.
Implementing Lunar Lander in C2 ,[object Object],[object Object],[object Object],[object Object],Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy;  (C)  2008 John Wiley & Sons, Inc. Reprinted with permission.
GameLogic Component import c2.framework.*; public class GameLogic extends ComponentThread{ public GameLogic(){ super.create(&quot;gameLogic&quot;, FIFOPort.class); } //Game constants final int GRAVITY = 2; //Internal state values for computation int altitude = 0; int fuel = 0; int velocity = 0; int time = 0; int burnRate = 0; public void start(){ super.start(); Request r = new Request(&quot;getGameState&quot;); send(r); } Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy;  (C)  2008 John Wiley & Sons, Inc. Reprinted with permission.
GameLogic Component import c2.framework.*; public class GameLogic extends ComponentThread{ public GameLogic(){ super.create(&quot;gameLogic&quot;, FIFOPort.class); } //Game constants final int GRAVITY = 2; //Internal state values for computation int altitude = 0; int fuel = 0; int velocity = 0; int time = 0; int burnRate = 0; public void start(){ super.start(); Request r = new Request(&quot;getGameState&quot;); send(r); } protected void handle(Notification n){ if(n.name().equals(&quot;gameState&quot;)){ if(n.hasParameter(&quot;altitude&quot;)){ this.altitude =  ((Integer)n.getParameter(&quot;altitude&quot;)).intValue(); } if(n.hasParameter(&quot;fuel&quot;)){ this.fuel =  ((Integer)n.getParameter(&quot;fuel&quot;)).intValue(); } if(n.hasParameter(&quot;velocity&quot;)){ this.velocity =  ((Integer)n.getParameter(&quot;velocity&quot;)).intValue(); } if(n.hasParameter(&quot;time&quot;)){ this.time =  ((Integer)n.getParameter(&quot;time&quot;)).intValue(); } if(n.hasParameter(&quot;burnRate&quot;)){ this.burnRate =  ((Integer)n.getParameter(&quot;burnRate&quot;)).intValue(); } } Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy;  (C)  2008 John Wiley & Sons, Inc. Reprinted with permission.
GameLogic Component import c2.framework.*; public class GameLogic extends ComponentThread{ public GameLogic(){ super.create(&quot;gameLogic&quot;, FIFOPort.class); } //Game constants final int GRAVITY = 2; //Internal state values for computation int altitude = 0; int fuel = 0; int velocity = 0; int time = 0; int burnRate = 0; public void start(){ super.start(); Request r = new Request(&quot;getGameState&quot;); send(r); } protected void handle(Notification n){ if(n.name().equals(&quot;gameState&quot;)){ if(n.hasParameter(&quot;altitude&quot;)){ this.altitude =  ((Integer)n.getParameter(&quot;altitude&quot;)).intValue(); } if(n.hasParameter(&quot;fuel&quot;)){ this.fuel =  ((Integer)n.getParameter(&quot;fuel&quot;)).intValue(); } if(n.hasParameter(&quot;velocity&quot;)){ this.velocity =  ((Integer)n.getParameter(&quot;velocity&quot;)).intValue(); } if(n.hasParameter(&quot;time&quot;)){ this.time =  ((Integer)n.getParameter(&quot;time&quot;)).intValue(); } if(n.hasParameter(&quot;burnRate&quot;)){ this.burnRate =  ((Integer)n.getParameter(&quot;burnRate&quot;)).intValue(); } } else if(n.name().equals(&quot;clockTick&quot;)){ //Calculate new lander state values int actualBurnRate = burnRate; if(actualBurnRate > fuel){ //Ensure we don’t burn more fuel than we have actualBurnRate = fuel; } time = time + 1; altitude = altitude - velocity; velocity = ((velocity + GRAVITY) * 10 – actualBurnRate * 2) / 10; fuel = fuel - actualBurnRate; //Determine if we landed (safely) boolean landedSafely = false; if(altitude <= 0){ altitude = 0; if(velocity <= 5){ landedSafely = true; } } Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy;  (C)  2008 John Wiley & Sons, Inc. Reprinted with permission.
GameLogic Component import c2.framework.*; public class GameLogic extends ComponentThread{ public GameLogic(){ super.create(&quot;gameLogic&quot;, FIFOPort.class); } //Game constants final int GRAVITY = 2; //Internal state values for computation int altitude = 0; int fuel = 0; int velocity = 0; int time = 0; int burnRate = 0; public void start(){ super.start(); Request r = new Request(&quot;getGameState&quot;); send(r); } protected void handle(Notification n){ if(n.name().equals(&quot;gameState&quot;)){ if(n.hasParameter(&quot;altitude&quot;)){ this.altitude =  ((Integer)n.getParameter(&quot;altitude&quot;)).intValue(); } if(n.hasParameter(&quot;fuel&quot;)){ this.fuel =  ((Integer)n.getParameter(&quot;fuel&quot;)).intValue(); } if(n.hasParameter(&quot;velocity&quot;)){ this.velocity =  ((Integer)n.getParameter(&quot;velocity&quot;)).intValue(); } if(n.hasParameter(&quot;time&quot;)){ this.time =  ((Integer)n.getParameter(&quot;time&quot;)).intValue(); } if(n.hasParameter(&quot;burnRate&quot;)){ this.burnRate =  ((Integer)n.getParameter(&quot;burnRate&quot;)).intValue(); } } else if(n.name().equals(&quot;clockTick&quot;)){ //Calculate new lander state values int actualBurnRate = burnRate; if(actualBurnRate > fuel){ //Ensure we don’t burn more fuel than we have actualBurnRate = fuel; } time = time + 1; altitude = altitude - velocity; velocity = ((velocity + GRAVITY) * 10 – actualBurnRate * 2) / 10; fuel = fuel - actualBurnRate; //Determine if we landed (safely) boolean landedSafely = false; if(altitude <= 0){ altitude = 0; if(velocity <= 5){ landedSafely = true; } } Request r = new Request(&quot;updateGameState&quot;); r.addParameter(&quot;time&quot;, time); r.addParameter(&quot;altitude&quot;, altitude); r.addParameter(&quot;velocity&quot;, velocity); r.addParameter(&quot;fuel&quot;, fuel); r.addParameter(&quot;landedSafely&quot;, landedSafely); send(r); } } protected void handle(Request r){ //This component does not handle requests } } Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy;  (C)  2008 John Wiley & Sons, Inc. Reprinted with permission.
Implementing Lunar Lander in C2 ,[object Object],[object Object],[object Object],Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy;  (C)  2008 John Wiley & Sons, Inc. Reprinted with permission.
GUI Component import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import c2.framework.*; public class GUI extends ComponentThread{ public GUI(){ super.create(&quot;gui&quot;, FIFOPort.class); } public void start(){ super.start(); Thread t = new Thread(){ public void run(){ processInput(); } }; t.start(); } Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy;  (C)  2008 John Wiley & Sons, Inc. Reprinted with permission.
GUI Component import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import c2.framework.*; public class GUI extends ComponentThread{ public GUI(){ super.create(&quot;gui&quot;, FIFOPort.class); } public void start(){ super.start(); Thread t = new Thread(){ public void run(){ processInput(); } }; t.start(); } public void processInput(){ System.out.println(&quot;Welcome to Lunar Lander&quot;); try{ BufferedReader inputReader = new BufferedReader( new InputStreamReader(System.in)); int burnRate = 0; do{ System.out.println(&quot;Enter burn rate or <0 to quit:&quot;); try{ String burnRateString = inputReader.readLine(); burnRate = Integer.parseInt(burnRateString); Request r = new Request(&quot;updateGameState&quot;); r.addParameter(&quot;burnRate&quot;, burnRate); send(r); } catch(NumberFormatException nfe){ System.out.println(&quot;Invalid burn rate.&quot;); } }while(burnRate >= 0); inputReader.close(); } catch(IOException ioe){ ioe.printStackTrace(); } } Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy;  (C)  2008 John Wiley & Sons, Inc. Reprinted with permission.
GUI Component import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import c2.framework.*; public class GUI extends ComponentThread{ public GUI(){ super.create(&quot;gui&quot;, FIFOPort.class); } public void start(){ super.start(); Thread t = new Thread(){ public void run(){ processInput(); } }; t.start(); } public void processInput(){ System.out.println(&quot;Welcome to Lunar Lander&quot;); try{ BufferedReader inputReader = new BufferedReader( new InputStreamReader(System.in)); int burnRate = 0; do{ System.out.println(&quot;Enter burn rate or <0 to quit:&quot;); try{ String burnRateString = inputReader.readLine(); burnRate = Integer.parseInt(burnRateString); Request r = new Request(&quot;updateGameState&quot;); r.addParameter(&quot;burnRate&quot;, burnRate); send(r); } catch(NumberFormatException nfe){ System.out.println(&quot;Invalid burn rate.&quot;); } }while(burnRate >= 0); inputReader.close(); } catch(IOException ioe){ ioe.printStackTrace(); } } protected void handle(Notification n){ if(n.name().equals(&quot;gameState&quot;)){ System.out.println(); System.out.println(&quot;New game state:&quot;); if(n.hasParameter(&quot;altitude&quot;)){ System.out.println(&quot;  Altitude: &quot; + n.getParameter(&quot;altitude&quot;)); } if(n.hasParameter(&quot;fuel&quot;)){ System.out.println(&quot;  Fuel: &quot; + n.getParameter(&quot;fuel&quot;)); } if(n.hasParameter(&quot;velocity&quot;)){ System.out.println(&quot;  Velocity: &quot; + n.getParameter(&quot;velocity&quot;)); } if(n.hasParameter(&quot;time&quot;)){ System.out.println(&quot;  Time: &quot; + n.getParameter(&quot;time&quot;)); } if(n.hasParameter(&quot;burnRate&quot;)){ System.out.println(&quot;  Burn rate: &quot; + n.getParameter(&quot;burnRate&quot;)); } Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy;  (C)  2008 John Wiley & Sons, Inc. Reprinted with permission.
GUI Component import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import c2.framework.*; public class GUI extends ComponentThread{ public GUI(){ super.create(&quot;gui&quot;, FIFOPort.class); } public void start(){ super.start(); Thread t = new Thread(){ public void run(){ processInput(); } }; t.start(); } public void processInput(){ System.out.println(&quot;Welcome to Lunar Lander&quot;); try{ BufferedReader inputReader = new BufferedReader( new InputStreamReader(System.in)); int burnRate = 0; do{ System.out.println(&quot;Enter burn rate or <0 to quit:&quot;); try{ String burnRateString = inputReader.readLine(); burnRate = Integer.parseInt(burnRateString); Request r = new Request(&quot;updateGameState&quot;); r.addParameter(&quot;burnRate&quot;, burnRate); send(r); } catch(NumberFormatException nfe){ System.out.println(&quot;Invalid burn rate.&quot;); } }while(burnRate >= 0); inputReader.close(); } catch(IOException ioe){ ioe.printStackTrace(); } } protected void handle(Notification n){ if(n.name().equals(&quot;gameState&quot;)){ System.out.println(); System.out.println(&quot;New game state:&quot;); if(n.hasParameter(&quot;altitude&quot;)){ System.out.println(&quot;  Altitude: &quot; + n.getParameter(&quot;altitude&quot;)); } if(n.hasParameter(&quot;fuel&quot;)){ System.out.println(&quot;  Fuel: &quot; + n.getParameter(&quot;fuel&quot;)); } if(n.hasParameter(&quot;velocity&quot;)){ System.out.println(&quot;  Velocity: &quot; + n.getParameter(&quot;velocity&quot;)); } if(n.hasParameter(&quot;time&quot;)){ System.out.println(&quot;  Time: &quot; + n.getParameter(&quot;time&quot;)); } if(n.hasParameter(&quot;burnRate&quot;)){ System.out.println(&quot;  Burn rate: &quot; + n.getParameter(&quot;burnRate&quot;)); } if(n.hasParameter(&quot;altitude&quot;)){ int altitude =  ((Integer)n.getParameter(&quot;altitude&quot;)).intValue(); if(altitude <= 0){ boolean landedSafely =  ((Boolean)n.getParameter(&quot;landedSafely&quot;)) .booleanValue(); if(landedSafely){ System.out.println(&quot;You have landed safely.&quot;); } else{ System.out.println(&quot;You have crashed.&quot;); } System.exit(0); } } } } protected void handle(Request r){ //This component does not handle requests } } Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy;  (C)  2008 John Wiley & Sons, Inc. Reprinted with permission.
Implementing Lunar Lander in C2 ,[object Object],[object Object],Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy;  (C)  2008 John Wiley & Sons, Inc. Reprinted with permission.
Main Program import c2.framework.*; public class LunarLander{ public static void main(String[] args){ //Create the Lunar Lander architecture Architecture lunarLander = new  SimpleArchitecture(&quot;LunarLander&quot;); //Create the components Component clock = new Clock(); Component gameState = new GameState(); Component gameLogic = new GameLogic(); Component gui = new GUI(); //Create the connectors Connector bus = new ConnectorThread(&quot;bus&quot;); //Add the components and connectors to the architecture lunarLander.addComponent(clock); lunarLander.addComponent(gameState); lunarLander.addComponent(gameLogic); lunarLander.addComponent(gui); lunarLander.addConnector(bus); Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy;  (C)  2008 John Wiley & Sons, Inc. Reprinted with permission.
Main Program import c2.framework.*; public class LunarLander{ public static void main(String[] args){ //Create the Lunar Lander architecture Architecture lunarLander = new  SimpleArchitecture(&quot;LunarLander&quot;); //Create the components Component clock = new Clock(); Component gameState = new GameState(); Component gameLogic = new GameLogic(); Component gui = new GUI(); //Create the connectors Connector bus = new ConnectorThread(&quot;bus&quot;); //Add the components and connectors to the architecture lunarLander.addComponent(clock); lunarLander.addComponent(gameState); lunarLander.addComponent(gameLogic); lunarLander.addComponent(gui); lunarLander.addConnector(bus); //Create the welds (links) between components and //connectors lunarLander.weld(clock, bus); lunarLander.weld(gameState, bus); lunarLander.weld(bus, gameLogic); lunarLander.weld(bus, gui); //Start the application lunarLander.start(); } } Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy;  (C)  2008 John Wiley & Sons, Inc. Reprinted with permission.
Takeaways ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

Más contenido relacionado

La actualidad más candente

Module 6 Session Hijacking
Module 6   Session HijackingModule 6   Session Hijacking
Module 6 Session Hijacking
leminhvuong
 
06 Computer Image Verification and Authentication - Notes
06 Computer Image Verification and Authentication - Notes06 Computer Image Verification and Authentication - Notes
06 Computer Image Verification and Authentication - Notes
Kranthi
 

La actualidad más candente (20)

HMAC - HASH FUNCTION AND DIGITAL SIGNATURES
HMAC  - HASH FUNCTION AND DIGITAL SIGNATURESHMAC  - HASH FUNCTION AND DIGITAL SIGNATURES
HMAC - HASH FUNCTION AND DIGITAL SIGNATURES
 
Network security & cryptography full notes
Network security & cryptography full notesNetwork security & cryptography full notes
Network security & cryptography full notes
 
Vehicle Tracking System Android Project Report
Vehicle Tracking System Android Project ReportVehicle Tracking System Android Project Report
Vehicle Tracking System Android Project Report
 
Incident response methodology
Incident response methodologyIncident response methodology
Incident response methodology
 
Lesson 2
Lesson 2Lesson 2
Lesson 2
 
Computerised voting system
Computerised voting systemComputerised voting system
Computerised voting system
 
Module 6 Session Hijacking
Module 6   Session HijackingModule 6   Session Hijacking
Module 6 Session Hijacking
 
Brain Fingerprinting PPT
Brain Fingerprinting PPTBrain Fingerprinting PPT
Brain Fingerprinting PPT
 
Message authentication
Message authenticationMessage authentication
Message authentication
 
02.security systems
02.security systems02.security systems
02.security systems
 
Fingerprint Based Biometric ATM Authentication System
Fingerprint Based Biometric ATM Authentication SystemFingerprint Based Biometric ATM Authentication System
Fingerprint Based Biometric ATM Authentication System
 
Incident response process
Incident response processIncident response process
Incident response process
 
Counterfeit Currency Detection
Counterfeit Currency DetectionCounterfeit Currency Detection
Counterfeit Currency Detection
 
Cyber Forensics Module 1
Cyber Forensics Module 1Cyber Forensics Module 1
Cyber Forensics Module 1
 
Packet Sniffing
Packet SniffingPacket Sniffing
Packet Sniffing
 
Seminar Presentation | Network Intrusion Detection using Supervised Machine L...
Seminar Presentation | Network Intrusion Detection using Supervised Machine L...Seminar Presentation | Network Intrusion Detection using Supervised Machine L...
Seminar Presentation | Network Intrusion Detection using Supervised Machine L...
 
06 Computer Image Verification and Authentication - Notes
06 Computer Image Verification and Authentication - Notes06 Computer Image Verification and Authentication - Notes
06 Computer Image Verification and Authentication - Notes
 
DETECTION OF FAKE ACCOUNTS IN INSTAGRAM USING MACHINE LEARNING
DETECTION OF FAKE ACCOUNTS IN INSTAGRAM USING MACHINE LEARNINGDETECTION OF FAKE ACCOUNTS IN INSTAGRAM USING MACHINE LEARNING
DETECTION OF FAKE ACCOUNTS IN INSTAGRAM USING MACHINE LEARNING
 
Public Key Distribution
Public Key Distribution Public Key Distribution
Public Key Distribution
 
Pm time management plan
Pm time management planPm time management plan
Pm time management plan
 

Destacado

17 applied architectures
17 applied architectures17 applied architectures
17 applied architectures
Majong DevJfu
 
S D D Program Development Tools
S D D  Program  Development  ToolsS D D  Program  Development  Tools
S D D Program Development Tools
gavhays
 
15 implementing architectures
15 implementing architectures15 implementing architectures
15 implementing architectures
Majong DevJfu
 

Destacado (13)

17 applied architectures
17 applied architectures17 applied architectures
17 applied architectures
 
S D D Program Development Tools
S D D  Program  Development  ToolsS D D  Program  Development  Tools
S D D Program Development Tools
 
15 implementing architectures
15 implementing architectures15 implementing architectures
15 implementing architectures
 
Software Development Techniques
Software Development TechniquesSoftware Development Techniques
Software Development Techniques
 
Architecture Patterns - Open Discussion
Architecture Patterns - Open DiscussionArchitecture Patterns - Open Discussion
Architecture Patterns - Open Discussion
 
The software Implementation Process
The software Implementation ProcessThe software Implementation Process
The software Implementation Process
 
What Makes Great Infographics
What Makes Great InfographicsWhat Makes Great Infographics
What Makes Great Infographics
 
Masters of SlideShare
Masters of SlideShareMasters of SlideShare
Masters of SlideShare
 
STOP! VIEW THIS! 10-Step Checklist When Uploading to Slideshare
STOP! VIEW THIS! 10-Step Checklist When Uploading to SlideshareSTOP! VIEW THIS! 10-Step Checklist When Uploading to Slideshare
STOP! VIEW THIS! 10-Step Checklist When Uploading to Slideshare
 
You Suck At PowerPoint!
You Suck At PowerPoint!You Suck At PowerPoint!
You Suck At PowerPoint!
 
10 Ways to Win at SlideShare SEO & Presentation Optimization
10 Ways to Win at SlideShare SEO & Presentation Optimization10 Ways to Win at SlideShare SEO & Presentation Optimization
10 Ways to Win at SlideShare SEO & Presentation Optimization
 
How To Get More From SlideShare - Super-Simple Tips For Content Marketing
How To Get More From SlideShare - Super-Simple Tips For Content MarketingHow To Get More From SlideShare - Super-Simple Tips For Content Marketing
How To Get More From SlideShare - Super-Simple Tips For Content Marketing
 
How to Make Awesome SlideShares: Tips & Tricks
How to Make Awesome SlideShares: Tips & TricksHow to Make Awesome SlideShares: Tips & Tricks
How to Make Awesome SlideShares: Tips & Tricks
 

Similar a 16 implementation techniques

01 intro to programming in .net
01   intro to programming in .net01   intro to programming in .net
01 intro to programming in .net
Felisha Hosein
 
18 applied architectures_part_2
18 applied architectures_part_218 applied architectures_part_2
18 applied architectures_part_2
Majong DevJfu
 
Cs 1023 lec 6 architecture (week 1)
Cs 1023 lec 6 architecture (week 1)Cs 1023 lec 6 architecture (week 1)
Cs 1023 lec 6 architecture (week 1)
stanbridge
 
Gervais Peter Resume Oct :2015
Gervais Peter Resume Oct :2015Gervais Peter Resume Oct :2015
Gervais Peter Resume Oct :2015
Peter Gervais
 
report_barc
report_barcreport_barc
report_barc
siontani
 
The Concurrency Challenge : Notes
The Concurrency Challenge : NotesThe Concurrency Challenge : Notes
The Concurrency Challenge : Notes
Subhajit Sahu
 
Software engineering
Software engineeringSoftware engineering
Software engineering
Fahe Em
 
Software engineering
Software engineeringSoftware engineering
Software engineering
Fahe Em
 
22 deployment and_mobility
22 deployment and_mobility22 deployment and_mobility
22 deployment and_mobility
Majong DevJfu
 

Similar a 16 implementation techniques (20)

01 intro to programming in .net
01   intro to programming in .net01   intro to programming in .net
01 intro to programming in .net
 
18 applied architectures_part_2
18 applied architectures_part_218 applied architectures_part_2
18 applied architectures_part_2
 
Cs 1023 lec 6 architecture (week 1)
Cs 1023 lec 6 architecture (week 1)Cs 1023 lec 6 architecture (week 1)
Cs 1023 lec 6 architecture (week 1)
 
Gervais Peter Resume Oct :2015
Gervais Peter Resume Oct :2015Gervais Peter Resume Oct :2015
Gervais Peter Resume Oct :2015
 
C# c# for beginners crash course master c# programming fast and easy today
C# c# for beginners crash course master c# programming fast and easy todayC# c# for beginners crash course master c# programming fast and easy today
C# c# for beginners crash course master c# programming fast and easy today
 
Unit 2 Java
Unit 2 JavaUnit 2 Java
Unit 2 Java
 
Dot net
Dot netDot net
Dot net
 
Resume
ResumeResume
Resume
 
CS8251_QB_answers.pdf
CS8251_QB_answers.pdfCS8251_QB_answers.pdf
CS8251_QB_answers.pdf
 
report_barc
report_barcreport_barc
report_barc
 
The Concurrency Challenge : Notes
The Concurrency Challenge : NotesThe Concurrency Challenge : Notes
The Concurrency Challenge : Notes
 
Software engineering
Software engineeringSoftware engineering
Software engineering
 
Software engineering
Software engineeringSoftware engineering
Software engineering
 
22 deployment and_mobility
22 deployment and_mobility22 deployment and_mobility
22 deployment and_mobility
 
Revealing C# 5
Revealing C# 5Revealing C# 5
Revealing C# 5
 
Srgoc dotnet_new
Srgoc dotnet_newSrgoc dotnet_new
Srgoc dotnet_new
 
Dot Net PPt.pptx
Dot Net PPt.pptxDot Net PPt.pptx
Dot Net PPt.pptx
 
3DD 1e 31 Luglio Apertura
3DD 1e 31 Luglio Apertura3DD 1e 31 Luglio Apertura
3DD 1e 31 Luglio Apertura
 
Aspect Oriented Programming Through C#.NET
Aspect Oriented Programming Through C#.NETAspect Oriented Programming Through C#.NET
Aspect Oriented Programming Through C#.NET
 
OMG CORBA Component Model tutorial
OMG CORBA Component Model tutorialOMG CORBA Component Model tutorial
OMG CORBA Component Model tutorial
 

Más de Majong DevJfu

9 - Architetture Software - SOA Cloud
9 - Architetture Software - SOA Cloud9 - Architetture Software - SOA Cloud
9 - Architetture Software - SOA Cloud
Majong DevJfu
 
8 - Architetture Software - Architecture centric processes
8 - Architetture Software - Architecture centric processes8 - Architetture Software - Architecture centric processes
8 - Architetture Software - Architecture centric processes
Majong DevJfu
 
7 - Architetture Software - Software product line
7 - Architetture Software - Software product line7 - Architetture Software - Software product line
7 - Architetture Software - Software product line
Majong DevJfu
 
6 - Architetture Software - Model transformation
6 - Architetture Software - Model transformation6 - Architetture Software - Model transformation
6 - Architetture Software - Model transformation
Majong DevJfu
 
5 - Architetture Software - Metamodelling and the Model Driven Architecture
5 - Architetture Software - Metamodelling and the Model Driven Architecture5 - Architetture Software - Metamodelling and the Model Driven Architecture
5 - Architetture Software - Metamodelling and the Model Driven Architecture
Majong DevJfu
 
4 - Architetture Software - Architecture Portfolio
4 - Architetture Software - Architecture Portfolio4 - Architetture Software - Architecture Portfolio
4 - Architetture Software - Architecture Portfolio
Majong DevJfu
 
3 - Architetture Software - Architectural styles
3 - Architetture Software - Architectural styles3 - Architetture Software - Architectural styles
3 - Architetture Software - Architectural styles
Majong DevJfu
 
2 - Architetture Software - Software architecture
2 - Architetture Software - Software architecture2 - Architetture Software - Software architecture
2 - Architetture Software - Software architecture
Majong DevJfu
 
1 - Architetture Software - Software as a product
1 - Architetture Software - Software as a product1 - Architetture Software - Software as a product
1 - Architetture Software - Software as a product
Majong DevJfu
 
10 - Architetture Software - More architectural styles
10 - Architetture Software - More architectural styles10 - Architetture Software - More architectural styles
10 - Architetture Software - More architectural styles
Majong DevJfu
 

Más de Majong DevJfu (20)

9 - Architetture Software - SOA Cloud
9 - Architetture Software - SOA Cloud9 - Architetture Software - SOA Cloud
9 - Architetture Software - SOA Cloud
 
8 - Architetture Software - Architecture centric processes
8 - Architetture Software - Architecture centric processes8 - Architetture Software - Architecture centric processes
8 - Architetture Software - Architecture centric processes
 
7 - Architetture Software - Software product line
7 - Architetture Software - Software product line7 - Architetture Software - Software product line
7 - Architetture Software - Software product line
 
6 - Architetture Software - Model transformation
6 - Architetture Software - Model transformation6 - Architetture Software - Model transformation
6 - Architetture Software - Model transformation
 
5 - Architetture Software - Metamodelling and the Model Driven Architecture
5 - Architetture Software - Metamodelling and the Model Driven Architecture5 - Architetture Software - Metamodelling and the Model Driven Architecture
5 - Architetture Software - Metamodelling and the Model Driven Architecture
 
4 - Architetture Software - Architecture Portfolio
4 - Architetture Software - Architecture Portfolio4 - Architetture Software - Architecture Portfolio
4 - Architetture Software - Architecture Portfolio
 
3 - Architetture Software - Architectural styles
3 - Architetture Software - Architectural styles3 - Architetture Software - Architectural styles
3 - Architetture Software - Architectural styles
 
2 - Architetture Software - Software architecture
2 - Architetture Software - Software architecture2 - Architetture Software - Software architecture
2 - Architetture Software - Software architecture
 
1 - Architetture Software - Software as a product
1 - Architetture Software - Software as a product1 - Architetture Software - Software as a product
1 - Architetture Software - Software as a product
 
10 - Architetture Software - More architectural styles
10 - Architetture Software - More architectural styles10 - Architetture Software - More architectural styles
10 - Architetture Software - More architectural styles
 
Uml3
Uml3Uml3
Uml3
 
Uml2
Uml2Uml2
Uml2
 
6
66
6
 
5
55
5
 
4 (uml basic)
4 (uml basic)4 (uml basic)
4 (uml basic)
 
3
33
3
 
2
22
2
 
1
11
1
 
Tmd template-sand
Tmd template-sandTmd template-sand
Tmd template-sand
 
26 standards
26 standards26 standards
26 standards
 

Último

Último (20)

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 

16 implementation techniques

  • 1. Implementation Techniques Software Architecture Lecture 16
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13. Framework #2: Flexible C2 Framework Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy; (C) 2008 John Wiley & Sons, Inc. Reprinted with permission.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19. GetBurnRate Filter //Import the java.io framework import java.io.*; public class GetBurnRate{ public static void main(String[] args){ //Send welcome message System.out.println(&quot;#Welcome to Lunar Lander&quot;); try{ //Begin reading from System input BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in)); //Set initial burn rate to 0 int burnRate = 0; do{ //Prompt user System.out.println(&quot;#Enter burn rate or <0 to quit:&quot;); . . . Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy; (C) 2008 John Wiley & Sons, Inc. Reprinted with permission.
  • 20. GetBurnRate Filter //Import the java.io framework import java.io.*; public class GetBurnRate{ public static void main(String[] args){ //Send welcome message System.out.println(&quot;#Welcome to Lunar Lander&quot;); try{ //Begin reading from System input BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in)); //Set initial burn rate to 0 int burnRate = 0; do{ //Prompt user System.out.println(&quot;#Enter burn rate or <0 to quit:&quot;); . . . . . . //Read user response try{ String burnRateString = inputReader.readLine(); burnRate = Integer.parseInt(burnRateString); //Send user-supplied burn rate to next filter System.out.println(&quot;%&quot; + burnRate); } catch(NumberFormatException nfe){ System.out.println(&quot;#Invalid burn rate.&quot;); } }while(burnRate >= 0); inputReader.close(); } catch(IOException ioe){ ioe.printStackTrace(); } } } Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy; (C) 2008 John Wiley & Sons, Inc. Reprinted with permission.
  • 21.
  • 22. CalcBurnRate Filter import java.io.*; public class CalcNewValues{ public static void main(String[] args){ //Initialize values final int GRAVITY = 2; int altitude = 1000; int fuel = 500; int velocity = 70; int time = 0; try{ BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in)); //Print initial values System.out.println(&quot;%a&quot; + altitude); System.out.println(&quot;%f&quot; + fuel); System.out.println(&quot;%v&quot; + velocity); System.out.println(&quot;%t&quot; + time); . . . Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy; (C) 2008 John Wiley & Sons, Inc. Reprinted with permission.
  • 23. CalcBurnRate Filter import java.io.*; public class CalcNewValues{ public static void main(String[] args){ //Initialize values final int GRAVITY = 2; int altitude = 1000; int fuel = 500; int velocity = 70; int time = 0; try{ BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in)); //Print initial values System.out.println(&quot;%a&quot; + altitude); System.out.println(&quot;%f&quot; + fuel); System.out.println(&quot;%v&quot; + velocity); System.out.println(&quot;%t&quot; + time); . . . String inputLine = null; do{ inputLine = inputReader.readLine(); if((inputLine != null) && (inputLine.length() > 0)){ if(inputLine.startsWith(&quot;#&quot;)){ //This is a status line of text, and //should be passed down the pipeline System.out.println(inputLine); } else if(inputLine.startsWith(&quot;%&quot;)){ //This is an input burn rate try{ int burnRate = Integer.parseInt(inputLine.substring(1)); if(altitude <= 0){ System.out.println(&quot;#The game is over.&quot;); } else if(burnRate > fuel){ System.out.println(&quot;#Sorry, you don't&quot; + &quot;have that much fuel.&quot;); } . . . Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy; (C) 2008 John Wiley & Sons, Inc. Reprinted with permission.
  • 24. CalcBurnRate Filter import java.io.*; public class CalcNewValues{ public static void main(String[] args){ //Initialize values final int GRAVITY = 2; int altitude = 1000; int fuel = 500; int velocity = 70; int time = 0; try{ BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in)); //Print initial values System.out.println(&quot;%a&quot; + altitude); System.out.println(&quot;%f&quot; + fuel); System.out.println(&quot;%v&quot; + velocity); System.out.println(&quot;%t&quot; + time); . . . String inputLine = null; do{ inputLine = inputReader.readLine(); if((inputLine != null) && (inputLine.length() > 0)){ if(inputLine.startsWith(&quot;#&quot;)){ //This is a status line of text, and //should be passed down the pipeline System.out.println(inputLine); } else if(inputLine.startsWith(&quot;%&quot;)){ //This is an input burn rate try{ int burnRate = Integer.parseInt(inputLine.substring(1)); if(altitude <= 0){ System.out.println(&quot;#The game is over.&quot;); } else if(burnRate > fuel){ System.out.println(&quot;#Sorry, you don't&quot; + &quot;have that much fuel.&quot;); } . . . else{ //Calculate new application state time = time + 1; altitude = altitude - velocity; velocity = ((velocity + GRAVITY) * 10 - burnRate * 2) / 10; fuel = fuel - burnRate; if(altitude <= 0){ altitude = 0; if(velocity <= 5){ System.out.println(&quot;#You have landed safely.&quot;); } else{ System.out.println(&quot;#You have crashed.&quot;); } } } //Print new values System.out.println(&quot;%a&quot; + altitude); System.out.println(&quot;%f&quot; + fuel); System.out.println(&quot;%v&quot; + velocity); System.out.println(&quot;%t&quot; + time); } catch(NumberFormatException nfe){ } . . . Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy; (C) 2008 John Wiley & Sons, Inc. Reprinted with permission.
  • 25. CalcBurnRate Filter import java.io.*; public class CalcNewValues{ public static void main(String[] args){ //Initialize values final int GRAVITY = 2; int altitude = 1000; int fuel = 500; int velocity = 70; int time = 0; try{ BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in)); //Print initial values System.out.println(&quot;%a&quot; + altitude); System.out.println(&quot;%f&quot; + fuel); System.out.println(&quot;%v&quot; + velocity); System.out.println(&quot;%t&quot; + time); . . . String inputLine = null; do{ inputLine = inputReader.readLine(); if((inputLine != null) && (inputLine.length() > 0)){ if(inputLine.startsWith(&quot;#&quot;)){ //This is a status line of text, and //should be passed down the pipeline System.out.println(inputLine); } else if(inputLine.startsWith(&quot;%&quot;)){ //This is an input burn rate try{ int burnRate = Integer.parseInt(inputLine.substring(1)); if(altitude <= 0){ System.out.println(&quot;#The game is over.&quot;); } else if(burnRate > fuel){ System.out.println(&quot;#Sorry, you don't&quot; + &quot;have that much fuel.&quot;); } . . . else{ //Calculate new application state time = time + 1; altitude = altitude - velocity; velocity = ((velocity + GRAVITY) * 10 - burnRate * 2) / 10; fuel = fuel - burnRate; if(altitude <= 0){ altitude = 0; if(velocity <= 5){ System.out.println(&quot;#You have landed safely.&quot;); } else{ System.out.println(&quot;#You have crashed.&quot;); } } } //Print new values System.out.println(&quot;%a&quot; + altitude); System.out.println(&quot;%f&quot; + fuel); System.out.println(&quot;%v&quot; + velocity); System.out.println(&quot;%t&quot; + time); } catch(NumberFormatException nfe){ } . . . } } }while((inputLine != null) && (altitude > 0)); inputReader.close(); } catch(IOException ioe){ ioe.printStackTrace(); } } } Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy; (C) 2008 John Wiley & Sons, Inc. Reprinted with permission.
  • 26.
  • 27. DisplayValues Filter import java.io.*; public class DisplayValues{ public static void main(String[] args){ try{ BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in)); String inputLine = null; do{ inputLine = inputReader.readLine(); if((inputLine != null) && (inputLine.length() > 0)){ if(inputLine.startsWith(&quot;#&quot;)){ //This is a status line of text, and //should be passed down the pipeline with //the pound-sign stripped off System.out.println(inputLine.substring(1)); } . . . Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy; (C) 2008 John Wiley & Sons, Inc. Reprinted with permission.
  • 28. DisplayValues Filter import java.io.*; public class DisplayValues{ public static void main(String[] args){ try{ BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in)); String inputLine = null; do{ inputLine = inputReader.readLine(); if((inputLine != null) && (inputLine.length() > 0)){ if(inputLine.startsWith(&quot;#&quot;)){ //This is a status line of text, and //should be passed down the pipeline with //the pound-sign stripped off System.out.println(inputLine.substring(1)); } . . . else if(inputLine.startsWith(&quot;%&quot;)){ //This is a value to display if(inputLine.length() > 1){ try{ char valueType = inputLine.charAt(1); int value = Integer.parseInt(inputLine.substring(2)); switch(valueType){ case 'a': System.out.println(&quot;Altitude: &quot; + value); break; case 'f': System.out.println(&quot;Fuel remaining: &quot; + value); break; case 'v': System.out.println(&quot;Current Velocity: “ + value); break; case 't': System.out.println(&quot;Time elapsed: &quot; + value); break; } } catch(NumberFormatException nfe){ } . . . Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy; (C) 2008 John Wiley & Sons, Inc. Reprinted with permission.
  • 29. DisplayValues Filter import java.io.*; public class DisplayValues{ public static void main(String[] args){ try{ BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in)); String inputLine = null; do{ inputLine = inputReader.readLine(); if((inputLine != null) && (inputLine.length() > 0)){ if(inputLine.startsWith(&quot;#&quot;)){ //This is a status line of text, and //should be passed down the pipeline with //the pound-sign stripped off System.out.println(inputLine.substring(1)); } . . . else if(inputLine.startsWith(&quot;%&quot;)){ //This is a value to display if(inputLine.length() > 1){ try{ char valueType = inputLine.charAt(1); int value = Integer.parseInt(inputLine.substring(2)); switch(valueType){ case 'a': System.out.println(&quot;Altitude: &quot; + value); break; case 'f': System.out.println(&quot;Fuel remaining: &quot; + value); break; case 'v': System.out.println(&quot;Current Velocity: “ + value); break; case 't': System.out.println(&quot;Time elapsed: &quot; + value); break; } } catch(NumberFormatException nfe){ } . . . } } } }while(inputLine != null); inputReader.close(); } catch(IOException ioe){ ioe.printStackTrace(); } } } Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy; (C) 2008 John Wiley & Sons, Inc. Reprinted with permission.
  • 30.
  • 31. Implementing Pipe and Filter Lunar Lander Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy; (C) 2008 John Wiley & Sons, Inc. Reprinted with permission.
  • 32. Implementing Pipe and Filter Lunar Lander
  • 33. Implementing Pipe and Filter Lunar Lander Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy; (C) 2008 John Wiley & Sons, Inc. Reprinted with permission.
  • 34. Implementing Pipe and Filter Lunar Lander
  • 35.
  • 36.
  • 37.
  • 38. Clock Component import c2.framework.*; public class Clock extends ComponentThread{ public Clock(){ super.create(&quot;clock&quot;, FIFOPort.class); } public void start(){ super.start(); Thread clockThread = new Thread(){ public void run(){ //Repeat while the application runs while(true){ //Wait for five seconds try{ Thread.sleep(5000); } catch(InterruptedException ie){} //Send out a tick notification Notification n = new Notification(&quot;clockTick&quot;); send(n); } } }; Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy; (C) 2008 John Wiley & Sons, Inc. Reprinted with permission.
  • 39. Clock Component import c2.framework.*; public class Clock extends ComponentThread{ public Clock(){ super.create(&quot;clock&quot;, FIFOPort.class); } public void start(){ super.start(); Thread clockThread = new Thread(){ public void run(){ //Repeat while the application runs while(true){ //Wait for five seconds try{ Thread.sleep(5000); } catch(InterruptedException ie){} //Send out a tick notification Notification n = new Notification(&quot;clockTick&quot;); send(n); } } }; clockThread.start(); } protected void handle(Notification n){ //This component does not handle notifications } protected void handle(Request r){ //This component does not handle requests } } Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy; (C) 2008 John Wiley & Sons, Inc. Reprinted with permission.
  • 40.
  • 41. GameState Component import c2.framework.*; public class GameState extends ComponentThread{ public GameState(){ super.create(&quot;gameState&quot;, FIFOPort.class); } //Internal game state and initial values int altitude = 1000; int fuel = 500; int velocity = 70; int time = 0; int burnRate = 0; boolean landedSafely = false; Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy; (C) 2008 John Wiley & Sons, Inc. Reprinted with permission.
  • 42. GameState Component import c2.framework.*; public class GameState extends ComponentThread{ public GameState(){ super.create(&quot;gameState&quot;, FIFOPort.class); } //Internal game state and initial values int altitude = 1000; int fuel = 500; int velocity = 70; int time = 0; int burnRate = 0; boolean landedSafely = false; protected void handle(Request r){ if(r.name().equals(&quot;updateGameState&quot;)){ //Update the internal game state if(r.hasParameter(&quot;altitude&quot;)){ this.altitude = ((Integer)r.getParameter(&quot;altitude&quot;)).intValue(); } if(r.hasParameter(&quot;fuel&quot;)){ this.fuel = ((Integer)r.getParameter(&quot;fuel&quot;)).intValue(); } if(r.hasParameter(&quot;velocity&quot;)){ this.velocity = ((Integer)r.getParameter(&quot;velocity&quot;)).intValue(); } if(r.hasParameter(&quot;time&quot;)){ this.time = ((Integer)r.getParameter(&quot;time&quot;)).intValue(); } if(r.hasParameter(&quot;burnRate&quot;)){ this.burnRate = ((Integer)r.getParameter(&quot;burnRate&quot;)).intValue(); } if(r.hasParameter(&quot;landedSafely&quot;)){ this.landedSafely = ((Boolean)r.getParameter(&quot;landedSafely&quot;)) .booleanValue(); } //Send out the updated game state Notification n = createStateNotification(); send(n); } Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy; (C) 2008 John Wiley & Sons, Inc. Reprinted with permission.
  • 43. GameState Component import c2.framework.*; public class GameState extends ComponentThread{ public GameState(){ super.create(&quot;gameState&quot;, FIFOPort.class); } //Internal game state and initial values int altitude = 1000; int fuel = 500; int velocity = 70; int time = 0; int burnRate = 0; boolean landedSafely = false; protected void handle(Request r){ if(r.name().equals(&quot;updateGameState&quot;)){ //Update the internal game state if(r.hasParameter(&quot;altitude&quot;)){ this.altitude = ((Integer)r.getParameter(&quot;altitude&quot;)).intValue(); } if(r.hasParameter(&quot;fuel&quot;)){ this.fuel = ((Integer)r.getParameter(&quot;fuel&quot;)).intValue(); } if(r.hasParameter(&quot;velocity&quot;)){ this.velocity = ((Integer)r.getParameter(&quot;velocity&quot;)).intValue(); } if(r.hasParameter(&quot;time&quot;)){ this.time = ((Integer)r.getParameter(&quot;time&quot;)).intValue(); } if(r.hasParameter(&quot;burnRate&quot;)){ this.burnRate = ((Integer)r.getParameter(&quot;burnRate&quot;)).intValue(); } if(r.hasParameter(&quot;landedSafely&quot;)){ this.landedSafely = ((Boolean)r.getParameter(&quot;landedSafely&quot;)) .booleanValue(); } //Send out the updated game state Notification n = createStateNotification(); send(n); } else if(r.name().equals(&quot;getGameState&quot;)){ //If a component requests the game state //without updating it, send out the state Notification n = createStateNotification(); send(n); } } protected Notification createStateNotification(){ //Create a new notification comprising the //current game state Notification n = new Notification(&quot;gameState&quot;); n.addParameter(&quot;altitude&quot;, altitude); n.addParameter(&quot;fuel&quot;, fuel); n.addParameter(&quot;velocity&quot;, velocity); n.addParameter(&quot;time&quot;, time); n.addParameter(&quot;burnRate&quot;, burnRate); n.addParameter(&quot;landedSafely&quot;, landedSafely); return n; } protected void handle(Notification n){ //This component does not handle notifications } } Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy; (C) 2008 John Wiley & Sons, Inc. Reprinted with permission.
  • 44.
  • 45. GameLogic Component import c2.framework.*; public class GameLogic extends ComponentThread{ public GameLogic(){ super.create(&quot;gameLogic&quot;, FIFOPort.class); } //Game constants final int GRAVITY = 2; //Internal state values for computation int altitude = 0; int fuel = 0; int velocity = 0; int time = 0; int burnRate = 0; public void start(){ super.start(); Request r = new Request(&quot;getGameState&quot;); send(r); } Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy; (C) 2008 John Wiley & Sons, Inc. Reprinted with permission.
  • 46. GameLogic Component import c2.framework.*; public class GameLogic extends ComponentThread{ public GameLogic(){ super.create(&quot;gameLogic&quot;, FIFOPort.class); } //Game constants final int GRAVITY = 2; //Internal state values for computation int altitude = 0; int fuel = 0; int velocity = 0; int time = 0; int burnRate = 0; public void start(){ super.start(); Request r = new Request(&quot;getGameState&quot;); send(r); } protected void handle(Notification n){ if(n.name().equals(&quot;gameState&quot;)){ if(n.hasParameter(&quot;altitude&quot;)){ this.altitude = ((Integer)n.getParameter(&quot;altitude&quot;)).intValue(); } if(n.hasParameter(&quot;fuel&quot;)){ this.fuel = ((Integer)n.getParameter(&quot;fuel&quot;)).intValue(); } if(n.hasParameter(&quot;velocity&quot;)){ this.velocity = ((Integer)n.getParameter(&quot;velocity&quot;)).intValue(); } if(n.hasParameter(&quot;time&quot;)){ this.time = ((Integer)n.getParameter(&quot;time&quot;)).intValue(); } if(n.hasParameter(&quot;burnRate&quot;)){ this.burnRate = ((Integer)n.getParameter(&quot;burnRate&quot;)).intValue(); } } Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy; (C) 2008 John Wiley & Sons, Inc. Reprinted with permission.
  • 47. GameLogic Component import c2.framework.*; public class GameLogic extends ComponentThread{ public GameLogic(){ super.create(&quot;gameLogic&quot;, FIFOPort.class); } //Game constants final int GRAVITY = 2; //Internal state values for computation int altitude = 0; int fuel = 0; int velocity = 0; int time = 0; int burnRate = 0; public void start(){ super.start(); Request r = new Request(&quot;getGameState&quot;); send(r); } protected void handle(Notification n){ if(n.name().equals(&quot;gameState&quot;)){ if(n.hasParameter(&quot;altitude&quot;)){ this.altitude = ((Integer)n.getParameter(&quot;altitude&quot;)).intValue(); } if(n.hasParameter(&quot;fuel&quot;)){ this.fuel = ((Integer)n.getParameter(&quot;fuel&quot;)).intValue(); } if(n.hasParameter(&quot;velocity&quot;)){ this.velocity = ((Integer)n.getParameter(&quot;velocity&quot;)).intValue(); } if(n.hasParameter(&quot;time&quot;)){ this.time = ((Integer)n.getParameter(&quot;time&quot;)).intValue(); } if(n.hasParameter(&quot;burnRate&quot;)){ this.burnRate = ((Integer)n.getParameter(&quot;burnRate&quot;)).intValue(); } } else if(n.name().equals(&quot;clockTick&quot;)){ //Calculate new lander state values int actualBurnRate = burnRate; if(actualBurnRate > fuel){ //Ensure we don’t burn more fuel than we have actualBurnRate = fuel; } time = time + 1; altitude = altitude - velocity; velocity = ((velocity + GRAVITY) * 10 – actualBurnRate * 2) / 10; fuel = fuel - actualBurnRate; //Determine if we landed (safely) boolean landedSafely = false; if(altitude <= 0){ altitude = 0; if(velocity <= 5){ landedSafely = true; } } Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy; (C) 2008 John Wiley & Sons, Inc. Reprinted with permission.
  • 48. GameLogic Component import c2.framework.*; public class GameLogic extends ComponentThread{ public GameLogic(){ super.create(&quot;gameLogic&quot;, FIFOPort.class); } //Game constants final int GRAVITY = 2; //Internal state values for computation int altitude = 0; int fuel = 0; int velocity = 0; int time = 0; int burnRate = 0; public void start(){ super.start(); Request r = new Request(&quot;getGameState&quot;); send(r); } protected void handle(Notification n){ if(n.name().equals(&quot;gameState&quot;)){ if(n.hasParameter(&quot;altitude&quot;)){ this.altitude = ((Integer)n.getParameter(&quot;altitude&quot;)).intValue(); } if(n.hasParameter(&quot;fuel&quot;)){ this.fuel = ((Integer)n.getParameter(&quot;fuel&quot;)).intValue(); } if(n.hasParameter(&quot;velocity&quot;)){ this.velocity = ((Integer)n.getParameter(&quot;velocity&quot;)).intValue(); } if(n.hasParameter(&quot;time&quot;)){ this.time = ((Integer)n.getParameter(&quot;time&quot;)).intValue(); } if(n.hasParameter(&quot;burnRate&quot;)){ this.burnRate = ((Integer)n.getParameter(&quot;burnRate&quot;)).intValue(); } } else if(n.name().equals(&quot;clockTick&quot;)){ //Calculate new lander state values int actualBurnRate = burnRate; if(actualBurnRate > fuel){ //Ensure we don’t burn more fuel than we have actualBurnRate = fuel; } time = time + 1; altitude = altitude - velocity; velocity = ((velocity + GRAVITY) * 10 – actualBurnRate * 2) / 10; fuel = fuel - actualBurnRate; //Determine if we landed (safely) boolean landedSafely = false; if(altitude <= 0){ altitude = 0; if(velocity <= 5){ landedSafely = true; } } Request r = new Request(&quot;updateGameState&quot;); r.addParameter(&quot;time&quot;, time); r.addParameter(&quot;altitude&quot;, altitude); r.addParameter(&quot;velocity&quot;, velocity); r.addParameter(&quot;fuel&quot;, fuel); r.addParameter(&quot;landedSafely&quot;, landedSafely); send(r); } } protected void handle(Request r){ //This component does not handle requests } } Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy; (C) 2008 John Wiley & Sons, Inc. Reprinted with permission.
  • 49.
  • 50. GUI Component import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import c2.framework.*; public class GUI extends ComponentThread{ public GUI(){ super.create(&quot;gui&quot;, FIFOPort.class); } public void start(){ super.start(); Thread t = new Thread(){ public void run(){ processInput(); } }; t.start(); } Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy; (C) 2008 John Wiley & Sons, Inc. Reprinted with permission.
  • 51. GUI Component import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import c2.framework.*; public class GUI extends ComponentThread{ public GUI(){ super.create(&quot;gui&quot;, FIFOPort.class); } public void start(){ super.start(); Thread t = new Thread(){ public void run(){ processInput(); } }; t.start(); } public void processInput(){ System.out.println(&quot;Welcome to Lunar Lander&quot;); try{ BufferedReader inputReader = new BufferedReader( new InputStreamReader(System.in)); int burnRate = 0; do{ System.out.println(&quot;Enter burn rate or <0 to quit:&quot;); try{ String burnRateString = inputReader.readLine(); burnRate = Integer.parseInt(burnRateString); Request r = new Request(&quot;updateGameState&quot;); r.addParameter(&quot;burnRate&quot;, burnRate); send(r); } catch(NumberFormatException nfe){ System.out.println(&quot;Invalid burn rate.&quot;); } }while(burnRate >= 0); inputReader.close(); } catch(IOException ioe){ ioe.printStackTrace(); } } Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy; (C) 2008 John Wiley & Sons, Inc. Reprinted with permission.
  • 52. GUI Component import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import c2.framework.*; public class GUI extends ComponentThread{ public GUI(){ super.create(&quot;gui&quot;, FIFOPort.class); } public void start(){ super.start(); Thread t = new Thread(){ public void run(){ processInput(); } }; t.start(); } public void processInput(){ System.out.println(&quot;Welcome to Lunar Lander&quot;); try{ BufferedReader inputReader = new BufferedReader( new InputStreamReader(System.in)); int burnRate = 0; do{ System.out.println(&quot;Enter burn rate or <0 to quit:&quot;); try{ String burnRateString = inputReader.readLine(); burnRate = Integer.parseInt(burnRateString); Request r = new Request(&quot;updateGameState&quot;); r.addParameter(&quot;burnRate&quot;, burnRate); send(r); } catch(NumberFormatException nfe){ System.out.println(&quot;Invalid burn rate.&quot;); } }while(burnRate >= 0); inputReader.close(); } catch(IOException ioe){ ioe.printStackTrace(); } } protected void handle(Notification n){ if(n.name().equals(&quot;gameState&quot;)){ System.out.println(); System.out.println(&quot;New game state:&quot;); if(n.hasParameter(&quot;altitude&quot;)){ System.out.println(&quot; Altitude: &quot; + n.getParameter(&quot;altitude&quot;)); } if(n.hasParameter(&quot;fuel&quot;)){ System.out.println(&quot; Fuel: &quot; + n.getParameter(&quot;fuel&quot;)); } if(n.hasParameter(&quot;velocity&quot;)){ System.out.println(&quot; Velocity: &quot; + n.getParameter(&quot;velocity&quot;)); } if(n.hasParameter(&quot;time&quot;)){ System.out.println(&quot; Time: &quot; + n.getParameter(&quot;time&quot;)); } if(n.hasParameter(&quot;burnRate&quot;)){ System.out.println(&quot; Burn rate: &quot; + n.getParameter(&quot;burnRate&quot;)); } Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy; (C) 2008 John Wiley & Sons, Inc. Reprinted with permission.
  • 53. GUI Component import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import c2.framework.*; public class GUI extends ComponentThread{ public GUI(){ super.create(&quot;gui&quot;, FIFOPort.class); } public void start(){ super.start(); Thread t = new Thread(){ public void run(){ processInput(); } }; t.start(); } public void processInput(){ System.out.println(&quot;Welcome to Lunar Lander&quot;); try{ BufferedReader inputReader = new BufferedReader( new InputStreamReader(System.in)); int burnRate = 0; do{ System.out.println(&quot;Enter burn rate or <0 to quit:&quot;); try{ String burnRateString = inputReader.readLine(); burnRate = Integer.parseInt(burnRateString); Request r = new Request(&quot;updateGameState&quot;); r.addParameter(&quot;burnRate&quot;, burnRate); send(r); } catch(NumberFormatException nfe){ System.out.println(&quot;Invalid burn rate.&quot;); } }while(burnRate >= 0); inputReader.close(); } catch(IOException ioe){ ioe.printStackTrace(); } } protected void handle(Notification n){ if(n.name().equals(&quot;gameState&quot;)){ System.out.println(); System.out.println(&quot;New game state:&quot;); if(n.hasParameter(&quot;altitude&quot;)){ System.out.println(&quot; Altitude: &quot; + n.getParameter(&quot;altitude&quot;)); } if(n.hasParameter(&quot;fuel&quot;)){ System.out.println(&quot; Fuel: &quot; + n.getParameter(&quot;fuel&quot;)); } if(n.hasParameter(&quot;velocity&quot;)){ System.out.println(&quot; Velocity: &quot; + n.getParameter(&quot;velocity&quot;)); } if(n.hasParameter(&quot;time&quot;)){ System.out.println(&quot; Time: &quot; + n.getParameter(&quot;time&quot;)); } if(n.hasParameter(&quot;burnRate&quot;)){ System.out.println(&quot; Burn rate: &quot; + n.getParameter(&quot;burnRate&quot;)); } if(n.hasParameter(&quot;altitude&quot;)){ int altitude = ((Integer)n.getParameter(&quot;altitude&quot;)).intValue(); if(altitude <= 0){ boolean landedSafely = ((Boolean)n.getParameter(&quot;landedSafely&quot;)) .booleanValue(); if(landedSafely){ System.out.println(&quot;You have landed safely.&quot;); } else{ System.out.println(&quot;You have crashed.&quot;); } System.exit(0); } } } } protected void handle(Request r){ //This component does not handle requests } } Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy; (C) 2008 John Wiley & Sons, Inc. Reprinted with permission.
  • 54.
  • 55. Main Program import c2.framework.*; public class LunarLander{ public static void main(String[] args){ //Create the Lunar Lander architecture Architecture lunarLander = new SimpleArchitecture(&quot;LunarLander&quot;); //Create the components Component clock = new Clock(); Component gameState = new GameState(); Component gameLogic = new GameLogic(); Component gui = new GUI(); //Create the connectors Connector bus = new ConnectorThread(&quot;bus&quot;); //Add the components and connectors to the architecture lunarLander.addComponent(clock); lunarLander.addComponent(gameState); lunarLander.addComponent(gameLogic); lunarLander.addComponent(gui); lunarLander.addConnector(bus); Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy; (C) 2008 John Wiley & Sons, Inc. Reprinted with permission.
  • 56. Main Program import c2.framework.*; public class LunarLander{ public static void main(String[] args){ //Create the Lunar Lander architecture Architecture lunarLander = new SimpleArchitecture(&quot;LunarLander&quot;); //Create the components Component clock = new Clock(); Component gameState = new GameState(); Component gameLogic = new GameLogic(); Component gui = new GUI(); //Create the connectors Connector bus = new ConnectorThread(&quot;bus&quot;); //Add the components and connectors to the architecture lunarLander.addComponent(clock); lunarLander.addComponent(gameState); lunarLander.addComponent(gameLogic); lunarLander.addComponent(gui); lunarLander.addConnector(bus); //Create the welds (links) between components and //connectors lunarLander.weld(clock, bus); lunarLander.weld(gameState, bus); lunarLander.weld(bus, gameLogic); lunarLander.weld(bus, gui); //Start the application lunarLander.start(); } } Software Architecture: Foundations, Theory, and Practice ; Richard N. Taylor, Nenad Medvidovic, and Eric M. Dashofy; (C) 2008 John Wiley & Sons, Inc. Reprinted with permission.
  • 57.