Commit 11114191 authored by Björn Richerzhagen's avatar Björn Richerzhagen
Browse files

SiS: updates of InfoProperties + RequestProperties

SiS: Data callback contains InfoProperties
parent 3f93aecb
...@@ -48,11 +48,13 @@ public interface MonitoringComponent extends HostComponent { ...@@ -48,11 +48,13 @@ public interface MonitoringComponent extends HostComponent {
* the {@link SiSType} * the {@link SiSType}
* @param request * @param request
* additional request properties * additional request properties
* @param resultCallback
* triggered, once the result is available
* @return * @return
*/ */
public <T> MonitoringHandle collectAggregatedObservation( public <T> MonitoringHandle collectAggregatedObservation(
AggregationFunction aggFunction, SiSType<T> type, AggregationFunction aggFunction, SiSType<T> type,
SiSRequest request, MonitoringStateCallback stateCallback); SiSRequest request, MonitoringResultCallback<T> resultCallback);
/** /**
* Requests raw values (i.e., per node) for the given type according to the * Requests raw values (i.e., per node) for the given type according to the
...@@ -71,7 +73,7 @@ public interface MonitoringComponent extends HostComponent { ...@@ -71,7 +73,7 @@ public interface MonitoringComponent extends HostComponent {
* IDs * IDs
*/ */
public <T> MonitoringHandle collectRawObservations(SiSType<T> type, public <T> MonitoringHandle collectRawObservations(SiSType<T> type,
SiSRequest request, MonitoringStateCallback stateCallback); SiSRequest request);
/** /**
* Stop collecting * Stop collecting
...@@ -84,8 +86,8 @@ public interface MonitoringComponent extends HostComponent { ...@@ -84,8 +86,8 @@ public interface MonitoringComponent extends HostComponent {
// marker // marker
} }
public interface MonitoringStateCallback { public interface MonitoringResultCallback<T> {
public void onResultsReady(); public void onResult(T result);
} }
} }
...@@ -62,15 +62,6 @@ public interface SiSComponent extends HostComponent { ...@@ -62,15 +62,6 @@ public interface SiSComponent extends HostComponent {
*/ */
public SiSInformationConsumer get(); public SiSInformationConsumer get();
/**
* For more complex requests and provider interactions, you might need to
* describe your information. Use the {@link SiSInfoPropertiesFactory} to
* achieve this task.
*
* @return
*/
public SiSInfoPropertiesFactory describe();
/** /**
* Use this method to test whether the provided {@link INodeID} corresponds * Use this method to test whether the provided {@link INodeID} corresponds
* to our own local node. If nodeID == null, this has to return true! * to our own local node. If nodeID == null, this has to return true!
......
...@@ -47,4 +47,11 @@ public interface SiSDataCallback<T> { ...@@ -47,4 +47,11 @@ public interface SiSDataCallback<T> {
public T getValue(SiSProviderHandle providerHandle) public T getValue(SiSProviderHandle providerHandle)
throws InformationNotAvailableException; throws InformationNotAvailableException;
/**
* Description of the data provided via this callback.
*
* @return
*/
public SiSInfoProperties getInfoProperties();
} }
...@@ -20,6 +20,9 @@ ...@@ -20,6 +20,9 @@
package de.tudarmstadt.maki.simonstrator.api.component.sis; package de.tudarmstadt.maki.simonstrator.api.component.sis;
import de.tudarmstadt.maki.simonstrator.api.Time;
/** /**
* A description object that characterizes a given information in the SiS. This * A description object that characterizes a given information in the SiS. This
...@@ -45,6 +48,8 @@ public class SiSInfoProperties implements Cloneable { ...@@ -45,6 +48,8 @@ public class SiSInfoProperties implements Cloneable {
private Class<?> sourceComponent = null; private Class<?> sourceComponent = null;
private long lastUpdateTimestamp = Time.getCurrentTime();
/* /*
* Here, we should collect some ideas for common description properties. * Here, we should collect some ideas for common description properties.
*/ */
...@@ -57,6 +62,14 @@ public class SiSInfoProperties implements Cloneable { ...@@ -57,6 +62,14 @@ public class SiSInfoProperties implements Cloneable {
* TODO accuracy of the information * TODO accuracy of the information
*/ */
public void setLastUpdateTimestamp() {
this.lastUpdateTimestamp = Time.getCurrentTime();
}
public long getLastUpdateTimestamp() {
return lastUpdateTimestamp;
}
/** /**
* Later, we might want to define scopes in a more flexible way? * Later, we might want to define scopes in a more flexible way?
* *
......
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of Simonstrator.KOM.
*
* Simonstrator.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package de.tudarmstadt.maki.simonstrator.api.component.sis;
import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSInfoProperties.SiSScope;
/**
* Convenience class that aids in creating {@link SiSInfoProperties} objects for
* a number of common scenarios
*
* @author Bjoern Richerzhagen
*
*/
public class SiSInfoPropertiesFactory {
/**
* {@link SiSInfoProperties} for local data from a given source
*
* @return
*/
public <T> SiSInfoProperties localDataFrom(
Class<T> source) {
SiSInfoProperties prop = new SiSInfoProperties();
prop.setSourceComponent(source).setScope(SiSScope.NODE_LOCAL);
return prop;
}
public SiSInfoProperties globalView() {
SiSInfoProperties prop = new SiSInfoProperties();
prop.setScope(SiSScope.GLOBAL);
return prop;
}
}
...@@ -167,35 +167,5 @@ public interface SiSInformationConsumer { ...@@ -167,35 +167,5 @@ public interface SiSInformationConsumer {
public <T> void rawObservations(SiSType<T> type, SiSRequest request, public <T> void rawObservations(SiSType<T> type, SiSRequest request,
SiSResultCallback<Map<INodeID, T>> callback); SiSResultCallback<Map<INodeID, T>> callback);
/**
* Create a plain request object for the given {@link SiSInfoProperties}.
* Use {@link SiSInfoProperties}.NONE in case you do not want to specify the
* information quality.
*
* @param infoProperties
* description of the desired information properties. Use
* {@link SiSInfoProperties}.NONE if you do not want to specify
* these.
*
* @return modifiable request object
*/
public SiSRequest newRequest(SiSInfoProperties infoProperties);
/**
* Create a plain request object for the given {@link SiSInfoProperties}.
* Use {@link SiSInfoProperties}.NONE in case you do not want to specify the
* information quality.
*
* @param infoProperties
* description of the desired information properties. Use
* {@link SiSInfoProperties}.NONE if you do not want to specify
* these.
* @param timeout
*
* @return modifiable request object
*/
public SiSRequest newRequest(SiSInfoProperties infoProperties, long timeout);
} }
...@@ -46,12 +46,11 @@ public interface SiSInformationProvider { ...@@ -46,12 +46,11 @@ public interface SiSInformationProvider {
* *
* @param type * @param type
* @param dataCallback * @param dataCallback
* @param informationProperties * containing the {@link SiSInfoProperties}
* @return * @return
*/ */
public <T> SiSProviderHandle localNodeState(SiSType<T> type, public <T> SiSProviderHandle localNodeState(SiSType<T> type,
SiSDataCallback<T> dataCallback, SiSDataCallback<T> dataCallback);
SiSInfoProperties informationProperties);
/** /**
* This method denotes that state about another node has been collected. In * This method denotes that state about another node has been collected. In
...@@ -62,12 +61,11 @@ public interface SiSInformationProvider { ...@@ -62,12 +61,11 @@ public interface SiSInformationProvider {
* @param observedNode * @param observedNode
* @param type * @param type
* @param dataCallback * @param dataCallback
* @param informationProperties * containing the {@link SiSInfoProperties}
* @return * @return
*/ */
public <T> SiSProviderHandle observedNodeState(INodeID observedNode, public <T> SiSProviderHandle observedNodeState(INodeID observedNode,
SiSType<T> type, SiSDataCallback<T> dataCallback, SiSType<T> type, SiSDataCallback<T> dataCallback);
SiSInfoProperties informationProperties);
/** /**
* Revoke access to the information registered with the provided handle * Revoke access to the information registered with the provided handle
......
...@@ -23,6 +23,7 @@ package de.tudarmstadt.maki.simonstrator.api.component.sis; ...@@ -23,6 +23,7 @@ package de.tudarmstadt.maki.simonstrator.api.component.sis;
import java.util.Map; import java.util.Map;
import de.tudarmstadt.maki.simonstrator.api.common.graph.INodeID; import de.tudarmstadt.maki.simonstrator.api.common.graph.INodeID;
import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSInformationConsumer.AggregationFunction;
import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSInformationProvider.SiSProviderHandle; import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSInformationProvider.SiSProviderHandle;
import de.tudarmstadt.maki.simonstrator.api.component.sis.exception.InformationNotAvailableException; import de.tudarmstadt.maki.simonstrator.api.component.sis.exception.InformationNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.sis.type.SiSType; import de.tudarmstadt.maki.simonstrator.api.component.sis.type.SiSType;
...@@ -62,6 +63,14 @@ public interface SiSInformationResolver { ...@@ -62,6 +63,14 @@ public interface SiSInformationResolver {
public <T> Map<INodeID, T> getAllLocalObservations(SiSType<T> type, public <T> Map<INodeID, T> getAllLocalObservations(SiSType<T> type,
SiSRequest request); SiSRequest request);
public <T> void aggregatedObservation(AggregationFunction aggFunction,
SiSType<T> type, SiSRequest request, SiSResultCallback<T> callback);
public <T> void rawObservations(SiSType<T> type, SiSRequest request,
SiSResultCallback<Map<INodeID, T>> callback);
/** /**
* Adds a local resolver to the SiS * Adds a local resolver to the SiS
* *
...@@ -69,12 +78,10 @@ public interface SiSInformationResolver { ...@@ -69,12 +78,10 @@ public interface SiSInformationResolver {
* (optional, can be null - null meaning: local node) * (optional, can be null - null meaning: local node)
* @param type * @param type
* @param dataCallback * @param dataCallback
* @param informationProperties
* @return * @return
*/ */
public <T> SiSProviderHandle addObservationProvider(INodeID observedNode, public <T> SiSProviderHandle addObservationProvider(INodeID observedNode,
SiSType<T> type, SiSDataCallback<T> dataCallback, SiSType<T> type, SiSDataCallback<T> dataCallback);
SiSInfoProperties informationProperties);
/** /**
* Removes the local provider with the given handle * Removes the local provider with the given handle
......
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
package de.tudarmstadt.maki.simonstrator.api.component.sis; package de.tudarmstadt.maki.simonstrator.api.component.sis;
import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSInfoProperties.SiSScope;
/** /**
* Properties that are exclusive to requests (e.g., a tolerable timeout, * Properties that are exclusive to requests (e.g., a tolerable timeout,
* thresholds, etc.). This is implemented in the API to ensure compatibility * thresholds, etc.). This is implemented in the API to ensure compatibility
...@@ -33,34 +35,92 @@ public class SiSRequest implements Cloneable { ...@@ -33,34 +35,92 @@ public class SiSRequest implements Cloneable {
/** /**
* "null" request * "null" request
*/ */
public static final SiSRequest NONE = new SiSRequest( public static final SiSRequest NONE = new SiSRequest();
SiSInfoProperties.NONE, 0);
private long timeout = 0;
private long maxInformationAge = Long.MAX_VALUE;
private final SiSInfoProperties infoProperties; private SiSScope scope = null;
private final long timeout; private Class<?> sourceComponent = null;
public SiSRequest() {
this(0, Long.MAX_VALUE, null, null);
}
public SiSRequest(SiSInfoProperties infoProperties, long timeout) { public SiSRequest(long timeout, long maxInformationAge, SiSScope scope,
this.infoProperties = infoProperties; Class<?> sourceComponent) {
this.timeout = timeout; this.timeout = timeout;
this.maxInformationAge = maxInformationAge;
this.scope = scope;
this.sourceComponent = sourceComponent;
}
protected SiSRequest(SiSRequest request) {
// TODO clone
this.timeout = request.timeout;
this.maxInformationAge = request.maxInformationAge;
this.scope = request.scope;
this.sourceComponent = request.sourceComponent;
} }
/** /**
* If the request has an attached {@link SiSInfoProperties} object, it is
* returned by this method.
* *
* @return {@link SiSInfoProperties} or null. * @return
*/ */
public SiSInfoProperties getInfoProperties() { public long getTimeout() {
return infoProperties; return timeout;
}
public long getMaxInformationAge() {
return maxInformationAge;
} }
/** /**
* Set the scope of the respective information
* *
* @param scope
* @return * @return
*/ */
public long getTimeout() { public SiSRequest setScope(SiSScope scope) {
return timeout; this.scope = scope;
return this;
}
/**
* Scope of this request
*
* @return scope or null
*/
public SiSScope getScope() {
return scope;
}
/**
* Optional filter based on the source component(s) of the data (e.g., only
* Bypass-Data). This is NOT limited to HostComponents.
*
* @param component
* interface of the (desired) source component. This supports
* type inheritance - if you specify e.g., PubSubComponent, you
* will get data from any source extending that interface, so
* from BypassPubSubComponent for example.
*
* @return reference to the current properties instance to support chaining
*/
public <T> SiSRequest setSourceComponent(Class<T> sourceComponent) {
this.sourceComponent = sourceComponent;
return this;
}
/**
* Source component of this information
*
* @return source component or null
*/
public Class<?> getSourceComponent() {
return sourceComponent;
} }
/* /*
...@@ -74,13 +134,29 @@ public class SiSRequest implements Cloneable { ...@@ -74,13 +134,29 @@ public class SiSRequest implements Cloneable {
@Override @Override
public SiSRequest clone() { public SiSRequest clone() {
return new SiSRequest(infoProperties.clone(), timeout); return new SiSRequest(this);
// TODO add inner request parameters, once they are defined!
} }
@Override /**
public String toString() { * Has to return true, if the given src described by
return "SiSRequest [" + infoProperties + "]"; * {@link SiSInfoProperties} satisfies the request.
*
* @param src
* @return
*/
public boolean satisfiableBy(SiSInfoProperties src) {
if (this.getScope() != null && getScope() != src.getScope()) {
return false;
}
if (getSourceComponent() != null) {
if (src.getSourceComponent() == null) {
return false;
}
if (!getSourceComponent()
.isAssignableFrom(src.getSourceComponent())) {
return false;
}
}
return true;
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment