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

Initial commit of the Simonstrator-API

parents
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
target/
bin/
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>SimonstratorInterface</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
encoding/src=UTF8
This diff is collapsed.
cleanup.add_default_serial_version_id=true
cleanup.add_generated_serial_version_id=false
cleanup.add_missing_annotations=true
cleanup.add_missing_deprecated_annotations=true
cleanup.add_missing_methods=false
cleanup.add_missing_nls_tags=false
cleanup.add_missing_override_annotations=true
cleanup.add_missing_override_annotations_interface_methods=true
cleanup.add_serial_version_id=false
cleanup.always_use_blocks=true
cleanup.always_use_parentheses_in_expressions=false
cleanup.always_use_this_for_non_static_field_access=false
cleanup.always_use_this_for_non_static_method_access=false
cleanup.convert_to_enhanced_for_loop=false
cleanup.correct_indentation=false
cleanup.format_source_code=false
cleanup.format_source_code_changes_only=false
cleanup.make_local_variable_final=true
cleanup.make_parameters_final=false
cleanup.make_private_fields_final=true
cleanup.make_type_abstract_if_missing_method=false
cleanup.make_variable_declarations_final=false
cleanup.never_use_blocks=false
cleanup.never_use_parentheses_in_expressions=true
cleanup.organize_imports=false
cleanup.qualify_static_field_accesses_with_declaring_class=false
cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
cleanup.qualify_static_member_accesses_with_declaring_class=true
cleanup.qualify_static_method_accesses_with_declaring_class=false
cleanup.remove_private_constructors=true
cleanup.remove_trailing_whitespaces=false
cleanup.remove_trailing_whitespaces_all=true
cleanup.remove_trailing_whitespaces_ignore_empty=false
cleanup.remove_unnecessary_casts=true
cleanup.remove_unnecessary_nls_tags=true
cleanup.remove_unused_imports=true
cleanup.remove_unused_local_variables=false
cleanup.remove_unused_private_fields=true
cleanup.remove_unused_private_members=false
cleanup.remove_unused_private_methods=true
cleanup.remove_unused_private_types=true
cleanup.sort_members=false
cleanup.sort_members_all=false
cleanup.use_blocks=false
cleanup.use_blocks_only_for_return_and_throw=false
cleanup.use_parentheses_in_expressions=false
cleanup.use_this_for_non_static_field_access=false
cleanup.use_this_for_non_static_field_access_only_if_necessary=true
cleanup.use_this_for_non_static_method_access=false
cleanup.use_this_for_non_static_method_access_only_if_necessary=true
cleanup_profile=org.eclipse.jdt.ui.default.eclipse_clean_up_profile
cleanup_settings_version=2
eclipse.preferences.version=1
editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
formatter_profile=org.eclipse.jdt.ui.default.eclipse_profile
formatter_settings_version=12
org.eclipse.jdt.ui.javadoc=false
org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?><templates><template autoinsert\="true" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment">/**\n * @return the ${bare_field_name}\n */</template><template autoinsert\="true" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment">/**\n * @param ${param} the ${bare_field_name} to set\n */</template><template autoinsert\="true" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment">/**\n * ${tags}\n */</template><template autoinsert\="true" context\="filecomment_context" deleted\="false" description\="Comment for created Java files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.filecomment" name\="filecomment">/**\n * \n */</template><template autoinsert\="true" context\="typecomment_context" deleted\="false" description\="Comment for created types" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.typecomment" name\="typecomment">/**\n * @author ${user}\n *\n * ${tags}\n */</template><template autoinsert\="true" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment">/**\n * \n */</template><template autoinsert\="true" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment">/**\n * ${tags}\n */</template><template autoinsert\="true" context\="overridecomment_context" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment">/* (non-Javadoc)\n * ${see_to_overridden}\n */</template><template autoinsert\="true" context\="delegatecomment_context" deleted\="false" description\="Comment for delegate methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name\="delegatecomment">/**\n * ${tags}\n * ${see_to_target}\n */</template><template autoinsert\="false" context\="newtype_context" deleted\="false" description\="Newly created files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.newtype" name\="newtype">/*\n * Copyright (c) 2005-2010 KOM \u2013 Multimedia Communications Lab\n *\n * This file is part of Simonstrator.KOM.\n * \n * Simonstrator.KOM is free software\: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * any later version.\n * \n * PeerfactSim.KOM is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n * \n * You should have received a copy of the GNU General Public License\n * along with PeerfactSim.KOM. If not, see &lt;http\://www.gnu.org/licenses/&gt;.\n *\n */\n\n${filecomment}\n${package_declaration}\n\n${typecomment}\n${type_declaration}</template><template autoinsert\="true" context\="classbody_context" deleted\="false" description\="Code in new class type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.classbody" name\="classbody">\n</template><template autoinsert\="true" context\="interfacebody_context" deleted\="false" description\="Code in new interface type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.interfacebody" name\="interfacebody">\n</template><template autoinsert\="true" context\="enumbody_context" deleted\="false" description\="Code in new enum type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.enumbody" name\="enumbody">\n</template><template autoinsert\="true" context\="annotationbody_context" deleted\="false" description\="Code in new annotation type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.annotationbody" name\="annotationbody">\n</template><template autoinsert\="true" context\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock">// ${todo} Auto-generated catch block\n${exception_var}.printStackTrace();</template><template autoinsert\="true" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">// ${todo} Auto-generated method stub\n${body_statement}</template><template autoinsert\="true" context\="constructorbody_context" deleted\="false" description\="Code in created constructor stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name\="constructorbody">${body_statement}\n// ${todo} Auto-generated constructor stub</template><template autoinsert\="true" context\="getterbody_context" deleted\="false" description\="Code in created getters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.getterbody" name\="getterbody">return ${field};</template><template autoinsert\="true" context\="setterbody_context" deleted\="false" description\="Code in created setters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.setterbody" name\="setterbody">${field} \= ${param};</template></templates>
sp_cleanup.add_default_serial_version_id=true
sp_cleanup.add_generated_serial_version_id=false
sp_cleanup.add_missing_annotations=true
sp_cleanup.add_missing_deprecated_annotations=true
sp_cleanup.add_missing_methods=false
sp_cleanup.add_missing_nls_tags=false
sp_cleanup.add_missing_override_annotations=true
sp_cleanup.add_missing_override_annotations_interface_methods=true
sp_cleanup.add_serial_version_id=false
sp_cleanup.always_use_blocks=true
sp_cleanup.always_use_parentheses_in_expressions=false
sp_cleanup.always_use_this_for_non_static_field_access=false
sp_cleanup.always_use_this_for_non_static_method_access=false
sp_cleanup.convert_to_enhanced_for_loop=false
sp_cleanup.correct_indentation=false
sp_cleanup.format_source_code=true
sp_cleanup.format_source_code_changes_only=true
sp_cleanup.make_local_variable_final=false
sp_cleanup.make_parameters_final=false
sp_cleanup.make_private_fields_final=true
sp_cleanup.make_type_abstract_if_missing_method=false
sp_cleanup.make_variable_declarations_final=true
sp_cleanup.never_use_blocks=false
sp_cleanup.never_use_parentheses_in_expressions=true
sp_cleanup.on_save_use_additional_actions=false
sp_cleanup.organize_imports=true
sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
sp_cleanup.qualify_static_member_accesses_with_declaring_class=false
sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
sp_cleanup.remove_private_constructors=true
sp_cleanup.remove_trailing_whitespaces=false
sp_cleanup.remove_trailing_whitespaces_all=true
sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
sp_cleanup.remove_unnecessary_casts=true
sp_cleanup.remove_unnecessary_nls_tags=false
sp_cleanup.remove_unused_imports=false
sp_cleanup.remove_unused_local_variables=false
sp_cleanup.remove_unused_private_fields=true
sp_cleanup.remove_unused_private_members=false
sp_cleanup.remove_unused_private_methods=true
sp_cleanup.remove_unused_private_types=true
sp_cleanup.sort_members=false
sp_cleanup.sort_members_all=false
sp_cleanup.use_blocks=false
sp_cleanup.use_blocks_only_for_return_and_throw=false
sp_cleanup.use_parentheses_in_expressions=false
sp_cleanup.use_this_for_non_static_field_access=false
sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true
sp_cleanup.use_this_for_non_static_method_access=false
sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true
/*
* 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;
import java.util.LinkedList;
import java.util.List;
import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.GlobalComponent;
/**
* Components have to register at the binder to be accessible from the other
* side of the API.
*
* @author Bjoern Richerzhagen
*
*/
public class Binder {
private static final List<GlobalComponent> components = new LinkedList<GlobalComponent>();
/**
* Returns the given component (only global components!)
*
* @param componentClass
* @return
*/
public static <T extends GlobalComponent> T getComponent(
Class<T> componentClass) throws ComponentNotAvailableException {
for (GlobalComponent component : components) {
if (componentClass.isInstance(component)) {
return componentClass.cast(component);
}
}
throw new ComponentNotAvailableException();
}
// /**
// * Returns all global components matching the interface
// *
// * @param componentClass
// * @return
// */
// public static <T extends GlobalComponent> List<T> getComponents(
// Class<T> componentClass) throws ComponentNotAvailableException {
// List<T> match = new LinkedList<T>();
// for (GlobalComponent component : components) {
// if (componentClass.isInstance(component)) {
// match.add(componentClass.cast(component));
// }
// }
// if (match.isEmpty()) {
// throw new ComponentNotAvailableException();
// } else {
// return match;
// }
// }
/**
* Register a global component (i.e., a component that is not instantiated
* on a per-host basis)
*
* @param component
*/
public static <T extends GlobalComponent> void registerComponent(T component) {
if (!components.contains(component)) {
components.add(component);
System.out.println("Registering Component in Binder: "
+ component.toString());
} else {
throw new UnsupportedOperationException("The component "
+ component.toString() + " is already registered!");
}
}
}
/*
* 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;
import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.core.SchedulerComponent;
/**
* Lightweight variant to an operation: an event. The Event is scheduled,
* executes some code and then terminates. No callback, no expected result, no
* typing. It is that simple.
*
* @author Bjoern Richerzhagen
*
*/
public final class Event {
private static SchedulerComponent scheduler = null;
private static SchedulerComponent getScheduler() {
if (scheduler == null) {
try {
scheduler = Binder.getComponent(SchedulerComponent.class);
} catch (ComponentNotAvailableException e) {
throw new AssertionError();
}
}
return scheduler;
}
/**
*
* @param handler
* @param content
*/
public static void scheduleImmediately(EventHandler handler,
Object content, int type) {
getScheduler().scheduleIn(0, handler, content, type);
}
/**
*
* @param time
* @param handler
* @param content
* @param type
* a int-type field for easier filtering of events. You should
* define the ints as constants in your EventHandlers.
*/
public static void scheduleWithDelay(long time, EventHandler handler,
Object content, int type) {
getScheduler().scheduleIn(time, handler, content, type);
}
}
/*
* Copyright (c) 2005-2011 KOM - Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.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;
/**
*
* The event handler is notified upon incoming events.
*
* @author Bjoern Richerzhagen
*
*/
public interface EventHandler {
/**
* This method passes an occurred Event to its appropriate EventHandler
*
* @param content
*/
public void eventOccurred(Object content, int type);
}
/*
* 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;
import java.util.List;
import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.HostComponent;
import de.tudarmstadt.maki.simonstrator.api.component.network.NetworkComponent;
import de.tudarmstadt.maki.simonstrator.api.component.transport.TransportComponent;
/**
* Host Interface for the Simonstrator, handles binding of per-host components
*
* @author Bjoern Richerzhagen
*
*/
public interface Host {
/**
* Returns the given component (only per-host components!). Global
* components need to be accessed via {@link Global}. Ensure, that you cache
* the result of this method locally (i.e., if you query for the transport
* layer, save it as an instance variable!), as too frequent calls to this
* method might result in degraded performance.
*
* @param componentClass
* @throws ComponentNotAvailableException
* if the component is not available
* @return
*/
public <T extends HostComponent> T getComponent(Class<T> componentClass)
throws ComponentNotAvailableException;
/**
* Register a host component (i.e., a component that is instantiated per
* host)
*
* @param component
*/
public <T extends HostComponent> void registerComponent(T component);
/**
* Returns a list of all components providing the given API
*
* @param componentClass
* @return
* @throws ComponentNotAvailableException
* if no component with the given API is available
*/
public <T extends HostComponent> List<T> getComponents(
Class<T> componentClass) throws ComponentNotAvailableException;
/*
* Convenience Methods
*/
/**
* Use the {@link TransportComponent} to send and receive messages. Binding
* should be done once in the initialize()-Method of the respective overlay
* node.
*
* @return
*/
public TransportComponent getTransportComponent();
/**
* The {@link NetworkComponent} enables access to all phyiscal connectivity
* options provided by the host.
*
* @return
*/
public NetworkComponent getNetworkComponent();
/**
* This method has to return a unique id for a host. Uniqueness even in a
* distributed system should be ensured with high probability.
*
* @return
*/
public long getHostId();
}
/*
* Copyright (c) 2005-2011 KOM - Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.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;
import java.io.Serializable;
/**
* General message interface for all messages exchanged between inside of the
* same layer in the simulator. Each layer and component will have their own
* sub-interface or implementation of this class.
*
* @author Konstantin Pussep
* @author Sebastian Kaune
* @version 3.0, 03.12.2007
*
*/
public interface Message extends Serializable {
/**
* Returns the message size in bytes
*
* @return message size in bytes
*/
public long getSize();
/**
* Returns the payload of a message
*
* @return payload of message
*/
public Message getPayload();
}
/*
* 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;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.List;
import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.core.MonitorComponent;
import de.tudarmstadt.maki.simonstrator.api.component.core.MonitorComponent.Analyzer;
import de.tudarmstadt.maki.simonstrator.api.component.core.MonitorComponent.AnalyzerNotAvailableException;
/**
* Bridge to local Monitoring on each Runtime.
*
* TODO: maybe we can include some basic logging-functionality in here as well,
* to be platform-independend.
*
* @author Bjoern Richerzhagen
*
*/
public final class Monitor {
private static MonitorComponent monitor = null;
private static MonitorComponent getMonitor() {
if (monitor == null) {
try {
monitor = Binder.getComponent(MonitorComponent.class);
} catch (ComponentNotAvailableException e) {
throw new AssertionError();
}
}
return monitor;
}
/**
* Logs a message to the platform-logger
*
* @param subject
* @param message
*/
public static void log(Class<?> subject, String message) {
getMonitor().log(subject, message);
}
/**
* Retrieve an analyzing-Interface (transparent multiplexing is performed,
* if multiple analyzers with the same interface are registered)
*
* @param analyzerType
* @return
* @throws AnalyzerNotAvailableException
*/
public static <A extends Analyzer> A get(Class<A> analyzerType)
throws AnalyzerNotAvailableException {
List<A> analyzers = getMonitor().getAnalyzers(analyzerType);
if (analyzers.size() == 1) {
// Do not depend on proxy
return analyzers.iterator().next();
}
// create proxy
Class<?>[] proxyInterfaces = new Class[]{analyzerType};
A proxy = (A) Proxy.newProxyInstance(analyzerType.getClassLoader(),
proxyInterfaces, new Delegator<A>(analyzers));
return proxy;
}
/**
* Transparent Proxy for calls to the analyzers
*
* @author bjoern
*
*/
protected static class Delegator<A extends Analyzer> implements
InvocationHandler {
private final List<A> analyzers;
public Delegator(List<A> analyzers) {
this.analyzers = analyzers;
}
@Override
public Object invoke(Object proxy, Method m, Object[] args)
throws Throwable {
for (A analyzer : analyzers) {
m.invoke(analyzer, args);
}
return null;
}
}
}
/*
* 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;
import java.util.List;
import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.core.OracleComponent;
/**
*
* @author Bjoern Richerzhagen
*
*/
public final class Oracle {
/*
* Provide meaningful Oracle via the oracle component
*/
private static OracleComponent oracle = null;
private static OracleComponent getOracle() {
if (oracle == null) {
try {
oracle = Binder.getComponent(OracleComponent.class);
} catch (ComponentNotAvailableException e) {
throw new AssertionError();
}
}
return oracle;
}
/**
* Access to all host objects. This is usually only available in a
* simulation environment.
*
* @return
*/
public static List<Host> getAllHosts() {
return getOracle().getAllHosts();
}
}
/*
* 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;
import java.util.Random;
import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.core.RandomGeneratorComponent;
/**
* Use this class to access random numbers. Do not use Math.random, as
* simulations will not be deterministic in this case!
*
* @author Bjoern Richerzhagen
*
*/
public final class Randoms {
/**
*
*/
public static RandomGeneratorComponent bindedRandom = null;
private static RandomGeneratorComponent getRandomGeneratorComponent() {
if (bindedRandom == null) {
try {
bindedRandom = Binder
.getComponent(RandomGeneratorComponent.class);
} catch (ComponentNotAvailableException e) {
throw new AssertionError("No Random Generator found!");
}
}
return bindedRandom;
}
/**
* Returns a random-generator for the given component
*
* @param topic
* for each new topic, a new source of random numbers is
* generated. A topic could, thus, be a given overlay node.
* @return
*/
public static Random getRandom(Object topic) {
return getRandomGeneratorComponent().getRandom(topic);
}
}
/*
* 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;
import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.core.TimeComponent;
/**
* Definition of time constants used for scaling and definition of the current
* time. Whenever times are calculated throughout the overlay/service/app, it
* has to be done based on these relative units!
*
* @author Bjoern Richerzhagen
*
*/
public final class Time {
/**
* A microsecond
*/
public final static long MICROSECOND = 1l;
/**
* A millisecond
*/
public final static long MILLISECOND = 1000l * MICROSECOND;
/**
* A second
*/
public final static long SECOND = 1000l * MILLISECOND;
/**
* A minute
*/
public final static long MINUTE = 60l * SECOND;
/**
* These constant should be ALWAYS used for virtual time calculations.
*/
public final static long HOUR = 60l * MINUTE;
public static final double NANOSECOND = 0.001d;
/**
*
*/
public static TimeComponent bindedTime = null;
private static TimeComponent getTimeComponent() {
if (bindedTime == null) {
try {
bindedTime = Binder.getComponent(TimeComponent.class);
} catch (ComponentNotAvailableException e) {
throw new AssertionError("No Time provider found!");
}
}
return bindedTime;
}
/**
* Returns the current unified time (i.e., in simulations the simTime and in
* real deployments the synchronized system time)
*
* @return time
*/
public static long getCurrentTime() {
return getTimeComponent().getCurrentTime();
}
/**
* Convenience method returning the current time as a readable string
*
* @return
*/
public static String getFormattedTime() {
return getFormattedTime(getCurrentTime());
}
/**
* Parse a time from a string containing units, i.e., 2s or 4h or 10ms or
* 1m.
*
* @param value
* @return
*/
public static long parseTime(String value) {
if (value.matches("\\d+(ms|s|m|h)")) {
String number;
long factor;
if (value.matches("\\d+(ms)")) {
number = value.substring(0, value.length() - 2);
factor = Time.MILLISECOND;
} else {
number = value.substring(0, value.length() - 1);
factor = 1;
char unit = value.charAt(value.length() - 1);
switch (unit) {
case 'h':
factor = Time.HOUR;
break;
case 'm':
factor = Time.MINUTE;
break;
case 's':
factor = Time.SECOND;
break;
default:
throw new IllegalStateException("time unit " + unit
+ " is not allowed");
}
}
return factor * Long.valueOf(number);
} else {
throw new AssertionError("Not a valid Time!");
}
}
/**
* Convenience method returning the given time as a readable string
*
* @param time
* @return
*/
public static String getFormattedTime(long time) {
return getHours(time) + ":" + getSimMinutes(time) % 60 + ":"
+ getSimSeconds(time) % 60 + ":" + getSimMilliSeconds(time)
% 1000 + " (H:m:s:ms)";
}
private static long getSimMilliSeconds(long time) {
return Math.round(Math.floor((double) time / Time.MILLISECOND));
}
private static long getSimSeconds(long time) {
return Math.round(Math.floor(getSimMilliSeconds(time) / 1000d));
}
private static long getSimMinutes(long time) {
return Math.round(Math.floor(getSimSeconds(time) / 60d));
}
private static long getHours(long time) {
return Math.round(Math.floor(getSimMinutes(time) / 60d));
}
}
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.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.common;
import java.io.Serializable;
import java.math.BigDecimal;
import java.math.BigInteger;
import de.tudarmstadt.maki.simonstrator.api.component.network.NetID;
/**
* An IDSpace Object should be passed to every Overlay upon configuration. This
* will ensure proper generation of OverlayIDs and OverlayKeys. By specifying
* multiple IDSpaces for one Overlay you might implement different Spaces for
* Keys and IDs (if that makes any sense at all). Please have a look at the
* DefaultIDSpace-Class
*
* @author Bjoern Richerzhagen
* @version 1.0, 06/18/2011
*/
public interface IDSpace extends Serializable{
/**
* Get the number of Bits used for IDs in this IDSpace
*
* @return
*/
public int getNumberOfBits();
/**
* Number of bytes used by an ID in this Space
*
* @return
*/
public int getNumberOfBytes();
/**
* Return the number of Distinct IDs (2^numberOfBits)
*
* @return
*/
public BigInteger getNumberOfDistinctIDs();
/**
* This will return a UniqueID to be used for Empty-IDs
*
* @return
*/
public UniqueID getEmptyID();
/**
* Create a new ID using the BigInteger provided
*
* @param bigInt
* @return
*/
public UniqueID createID(BigInteger bigInt);
/**
* Create a new ID using the BigDecimal provided
*
* @param bigDec
* @return
*/
public UniqueID createID(BigDecimal bigDec);
/**
* Convenience Method to create an ID based on a NetID. In the default
* implementation, this will hash the NetID using SHA1
*
* @param netID
* @return
*/
public UniqueID createID(NetID netID);
/**
* Convenience Method to create an ID from a String using SHA1.
*
* @param stringToHash
* @return
*/
public UniqueID createIDUsingSHA1(String stringToHash);
/**
* Returns a pseudorandom ID
*
* @return
*/
public UniqueID createRandomID();
/**
* returns true, if test lies between a and b, taking into account, that the
* ID-Space is circular
*
* @param test
* @param a
* @param b
* @return
*/
public boolean isBetween(UniqueID test, UniqueID a, UniqueID b);
/**
* Compute the numerical distance between a and b, and return the shortest
* distance (clockwise or counterclockwise)
*
* @param a
* @param b
* @return
*/
public BigInteger getMinDistance(UniqueID a, UniqueID b);
/**
* Compute the numerical distance between a and b in clockwise direction
*
* @param a
* @param b
* @return
*/
public BigInteger getClockwiseDistance(UniqueID a, UniqueID b);
/**
* Compute the numerical distance between a and b in counter-clockwise
* direction
*
* @param a
* @param b
* @return
*/
public BigInteger getCounterClockwiseDistance(UniqueID a, UniqueID b);
/**
* Returns the ith digit of the ID (in base 2^b). i=0 returns the least
* significant digit.
*
* @param i
* @return the ith digit of the ID (in base 2^b)
*/
public int getDigit(UniqueID id, int i, int b);
/**
* Returns the index of the most significant different digit (MSDD) in a
* given base b.
*
* @param id
* first ID
* @param otherId
* another node id to compare with.
* @param b
* base is 2^b
* @return the index of the MSDD (0 is the least significant) / will return
* negative if they do not differ.
*/
public int indexOfMSDD(UniqueID id, UniqueID otherId, int b);
}
/*
* Copyright (c) 2005-2011 KOM - Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.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.common;
/**
* Used for entities that might be transmitted as part of a message
*
* @author Julius Rueckert
*/
public interface Transmitable {
/**
* @return the transmission size of this entity in byte
*/
public int getTransmissionSize();
}
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.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.common;
import java.io.Serializable;
import java.math.BigDecimal;
import java.math.BigInteger;
/**
* An ID within a IDSpace
*
* @author Bjoern Richerzhagen
* @version 1.0, 06/18/2011
*/
public interface UniqueID extends Transmitable, Comparable<UniqueID>,
Serializable {
/**
* Return the IDSpace this ID came from
*
* @return
*/
public IDSpace getIDSpace();
/**
* Representation as a BigInteger
*
* @return
*/
public BigInteger getBigInteger();
/**
* Representation as a BigDecimal
*
* @return
*/
public BigDecimal getBigDecimal();
/**
* Returns a double value >=0 and <1, which resembles the given
* key. The returned double is the closest double value to this UniqueID,
* divided by maximumID+1(=numberOfDistinctIDs). Note that two distinct
* UniqueIDs may return the same double value, if they are very close together.
* @return
*/
public double getDouble();
}
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.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.common.metric;
import de.tudarmstadt.maki.simonstrator.api.common.metric.Metric.MetricValue;
/**
* A metric that is actively updated (for example based on a sampling interval).
* Normally, only derived metrics (i.e. metrics that passed through a filter)
* should be active metrics, but in some cases overlays might want to provide
* metrics that are updated on specific operations.
*
* @author Bjoern Richerzhagen
* @version 1.0, 13.08.2012
*/
public interface ActiveMetric<M extends MetricValue<?>> extends Metric<M> {
/**
* Add a listener that is informed whenever the metric is updated
*
* @param listener
*/
public void addActiveMetricListener(ActiveMetricListener listener);
/**
* Listener that is informed whenever the {@link ActiveMetric} is updated.
*
* @author Bjoern Richerzhagen
* @version 1.0, 13.08.2012
*/
public interface ActiveMetricListener {
/**
* The given metric was updated
*
* @param metric
*/
public void onMetricUpdate(ActiveMetric<?> metric);
}
}
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.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.common.metric;
import java.util.List;
import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.common.metric.Metric.MetricValue;
/**
* This allows metrics to be defined without a specific analyzer or output-type
* in mind (DB, CSV, Live...). Use in conjunction with the
* {@link MetricAnalyzer}. This is intended for overlay or app-specific metrics
* that are very hard to measure using the normal Analyzer-Interfaces for
* messages or operations.
*
* @author Bjoern Richerzhagen
* @version 1.0, 07.08.2012
*/
public interface Metric<M extends MetricValue<?>> {
/**
* Units for your metrics.
*
* @author Bjoern Richerzhagen
* @version 1.0, 08.08.2012
*/
public enum MetricUnit {
NONE(""), TRAFFIC("byte/s"), TIME("us"), DATA(
"byte"), UNKNOWN("unknown");
private final String representation;
private MetricUnit(String representation) {
this.representation = representation;
}
@Override
public String toString() {
return representation;
}
}
/**
* Called as soon as the Monitor starts.
*
* @param host
*/
public void initialize(List<Host> hosts);
/**
* Values for all hosts by hostId. If this is provided, getOverallMetric
* should return null.
*
* @return map or null, if the metric is not defined as a per-host metric
* (for example "numberOfOnlineHosts")
*/
public M getPerHostMetric(Host host);
/**
* List of all Per-Host metrics
*
* @return
*/
public List<M> getAllPerHostMetrics();
/**
* Value of the Metric aggregated for all hosts. If this is provided,
* getPerHostMetric should return null.
*
* @return value or null, if the metric can not be aggregated in a
* meaningful way.
*/
public M getOverallMetric();
/**
* Has to return true, if the metric is an overall metric (not per host)
*
* @return
*/
public boolean isOverallMetric();
/**
* Name of the Metric - should be an unique identifier
*
* @return
*/
public String getName();
/**
* A more descriptive name or text of the metric
*
* @return
*/
public String getDescription();
/**
* Unit the metric is measured in
*
* @return
*/
public MetricUnit getUnit();
/**
* Value of a metric. The {@link Metric}-concept implies that the
* aggregation of values is to be handled by the analyzer that calls
* getValue().
*
* For OverallMetrics (i.e. metrics that are already available as an
* aggregate), you should also implement toString in a meaningful way, as
* this string will be used by the live monitor.
*
* @author Bjoern Richerzhagen
* @version 1.0, 07.08.2012
* @param <T>
*/
public interface MetricValue<T> {
/**
* Value of the metric, call this before checking isValid!
*
* @return
*/
public T getValue();
/**
* True, if the value is valid and should be used, false otherwise. This
* might be used to exclude values from offline hosts. You have to call
* getValue before calling this method!
*
* @return
*/
public boolean isValid();
}
}
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