Dynamic Architectures (Component Reconfiguration) with Fractal.

Slides:



Advertisements
Similar presentations
Chapter 6 Server-side Programming: Java Servlets
Advertisements

Practical Session 6 Multitasking vs. multithreading Threads Concurrency vs. Parallelism Java Threads Thread confinement Object/Class Immutability.
Concurrency (p2) synchronized (this) { doLecture(part2); } synchronized (this) { doLecture(part2); }
Multiplexing/Demux. CPSC Transport Layer 3-2 Multiplexing/demultiplexing application transport network link physical P1 application transport network.
CS 5704 Fall 00 1 Monitors in Java Model and Examples.
Using TCP sockets in Java Created by M Bateman, A Ruddle & C Allison As part of the TCP View project.
Java Threads A tool for concurrency. OS schedules processes Ready Running 200 Blocked A process loses the CPU and another.
CS220 Software Development Lecture: Multi-threading A. O’Riordan, 2009.
System Programming Practical session 11 Multiple clients server Non-Blocking I/O.
Ceng Operating Systems Chapter 2.1 : Processes Process concept Process scheduling Interprocess communication Deadlocks Threads.
OOP&M - theory lectures1 OOP&M – and there it was an eighth day “I f you know what I know, what am I doing here? ” - Aristoteles -
29-Jun-15 Java Concurrency. Definitions Parallel processes—two or more Threads are running simultaneously, on different cores (processors), in the same.
Multithreading in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Threads II. Review A thread is a single flow of control through a program Java is multithreaded—several threads may be executing “simultaneously” If you.
More Multithreaded Programming in Java David Meredith Aalborg University.
Web Proxy Server. Proxy Server Introduction Returns status and error messages. Handles http CGI requests. –For more information about CGI please refer.
Parallel Processing (CS526) Spring 2012(Week 8).  Thread Status.  Synchronization in Shared Memory Programming(Java threads ) ◦ Locks ◦ Barriars.
A Bridge to Your First Computer Science Course Prof. H.E. Dunsmore Concurrent Programming Threads Synchronization.
Web Security Programming I Building Security in from the Start Except where otherwise noted all portions of this work are Copyright (c) 2007 Google and.
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
Ryerson University CPS Distributing Computing with Java.
Object Oriented Programming Lecture 8: Introduction to laboratorial exercise – part II, Introduction to GUI frames in Netbeans, Introduction to threads.
Critical Reference An occurrence of a variable v is defined to be critical reference: a. if it is assigned to in one process and has an occurrence in another.
CHEN Ge CSIS, HKU March 9, Jigsaw W3C’s Java Web Server.
Win32 Programming Lesson 10: Thread Scheduling and Priorities.
REVIEW On Friday we explored Client-Server Applications with Sockets. Servers must create a ServerSocket object on a specific Port #. They then can wait.
Java Threads 11 Threading and Concurrent Programming in Java Introduction and Definitions D.W. Denbo Introduction and Definitions D.W. Denbo.
1 Tutorial: CSI 3310 Dewan Tanvir Ahmed SITE, UofO.
© 2004, D. J. Foreman 2-1 Concurrency, Processes and Threads.
111 © 2002, Cisco Systems, Inc. All rights reserved.
1 Chapter 2.1 : Processes Process concept Process concept Process scheduling Process scheduling Interprocess communication Interprocess communication Threads.
1 Web Based Programming Section 8 James King 12 August 2003.
Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 RMI.
Semaphores, Locks and Monitors By Samah Ibrahim And Dena Missak.
1 (Worker Queues) cs What is a Thread Pool? A collection of threads that are created once (e.g. when a server starts) That is, no need to create.
Li Tak Sing COMPS311F. Case study: consumers and producers A fixed size buffer which can hold at most certain integers. A number of producers which generate.
CSC321 Concurrent Programming: §5 Monitors 1 Section 5 Monitors.
Event Driven Programming Minus the GUI Plus a Robot By Charlie Vick.
Multithreading in Java Sameer Singh Chauhan Lecturer, I. T. Dept., SVIT, Vasad.
Concurrency in Java Brad Vander Zanden. Processes and Threads Process: A self-contained execution environment Thread: Exists within a process and shares.
Jigsaw Performance Analysis Potential Bottlenecks.
In Java processes are called threads. Additional threads are associated with objects. An application is associated with an initial thread via a static.
Multithreading in JAVA
Threads II IS Outline  Quiz  Thread review  Stopping a thread  java.util.Timer  Swing threads javax.swing.Timer  ProgressMonitor.
Threads Eivind J. Nordby University of Karlstad Inst. for Information Technology Dept. of Computer Science.
Threads in Java1 Concurrency Synchronizing threads, thread pools, etc.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
©SoftMoore ConsultingSlide 1 Filters. Filters can be used in a web application to intercept, examine, and possibly transform requests or responses associated.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Operating Systems Processes and Threads.
Chapter11 Concurrent. 集美大学 计算机工程学院 Java 程序设计 年 第二版 Concurrent ●Computer users take it for granted that their systems can do more than one thing.
Threads in Java Threads Introduction: After completing this chapter, you will be able to code your own thread, control them efficiently without.
Java Server Sockets ServerSocket : Object to listen for client connection requests Throws IOException accept() method to take the client connection. Returns.
Threads b A thread is a flow of control in a program. b The Java Virtual Machine allows an application to have multiple threads of execution running concurrently.
Chapter 13: Multithreading The Thread class The Thread class The Runnable Interface The Runnable Interface Thread States Thread States Thread Priority.
Concurrency (Threads) Threads allow you to do tasks in parallel. In an unthreaded program, you code is executed procedurally from start to finish. In a.
Concurrency in Java MD. ANISUR RAHMAN. slide 2 Concurrency  Multiprogramming  Single processor runs several programs at the same time  Each program.
Concurrent Programming in Java Based on Notes by J. Johns (based on Java in a Nutshell, Learning Java) Also Java Tutorial, Concurrent Programming in Java.
Today Threading, Cont. Multi-core processing. Java Never Ends! Winter 2016CMPE212 - Prof. McLeod1.
Threads in Java Two ways to start a thread
Thread Pools (Worker Queues) cs
Thread Pools (Worker Queues) cs
Java Servlets By: Tejashri Udavant..
Advanced Topics in Concurrency and Reactive Programming: Asynchronous Programming Majeed Kassis.
Concurrency, Processes and Threads
Multithreaded Programming in Java
I/O Basics.
Multithreading.
Multithreaded Programming
Concurrency, Processes and Threads
Threads and concurrency / Safety
Presentation transcript:

Dynamic Architectures (Component Reconfiguration) with Fractal

Example: Comanche A minimal HTTP Server Fractal tutorial case study: Functionality of Server explained in pseudocode: Server { Socket server_socket; Socket worker; while true do server_socket = create server socket. worker_socket = accept(server_socket, port) // accept is // a blocking call, it returns only when it has accepted a connection create new worker thread, passing it worker_socket end while }

Example: Comanche (cont) WorkerThread { read request on socket print first line of request // analyse request if (request starts with "GET /") then get actual filename // up to the second " " of the first line of a well-formed request if ((file exists) and (file is not a directory)) then write "HTTP/ OK\n\n" to socket write contents of file to socket else write "HTTP/ Not Found\n\n" to socket write " Document not found. " to socket end if close socket }

Dynamic Component Architectures with Fractal Design –Finding the components –Defining component architecture –Defining component contracts Implementation –Implementing interfaces and components Configuration –Programmatic (direct API based) –ADL-based Reconfiguration –Life cycle management –Introspection

Finding the services -> components Main services: –a request receiver service –a request processor service Other services: –the request receiver service uses a thread factory, to create a new thread for each request. This thread factory service can be generalized into a scheduler service that can be implemented in several way (sequential, multi thread, multi thread with a thread pool, etc) –the request processor uses a request analyzer service, and a logger service, before effectively responding to a request. This response is itself constructed by using a file server service, or an error manager service. This can be generalized into a request dispatcher service that dispatches requests to several request handlers sequentially, until one handler can handle the request (we can then imagine file handlers, servlet handlers, etc)

Comanche component architecture

Interfaces public interface RequestHandler { void handleRequest (Request r) throws IOException; } public interface Scheduler { void schedule (Runnable task); } public interface Logger { void log (String msg); } public class Request { public Socket s; public Reader in; public PrintStream out; public String url; public Request (Socket s) { this.s = s; } }

Implementing Components In component oriented programming, and in Fractal in particular, the components that have dependencies to other components must be programmed in a specific way ! The above example is good OOP, but: –It solves the modularity problem only at deployment time: it is still impossible to change the scheduler or the request analyzer used by the request receiver at runtime –in Fractal, a component with dependencies (or bindings) to other components must implement the BindingController interface public class RequestReceiver implements Runnable { private Scheduler s; private RequestHandler rh; public RequestReceiver (Scheduler s, RequestHandler rh) { this.s = s; this.rh = rh; } public void run () { // rest of the code not shown

Example – Implementing RequestReceiver public class RequestReceiver implements Runnable, BindingController { private Scheduler s; private RequestHandler rh; // configuration concern public String[] listFc () { return new String[] { "s", "rh" }; } public Object lookupFc (String itfName) { if (itfName.equals("s")) { return s; } else if (itfName.equals("rh")) { return rh; } else return null; } public void bindFc (String itfName, Object itfValue) { if (itfName.equals("s")) { s = (Scheduler)itfValue; } else if (itfName.equals("rh")) { rh = (RequestHandler)itfValue; } } public void unbindFc (String itfName) { if (itfName.equals("s")) { s = null; } else if (itfName.equals("rh")) { rh = null; } } // functional concern public void run () { /* see Appendix A */ } }A

Programmatic configuration public class Server { public static void main (String[] args) { RequestReceiver rr = new RequestReceiver(); RequestAnalyzer ra = new RequestAnalyzer(); RequestDispatcher rd = new RequestDispatcher(); FileRequestHandler frh = new FileRequestHandler(); ErrorRequestHandler erh = new ErrorRequestHandler(); Scheduler s = new MultiThreadScheduler(); Logger l = new BasicLogger(); rr.bindFc("rh", ra); rr.bindFc("s", s); ra.bindFc("rh", rd); ra.bindFc("l", l); rd.bindFc("h0", frh); rd.bindFc("h1", erh); rr.run(); } }

ADL-based configuration

Reconfiguration In order to reconfigure an application, the easiest solution is to stop it, to modify its architecture description, and then to restart it. This solution is not always possible, in particular if the service provided by the application must not be interrupted. In these cases, the application must be reconfigured at runtime while it is in execution. – danger: if the reconfiguration process is not carefully synchronized with the normal application activities, the application's state may become inconsistent, or the application may simply crash. –A basic practice to realize this synchronization is to temporarily suspend the normal application activities in the part of the application that needs to be reconfigured. This is what is called life cycle management in Fractal.

Reconfiguration example Example: we want to replace, in a Comanche server, the file request handler component with a new implementation that can manage both files and directories. We will consider here that the HTTP server must be always available, so that the previous change must be done dynamically, while the server is running.

Reconfiguration example If rd is a reference to the request dispatcher component, this reconfiguration can be done with the following instructions: RequestHandler rh = new FileAndDirectoryRequestHandler(); rd.unbindFc("h0"); rd.bindFc("h0", rh); this reconfiguration method may produce undefined results, or even errors. – The RequestDispatcher component uses a TreeMap to manage its bindings but this class does not support concurrent accesses. Modifying this map in a reconfiguration thread, while it is also accessed, via an iterator, in the applicative threads that execute the handleRequest method, may therefore cause errors or inconsistencies. In order to solve this problem, a generic solution is to: 1.temporarily suspend the application activities in the request dispatcher component, 2.execute the above reconfiguration instructions, and 3.resume the application activities.

Lifecycle control In order to do that the request dispatcher component must implement the LifeCycleController interface, defined in the Fractal specification. This interface defines two methods startFc and stopFc, to suspend and resume the application activities in a component, and an additional getFcState method. A possible way to implement this interface is to use a counter of the number of threads that are currently executing a functional method, and to wait for this counter to become null to stop the component:

LifeCycleController – version 1 public class RequestDispatcher implements RequestHandler, BindingController, LifeCycleController { private boolean started; private int counter; public String getFcState () { return started ? STARTED : STOPPED; } public synchronized void startFc () { started = true; notifyAll(); } public synchronized void stopFc () { while (counter > 0) { try { wait(); } catch (InterruptedException _) {} } started = false; } public void handleRequest (Request r) throws IOException { synchronized (this) { while (counter == 0 && !started) { try { wait(); } catch (InterruptedException _) {} } ++counter; } try { // original code } finally { synchronized (this) { -counter; if (counter == 0) { notifyAll(); } } } } // rest of the class unchanged }

LifeCycleController – Version 2 public class Interceptor implements RequestHandler, LifeCycleController { public RequestHandler delegate; private boolean started; private int counter; public String getFcState () { /* as above */ } public synchronized void startFc () { /* as above */ } public synchronized void stopFc () { /* as above */ } public void handleRequest (Request r) throws IOException { synchronized (this) { /* as above */ } try { delegate.handleRequest(r); } finally { synchronized (this) { /* as above */ } } } } Life cycle management concerns are separated from the functional concerns in a Interceptor component that wraps it up

Encapsulating components (“interceptors”) can be automatically generated around primitive components

Introspection