The Second Mandatory Programming Assignment: Refactoring the

advertisement

The Second Mandatory Programming Assignment:

Refactoring the Fractal Comanche Server

INF5040 Autumn 2012

Objective

Development and evolution of component-based software systems;

Using the Fractal Component Model;

Apply the concepts of configuration, introspection and reconfiguration.

Scope

Fractal is a minimal, extensible and modular component model. As discussed in the lecture on distributed components , it provides a light-weight component model, with no prescriptive solutions for deployment, life-cycle management, etc. For this programming assignment you have to study this component model (benefits and limitations), in particular the Java reference implementation (Julia).

You are then asked to perform a series of refactoring tasks for the Comanche application, and implement examples of introspection and reconfiguration code. Comanche is an extremely minimal

HTTP server. A reference implementation can be obtained from Fractal website and is extensively discussed in one of the Fractal tutorials . You should read the tutorial carefully to understand the application design and the refactoring tasks that you need to perform.

Technical features

1.

Refactoring tasks a.

Instead of loading the initial ADL configuration in the pom.xml

file, create a new class named ComancheServer and load it from there. The helloworld-julia-adl project has an example of how to do it. b.

Prepare the application for introspection : Replace the inappropriate short names given in the ADL definition for more relevant names. For example: i.

Replace the component name fe with Frontend and the interface name rh with request-handler c.

Prepare the application for reconfiguration : Separate the life-cycle and binding management aspects from the functional aspects of the component. You can do it by following the suggestions presented in the chapter 5 of the tutorial. The implementation of the methods of the BindingController and LifeCycleController interfaces should not mixed and present in the Java classes containing the functional aspects of the application! d.

Create a new alternative component implementation for the Logger interface named

TimedLogger that presents the log message with the current time. For example:

i.

00:03:40 - GET /README.txt HTTP/1.1

e.

Create a new alternative component implementation for the Scheduler interface named ThreadPoolScheduler that creates a thread pool with a fixed number of slots.

The scheduler inserts the tasks in a queue. The idle threads from the pool will dequeue the tasks and process them. f.

Create a new alternative component implementation for the RequestHandler interface named DirectoryRequestHandler that can handle directories. The handler should return a list of the files contained in the directory (names of the files listed in HTML format to be interpreted by the browser).

2.

Introspection a.

Use the controllers available in the Fractal API and create a method to list all the components and interfaces of the current running configuration. Starting from the root component, print its name and interfaces and navigate through the subcomponents printing theirs contents as well (in a hierarchical fashion). The method should be called after the server is started and running. The output should look like:

Component: comanche.Comanche, with interfaces: runnable.

Component: Frontend, with interfaces: runnable request-handler.

Component: RequestReceiver, with interfaces: runnable scheduler request-handler. No internal components.

Component: Scheduler, with interfaces: scheduler. No internal components.

Component: Backend, with interfaces: request-handler.

Component: RequestAnalyzer, with interfaces: request-handler logger analyzer. No internal components.

Component: RequestHandler, with interfaces: request-handler.

Component: RequestDispatcher, with interfaces: request-handler handlers-1 handlers-0.

No internal components.

Component: FileRequestHandler, with interfaces: request-handler. No internal components.

Component: ErrorRequestHandler, with interfaces: request-handler. No internal components.

Component: Logger, with interfaces: logger. No internal components.

3.

Reconfiguration a.

After printing the current configuration, make the main thread sleep for some time.

Then, replace the current Logger and Scheduler by the TimedLogger and

ThreadPoolScheduler implementations. You should do it by using the methods provided by the LifeCycleControler and BindingControler classes.

b.

Add the DirectoryRequestHandler into the RequestDispatcher

’s handlers map. The dispatcher should send the request first to the file handler, then to the directory handler and, in last case, to the error handler.

c.

Run the application and verify if the reconfiguration is taking place: While the thread is sleeping, a request pointing to a directory will produce and error. After the threads awakes and the reconfiguration takes place, the request should return the list of files contained in the directory. The new scheduler and logger should also be running.

Development Tools:

1.

Integrated Development Environment : Eclipse IDE for Java EE Developers:

http://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/junor

2.

Fractal Component Model : http://fractal.ow2.org/index.html

a.

Comanche code and other examples: http://fractal.ow2.org/download/index.html

3.

Apache Maven: a.

http://maven.apache.org/ b.

Or the Eclipse plug-in: http://eclipse.org/m2e/

We will accept minor deviations in the programming environment from the description above if agreed with the TA. Such deviations should be coordinated with the TA as soon as possible. Note that you also have to provide detailed instructions in your documentation on how to install and execute your software.

Deliverables:

Via the Devilry system.

Documentation containing your impressions about the Fractal Component model: o What are the benefits of using such model? o What are the main limitations? o Describe the main differences between programming with components and programming with objects. Are those differences clear in the Fractal model? o Include some screenshots of the outputs produced by your application.

The complete source code of the modified Comanche application, including ADLs and maven scripts (in a zip file).

Deadline: 23:00 on Monday 29. October, 2012

Download