Commit a295f838 authored by Christophe Demarey's avatar Christophe Demarey
Browse files

Add the qos module.

parent 36dc158b
......@@ -4,13 +4,19 @@
<modelVersion>4.0.0</modelVersion>
<name>Home Automation Demonstration</name>
<name>Home Automation Demonstration Core module</name>
<groupId>org.ow2.frascati.demo</groupId>
<artifactId>home-automation</artifactId>
<artifactId>home-automation-core</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>org.ow2.frascati.demo</groupId>
<artifactId>home-automation-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<!-- ===== -->
<!-- Build. -->
<!-- ===== -->
......
<?xml version="1.0" encoding="UTF-8" ?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<name>Home Automation Demonstration</name>
<groupId>org.ow2.frascati.demo</groupId>
<artifactId>home-automation-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<!-- ===== -->
<!-- Build. -->
<!-- ===== -->
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins
</groupId>
<artifactId>maven-compiler-plugin
</artifactId>
<inherited>true</inherited>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<!-- ============= -->
<!-- Properties -->
<!-- ============= -->
<properties>
<frascati.version>1.3-SNAPSHOT</frascati.version>
<gdata.java.client.version>1.41.1-SNAPSHOT</gdata.java.client.version>
<cxf.version>2.2.7</cxf.version>
</properties>
<!-- ============= -->
<!-- Repositories. -->
<!-- ============= -->
<repositories>
<repository>
<id>inria-galaxy-repository</id>
<name>INRIA Galaxy Maven Repository</name>
<url>http://galaxy.gforge.inria.fr/repository/maven2</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>ow2-snapshot</id>
<url>http://maven.ow2.org//maven2-snapshot</url>
</repository>
<repository>
<id>apache.incubator</id>
<url>http://people.apache.org/repo/m2-incubating-repository</url>
</repository>
<!-- for Google artefacts -->
<repository>
<releases>
<enabled>false</enabled>
<checksumPolicy>fail</checksumPolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
<id>sonatype-nexus-snapshots</id>
<name>Sonatype Nexus Snapshots</name>
<url>http://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
<!-- for mp3spi -->
<repository>
<id>softlab</id>
<url>http://softlab.tsukuba-bunko.org/maven/repository/</url>
</repository>
<!-- for tritonus -->
<repository>
<id>pppnetmedia</id>
<url>http://ppnetmedia.com/repository</url>
</repository>
</repositories>
<!-- ============ -->
<!-- Dependencies -->
<!-- ============ -->
<!-- ======= -->
<!-- Modules -->
<!-- ======= -->
<modules>
<module>core</module>
<module>qos</module>
</modules>
</project>
<?xml version="1.0" encoding="UTF-8" ?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<name>Home Automation Demonstration QoS module</name>
<groupId>org.ow2.frascati.demo</groupId>
<artifactId>home-automation-qos</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>org.ow2.frascati.demo</groupId>
<artifactId>home-automation-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<!-- ===== -->
<!-- Build. -->
<!-- ===== -->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins
</groupId>
<artifactId>maven-compiler-plugin
</artifactId>
<inherited>true</inherited>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<!-- ============= -->
<!-- Properties -->
<!-- ============= -->
<properties>
</properties>
<!-- ============= -->
<!-- Repositories. -->
<!-- ============= -->
<repositories>
<repository>
<id>MonFW</id>
<name>Tuvalu MonFW Maven Repository</name>
<url>http://tuvalu.inrialpes.fr/maven2</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<!-- ============ -->
<!-- Dependencies -->
<!-- ============ -->
<dependencies>
<dependency>
<groupId>org.ow2.frascati.demo</groupId>
<artifactId>home-automation-core</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- WildCat core -->
<dependency>
<groupId>org.ow2.wildcat</groupId>
<artifactId>wildcat-core</artifactId>
<version>2.2.1-SNAPSHOT</version>
</dependency>
<!-- Monitoring Framework -->
<dependency>
<groupId>fr.inria.monitoring.bep</groupId>
<artifactId>monfw-server</artifactId>
<version>1.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>fr.inria.galaxy.monitoring</groupId>
<artifactId>monitoring-wildcat-adapter</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
/***
* OW2 FraSCAti: Home Automation demonstration
* Copyright (C) 2010 INRIA, IRISA, University of Lille 1
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: frascati@ow2.org
*
* Author(s): Grégory Nain, Mahmoud Ben Hassine
*
* Contributor(s):
*/
package fr.inria.galaxy.demo.homeautomation.qos;
import org.osoa.sca.annotations.Property;
import org.osoa.sca.annotations.Scope;
import org.osoa.sca.annotations.Service;
import org.osoa.sca.ServiceUnavailableException;
import org.ow2.frascati.tinfi.control.intent.IntentHandler;
import org.ow2.frascati.tinfi.control.intent.IntentJoinPoint;
@Scope("COMPOSITE")
@Service(IntentHandler.class)
public class AvailabilityIntentHandler implements IntentHandler {
// Default timeout if not set.
private static final long DEFAULT_TIMEOUT = 2000;
// Timeout for the proceed thread.
private long timeout = DEFAULT_TIMEOUT;
/**
* Setter for the timeout property.
* @param timeout
*/
@Property
public void setTimeout(final long timeout) {
System.out.println(this + ".setTimeout(" + timeout + ")");
this.timeout = timeout;
}
@Override
public Object invoke(final IntentJoinPoint ijp) throws ServiceUnavailableException, Throwable {
// run the proceed in a separate thread.
ProceedThread pt = new ProceedThread();
// set the IntentJoinPoint to proceed.
pt.ijp = ijp;
// start the proceed thread.
pt.start();
try {
// wait the proceed thread to return for maximum timeout value.
pt.join(timeout);
// timeout exceeded and the thread didn't returned yet.
if (pt.isAlive()) {
// don't interrupt the proceed thread because we don't know in which state it is.
throw new ServiceUnavailableException("Timeout of " + timeout + " ms exceeded");
}
} catch (InterruptedException e) {
}
// throw the exception caught by the proceed thread.
if(pt.throwable != null)
throw pt.throwable;
// the thread returned before timeout => return the value.
return pt.result;
}
}
class ProceedThread extends Thread {
// The intent join point to proceed.
IntentJoinPoint ijp = null;
// The result returned by proceed().
Object result = null;
// Exception thrown by proceed().
Throwable throwable = null;
public void run() {
try {
result = ijp.proceed();
} catch (Throwable e) {
throwable = e;
}
}
}
/***
* OW2 FraSCAti: Home Automation demonstration
* Copyright (C) 2010 INRIA, IRISA, University of Lille 1
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: frascati@ow2.org
*
* Author(s): Grégory Nain, Mahmoud Ben Hassine
*
* Contributor(s):
*/
package fr.inria.galaxy.demo.homeautomation.qos;
/**
* A simple bean encapsulating monitoring data to be notified to wildcat context
*
* @author Mahmoud Ben Hassine
*
*/
public class MonitoringData {
private String componentName;
private String serviceName;
private long responseTime;
public MonitoringData(long responseTime, String componentName, String serviceName) {
this.responseTime = responseTime;
this.componentName = componentName;
this.serviceName = serviceName;
}
public MonitoringData() {}
public long getResponseTime() {
return responseTime;
}
public void setResponseTime(long responseTime) {
this.responseTime = responseTime;
}
public String getComponentName() {
return componentName;
}
public void setComponentName(String componentName) {
this.componentName = componentName;
}
public String getServiceName() {
return serviceName;
}
public void setServiceName(String serviceName) {
this.serviceName = serviceName;
}
@Override
public String toString() {
return "Monitoring data : date = " + java.util.Calendar.getInstance().getTime()
+ " - component name = " + componentName
+ " - service called = " + serviceName
+ " - response time = " + responseTime + " ms";
}
}
/***
* OW2 FraSCAti: Home Automation demonstration
* Copyright (C) 2010 INRIA, IRISA, University of Lille 1
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: frascati@ow2.org
*
* Author(s): Grégory Nain, Mahmoud Ben Hassine
*
* Contributor(s):
*/
package fr.inria.galaxy.demo.homeautomation.qos;
import org.ow2.wildcat.ContextException;
/**
* Service used to notify monitoring data to wildcat context
*
* @author Mahmoud Ben Hassine
*
*/
public interface MonitoringService {
/**
* Notify monitoring data to wildcat context
*
* @param md
* monitoring data to be notified
* @throws ContextException
* thrown if monitoring data cannot be notified to wildcat
* context
*/
public void notifyMonitoringData(MonitoringData md) throws ContextException;
}
/***
* OW2 FraSCAti: Home Automation demonstration
* Copyright (C) 2010 INRIA, IRISA, University of Lille 1
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: frascati@ow2.org
*
* Author(s): Grégory Nain, Mahmoud Ben Hassine
*
* Contributor(s):
*/
package fr.inria.galaxy.demo.homeautomation.qos;
import org.osoa.sca.annotations.Init;
import org.osoa.sca.annotations.Reference;
import org.osoa.sca.annotations.Scope;
import org.ow2.wildcat.Context;
import org.ow2.wildcat.ContextException;
import org.ow2.wildcat.ContextFactory;
import fr.inria.galaxy.demo.homeautomation.util.DemoServices;
/**
* Implementation of the {@link MonitoringService} interface
*
* @author Mahmoud Ben Hassine
*
*/
@Scope("COMPOSITE")
public class MonitoringServiceImpl implements MonitoringService{
/**
* reference to wildcat service used to create hierarchy, queries and listeners
*/
@Reference
private Context wildcatContext;
@Init
public void init(){
/*
* create a wildcat context
*/
wildcatContext = ContextFactory.getDefaultFactory().createContext();
PersistEventAction pea = new PersistEventAction();
String updateQuery = "select * from WAttributeEvent(source = 'self://demoHA/services#lastMonitoringData')";
try {
/*
* Create wildcat resources hierarchy
*/
for (DemoServices service : DemoServices.values())
wildcatContext.createAttribute("self://demoHA/services/" + service + "#responseTime",0);
/*
* add a basic attribute to get last monitoring data
*/
wildcatContext.createAttribute("self://demoHA/services#lastMonitoringData",new MonitoringData());
/*
* register a new action to persist events
*/
wildcatContext.registerActions(updateQuery, pea);
} catch (ContextException e) {
e.printStackTrace();
}
}
public void notifyMonitoringData(MonitoringData md) throws ContextException {
wildcatContext.setValue("self://demoHA/services#lastMonitoringData", md);
wildcatContext.setValue("self://demoHA/services/" + md.getServiceName() + "#responseTime", md.getResponseTime());
}
}
/***
* OW2 FraSCAti: Home Automation demonstration
* Copyright (C) 2010 INRIA, IRISA, University of Lille 1
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: frascati@ow2.org
*
* Author(s): Grégory Nain, Mahmoud Ben Hassine
*
* Contributor(s):
*/
package fr.inria.galaxy.demo.homeautomation.qos;
import java.sql.Timestamp;
import org.ow2.wildcat.WAction;
import fr.inria.galaxy.monitoring.BEP4galaxy;
import fr.inria.galaxy.monitoring.event.FraSCAtiServiceEvent;
/**
* WAction to persist monitoring data to the monitoring framework database