From: <jsa...@us...> - 2008-10-26 10:59:24
|
Revision: 37 http://flexotask.svn.sourceforge.net/flexotask/?rev=37&view=rev Author: jsauerbach Date: 2008-10-26 10:58:00 +0000 (Sun, 26 Oct 2008) Log Message: ----------- Initial import into repository Added Paths: ----------- trunk/flexotask-functiontest/.classpath trunk/flexotask-functiontest/.externalToolBuilders/ trunk/flexotask-functiontest/.externalToolBuilders/Build Flexotask Template Generators.launch trunk/flexotask-functiontest/.project trunk/flexotask-functiontest/.settings/ trunk/flexotask-functiontest/.settings/org.eclipse.jdt.ui.prefs trunk/flexotask-functiontest/export.manifest trunk/flexotask-functiontest/export.xml trunk/flexotask-functiontest/generators.xml trunk/flexotask-functiontest/launch/ trunk/flexotask-functiontest/launch/Export Flexotask Function Test for Runtime.launch trunk/flexotask-functiontest/launch/Run Flexotask Function Test Under Eclipse.launch trunk/flexotask-functiontest/src/ trunk/flexotask-functiontest/src/alltests/ trunk/flexotask-functiontest/src/alltests/Testcases.java trunk/flexotask-functiontest/src/communicating/ trunk/flexotask-functiontest/src/communicating/Example.ftg trunk/flexotask-functiontest/src/communicating/InputHandler.java trunk/flexotask-functiontest/src/communicating/Main.java trunk/flexotask-functiontest/src/communicating/OutputHandler.java trunk/flexotask-functiontest/src/communicating/T1.java trunk/flexotask-functiontest/src/communicating/T2.java trunk/flexotask-functiontest/src/communicating/T3.java trunk/flexotask-functiontest/src/highfreqread/ trunk/flexotask-functiontest/src/highfreqread/Channel.java trunk/flexotask-functiontest/src/highfreqread/HighFreqReader.java trunk/flexotask-functiontest/src/highfreqread/HighFreqReaderIntf.java trunk/flexotask-functiontest/src/highfreqread/Main.java trunk/flexotask-functiontest/src/highfreqread/MemoryAllocator.java trunk/flexotask-functiontest/src/highfreqread/State.java trunk/flexotask-functiontest/src/lctes2007/ trunk/flexotask-functiontest/src/lctes2007/Actuator.java trunk/flexotask-functiontest/src/lctes2007/Compute.java trunk/flexotask-functiontest/src/lctes2007/Example.ftg trunk/flexotask-functiontest/src/lctes2007/Generator.java trunk/flexotask-functiontest/src/lctes2007/Main.java trunk/flexotask-functiontest/src/lctes2007/Sensor.java trunk/flexotask-functiontest/src/modes/ trunk/flexotask-functiontest/src/modes/DownCounter.java trunk/flexotask-functiontest/src/modes/Equals.java trunk/flexotask-functiontest/src/modes/Example.ftg trunk/flexotask-functiontest/src/modes/Generator.java trunk/flexotask-functiontest/src/modes/Main.java trunk/flexotask-functiontest/src/modes/Report.java trunk/flexotask-functiontest/src/modes/UpCounter.java trunk/flexotask-functiontest/src/types/ trunk/flexotask-functiontest/src/types/DataSink.java trunk/flexotask-functiontest/src/types/DataSource.java trunk/flexotask-functiontest/src/types/Main.java Property Changed: ---------------- trunk/flexotask-functiontest/ Property changes on: trunk/flexotask-functiontest ___________________________________________________________________ Added: svn:ignore + generated *.jar Added: trunk/flexotask-functiontest/.classpath =================================================================== --- trunk/flexotask-functiontest/.classpath (rev 0) +++ trunk/flexotask-functiontest/.classpath 2008-10-26 10:58:00 UTC (rev 37) @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="src"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="con" path="com.ibm.realtime.flexotask.editor.classpath/1.0"/> + <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> + <classpathentry kind="output" path="bin"/> +</classpath> Added: trunk/flexotask-functiontest/.externalToolBuilders/Build Flexotask Template Generators.launch =================================================================== --- trunk/flexotask-functiontest/.externalToolBuilders/Build Flexotask Template Generators.launch (rev 0) +++ trunk/flexotask-functiontest/.externalToolBuilders/Build Flexotask Template Generators.launch 2008-10-26 10:58:00 UTC (rev 37) @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="UTF-8"?> +<launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType"> +<booleanAttribute key="org.eclipse.ant.ui.ATTR_TARGETS_UPDATED" value="true"/> +<booleanAttribute key="org.eclipse.ant.ui.DEFAULT_VM_INSTALL" value="false"/> +<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS"> +<listEntry value="/flexotask-functiontest/generators.xml"/> +</listAttribute> +<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES"> +<listEntry value="1"/> +</listAttribute> +<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/> +<booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/> +<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/> +<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="true"/> +<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="flexotask-functiontest"/> +<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/flexotask-functiontest/generators.xml}"/> +<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value=""/> +<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/> +<stringAttribute key="org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY" value="${workspace_loc:/flexotask-functiontest}"/> +</launchConfiguration> Added: trunk/flexotask-functiontest/.project =================================================================== --- trunk/flexotask-functiontest/.project (rev 0) +++ trunk/flexotask-functiontest/.project 2008-10-26 10:58:00 UTC (rev 37) @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>flexotask-functiontest</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.ui.externaltools.ExternalToolBuilder</name> + <triggers>full,incremental,</triggers> + <arguments> + <dictionary> + <key>LaunchConfigHandle</key> + <value><project>/.externalToolBuilders/Build Flexotask Template Generators.launch</value> + </dictionary> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>FlexotaskBuilder.builder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.jdt.core.javanature</nature> + <nature>FlexotaskBuilder.nature</nature> + </natures> +</projectDescription> Added: trunk/flexotask-functiontest/.settings/org.eclipse.jdt.ui.prefs =================================================================== --- trunk/flexotask-functiontest/.settings/org.eclipse.jdt.ui.prefs (rev 0) +++ trunk/flexotask-functiontest/.settings/org.eclipse.jdt.ui.prefs 2008-10-26 10:58:00 UTC (rev 37) @@ -0,0 +1,3 @@ +#Wed Oct 22 15:27:15 EDT 2008 +eclipse.preferences.version=1 +org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8"?><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">/**\r\n * @return the ${bare_field_name}\r\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">/**\r\n * @param ${param} the ${bare_field_name} to set\r\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">/**\r\n * ${tags}\r\n */</template><template autoinsert\="false" context\="filecomment_context" deleted\="false" description\="Comment for created Java files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.filecomment" name\="filecomment">/*\r\n * This file is part of Flexible Task Graphs\r\n * (http\://sourceforge.net/projects/flexotasks)\r\n *\r\n * Copyright (c) 2006 - 2008 IBM Corporation.\r\n * All rights reserved. This program and the accompanying materials\r\n * are made available under the terms of the Eclipse Public License v1.0\r\n * which accompanies this distribution, and is available at\r\n * http\://www.eclipse.org/legal/epl-v10.html\r\n *\r\n * Contributors\:\r\n * IBM Corporation - initial API and implementation\r\n */\r\n</template><template autoinsert\="false" context\="typecomment_context" deleted\="false" description\="Comment for created types" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.typecomment" name\="typecomment">/**\r\n * ${tags}\r\n */</template><template autoinsert\="false" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment">/** */</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">/**\r\n * ${tags}\r\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)\r\n * ${see_to_overridden}\r\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">/**\r\n * ${tags}\r\n * ${see_to_target}\r\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">/*\r\n * This file is part of Flexible Task Graphs\r\n * (http\://sourceforge.net/projects/flexotasks)\r\n *\r\n * Copyright (c) 2006 - 2008 IBM Corporation.\r\n * All rights reserved. This program and the accompanying materials\r\n * are made available under the terms of the Eclipse Public License v1.0\r\n * which accompanies this distribution, and is available at\r\n * http\://www.eclipse.org/legal/epl-v10.html\r\n *\r\n * Contributors\:\r\n * IBM Corporation - initial API and implementation\r\n */\r\n${package_declaration}\r\n\r\n${typecomment}\r\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">\r\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">\r\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">\r\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">\r\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\r\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\r\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}\r\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> Added: trunk/flexotask-functiontest/export.manifest =================================================================== --- trunk/flexotask-functiontest/export.manifest (rev 0) +++ trunk/flexotask-functiontest/export.manifest 2008-10-26 10:58:00 UTC (rev 37) @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: alltests.Testcases +Class-Path: junit.jar Added: trunk/flexotask-functiontest/export.xml =================================================================== --- trunk/flexotask-functiontest/export.xml (rev 0) +++ trunk/flexotask-functiontest/export.xml 2008-10-26 10:58:00 UTC (rev 37) @@ -0,0 +1,13 @@ +<project default="jars"> + <target name="clean"> + <delete file="flexotaskFunctionTest.jar"/> + </target> + <target name="jars" depends="clean"> + <jar destfile="flexotaskFunctionTest.jar" manifest="export.manifest"> + <fileset dir="generated"/> + </jar> + <jar destfile="flexotaskFunctionTest.jar" update="yes" duplicate="preserve"> + <fileset dir="bin"/> + </jar> + </target> +</project> \ No newline at end of file Property changes on: trunk/flexotask-functiontest/export.xml ___________________________________________________________________ Added: svn:mime-type + text/xml Added: svn:eol-style + native Added: trunk/flexotask-functiontest/generators.xml =================================================================== --- trunk/flexotask-functiontest/generators.xml (rev 0) +++ trunk/flexotask-functiontest/generators.xml 2008-10-26 10:58:00 UTC (rev 37) @@ -0,0 +1,24 @@ +<project default="graphs"> + <target name="graphs"> + <java classname="com.ibm.realtime.flexotask.tools.FlexotaskXMLParser" + dir="${basedir}/src/lctes2007/" fork="yes"> + <classpath> + <pathelement path="${flexotask.library}"/> + </classpath> + <arg value="Example.ftg"/> + <arg value="Generator"/> + <arg value="lctes2007"/> + </java> + <java classname="com.ibm.realtime.flexotask.tools.FlexotaskXMLParser" + dir="${basedir}/src/modes/" fork="yes"> + <classpath> + <pathelement path="${flexotask.library}"/> + </classpath> + <arg value="Example.ftg"/> + <arg value="Generator"/> + <arg value="modes"/> + </java> + <eclipse.convertPath fileSystemPath="${basedir}" property="resourcePath"/> + <eclipse.refreshLocal resource="${resourcePath}" depth="infinite"/> + </target> +</project> \ No newline at end of file Property changes on: trunk/flexotask-functiontest/generators.xml ___________________________________________________________________ Added: svn:mime-type + text/xml Added: svn:eol-style + native Added: trunk/flexotask-functiontest/launch/Export Flexotask Function Test for Runtime.launch =================================================================== --- trunk/flexotask-functiontest/launch/Export Flexotask Function Test for Runtime.launch (rev 0) +++ trunk/flexotask-functiontest/launch/Export Flexotask Function Test for Runtime.launch 2008-10-26 10:58:00 UTC (rev 37) @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="UTF-8"?> +<launchConfiguration type="org.eclipse.ant.AntLaunchConfigurationType"> +<stringAttribute key="bad_container_name" value="\flexotask-functiontest\launc"/> +<booleanAttribute key="org.eclipse.ant.ui.DEFAULT_VM_INSTALL" value="true"/> +<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS"> +<listEntry value="/flexotask-functiontest/export.xml"/> +</listAttribute> +<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES"> +<listEntry value="1"/> +</listAttribute> +<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/> +<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/> +<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.ant.internal.ui.antsupport.InternalAntRunner"/> +<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="flexotask-functiontest"/> +<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/> +<stringAttribute key="org.eclipse.jdt.launching.VM_INSTALL_NAME" value="IBM-J9"/> +<stringAttribute key="org.eclipse.jdt.launching.VM_INSTALL_TYPE_ID" value="org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType"/> +<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/flexotask-functiontest/export.xml}"/> +<stringAttribute key="process_factory_id" value="org.eclipse.ant.ui.remoteAntProcessFactory"/> +</launchConfiguration> Added: trunk/flexotask-functiontest/launch/Run Flexotask Function Test Under Eclipse.launch =================================================================== --- trunk/flexotask-functiontest/launch/Run Flexotask Function Test Under Eclipse.launch (rev 0) +++ trunk/flexotask-functiontest/launch/Run Flexotask Function Test Under Eclipse.launch 2008-10-26 10:58:00 UTC (rev 37) @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8"?> +<launchConfiguration type="org.eclipse.jdt.junit.launchconfig"> +<stringAttribute key="bad_container_name" value="\flexotask-functiontest\launc"/> +<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS"> +<listEntry value="/flexotask-functiontest"/> +</listAttribute> +<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES"> +<listEntry value="4"/> +</listAttribute> +<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/> +<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value="=flexotask-functiontest"/> +<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/> +<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/> +<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/> +<listAttribute key="org.eclipse.jdt.launching.CLASSPATH"> +<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry containerPath="org.eclipse.jdt.launching.JRE_CONTAINER" javaProject="flexotask-functiontest" path="1" type="4"/> "/> +<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry internalArchive="/flexotask-functiontest/generated" path="3" type="2"/> "/> +<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry id="org.eclipse.jdt.launching.classpathentry.defaultClasspath"> <memento exportedEntriesOnly="false" project="flexotask-functiontest"/> </runtimeClasspathEntry> "/> +</listAttribute> +<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="false"/> +<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value=""/> +<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="flexotask-functiontest"/> +</launchConfiguration> Added: trunk/flexotask-functiontest/src/alltests/Testcases.java =================================================================== --- trunk/flexotask-functiontest/src/alltests/Testcases.java (rev 0) +++ trunk/flexotask-functiontest/src/alltests/Testcases.java 2008-10-26 10:58:00 UTC (rev 37) @@ -0,0 +1,102 @@ +/* + * This file is part of Flexible Task Graphs + * (http://sourceforge.net/projects/flexotasks) + * + * Copyright (c) 2006 - 2008 IBM Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + */ +package alltests; + +import java.io.IOException; + +import javax.xml.parsers.ParserConfigurationException; + +import org.junit.Test; +import org.junit.internal.runners.TextListener; +import org.junit.runner.Description; +import org.junit.runner.JUnitCore; +import org.junit.runner.notification.Failure; +import org.junit.runner.notification.RunListener; +import org.xml.sax.SAXException; + +import com.ibm.realtime.flexotask.template.FlexotaskValidationException; + +/** + * Testcases for the Flexible Task Graphs System + */ +public class Testcases +{ + /* TODO these tests only fail by crashing or throwing exceptions: more self-checking is needed */ + @Test + public void testCommunicating() throws FlexotaskValidationException, + SAXException, IOException, ParserConfigurationException + { + communicating.Main.main(new String[0]); + } + + @Test + public void testHighfreqread() throws FlexotaskValidationException, + InterruptedException, IOException + { + highfreqread.Main.main(new String[] { "500" }); + } + + @Test + public void testLctes2007() throws FlexotaskValidationException, + InterruptedException + { + lctes2007.Main.main(new String[0]); + } + + @Test + public void testModes() throws FlexotaskValidationException, + InterruptedException + { + modes.Main.main(new String[0]); + } + + @Test + public void testTypes() throws SAXException, IOException, + ParserConfigurationException, FlexotaskValidationException, + InterruptedException + { + types.Main.main(new String[0]); + } + + /** + * Method to test in a non-eclipse environment (e.g. a realtime VM) + */ + public static void main(String[] args) { + RunListener listener = new BatchRunListener(); + JUnitCore runner = new JUnitCore(); + runner.addListener(listener); + runner.run(Testcases.class); + } + + /** + * A RunListener for batch mode operation + */ + private static class BatchRunListener extends TextListener + { + public void testFailure(Failure failure) + { + System.err.println("Test failed: " + failure.getTestHeader() + ". More details later."); + } + + public void testIgnored(Description description) + { + System.err.println("Test ignored: " + description); + } + + public void testStarted(Description description) + { + System.err.println("Starting test: " + description); + } + } +} Property changes on: trunk/flexotask-functiontest/src/alltests/Testcases.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: trunk/flexotask-functiontest/src/communicating/Example.ftg =================================================================== --- trunk/flexotask-functiontest/src/communicating/Example.ftg (rev 0) +++ trunk/flexotask-functiontest/src/communicating/Example.ftg 2008-10-26 10:58:00 UTC (rev 37) @@ -0,0 +1,33 @@ +<FlexotaskTemplate> + <TimingProvider kind='simple' parser='com.ibm.realtime.flexotask.timing.simple.SimpleTimingDataParser' graphics='100 60 344 59' period='50'/> + <Task id='T3' implementation='communicating.T3' graphics='60 60 468 188'> + <Input id='in' type='java.lang.Integer'/> + <Output id='out' type='java.lang.Integer'/> + <Timing offsets='40'/> + </Task> + <Task id='T2' implementation='communicating.T2' graphics='60 60 326 188'> + <Input id='in' type='java.lang.Integer'/> + <Output id='out' type='java.lang.Integer'/> + <Timing offsets='30'/> + </Task> + <Task id='T1' implementation='communicating.T1' graphics='60 60 176 188'> + <Input id='in' type='java.lang.Integer'/> + <Output id='out' type='java.lang.Integer'/> + <Timing offsets='10'/> + </Task> + <Task id='Input' implementation='communicating.InputHandler' isolation='weak' graphics='60 60 41 188'> + <Output id='out0' type='java.lang.Integer'/> + </Task> + <Task id='Output' implementation='communicating.OutputHandler' isolation='weak' graphics='60 60 614 188'> + <Input id='in0' type='java.lang.Integer'/> + <Timing offsets='50'/> + </Task> + <Connection id='T1_T2' source='T1' target='T2'> + </Connection> + <Connection id='T3_Output' source='T3' target='Output'> + </Connection> + <Connection id='T2_T3' source='T2' target='T3'> + </Connection> + <Connection id='Input_T1' source='Input' target='T1'> + </Connection> +</FlexotaskTemplate> Added: trunk/flexotask-functiontest/src/communicating/InputHandler.java =================================================================== --- trunk/flexotask-functiontest/src/communicating/InputHandler.java (rev 0) +++ trunk/flexotask-functiontest/src/communicating/InputHandler.java 2008-10-26 10:58:00 UTC (rev 37) @@ -0,0 +1,34 @@ +/* + * This file is part of Flexible Task Graphs + * (http://sourceforge.net/projects/flexotasks) + * + * Copyright (c) 2006 - 2008 IBM Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + */ +package communicating; + +import com.ibm.realtime.flexotask.Flexotask; +import com.ibm.realtime.flexotask.FlexotaskInputPort; +import com.ibm.realtime.flexotask.FlexotaskOutputPort; + +public class InputHandler implements Flexotask +{ + public int[] valueBuffer; + private FlexotaskOutputPort<Integer> out0; + public void execute() + { + out0.setValue(valueBuffer[0]); + } + @SuppressWarnings("unchecked") + public void initialize(FlexotaskInputPort[] inputPorts, FlexotaskOutputPort[] outputPorts, Object parameter) + { + out0 = outputPorts[0]; + valueBuffer = (int[]) parameter; + } +} Property changes on: trunk/flexotask-functiontest/src/communicating/InputHandler.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: trunk/flexotask-functiontest/src/communicating/Main.java =================================================================== --- trunk/flexotask-functiontest/src/communicating/Main.java (rev 0) +++ trunk/flexotask-functiontest/src/communicating/Main.java 2008-10-26 10:58:00 UTC (rev 37) @@ -0,0 +1,79 @@ +/* + * This file is part of Flexible Task Graphs + * (http://sourceforge.net/projects/flexotasks) + * + * Copyright (c) 2006 - 2008 IBM Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + */ +package communicating; + +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; +import java.util.Map; + +import javax.xml.parsers.ParserConfigurationException; + +import org.xml.sax.SAXException; + +import com.ibm.realtime.flexotask.FlexotaskGraph; +import com.ibm.realtime.flexotask.FlexotaskRunner; +import com.ibm.realtime.flexotask.template.FlexotaskTemplate; +import com.ibm.realtime.flexotask.template.FlexotaskValidationException; +import com.ibm.realtime.flexotask.tools.FlexotaskXMLParser; + +public class Main { + public static void main(String[] args) throws FlexotaskValidationException, SAXException, IOException, + ParserConfigurationException + { + // create the communication buffers + int[] sensor = new int[] {0}; + int[] actuator = new int[] {-1}; + + // build the graph + InputStream in = Main.class.getResourceAsStream("Example.ftg"); + FlexotaskTemplate spec = FlexotaskXMLParser.parseStream(in); + Map<String,Object> parameters = new HashMap<String,Object>(); + parameters.put("Input", sensor); + parameters.put("Output", actuator); + FlexotaskGraph graph = spec.validate("TTScheduler", parameters); + + //retrieve the Runner + FlexotaskRunner runner = graph.getRunner(); + + for (int i = 0; i < 3; i++) { + /* Do start/run/stop sequence three times. */ + /* Start the graph running */ + System.err.println("Starting graph"); + runner.start(); + try { + // sleep for at least one period so actuator value will be available + Thread.sleep(100); + } catch (InterruptedException e1) {} + + for (int j = 1; j < 100; j++) { + System.err.println("Feeding " + j); + sensor[0] = j; + System.err.print("Reading "); + System.err.println(actuator[0]); + try { + Thread.sleep(50); + } catch (InterruptedException e) {} + } + System.err.println("Stopping graph"); + runner.stop(); + try { + // Let the pause be noticed + Thread.sleep(1000); + } catch (InterruptedException e1) {} + } + System.err.println("Shutting down"); + runner.shutdown(); + } +} Property changes on: trunk/flexotask-functiontest/src/communicating/Main.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: trunk/flexotask-functiontest/src/communicating/OutputHandler.java =================================================================== --- trunk/flexotask-functiontest/src/communicating/OutputHandler.java (rev 0) +++ trunk/flexotask-functiontest/src/communicating/OutputHandler.java 2008-10-26 10:58:00 UTC (rev 37) @@ -0,0 +1,34 @@ +/* + * This file is part of Flexible Task Graphs + * (http://sourceforge.net/projects/flexotasks) + * + * Copyright (c) 2006 - 2008 IBM Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + */ +package communicating; + +import com.ibm.realtime.flexotask.Flexotask; +import com.ibm.realtime.flexotask.FlexotaskInputPort; +import com.ibm.realtime.flexotask.FlexotaskOutputPort; + +public class OutputHandler implements Flexotask +{ + public int[] valueBuffer; + private FlexotaskInputPort<Integer> in0; + public void execute() + { + valueBuffer[0] = in0.getValue(); + } + @SuppressWarnings("unchecked") + public void initialize(FlexotaskInputPort[] inputPorts, FlexotaskOutputPort[] outputPorts, Object parameter) + { + in0 = inputPorts[0]; + valueBuffer = (int[]) parameter; + } +} Property changes on: trunk/flexotask-functiontest/src/communicating/OutputHandler.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: trunk/flexotask-functiontest/src/communicating/T1.java =================================================================== --- trunk/flexotask-functiontest/src/communicating/T1.java (rev 0) +++ trunk/flexotask-functiontest/src/communicating/T1.java 2008-10-26 10:58:00 UTC (rev 37) @@ -0,0 +1,37 @@ +/* + * This file is part of Flexible Task Graphs + * (http://sourceforge.net/projects/flexotasks) + * + * Copyright (c) 2006 - 2008 IBM Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + */ +package communicating; + +import com.ibm.realtime.flexotask.Flexotask; +import com.ibm.realtime.flexotask.FlexotaskInputPort; +import com.ibm.realtime.flexotask.FlexotaskOutputPort; + +public class T1 implements Flexotask { + private FlexotaskInputPort<Integer> in; + private FlexotaskOutputPort<Integer> out; + + public void execute() + { + int val = in.getValue(); + out.setValue(val + 1); + } + + @SuppressWarnings("unchecked") + public void initialize(FlexotaskInputPort[] inputPorts, FlexotaskOutputPort[] outputPorts, Object parameter) + { + in = inputPorts[0]; + out = outputPorts[0]; + out.setValue(new Integer(0)); + } +} Property changes on: trunk/flexotask-functiontest/src/communicating/T1.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: trunk/flexotask-functiontest/src/communicating/T2.java =================================================================== --- trunk/flexotask-functiontest/src/communicating/T2.java (rev 0) +++ trunk/flexotask-functiontest/src/communicating/T2.java 2008-10-26 10:58:00 UTC (rev 37) @@ -0,0 +1,37 @@ +/* + * This file is part of Flexible Task Graphs + * (http://sourceforge.net/projects/flexotasks) + * + * Copyright (c) 2006 - 2008 IBM Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + */ +package communicating; + +import com.ibm.realtime.flexotask.Flexotask; +import com.ibm.realtime.flexotask.FlexotaskInputPort; +import com.ibm.realtime.flexotask.FlexotaskOutputPort; + +public class T2 implements Flexotask { + private FlexotaskInputPort<Integer> in; + private FlexotaskOutputPort<Integer> out; + + public void execute() + { + int val = in.getValue(); + out.setValue(2 * val); + } + + @SuppressWarnings("unchecked") + public void initialize(FlexotaskInputPort[] inputPorts, FlexotaskOutputPort[] outputPorts, Object parameter) + { + in = inputPorts[0]; + out = outputPorts[0]; + out.setValue(new Integer(0)); + } +} Property changes on: trunk/flexotask-functiontest/src/communicating/T2.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: trunk/flexotask-functiontest/src/communicating/T3.java =================================================================== --- trunk/flexotask-functiontest/src/communicating/T3.java (rev 0) +++ trunk/flexotask-functiontest/src/communicating/T3.java 2008-10-26 10:58:00 UTC (rev 37) @@ -0,0 +1,37 @@ +/* + * This file is part of Flexible Task Graphs + * (http://sourceforge.net/projects/flexotasks) + * + * Copyright (c) 2006 - 2008 IBM Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + */ +package communicating; + +import com.ibm.realtime.flexotask.Flexotask; +import com.ibm.realtime.flexotask.FlexotaskInputPort; +import com.ibm.realtime.flexotask.FlexotaskOutputPort; + +public class T3 implements Flexotask { + private FlexotaskInputPort<Integer> in; + private FlexotaskOutputPort<Integer> out; + + public void execute() + { + int val = in.getValue(); + out.setValue(val - 1); + } + + @SuppressWarnings("unchecked") + public void initialize(FlexotaskInputPort[] inputPorts, FlexotaskOutputPort[] outputPorts, Object parameter) + { + in = inputPorts[0]; + out = outputPorts[0]; + out.setValue(new Integer(0)); + } +} Property changes on: trunk/flexotask-functiontest/src/communicating/T3.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: trunk/flexotask-functiontest/src/highfreqread/Channel.java =================================================================== --- trunk/flexotask-functiontest/src/highfreqread/Channel.java (rev 0) +++ trunk/flexotask-functiontest/src/highfreqread/Channel.java 2008-10-26 10:58:00 UTC (rev 37) @@ -0,0 +1,23 @@ +/* + * This file is part of Flexible Task Graphs + * (http://sourceforge.net/projects/flexotasks) + * + * Copyright (c) 2006 - 2008 IBM Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + */ +package highfreqread; + +public class Channel +{ + public short value; + public short read() + { + return value; + } +} Property changes on: trunk/flexotask-functiontest/src/highfreqread/Channel.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: trunk/flexotask-functiontest/src/highfreqread/HighFreqReader.java =================================================================== --- trunk/flexotask-functiontest/src/highfreqread/HighFreqReader.java (rev 0) +++ trunk/flexotask-functiontest/src/highfreqread/HighFreqReader.java 2008-10-26 10:58:00 UTC (rev 37) @@ -0,0 +1,64 @@ +/* + * This file is part of Flexible Task Graphs + * (http://sourceforge.net/projects/flexotasks) + * + * Copyright (c) 2006 - 2008 IBM Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + */ +package highfreqread; + +import java.util.ArrayList; +import java.util.List; + +import com.ibm.realtime.flexotask.AtomicException; +import com.ibm.realtime.flexotask.AtomicFlexotask; +import com.ibm.realtime.flexotask.FlexotaskInputPort; +import com.ibm.realtime.flexotask.FlexotaskOutputPort; +import com.ibm.realtime.flexotask.util.ESystem; + +public class HighFreqReader extends AtomicFlexotask implements HighFreqReaderIntf +{ + private static final boolean DEBUG = false; + private State state; + int idx; + public void execute() + { + List<Short> data = new ArrayList<Short>(); + for(int i=0;i<state.size();i++) { + data.add(state.current.read()); + } + state.update(data); + if (DEBUG) { + ESystem.err.println("Updated"); + idx++; + ESystem.err.println("Incremented"); + idx = idx % state.size(); + ESystem.err.println("Wrapped"); + Channel[] channels = state.channels; + ESystem.err.println("Got channels"); + Channel current = channels[idx]; + ESystem.err.println("Got current"); + state.current = current; + ESystem.err.println("Execution complete"); + } else { + state.current = state.channels[idx++ % state.size()]; + } + } + @SuppressWarnings("unchecked") + public void initialize(FlexotaskInputPort[] inputPorts, + FlexotaskOutputPort[] outputPorts, Object parameter) + { + int size = ((Integer) parameter); + state = new State(size); + } + public void update(short value) throws AtomicException + { + state.current.value = value; + } +} Property changes on: trunk/flexotask-functiontest/src/highfreqread/HighFreqReader.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: trunk/flexotask-functiontest/src/highfreqread/HighFreqReaderIntf.java =================================================================== --- trunk/flexotask-functiontest/src/highfreqread/HighFreqReaderIntf.java (rev 0) +++ trunk/flexotask-functiontest/src/highfreqread/HighFreqReaderIntf.java 2008-10-26 10:58:00 UTC (rev 37) @@ -0,0 +1,21 @@ +/* + * This file is part of Flexible Task Graphs + * (http://sourceforge.net/projects/flexotasks) + * + * Copyright (c) 2006 - 2008 IBM Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + */ +package highfreqread; + +import com.ibm.realtime.flexotask.AtomicException; +import com.ibm.realtime.flexotask.ExternalMethods; + +public interface HighFreqReaderIntf extends ExternalMethods { + public void update(short value) throws AtomicException; +} Property changes on: trunk/flexotask-functiontest/src/highfreqread/HighFreqReaderIntf.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: trunk/flexotask-functiontest/src/highfreqread/Main.java =================================================================== --- trunk/flexotask-functiontest/src/highfreqread/Main.java (rev 0) +++ trunk/flexotask-functiontest/src/highfreqread/Main.java 2008-10-26 10:58:00 UTC (rev 37) @@ -0,0 +1,136 @@ +/* + * This file is part of Flexible Task Graphs + * (http://sourceforge.net/projects/flexotasks) + * + * Copyright (c) 2006 - 2008 IBM Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + */ +package highfreqread; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import org.junit.Test; + +import com.ibm.realtime.flexotask.AtomicException; +import com.ibm.realtime.flexotask.FlexotaskGraph; +import com.ibm.realtime.flexotask.system.FlexotaskValidator; +import com.ibm.realtime.flexotask.template.FlexotaskStableMode; +import com.ibm.realtime.flexotask.template.FlexotaskTaskTemplate; +import com.ibm.realtime.flexotask.template.FlexotaskTemplate; +import com.ibm.realtime.flexotask.template.FlexotaskValidationException; +import com.ibm.realtime.flexotask.timing.simple.Period; +import com.ibm.realtime.flexotask.timing.simple.SimpleTimingAnnotation; +import com.ibm.realtime.flexotask.tracing.InterarrivalTracer; +import com.ibm.realtime.flexotask.tracing.IntervalStatistics; +import com.ibm.realtime.flexotask.tracing.TaskByNameTracerFactory; +import com.ibm.realtime.flexotask.tuningfork.TFTracerFactory; + +public class Main +{ + public static void main(String[] args) + throws FlexotaskValidationException, InterruptedException, IOException + { + /* 1st argument is period in microseconds, no default */ + int period; + if (args.length > 0) { + period = Integer.parseInt(args[0]); + } else { + System.err.println("Syntax: <pgm> period [ othreadsleep [ duration ] ]"); + System.err.println("Also system properties ALLOCATION_RATE, COMMUNICATE, and DISABLE_SAFE_POINT_DEFERRAL"); + throw new IllegalArgumentException(); + } + /* 2nd argument is o-thread sleep interval in milliseconds, default is 20 */ + int oThreadSleep = 20; + if (args.length > 1) { + oThreadSleep = Integer.parseInt(args[1]); + } + /* 3rd argument is length of run in seconds, default is 20 */ + int runlength = 20; + if (args.length > 2) { + runlength = Integer.parseInt(args[2]); + } + + /* Make the graph specification */ + FlexotaskTemplate spec = new FlexotaskTemplate(); + spec.setTimingData(new Period(period*1000)); + FlexotaskTaskTemplate task = new FlexotaskTaskTemplate(); + task.setImplementationClass(HighFreqReader.class.getName()); + task.setName("Test"); + task.setTimingData(new SimpleTimingAnnotation(new long[]{0})); + spec.getTasks().add(task); + spec.setStableMode(FlexotaskStableMode.MANUAL); + Set<String> stable = spec.getStableClasses(); + stable.add(HighFreqReader.class.getName()); + stable.add(Channel.class.getName()); + stable.add(Channel[].class.getName()); + stable.add(State.class.getName()); + + /* Determine if TF tracing is requested and enable it (only tracing to port is supported) */ + String tracing = System.getProperty("TF_TRACE"); + if (tracing != null && tracing.length() > 0) { + int port = Integer.parseInt(tracing); + FlexotaskValidator.setTracer(new TFTracerFactory(port)); + } else { + /* Use interarrival tracer instead */ + int reportAt = (int)((long) runlength * 1000 * 1000 / period); + int jitter = period / 20; + long[] range = {period - jitter, period + jitter}; + IntervalStatistics stats = new IntervalStatistics("Test", reportAt, new long[][]{range}); + InterarrivalTracer tracer = new InterarrivalTracer(stats, stats); + TaskByNameTracerFactory factory = new TaskByNameTracerFactory(1, false); + factory.addTask("Test", tracer); + FlexotaskValidator.setTracer(factory); + } + + /* Start competing allocation thread to cause frequent GCs */ + String alloc = System.getProperty("ALLOCATION_RATE"); + if (alloc != null && alloc.length() > 0) { + int rate = Integer.parseInt(alloc); + MemoryAllocator.setupMemoryAllocation(rate * 1024); + } + + /* Determine if the the o-thread will attempt communication, default is yes */ + boolean communicate = Boolean.valueOf(System.getProperty("COMMUNICATE", "true")).booleanValue(); + + System.gc(); + + /* Make the graph */ + Map<String,Object> parameters = new HashMap<String,Object>(); + parameters.put("Test", new Integer(4)); + FlexotaskGraph graph = spec.validate("TTScheduler", parameters); + + /* Run the highfreqread */ + graph.getRunner().start(); + HighFreqReaderIntf guard = (HighFreqReaderIntf) graph.getGuardObject("Test"); + + System.err.println("Graph started"); + int sleepsPerSecond = 1000 / oThreadSleep; + for (int i = 0; i < runlength * 1000 / oThreadSleep; i++) { + Thread.sleep(oThreadSleep); + if (communicate) { + try { + guard.update((short) i); + } catch (AtomicException e) { + System.err.println("Transaction " + i + " aborted"); + } catch (Exception e) { + e.printStackTrace(); + } + } + if (i % sleepsPerSecond == 0) { + System.err.println(i + (communicate ? " updates" : " waits")); + } + } + System.err.println("Destroying graph"); + graph.destroy(); + System.err.println("Done"); + } +} Property changes on: trunk/flexotask-functiontest/src/highfreqread/Main.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: trunk/flexotask-functiontest/src/highfreqread/MemoryAllocator.java =================================================================== --- trunk/flexotask-functiontest/src/highfreqread/MemoryAllocator.java (rev 0) +++ trunk/flexotask-functiontest/src/highfreqread/MemoryAllocator.java 2008-10-26 10:58:00 UTC (rev 37) @@ -0,0 +1,349 @@ +/* + * This file is part of Flexible Task Graphs + * (http://sourceforge.net/projects/flexotasks) + * + * Copyright (c) 2006 - 2008 IBM Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + */ +package highfreqread; + +/** + * A class that allows to allocate memory for simulating regular memory + * consumption. This can serve to activate the gc. + * + * @author florian + */ +public class MemoryAllocator { + + /** + * debugging flag + */ + public static boolean DEBUG_ALLOCATETHREAD = false; + + /** + * the allocation rate in bytes/second + */ + private int allocationRate; + + /** + * The size of each created object, in bytes + */ + private int allocateObjectSize = 48; + + /** + * Number of objects whose reference is kept in an array + */ + private int referenceObjectCount = 150000; + + /** + * The thread instance + */ + private AllocateThread thread; + + /** + * total number of allocated objects + */ + private int totalAllocatedObjects = 0; + + private int currentRetention = 0; + + public static MemoryAllocator staticAllocator; + + public static void setupMemoryAllocation(int allocationRate) { + staticAllocator = new MemoryAllocator(allocationRate); + staticAllocator.setEnabled(true); + + } + + /** + * Create a disabled MemoryAllocator instance + */ + public MemoryAllocator(int allocationRate) { + this.allocationRate = allocationRate; + } + + /** + * trigger the thread's change() method + */ + private synchronized void change() { + if (thread != null) { + thread.change(); + } + } + + /** + * Enable the memory allocator. If enable is true, the allocate thread is + * created and it will start allocating memory. + * + * @param enable if true, start the allocator, otherwise stop it and remove + * the thread + */ + public synchronized void setEnabled(boolean enable) { + if (isEnabled() != enable) { + if (enable) { + thread = new AllocateThread(); + } else { + thread.stopAllocator(); + thread = null; + totalAllocatedObjects = 0; + currentRetention = 0; + } + } + } + + /** + * @return true if the allocator is running + */ + public synchronized boolean isEnabled() { + return (thread != null); + } + + /** + * @return the allocateObjectSize in bytes + */ + public int getAllocateObjectSize() { + return allocateObjectSize; + } + + /** + * @param allocateObjectSize the allocateObjectSize to set in bytes + */ + public void setAllocateObjectSize(int allocateObjectSize) { + this.allocateObjectSize = allocateObjectSize; + change(); + } + + /** + * @return the allocationRate in bytes/second + */ + public int getAllocationRate() { + return allocationRate; + } + + /** + * @param allocationRate the allocationRate to set in bytes/second + */ + public void setAllocationRate(int allocationRate) { + this.allocationRate = allocationRate; + change(); + } + + /** + * @return number of objects kept in an array + */ + public int getReferenceObjectCount() { + return referenceObjectCount; + } + + /** + * @param referenceObjectCount the referenceObjectCount to set + */ + public void setReferenceObjectCount(int referenceObjectCount) { + this.referenceObjectCount = referenceObjectCount; + change(); + } + + // status + + /** + * @return how many bytes currently held by the retention array + */ + public int getCurrentRetentionSize() { + return currentRetention; + } + + /** + * @return the total number of allocated objects + */ + public int getTotalAllocatedObjects() { + return totalAllocatedObjects; + } + + /** + * The actual allocator thread. + */ + private class AllocateThread extends Thread { + + /** + * The number of bytes allocated in total + */ + private long totalAllocated = 0; + + /** + * flag to notify the thread to stop + */ + private volatile boolean stopped = false; + + /** + * the array to hold a reference to the last allocated objects + */ + private Object[] allocateArray = null; + + /* + * the next write index in allocateArray + */ + private int arrayIndex = 0; + + /** + * The start time of allocating with one parameter set + */ + private long checkpointMillis; + + /** + * the number of bytes allocated since the checkpoint + */ + private long allocatedSinceCheckpoint; + + /** + * Create and start the maintenance thread + */ + public AllocateThread() { + super("Allocator Thread"); + setDaemon(true); + change(); + start(); + } + + /** + * Stops and wait for the end of the execution of this thread. + */ + public void stopAllocator() { + synchronized (this) { + stopped = true; + this.notifyAll(); + } + if (isAlive()) { + try { + this.join(2000); + } catch (InterruptedException ie) { + } + } + } + + private synchronized void recalcCurrentRetention() { + currentRetention = 0; + if (allocateArray != null) { + for (int i = 0; i < allocateArray.length; i++) { + Object o = allocateArray[i]; + if (o != null) { + currentRetention += ((byte[]) o).length; + } + } + } + } + + /** + * Called to re-setup the internal runtime variables + */ + public synchronized void change() { + if (allocateArray == null + || allocateArray.length != referenceObjectCount) { + // create new array + Object[] newArray = new Object[referenceObjectCount]; + if (allocateArray != null) { + System.arraycopy(allocateArray, 0, newArray, 0, Math.min( + referenceObjectCount, allocateArray.length)); + } + allocateArray = newArray; + recalcCurrentRetention(); + } + // reset the checkpoint + checkpointMillis = System.currentTimeMillis(); + allocatedSinceCheckpoint = 0; + } + + /** + * allocate the specified number of bytes on the rcd.rtsj.heap. + */ + private synchronized void allocate(int bytes) { + Object newObject = new byte[bytes]; + if (arrayIndex >= allocateArray.length) { + arrayIndex = 0; + } + totalAllocated += bytes; + allocatedSinceCheckpoint += bytes; + totalAllocatedObjects++; + + if (allocateArray != null && arrayIndex < allocateArray.length) { + currentRetention += bytes; + if (allocateArray[arrayIndex] != null) { + currentRetention -= ((byte[]) allocateArray[arrayIndex]).length; + } + allocateArray[arrayIndex++] = newObject; + } + } + + /** + * in a loop, allocate the objects + */ + public void run() { + while (!stopped) { + try { + synchronized (this) { + long elapsedSinceCheckpoint = (System.currentTimeMillis()) + - checkpointMillis; + long shouldHaveAllocated = (long) (((double) allocationRate) * (elapsedSinceCheckpoint / 1000.0)); + // number of bytes that should be allocated now is + // the difference of shouldHaveAllocated and allocatedSinceCheckpoint + // we only allocate in chunks of allocateObjectSize + while ((shouldHaveAllocated - allocatedSinceCheckpoint) >= allocateObjectSize) { + allocate(allocateObjectSize); + } + this.wait(10); + } + } catch (Throwable t) { + System.err.println("Error in allocation thread: " + t); + t.printStackTrace(); + } + } + } + + } + + public String toString() { + return "Allocator: " + getFriendlyByteSize(getAllocationRate()) + + "/s with " + getFriendlyByteSize(getAllocateObjectSize()) + + " objects; " + getFriendlyByteSize(getCurrentRetentionSize()) + + " in use (maximum " + getFriendlyByteSize(getReferenceObjectCount() * getAllocateObjectSize()) + + ")"; + } + + /** + * @return a string with the byte size with a suitable unit, bytes, KB, etc. + */ + public static String getFriendlyByteSize(long bytes) { + long threshold = 2 << 10; + if (bytes < 4*threshold) { + return Long.toString(bytes)+" bytes"; + } + threshold = threshold << 10; + if (bytes < 4*threshold) { + return format2(bytes / 1024.0)+" KB"; + } + threshold = threshold << 10; + if (bytes < 4*threshold) { + return format2(bytes / (1024.0*1024.0))+" MB"; + } + threshold = threshold << 10; + if (bytes < 4*threshold) { + return format2(bytes / (1024.0*1024.0*1024.0))+" GB"; + } + return format2(bytes / (1024.0*1024.0*1024.0*1024.0))+" TB"; + } + + /** + * Format a floating point number with 2 decimals. + * + * @param d the number to convert to string + * @return the string with the number d with 3 decimals. + */ + public static final String format2(double d) { + return "" + (Math.rint(d * 100.0) / 100.0); + } +} Property changes on: trunk/flexotask-functiontest/src/highfreqread/MemoryAllocator.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: trunk/flexotask-functiontest/src/highfreqread/State.java =================================================================== --- trunk/flexotask-functiontest/src/highfreqread/State.java (rev 0) +++ trunk/flexotask-functiontest/src/highfreqread/State.java 2008-10-26 10:58:00 UTC (rev 37) @@ -0,0 +1,38 @@ +/* + * This file is part of Flexible Task Graphs + * (http://sourceforge.net/projects/flexotasks) + * + * Copyright (c) 2006 - 2008 IBM Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + */ +package highfreqread; + +import java.util.List; + +public class State +{ + public Channel current; + public Channel[] channels; + public State(int size) + { + channels = new Channel[size]; + for (int i = 0; i < channels.length; i++) { + channels[i] = new Channel(); + } + current = channels[0]; + } + public void update(List<Short> v) + { + // Toy + } + public int size() + { + return channels.length; + } +} Property changes on: trunk/flexotask-functiontest/src/highfreqread/State.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: trunk/flexotask-functiontest/src/lctes2007/Actuator.java =================================================================== --- trunk/flexotask-functiontest/src/lctes2007/Actuator.java (rev 0) +++ trunk/flexotask-functiontest/src/lctes2007/Actuator.java 2008-10-26 10:58:00 UTC (rev 37) @@ -0,0 +1,36 @@ +/* + * This file is part of Flexible Task Graphs + * (http://sourceforge.net/projects/flexotasks) + * + * Copyright (c) 2006 - 2008 IBM Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + */ +package lctes2007; + +import com.ibm.realtime.flexotask.Flexotask; +import com.ibm.realtime.flexotask.FlexotaskInputPort; +import com.ibm.realtime.flexotask.FlexotaskOutputPort; +import com.ibm.realtime.flexotask.util.ESystem; + +public class Actuator implements Flexotask +{ + + private FlexotaskInputPort<java.lang.Double> in0; + + @SuppressWarnings("unchecked") + public void initialize(FlexotaskInputPort[] inputs, FlexotaskOutputPort[] outputs, Object parameter) + { + in0 = inputs[0]; + } + + public void execute() + { + ESystem.out.println(in0.getValue().doubleValue()); + } +} Property changes on: trunk/flexotask-functiontest/src/lctes2007/Actuator.java ______________________________________... [truncated message content] |