Skip to content

Commit 23c2007

Browse files
committed
Broken state. In the process of extracting the meta-adaptations into
separate library.
1 parent 658d5e7 commit 23c2007

24 files changed

+1871
-0
lines changed

.classpath

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" output="target/classes" path="src">
4+
<attributes>
5+
<attribute name="optional" value="true"/>
6+
<attribute name="maven.pomderived" value="true"/>
7+
</attributes>
8+
</classpathentry>
9+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
10+
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
11+
<attributes>
12+
<attribute name="maven.pomderived" value="true"/>
13+
</attributes>
14+
</classpathentry>
15+
<classpathentry kind="output" path="target/classes"/>
16+
</classpath>

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/bin/
2+
/target/

.project

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>meta-adaptation-manager</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.m2e.core.maven2Builder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
</buildSpec>
19+
<natures>
20+
<nature>org.eclipse.m2e.core.maven2Nature</nature>
21+
<nature>org.eclipse.jdt.core.javanature</nature>
22+
</natures>
23+
</projectDescription>

.settings/org.eclipse.jdt.core.prefs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
4+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5+
org.eclipse.jdt.core.compiler.compliance=1.8
6+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
8+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11+
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
12+
org.eclipse.jdt.core.compiler.source=1.8

.settings/org.eclipse.m2e.core.prefs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
activeProfiles=
2+
eclipse.preferences.version=1
3+
resolveWorkspaceProjects=true
4+
version=1

pom.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<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/xsd/maven-4.0.0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
<groupId>cz.cuni.mff.d3s</groupId>
4+
<artifactId>meta-adaptation-manager</artifactId>
5+
<version>0.0.1-SNAPSHOT</version>
6+
<build>
7+
<sourceDirectory>src</sourceDirectory>
8+
<plugins>
9+
<plugin>
10+
<artifactId>maven-compiler-plugin</artifactId>
11+
<version>3.5.1</version>
12+
<configuration>
13+
<source/>
14+
<target/>
15+
</configuration>
16+
</plugin>
17+
</plugins>
18+
</build>
19+
</project>
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package cz.cuni.mff.d3s.metaadaptation;
2+
3+
import java.io.File;
4+
import java.io.InputStream;
5+
import java.util.logging.ConsoleHandler;
6+
import java.util.logging.Level;
7+
import java.util.logging.LogManager;
8+
9+
10+
/**
11+
* Simple wrapper of java.util.logging.Logger with lazy-initialized singleton
12+
* object and thread-safe methods
13+
*
14+
* @author Ilias Gerostathopoulos
15+
*
16+
*/
17+
public class Log {
18+
19+
private static final Log INSTANCE = new Log();
20+
21+
public static Log getInstance() {
22+
return INSTANCE;
23+
}
24+
25+
26+
/**
27+
* The default directory where the log files are placed.
28+
*/
29+
private static final String LOG_DIRECTORY = "logs";
30+
31+
private java.util.logging.Logger logger;
32+
33+
34+
private Log() {
35+
36+
// Check whether the directory for log files exists and create it if needed
37+
File logDirectory = new File(LOG_DIRECTORY);
38+
if(!logDirectory.exists() || !logDirectory.isDirectory()){
39+
logDirectory.mkdirs();
40+
}
41+
42+
43+
logger = java.util.logging.Logger.getLogger(getClass().getPackage().getName());
44+
String confPath = System.getProperty("java.util.logging.config.file");
45+
if (confPath == null || confPath.equals(""))
46+
confPath = "logging.properties";
47+
InputStream inputStream = getClass().getClassLoader()
48+
.getResourceAsStream(confPath);
49+
try {
50+
LogManager.getLogManager().readConfiguration(inputStream);
51+
} catch (Exception e) {
52+
logger = java.util.logging.Logger.getLogger("default");
53+
ConsoleHandler ch = new ConsoleHandler();
54+
logger.addHandler(ch);
55+
logger.severe("Could not load logging.properties file - falling backing to console logging");
56+
}
57+
}
58+
59+
public synchronized void debug(String s) {
60+
logger.log(Level.FINEST, s);
61+
}
62+
63+
public synchronized void debug(String s, Throwable t) {
64+
logger.log(Level.FINEST, s, t);
65+
}
66+
67+
public synchronized void info(String s) {
68+
logger.log(Level.FINEST, s);
69+
}
70+
71+
public synchronized void info(String s, Throwable t) {
72+
logger.log(Level.INFO, s, t);
73+
}
74+
75+
public synchronized void warning(String s) {
76+
logger.log(Level.WARNING, s);
77+
}
78+
79+
public synchronized void warning(String s, Throwable t) {
80+
logger.log(Level.WARNING, s, t);
81+
}
82+
83+
public synchronized void error(String s) {
84+
logger.log(Level.SEVERE, s);
85+
}
86+
87+
public synchronized void error(String s, Throwable t) {
88+
logger.log(Level.SEVERE, s, t);
89+
}
90+
91+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package cz.cuni.mff.d3s.metaadaptation;
2+
3+
/**
4+
* Interface for adaptation manager to control individual adaptations.
5+
*/
6+
public interface MAPEAdaptation {
7+
8+
/**
9+
* Monitor the context or inner state.
10+
*/
11+
void monitor();
12+
13+
/**
14+
* Analyze the monitored data.
15+
* The provided value indicates the applicability of the adaptation.
16+
* False means no applicability of the adaptation, True expresses
17+
* the adaptation being suitable in the current situation.
18+
*
19+
* @return A suitability of the adaptation.
20+
*/
21+
boolean analyze();
22+
23+
/**
24+
* Plan and prepare the adaptation changes.
25+
*/
26+
void plan();
27+
28+
/**
29+
* Apply the adaptation.
30+
*/
31+
void execute();
32+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*******************************************************************************
2+
* Copyright 2017 Charles University in Prague
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*******************************************************************************/
16+
package cz.cuni.mff.d3s.metaadaptation;
17+
18+
import java.util.ArrayList;
19+
import java.util.List;
20+
21+
22+
/**
23+
* @author Dominik Skoda <[email protected]>
24+
*
25+
*/
26+
public class MetaAdaptationManager {
27+
28+
public List<MAPEAdaptation> adaptations;
29+
30+
public MetaAdaptationManager(){
31+
adaptations = new ArrayList<>();
32+
}
33+
34+
public void addAdaptation(MAPEAdaptation adaptation){
35+
adaptations.add(adaptation);
36+
}
37+
38+
/**
39+
* Run the MAPE loop of all registered {@link MAPEAdaptation}s.
40+
*/
41+
public void reason() {
42+
for(MAPEAdaptation adaptation : adaptations){
43+
adaptation.monitor();
44+
boolean isApplicable = adaptation.analyze();
45+
if(isApplicable){
46+
adaptation.plan();
47+
adaptation.execute();
48+
}
49+
}
50+
51+
}
52+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package cz.cuni.mff.d3s.metaadaptation.correlation;
2+
3+
import java.io.Serializable;
4+
5+
/**
6+
* Holds a boundary value together with a flag indicating whether the value
7+
* has changed since it was lastly used.
8+
*
9+
* @author Dominik Skoda <[email protected]>
10+
*
11+
*/
12+
public class BoundaryValueHolder implements Serializable {
13+
14+
/**
15+
* Generated UID.
16+
*/
17+
private static final long serialVersionUID = -6438264656364851855L;
18+
19+
/**
20+
* The limit beyond which two doubles are considered equal.
21+
* The value of this constant influences the granularity of changing
22+
* the boundary.
23+
*/
24+
protected static final double EPSILON = 0.01;
25+
26+
/**
27+
* Stored value of the boundary.
28+
*/
29+
private double boundary;
30+
/**
31+
* Flag indicating whether the boundary has changed enough (see {@link #EPSILON})
32+
* since it was lastly used.
33+
*/
34+
private boolean changed;
35+
36+
/**
37+
* Construct new instance of the {@link BoundaryValueHolder} with the
38+
* given value to hold. The {@link #hasChanged()} flag is set by default
39+
* to true.
40+
* @param boundary The boundary value to be held.
41+
*/
42+
public BoundaryValueHolder(double boundary) {
43+
this.boundary = boundary;
44+
this.changed = true;
45+
}
46+
47+
/**
48+
* Set new boundary to be held. If the boundary differs from the previous
49+
* one more than {@link #EPSILON} than the {@link #hasChanged()} flag
50+
* is set to true.
51+
* @param boundary The boundary to be held.
52+
*/
53+
public void setBoundary(double boundary) {
54+
if(Double.isNaN(boundary) && Double.isNaN(this.boundary)) {
55+
return;
56+
}
57+
if(Double.isNaN(boundary) || Double.isNaN(this.boundary)
58+
|| Math.abs(this.boundary - boundary) > EPSILON) {
59+
this.boundary = boundary;
60+
changed = true;
61+
}
62+
}
63+
64+
/**
65+
* Read the stored boundary.
66+
* @return The stored boundary.
67+
*/
68+
public double getBoundary() {
69+
return boundary;
70+
}
71+
72+
/**
73+
* Indicates whether the boundary is valid (is not NaN).
74+
* @return True if the boundary is not NaN.
75+
*/
76+
public boolean isValid() {
77+
return !Double.isNaN(boundary);
78+
}
79+
80+
/**
81+
* Set the {@link #hasChanged()} flag to false. Indicate that
82+
* the current value has been used.
83+
*/
84+
public void boundaryUsed() {
85+
changed = false;
86+
}
87+
88+
/**
89+
* Indicates whether the stored boundary value has changed enough
90+
* (see {@link #EPSILON}) since its last usage.
91+
* @return
92+
*/
93+
public boolean hasChanged() {
94+
return changed;
95+
}
96+
97+
}

0 commit comments

Comments
 (0)