From: <jsa...@us...> - 2009-02-16 21:06:07
|
Revision: 138 http://flexotask.svn.sourceforge.net/flexotask/?rev=138&view=rev Author: jsauerbach Date: 2009-02-16 21:06:02 +0000 (Mon, 16 Feb 2009) Log Message: ----------- Support the reactive scheduler with a timing grammar and editor support. Expand the nativeio testcase to meaningfully test this scheduler. Modified Paths: -------------- trunk/flexotask/META-INF/MANIFEST.MF trunk/flexotask/src/com/ibm/realtime/flexotask/scheduling/reactive/ReactiveRunnableElement.java trunk/flexotask/src/com/ibm/realtime/flexotask/scheduling/reactive/ReactiveRunner.java trunk/flexotask/src/com/ibm/realtime/flexotask/scheduling/reactive/ReactiveScheduler.java trunk/flexotask-editor/META-INF/MANIFEST.MF trunk/flexotask-editor/plugin.xml trunk/flexotask-editor/src/com/ibm/realtime/flexotask/editor/model/ModelElement.java trunk/flexotask-editor/src/com/ibm/realtime/flexotask/editor/model/TaskDiagram.java trunk/flexotask-functiontest/src/alltests/Testcases.java trunk/flexotask-functiontest/src/nativeio/Main.java Added Paths: ----------- trunk/flexotask/src/com/ibm/realtime/flexotask/ClockTask.java trunk/flexotask/src/com/ibm/realtime/flexotask/FileDescriptor.java trunk/flexotask/src/com/ibm/realtime/flexotask/scheduling/reactive/package.html trunk/flexotask/src/com/ibm/realtime/flexotask/timing/reactive/ trunk/flexotask/src/com/ibm/realtime/flexotask/timing/reactive/ClockAnnotation.java trunk/flexotask/src/com/ibm/realtime/flexotask/timing/reactive/ReactiveTiming.java trunk/flexotask/src/com/ibm/realtime/flexotask/timing/reactive/ReactiveTimingDataParser.java trunk/flexotask/src/com/ibm/realtime/flexotask/timing/reactive/package.html trunk/flexotask-editor/src/com/ibm/realtime/flexotask/editor/timing/reactive/ trunk/flexotask-editor/src/com/ibm/realtime/flexotask/editor/timing/reactive/ClockAnnotator.java trunk/flexotask-editor/src/com/ibm/realtime/flexotask/editor/timing/reactive/ReactiveGlobalTiming.java trunk/flexotask-editor/src/com/ibm/realtime/flexotask/editor/timing/reactive/ReactiveGrammarProvider.java trunk/flexotask-functiontest/src/nativeio/Reactive.ftg trunk/flexotask-functiontest/src/nativeio/Reporter.java trunk/flexotask-functiontest/src/nativeio/TestReader.java Removed Paths: ------------- trunk/flexotask/src/com/ibm/realtime/flexotask/scheduling/reactive/ReactiveTaskParameter.java Modified: trunk/flexotask/META-INF/MANIFEST.MF =================================================================== --- trunk/flexotask/META-INF/MANIFEST.MF 2009-02-16 21:04:53 UTC (rev 137) +++ trunk/flexotask/META-INF/MANIFEST.MF 2009-02-16 21:06:02 UTC (rev 138) @@ -9,9 +9,11 @@ com.ibm.realtime.flexotask.cloning, com.ibm.realtime.flexotask.distribution, com.ibm.realtime.flexotask.scheduling, + com.ibm.realtime.flexotask.scheduling.reactive, com.ibm.realtime.flexotask.scheduling.simple, com.ibm.realtime.flexotask.template, com.ibm.realtime.flexotask.timing, + com.ibm.realtime.flexotask.timing.reactive, com.ibm.realtime.flexotask.timing.simple, com.ibm.realtime.flexotask.tools, com.ibm.realtime.flexotask.tracing, Added: trunk/flexotask/src/com/ibm/realtime/flexotask/ClockTask.java =================================================================== --- trunk/flexotask/src/com/ibm/realtime/flexotask/ClockTask.java (rev 0) +++ trunk/flexotask/src/com/ibm/realtime/flexotask/ClockTask.java 2009-02-16 21:06:02 UTC (rev 138) @@ -0,0 +1,45 @@ +/* + * 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 com.ibm.realtime.flexotask; + +/** + * A simple TimeAware Flexotask that emits the "current time" (as reflected by the supplied + * FlexotaskTimer) on its single output port. To be useful, this task must be scheduled in + * a timing grammar that understands the semantic context. + */ +public class ClockTask implements TimeAware, Flexotask { + private FlexotaskTimer timer; + private FlexotaskOutputPort outputPort; + + /* (non-Javadoc) + * @see com.ibm.realtime.flexotask.TimeAware#setTimer(com.ibm.realtime.flexotask.FlexotaskTimer) + */ + public void setTimer(FlexotaskTimer timer) { + this.timer = timer; + } + + /* (non-Javadoc) + * @see com.ibm.realtime.flexotask.Flexotask#execute() + */ + public void execute() { + outputPort.setValue(Long.valueOf(timer.nanoTime())); + } + + /* (non-Javadoc) + * @see com.ibm.realtime.flexotask.Flexotask#initialize(com.ibm.realtime.flexotask.FlexotaskInputPort[], com.ibm.realtime.flexotask.FlexotaskOutputPort[], java.lang.Object) + */ + public void initialize(FlexotaskInputPort[] inputPorts, FlexotaskOutputPort[] outputPorts, Object parameter) { + outputPort = outputPorts[0]; + } +} Property changes on: trunk/flexotask/src/com/ibm/realtime/flexotask/ClockTask.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: trunk/flexotask/src/com/ibm/realtime/flexotask/FileDescriptor.java =================================================================== --- trunk/flexotask/src/com/ibm/realtime/flexotask/FileDescriptor.java (rev 0) +++ trunk/flexotask/src/com/ibm/realtime/flexotask/FileDescriptor.java 2009-02-16 21:06:02 UTC (rev 138) @@ -0,0 +1,41 @@ +/* + * 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 com.ibm.realtime.flexotask; + +/** + * A class that is useful in the context of a reactive scheduling discipline that will call a Flexotask whenever a file + * descriptor is ready. This class (which may be subclassed to provide additional information) is designed to be used + * as the Flexotask parameter (in either isolation model, since a shared reference is not required) so that the scheduler + * and the Flexotask will both know the file descriptor to be used. Appropriate use requires a timing grammar and scheduler + * that understands the intended semantics. + */ +public class FileDescriptor { + private int fileDescriptor; + + /** + * Make a new FileDescriptor object + * @param fileDescriptor the numer file descriptor wrapped by the object + */ + public FileDescriptor(int fileDescriptor) { + this.fileDescriptor = fileDescriptor; + } + + /** + * Get the numeric file descriptor wrapped by this object + * @return the intended file descriptor + */ + public int getFileDescriptor() { + return fileDescriptor; + } +} Property changes on: trunk/flexotask/src/com/ibm/realtime/flexotask/FileDescriptor.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Modified: trunk/flexotask/src/com/ibm/realtime/flexotask/scheduling/reactive/ReactiveRunnableElement.java =================================================================== --- trunk/flexotask/src/com/ibm/realtime/flexotask/scheduling/reactive/ReactiveRunnableElement.java 2009-02-16 21:04:53 UTC (rev 137) +++ trunk/flexotask/src/com/ibm/realtime/flexotask/scheduling/reactive/ReactiveRunnableElement.java 2009-02-16 21:06:02 UTC (rev 138) @@ -13,25 +13,29 @@ */ package com.ibm.realtime.flexotask.scheduling.reactive; +import com.ibm.realtime.flexotask.FileDescriptor; import com.ibm.realtime.flexotask.scheduling.ConnectionDriver; import com.ibm.realtime.flexotask.scheduling.FlexotaskController; import com.ibm.realtime.flexotask.scheduling.NonAllocatingFifo; import com.ibm.realtime.flexotask.scheduling.NonAllocatingFifoElement; import com.ibm.realtime.flexotask.template.FlexotaskTemplateElement; import com.ibm.realtime.flexotask.template.FlexotaskValidationException; +import com.ibm.realtime.flexotask.timing.FlexotaskTimingData; +import com.ibm.realtime.flexotask.timing.reactive.ClockAnnotation; import com.ibm.realtime.flexotask.util.ESystem; /** * Represents one runnable element (connection or task) for the ReactiveScheduler */ public class ReactiveRunnableElement extends NonAllocatingFifoElement { + private static final boolean DEBUG = false; private FlexotaskTemplateElement templateElement; private Runnable toRun; - private ReactiveTaskParameter parameter; + private FileDescriptor parameter; private ReactiveRunnableElement[] successors; private ReactiveRunnableElement[] predecessors; private boolean moving; - private static final boolean DEBUG = false; + private long period; /** * Make a new element for a non-source task or for a connection @@ -47,18 +51,26 @@ * Make a new element for a source task, which must actually react to input * @param element the template element for this runnable element * @param toRun the Runnable for this runnable element - * @param parameter the ReactiveTaskParameter containing the file descriptor used to dispatch this runnable + * @param parameter the parameter being passed to the task. Either task must have a ClockAnnotation or this parameter + * must be a FileDescriptor * @throws FlexotaskValidationException if the parameter is null or of the wrong type */ public ReactiveRunnableElement(FlexotaskTemplateElement element, Runnable toRun, Object parameter) throws FlexotaskValidationException { this(element, toRun); - if (parameter instanceof ReactiveTaskParameter) { - this.parameter = (ReactiveTaskParameter) parameter; + if (parameter instanceof FileDescriptor ) { + this.parameter = (FileDescriptor) parameter; } else { - throw new FlexotaskValidationException("Source task " + element.getName() + - " does not have an appropriate parameter for the reactive scheduler"); + FlexotaskTimingData timing = element.getTimingData(); + if (timing instanceof ClockAnnotation) { + period = ((ClockAnnotation) timing).getPeriod(); + } else { + throw new FlexotaskValidationException("Source task " + element.getName() + + " has neither a FileDescriptor parameter nor a clock annotation; " + + "one or the other is needed for the reactive scheduler" + ); + } } } @@ -97,13 +109,21 @@ } /** - * @return the file descriptor if this is a source task or -1 if not + * @return the file descriptor if this is a source task with a file descriptor or -1 if not */ public int getFileDescriptor() { return parameter == null ? -1 : parameter.getFileDescriptor(); } /** + * Get the period (if zero, this task is not periodic) + * @return the specified period + */ + public long getPeriod() { + return period; + } + + /** * @return the template element for this element */ public FlexotaskTemplateElement getTemplate() { Modified: trunk/flexotask/src/com/ibm/realtime/flexotask/scheduling/reactive/ReactiveRunner.java =================================================================== --- trunk/flexotask/src/com/ibm/realtime/flexotask/scheduling/reactive/ReactiveRunner.java 2009-02-16 21:04:53 UTC (rev 137) +++ trunk/flexotask/src/com/ibm/realtime/flexotask/scheduling/reactive/ReactiveRunner.java 2009-02-16 21:06:02 UTC (rev 138) @@ -22,21 +22,38 @@ * The FlexotaskRunner and FlexotaskSchedulerRunnable for the Reactive Scheduler */ public class ReactiveRunner extends FlexotaskSingleThreadRunner { - private ReactiveRunnableElement[] elements; + private ReactiveRunnableElement[] fdElements; + private ReactiveRunnableElement[] clockElements; private short[] states; + private long[] periods; + private long[] deadlines; private FlexotaskWaitSet waitSet; NonAllocatingFifo runQueue = new NonAllocatingFifo(0, ReactiveRunnableElement.class); /** * Make a ReactiveRunner from the source elements of the graph, which have the rest of the graph as successors * @param elements the elements to use + * @param clocks the number of elements that are clocks */ - public ReactiveRunner(ReactiveRunnableElement[] elements) { - this.elements = elements; - this.states = new short[elements.length]; - FlexotaskFileDescriptorState[] states = new FlexotaskFileDescriptorState[elements.length]; + public ReactiveRunner(ReactiveRunnableElement[] elements, int clocks) { + fdElements = new ReactiveRunnableElement[elements.length - clocks]; + clockElements = new ReactiveRunnableElement[clocks]; + FlexotaskFileDescriptorState[] states = new FlexotaskFileDescriptorState[fdElements.length]; + this.states = new short[fdElements.length]; + periods = new long[clockElements.length]; + deadlines = new long[clockElements.length]; + int clockIndex = 0; + int fdIndex = 0; for (int i = 0; i < elements.length; i++) { - states[i] = new FlexotaskFileDescriptorState(elements[i].getFileDescriptor(), FlexotaskFileDescriptorState.READ); + ReactiveRunnableElement element = elements[i]; + int fd = element.getFileDescriptor(); + if (fd > -1) { + fdElements[fdIndex] = element; + states[fdIndex++] = new FlexotaskFileDescriptorState(fd, FlexotaskFileDescriptorState.READ); + } else { + clockElements[clockIndex] = element; + periods[clockIndex++] = element.getPeriod(); + } } waitSet = new FlexotaskWaitSet(states); } @@ -45,14 +62,29 @@ * @see com.ibm.realtime.flexotask.scheduling.FlexotaskSingleThreadRunner#runFlexotasks(boolean) */ public boolean runFlexotasks(boolean freshRun) { + if (freshRun && deadlines.length > 0) { + long time = nanoTime(); + for (int i = 0; i < deadlines.length; i++) { + deadlines[i] = time + periods[i]; + } + } /* Wait for some input */ - waitSet.wait(-1, states); + waitSet.wait(timeToNextDeadline(), states); /* Run those tasks that are ready */ for (int i = 0; i < states.length; i++) { if (states[i] != 0) { - elements[i].run(runQueue); + fdElements[i].run(runQueue); } } + if (deadlines.length > 0) { + long time = nanoTime(); + for (int i = 0; i < deadlines.length; i++) { + if (time >= deadlines[i]) { + clockElements[i].run(runQueue); + deadlines[i] = time + periods[i]; + } + } + } /* Run the successors until quiescent */ ReactiveRunnableElement element = (ReactiveRunnableElement) runQueue.getFirst(); while (element != null) { @@ -62,4 +94,25 @@ } return false; } + + /** + * @return the number of nanoseconds until the next deadline, or -1 if there are no clocks or 0 if one or more deadlines have + * passed + */ + private long timeToNextDeadline() { + if (deadlines.length == 0) { + return -1; + } + long time = nanoTime(); + long ans = Long.MAX_VALUE; + for (int i = 0; i < deadlines.length; i++) { + if (time > deadlines[i]) { + return 0; + } + if (deadlines[i] < ans) { + ans = deadlines[i]; + } + } + return ans - time; + } } Modified: trunk/flexotask/src/com/ibm/realtime/flexotask/scheduling/reactive/ReactiveScheduler.java =================================================================== --- trunk/flexotask/src/com/ibm/realtime/flexotask/scheduling/reactive/ReactiveScheduler.java 2009-02-16 21:04:53 UTC (rev 137) +++ trunk/flexotask/src/com/ibm/realtime/flexotask/scheduling/reactive/ReactiveScheduler.java 2009-02-16 21:06:02 UTC (rev 138) @@ -28,6 +28,8 @@ 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.FlexotaskGlobalTimingData; +import com.ibm.realtime.flexotask.timing.reactive.ReactiveTiming; /** * Defines a reactive scheduler that works with any non-cyclic graph regardless of timing @@ -35,18 +37,28 @@ * as its parameter */ public class ReactiveScheduler extends AbstractScheduler { + private String rejectionReason = ""; + /* (non-Javadoc) * @see com.ibm.realtime.flexotask.scheduling.FlexotaskScheduler#getRejectionReason() */ public String getRejectionReason() { - return "Unknown error"; + return rejectionReason; } /* (non-Javadoc) * @see com.ibm.realtime.flexotask.scheduling.FlexotaskScheduler#isSchedulable(com.ibm.realtime.flexotask.template.FlexotaskTemplate, com.ibm.realtime.flexotask.scheduling.FlexotaskSchedulingData) */ public boolean isSchedulable(FlexotaskTemplate toSchedule, FlexotaskSchedulingData schedulingData) { - return true; + /* We cannot check everything here because we do not have the instantiation map. Consequently, all we check for is + * the timing grammar + */ + FlexotaskGlobalTimingData timing = toSchedule.getTimingData(); + if (timing instanceof ReactiveTiming) { + return true; + } + rejectionReason = "Graph does not use the reactive timing grammar"; + return false; } /* (non-Javadoc) @@ -82,14 +94,19 @@ if (reactiveTasks.size() == 0) { throw new FlexotaskValidationException("No reactive tasks, graph must be cyclic"); } - /* From each reactive task, record all successors, recursively */ + /* From each reactive task, record all successors, recursively. Also count the number of clock tasks */ + int nClocks = 0; for (Iterator iterator = reactiveTasks.iterator(); iterator.hasNext();) { ReactiveRunnableElement element = (ReactiveRunnableElement) iterator.next(); + if (element.getPeriod() > 0) { + nClocks++; + } recordSuccessors(element, toSchedule, elementMap, new ArrayList()); } /* The resulting structure is the core of the Runner */ ReactiveRunner toRun = - new ReactiveRunner((ReactiveRunnableElement[]) reactiveTasks.toArray(new ReactiveRunnableElement[reactiveTasks.size()])); + new ReactiveRunner((ReactiveRunnableElement[]) reactiveTasks.toArray(new ReactiveRunnableElement[reactiveTasks.size()]), + nClocks); return FlexotaskSingleThreadRunner.cloneAndStartThread(toRun, threadFactory); } Deleted: trunk/flexotask/src/com/ibm/realtime/flexotask/scheduling/reactive/ReactiveTaskParameter.java =================================================================== --- trunk/flexotask/src/com/ibm/realtime/flexotask/scheduling/reactive/ReactiveTaskParameter.java 2009-02-16 21:04:53 UTC (rev 137) +++ trunk/flexotask/src/com/ibm/realtime/flexotask/scheduling/reactive/ReactiveTaskParameter.java 2009-02-16 21:06:02 UTC (rev 138) @@ -1,21 +0,0 @@ -/* - * 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 com.ibm.realtime.flexotask.scheduling.reactive; - -/** - * Interface to be implemented by parameters passed to source tasks when using the reactive scheduler - */ -public interface ReactiveTaskParameter { - int getFileDescriptor(); -} Added: trunk/flexotask/src/com/ibm/realtime/flexotask/scheduling/reactive/package.html =================================================================== --- trunk/flexotask/src/com/ibm/realtime/flexotask/scheduling/reactive/package.html (rev 0) +++ trunk/flexotask/src/com/ibm/realtime/flexotask/scheduling/reactive/package.html 2009-02-16 21:06:02 UTC (rev 138) @@ -0,0 +1,5 @@ +<body> +Provides a reactive scheduler, which schedules "source" tasks (those with no inputs) based either on +time or on the readiness of a file descriptor, and then schedules dependent tasks based on availability +of data. Graphs must be acyclic. +</body> Property changes on: trunk/flexotask/src/com/ibm/realtime/flexotask/scheduling/reactive/package.html ___________________________________________________________________ Added: svn:mime-type + text/html Added: svn:eol-style + native Added: trunk/flexotask/src/com/ibm/realtime/flexotask/timing/reactive/ClockAnnotation.java =================================================================== --- trunk/flexotask/src/com/ibm/realtime/flexotask/timing/reactive/ClockAnnotation.java (rev 0) +++ trunk/flexotask/src/com/ibm/realtime/flexotask/timing/reactive/ClockAnnotation.java 2009-02-16 21:06:02 UTC (rev 138) @@ -0,0 +1,58 @@ +/* + * 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 com.ibm.realtime.flexotask.timing.reactive; + +import com.ibm.realtime.flexotask.timing.FlexotaskTimingData; +import com.ibm.realtime.flexotask.timing.FlexotaskTimingDataParser; + +/** + * The reactive grammer permits source tasks (those with no input ports) to be declared as clocks. These have an output port + * of type Long on which time can be sent. The clock task is called by the reactive scheduler on a time-periodic basis even + * though the rest of the graph is scheduled reactively. It is as if there were an external clock being read in the same way + * that file descriptors are read, even though that is not actually what is happening. + */ +public class ClockAnnotation extends FlexotaskTimingData { + private long period; + + /** + * Make a new ClockAnnotation + * @param period the period to use + */ + public ClockAnnotation(long period) { + this.period = period; + } + + /* (non-Javadoc) + * @see com.ibm.realtime.flexotask.timing.FlexotaskTimingData#generateSource() + */ + public String generateSource() { + return new StringBuffer().append("new ").append(ClockAnnotation.class.getName()).append("(") + .append(period).append("L)").toString(); + } + + /* (non-Javadoc) + * @see com.ibm.realtime.flexotask.timing.FlexotaskTimingData#generateXML() + */ + public String generateXML() { + StringBuilder ans = new StringBuilder("<Timing period='").append(FlexotaskTimingDataParser.formatTime(period)); + return ans.append("'/>").toString(); + } + + /** + * @return the period in nanoseconds + */ + public long getPeriod() { + return period; + } +} Property changes on: trunk/flexotask/src/com/ibm/realtime/flexotask/timing/reactive/ClockAnnotation.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: trunk/flexotask/src/com/ibm/realtime/flexotask/timing/reactive/ReactiveTiming.java =================================================================== --- trunk/flexotask/src/com/ibm/realtime/flexotask/timing/reactive/ReactiveTiming.java (rev 0) +++ trunk/flexotask/src/com/ibm/realtime/flexotask/timing/reactive/ReactiveTiming.java 2009-02-16 21:06:02 UTC (rev 138) @@ -0,0 +1,58 @@ +/* + * 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 com.ibm.realtime.flexotask.timing.reactive; + +import com.ibm.realtime.flexotask.template.FlexotaskTemplate; +import com.ibm.realtime.flexotask.template.FlexotaskValidationException; +import com.ibm.realtime.flexotask.timing.FlexotaskGlobalTimingData; + +/** + * A very simple timing grammar for use with the rudimentary reactive scheduler. Permits + * some source tasks to be designated as clocks. + */ +public class ReactiveTiming extends FlexotaskGlobalTimingData { + /** + * Override to indicate that this grammar does not (yet) implement composition + * @see com.ibm.realtime.flexotask.timing.FlexotaskGlobalTimingData#completeComposition(com.ibm.realtime.flexotask.template.FlexotaskTemplate, com.ibm.realtime.flexotask.template.FlexotaskTemplate, com.ibm.realtime.flexotask.template.FlexotaskTemplate) + */ + public void completeComposition(FlexotaskTemplate composed, FlexotaskTemplate one, FlexotaskTemplate two) + throws FlexotaskValidationException + { + throw new FlexotaskValidationException("Composition not implemented"); + } + + /* (non-Javadoc) + * @see com.ibm.realtime.flexotask.timing.FlexotaskGlobalTimingData#isComposableWith(com.ibm.realtime.flexotask.timing.FlexotaskGlobalTimingData) + */ + public boolean isComposableWith(FlexotaskGlobalTimingData partner) { + return partner instanceof ReactiveTiming; + } + + /* (non-Javadoc) + * @see com.ibm.realtime.flexotask.timing.FlexotaskTimingData#generateSource() + */ + public String generateSource() { + return new StringBuffer().append("new ").append(ReactiveTiming.class.getName()).append("()").toString(); + } + + /* (non-Javadoc) + * @see com.ibm.realtime.flexotask.timing.FlexotaskTimingData#generateXML() + */ + public String generateXML() { + StringBuilder ans = new StringBuilder("<TimingProvider kind='reactive' parser='"); + ans.append(ReactiveTimingDataParser.class.getName()).append("'"); + addGraphicsXML(ans); + return ans.append("/>").toString(); + } +} Property changes on: trunk/flexotask/src/com/ibm/realtime/flexotask/timing/reactive/ReactiveTiming.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: trunk/flexotask/src/com/ibm/realtime/flexotask/timing/reactive/ReactiveTimingDataParser.java =================================================================== --- trunk/flexotask/src/com/ibm/realtime/flexotask/timing/reactive/ReactiveTimingDataParser.java (rev 0) +++ trunk/flexotask/src/com/ibm/realtime/flexotask/timing/reactive/ReactiveTimingDataParser.java 2009-02-16 21:06:02 UTC (rev 138) @@ -0,0 +1,57 @@ +/* + * 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 com.ibm.realtime.flexotask.timing.reactive; + +import org.w3c.dom.Element; + +import com.ibm.realtime.flexotask.template.FlexotaskValidationException; +import com.ibm.realtime.flexotask.timing.FlexotaskGlobalTimingData; +import com.ibm.realtime.flexotask.timing.FlexotaskTimingData; +import com.ibm.realtime.flexotask.timing.FlexotaskTimingDataParser; + +/** + * An essentially trivial parser for the reactive timing grammar + */ +public class ReactiveTimingDataParser extends FlexotaskTimingDataParser { + /* (non-Javadoc) + * @see com.ibm.realtime.flexotask.timing.FlexotaskTimingDataParser#parseConnectionAnnotation(org.w3c.dom.Element, java.lang.String) + */ + public FlexotaskTimingData parseConnectionAnnotation(Element element, String locus) throws FlexotaskValidationException { + if (element == null) { + return null; + } + throw new FlexotaskValidationException("Reactive timing grammar does not accept annotations on connections"); + } + + /* (non-Javadoc) + * @see com.ibm.realtime.flexotask.timing.FlexotaskTimingDataParser#parseGraphAnnotation(org.w3c.dom.Element) + */ + public FlexotaskGlobalTimingData parseGraphAnnotation(Element element) throws FlexotaskValidationException { + return new ReactiveTiming(); + } + + /* (non-Javadoc) + * @see com.ibm.realtime.flexotask.timing.FlexotaskTimingDataParser#parseTaskAnnotation(org.w3c.dom.Element, java.lang.String) + */ + public FlexotaskTimingData parseTaskAnnotation(Element element, String locus) throws FlexotaskValidationException { + if (element == null) { + return null; + } + String period = element.getAttribute("period"); + if (period == null || period.length() == 0) { + throw new FlexotaskValidationException("Unrecognized timing annotation for reactive grammar"); + } + return new ClockAnnotation(parseTime(period)); + } +} Property changes on: trunk/flexotask/src/com/ibm/realtime/flexotask/timing/reactive/ReactiveTimingDataParser.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: trunk/flexotask/src/com/ibm/realtime/flexotask/timing/reactive/package.html =================================================================== --- trunk/flexotask/src/com/ibm/realtime/flexotask/timing/reactive/package.html (rev 0) +++ trunk/flexotask/src/com/ibm/realtime/flexotask/timing/reactive/package.html 2009-02-16 21:06:02 UTC (rev 138) @@ -0,0 +1,5 @@ +<body> +Provides a reactive timing grammar for use with the reactive scheduler. Allows "clock" tasks to +be identified and associated with a period of execution. Source tasks associated with file descriptors +are not annotated, and no annotations appear on any connections or interior tasks. +</body> Property changes on: trunk/flexotask/src/com/ibm/realtime/flexotask/timing/reactive/package.html ___________________________________________________________________ Added: svn:mime-type + text/html Added: svn:eol-style + native Modified: trunk/flexotask-editor/META-INF/MANIFEST.MF =================================================================== --- trunk/flexotask-editor/META-INF/MANIFEST.MF 2009-02-16 21:04:53 UTC (rev 137) +++ trunk/flexotask-editor/META-INF/MANIFEST.MF 2009-02-16 21:06:02 UTC (rev 138) @@ -12,6 +12,7 @@ com.ibm.realtime.flexotask.editor.model, com.ibm.realtime.flexotask.editor.model.commands, com.ibm.realtime.flexotask.editor.parts, + com.ibm.realtime.flexotask.editor.timing.reactive, com.ibm.realtime.flexotask.editor.timing.simple Require-Bundle: com.ibm.realtime.flexotask.generic, com.ibm.realtime.flexotask, Modified: trunk/flexotask-editor/plugin.xml =================================================================== --- trunk/flexotask-editor/plugin.xml 2009-02-16 21:04:53 UTC (rev 137) +++ trunk/flexotask-editor/plugin.xml 2009-02-16 21:06:02 UTC (rev 138) @@ -91,4 +91,13 @@ class="com.ibm.realtime.flexotask.editor.dialogs.OpenRuntimeProvider"> </handler> </extension> + <extension + id="com.ibm.realtime.flexotask.editor.timing.reactive" + name="Reactive Timing Grammar Provider" + point="com.ibm.realtime.flexotask.editor.TimingGrammar"> + <handler + class="com.ibm.realtime.flexotask.editor.timing.reactive.ReactiveGrammarProvider" + kind="Reactive Timing"> + </handler> + </extension> </plugin> Modified: trunk/flexotask-editor/src/com/ibm/realtime/flexotask/editor/model/ModelElement.java =================================================================== --- trunk/flexotask-editor/src/com/ibm/realtime/flexotask/editor/model/ModelElement.java 2009-02-16 21:04:53 UTC (rev 137) +++ trunk/flexotask-editor/src/com/ibm/realtime/flexotask/editor/model/ModelElement.java 2009-02-16 21:06:02 UTC (rev 138) @@ -245,6 +245,7 @@ if (labels.size() == 0) { toolTip = null; color = okColor; + firePropertyChange(COLOR_PROP, null, color); return; } toolTip = new Panel(); Modified: trunk/flexotask-editor/src/com/ibm/realtime/flexotask/editor/model/TaskDiagram.java =================================================================== --- trunk/flexotask-editor/src/com/ibm/realtime/flexotask/editor/model/TaskDiagram.java 2009-02-16 21:04:53 UTC (rev 137) +++ trunk/flexotask-editor/src/com/ibm/realtime/flexotask/editor/model/TaskDiagram.java 2009-02-16 21:06:02 UTC (rev 138) @@ -416,7 +416,9 @@ } // Set the new value setTiming(timing); - timing.setParent(this); + if (timing != null) { + timing.setParent(this); + } // Ensure the controller knows of the new value (which may be null) if (timing != null && children.add(timing)) { firePropertyChange(CHILD_ADDED_PROP, null, timing); Added: trunk/flexotask-editor/src/com/ibm/realtime/flexotask/editor/timing/reactive/ClockAnnotator.java =================================================================== --- trunk/flexotask-editor/src/com/ibm/realtime/flexotask/editor/timing/reactive/ClockAnnotator.java (rev 0) +++ trunk/flexotask-editor/src/com/ibm/realtime/flexotask/editor/timing/reactive/ClockAnnotator.java 2009-02-16 21:06:02 UTC (rev 138) @@ -0,0 +1,155 @@ +/* + * 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 com.ibm.realtime.flexotask.editor.timing.reactive; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.draw2d.Label; +import org.eclipse.ui.views.properties.IPropertyDescriptor; +import org.eclipse.ui.views.properties.PropertyDescriptor; +import org.eclipse.ui.views.properties.TextPropertyDescriptor; + +import com.ibm.realtime.flexotask.editor.model.Category; +import com.ibm.realtime.flexotask.editor.model.Connection; +import com.ibm.realtime.flexotask.editor.model.LocalTiming; +import com.ibm.realtime.flexotask.editor.model.ModelElement; +import com.ibm.realtime.flexotask.editor.model.NormalTask; +import com.ibm.realtime.flexotask.timing.FlexotaskTimingData; +import com.ibm.realtime.flexotask.timing.FlexotaskTimingDataParser; +import com.ibm.realtime.flexotask.timing.reactive.ClockAnnotation; + +/** + * LocalTiming ("annotator") for tasks that appear to have no incoming connections. These can be optionally designated as + * clocks. + */ +public class ClockAnnotator implements LocalTiming +{ + private static final String CLOCK_PERIOD_ID = "ReactiveTimingClockPeriod"; + private static final Label incomingError = new Label("Clock annotation can only appear ona source task", + ModelElement.ERROR_IMAGE); + private NormalTask task; + private ClockAnnotation annotation; + + /** + * Make a new ClockAnnotator + * @param task the task to which this annotator is attached + */ + public ClockAnnotator(NormalTask task) { + this.task = task; + } + + /* (non-Javadoc) + * @see com.ibm.realtime.flexotask.editor.model.LocalTiming#getAnnotation() + */ + public FlexotaskTimingData getAnnotation() { + return annotation; + } + + /* (non-Javadoc) + * @see com.ibm.realtime.flexotask.editor.model.LocalTiming#getToolTipLabels(java.util.List) + */ + public void getToolTipLabels(List<Label> labels) { + /* First check if the task has acquired any incoming connections; this could require an error indication */ + List<Connection> connections = task.getIncomingConnections(); + if (connections != null && connections.size() > 0) { + if (annotation == null) { + /* Task was never annotated, so just allow it silently ... no labels needed */ + return; + } + /* Annotation is illegal */ + labels.add(incomingError); + return; + } + Label label = new Label(ModelElement.OK_IMAGE); + if (annotation == null) { + label.setText("To be scheduled via file descriptor readiness"); + } else { + label.setText("Clock task with period " + annotation.getPeriod()); + } + labels.add(label); + } + + /* (non-Javadoc) + * @see com.ibm.realtime.flexotask.editor.model.LocalTiming#setAnnotation(com.ibm.realtime.flexotask.timing.FlexotaskTimingData) + */ + public void setAnnotation(FlexotaskTimingData annotation) { + this.annotation = (ClockAnnotation) annotation; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.views.properties.IPropertySource#getEditableValue() + */ + public Object getEditableValue() { + return this; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyDescriptors() + */ + public IPropertyDescriptor[] getPropertyDescriptors() { + List<IPropertyDescriptor> propertyList = new ArrayList<IPropertyDescriptor>(); + PropertyDescriptor pd = new TextPropertyDescriptor(CLOCK_PERIOD_ID, "Clock period"); + pd.setCategory(Category.BASIC_CATEGORY); + propertyList.add(pd); + return propertyList.toArray(new IPropertyDescriptor[0]); + } + + /* (non-Javadoc) + * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyValue(java.lang.Object) + */ + public Object getPropertyValue(Object id) { + if (CLOCK_PERIOD_ID.equals(id)) { + if (annotation == null) { + return ""; + } else { + return FlexotaskTimingDataParser.formatTime(annotation.getPeriod()); + } + } + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.views.properties.IPropertySource#isPropertySet(java.lang.Object) + */ + public boolean isPropertySet(Object id) { + if (CLOCK_PERIOD_ID.equals(id)) { + return annotation != null; + } + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.views.properties.IPropertySource#resetPropertyValue(java.lang.Object) + */ + public void resetPropertyValue(Object id) { + if (CLOCK_PERIOD_ID.equals(id)) { + setAnnotation(null); + } + } + + /* (non-Javadoc) + * @see org.eclipse.ui.views.properties.IPropertySource#setPropertyValue(java.lang.Object, java.lang.Object) + */ + public void setPropertyValue(Object id, Object value) { + if (CLOCK_PERIOD_ID.equals(id)) { + if ("".equals(value)) { + setAnnotation(null); + } else { + long period = FlexotaskTimingDataParser.parseTime((String) value); + setAnnotation(new ClockAnnotation(period)); + } + } + } +} Property changes on: trunk/flexotask-editor/src/com/ibm/realtime/flexotask/editor/timing/reactive/ClockAnnotator.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: trunk/flexotask-editor/src/com/ibm/realtime/flexotask/editor/timing/reactive/ReactiveGlobalTiming.java =================================================================== --- trunk/flexotask-editor/src/com/ibm/realtime/flexotask/editor/timing/reactive/ReactiveGlobalTiming.java (rev 0) +++ trunk/flexotask-editor/src/com/ibm/realtime/flexotask/editor/timing/reactive/ReactiveGlobalTiming.java 2009-02-16 21:06:02 UTC (rev 138) @@ -0,0 +1,118 @@ +/* + * 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 com.ibm.realtime.flexotask.editor.timing.reactive; + +import java.util.List; + +import org.eclipse.draw2d.Label; +import org.eclipse.ui.views.properties.IPropertyDescriptor; + +import com.ibm.realtime.flexotask.editor.model.Connection; +import com.ibm.realtime.flexotask.editor.model.GlobalTiming; +import com.ibm.realtime.flexotask.editor.model.LocalTiming; +import com.ibm.realtime.flexotask.editor.model.ModelElement; +import com.ibm.realtime.flexotask.editor.model.NormalTask; +import com.ibm.realtime.flexotask.editor.model.Predicate; +import com.ibm.realtime.flexotask.timing.FlexotaskTimingData; +import com.ibm.realtime.flexotask.timing.reactive.ReactiveTiming; + +/** + * A GlobalTiming for the reactive grammar + */ +public class ReactiveGlobalTiming extends GlobalTiming +{ + private static final IPropertyDescriptor[] noDescriptors = new IPropertyDescriptor[0]; + + private static final ReactiveTiming timing = new ReactiveTiming(); + + /** + * Make a new ReactiveGlobalTiming + */ + public ReactiveGlobalTiming() { + computeToolTipAndColor(); + } + + /* (non-Javadoc) + * @see com.ibm.realtime.flexotask.editor.model.LocalTiming#getAnnotation() + */ + public FlexotaskTimingData getAnnotation() { + return timing; + } + + /* (non-Javadoc) + * @see com.ibm.realtime.flexotask.editor.model.GlobalTiming#getElementAnnotator(com.ibm.realtime.flexotask.editor.model.ModelElement) + */ + public LocalTiming getElementAnnotator(ModelElement element) { + if (!(element instanceof NormalTask) || element instanceof Predicate) { + return null; + } + List<Connection> connections = ((NormalTask) element).getIncomingConnections(); + if (connections != null && connections.size() > 0) { + return null; + } + return new ClockAnnotator((NormalTask) element); + } + + /* (non-Javadoc) + * @see com.ibm.realtime.flexotask.editor.model.ModelElement#getName() + */ + public String getName() { + return "Reactive Timing"; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyDescriptors() + */ + public IPropertyDescriptor[] getPropertyDescriptors() { + return noDescriptors; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.views.properties.IPropertySource#getPropertyValue(java.lang.Object) + */ + public Object getPropertyValue(Object id) { + return null; + } + + /* (non-Javadoc) + * @see com.ibm.realtime.flexotask.editor.model.ModelElement#getToolTipLabels(java.util.List) + */ + public void getToolTipLabels(List<Label> labels) { + } + + /* (non-Javadoc) + * @see org.eclipse.ui.views.properties.IPropertySource#isPropertySet(java.lang.Object) + */ + public boolean isPropertySet(Object id) { + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.views.properties.IPropertySource#resetPropertyValue(java.lang.Object) + */ + public void resetPropertyValue(Object id) { + } + + /* (non-Javadoc) + * @see com.ibm.realtime.flexotask.editor.model.LocalTiming#setAnnotation(com.ibm.realtime.flexotask.timing.FlexotaskTimingData) + */ + public void setAnnotation(FlexotaskTimingData annotation) { + } + + /* (non-Javadoc) + * @see org.eclipse.ui.views.properties.IPropertySource#setPropertyValue(java.lang.Object, java.lang.Object) + */ + public void setPropertyValue(Object id, Object value) { + } +} Property changes on: trunk/flexotask-editor/src/com/ibm/realtime/flexotask/editor/timing/reactive/ReactiveGlobalTiming.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: trunk/flexotask-editor/src/com/ibm/realtime/flexotask/editor/timing/reactive/ReactiveGrammarProvider.java =================================================================== --- trunk/flexotask-editor/src/com/ibm/realtime/flexotask/editor/timing/reactive/ReactiveGrammarProvider.java (rev 0) +++ trunk/flexotask-editor/src/com/ibm/realtime/flexotask/editor/timing/reactive/ReactiveGrammarProvider.java 2009-02-16 21:06:02 UTC (rev 138) @@ -0,0 +1,73 @@ +/* + * 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 com.ibm.realtime.flexotask.editor.timing.reactive; + +import java.util.List; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jdt.core.IClasspathEntry; + +import com.ibm.realtime.flexotask.editor.model.GlobalTiming; +import com.ibm.realtime.flexotask.editor.model.TimingGrammarProvider; +import com.ibm.realtime.flexotask.timing.FlexotaskTimingData; +import com.ibm.realtime.flexotask.timing.FlexotaskTimingDataParser; +import com.ibm.realtime.flexotask.timing.reactive.ReactiveTimingDataParser; + +/** + * A TimingGrammarProvider for the reactive grammar. The only supported annotation is the + * clock annotation on source tasks. + */ +public class ReactiveGrammarProvider implements TimingGrammarProvider +{ + /* (non-Javadoc) + * @see com.ibm.realtime.flexotask.editor.model.TimingGrammarProvider#getGlobalTiming(com.ibm.realtime.flexotask.timing.FlexotaskTimingData) + */ + public GlobalTiming getGlobalTiming(FlexotaskTimingData annotation) { + return new ReactiveGlobalTiming(); + } + + /* (non-Javadoc) + * @see com.ibm.realtime.flexotask.editor.model.TimingGrammarProvider#getLabel() + */ + public String getLabel() { + return "Reactive Timing"; + } + + /* (non-Javadoc) + * @see com.ibm.realtime.flexotask.editor.model.TimingGrammarProvider#getParser() + */ + public FlexotaskTimingDataParser getParser() { + return new ReactiveTimingDataParser(); + } + + /* (non-Javadoc) + * @see com.ibm.realtime.flexotask.editor.model.TimingGrammarProvider#getTemplateClass() + */ + public Class<? extends GlobalTiming> getTemplateClass() { + return ReactiveGlobalTiming.class; + } + + /* (non-Javadoc) + * @see com.ibm.realtime.flexotask.editor.model.LibraryProvider#addToClasspath(java.util.List) + */ + public void addToClasspath(List<IClasspathEntry> accumulator) throws CoreException { + } + + /* (non-Javadoc) + * @see com.ibm.realtime.flexotask.editor.model.LibraryProvider#getDescription() + */ + public String getDescription() { + return "Reactive scheduling based on file descriptor readiness of 'source' tasks and 'clock' tasks"; + } +} Property changes on: trunk/flexotask-editor/src/com/ibm/realtime/flexotask/editor/timing/reactive/ReactiveGrammarProvider.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Modified: trunk/flexotask-functiontest/src/alltests/Testcases.java =================================================================== --- trunk/flexotask-functiontest/src/alltests/Testcases.java 2009-02-16 21:04:53 UTC (rev 137) +++ trunk/flexotask-functiontest/src/alltests/Testcases.java 2009-02-16 21:06:02 UTC (rev 138) @@ -70,7 +70,7 @@ } @Test - public void testNativeIO() throws IOException + public void testNativeIO() throws IOException, SAXException, ParserConfigurationException, FlexotaskValidationException { nativeio.Main.main(new String[0]); } Modified: trunk/flexotask-functiontest/src/nativeio/Main.java =================================================================== --- trunk/flexotask-functiontest/src/nativeio/Main.java 2009-02-16 21:04:53 UTC (rev 137) +++ trunk/flexotask-functiontest/src/nativeio/Main.java 2009-02-16 21:06:02 UTC (rev 138) @@ -14,12 +14,22 @@ package nativeio; import java.io.IOException; +import java.io.InputStream; import java.lang.Thread.UncaughtExceptionHandler; +import java.util.HashMap; +import java.util.Map; -import com.ibm.realtime.flexotask.scheduling.FlexotaskFileDescriptorState; -import com.ibm.realtime.flexotask.scheduling.FlexotaskWaitSet; +import javax.xml.parsers.ParserConfigurationException; + +import org.xml.sax.SAXException; + +import com.ibm.realtime.flexotask.FileDescriptor; +import com.ibm.realtime.flexotask.FlexotaskGraph; +import com.ibm.realtime.flexotask.template.FlexotaskTemplate; +import com.ibm.realtime.flexotask.template.FlexotaskValidationException; +import com.ibm.realtime.flexotask.tools.FlexotaskXMLParser; +import com.ibm.realtime.flexotask.util.ESystem; import com.ibm.realtime.flexotask.util.NativeIO; -import com.ibm.realtime.flexotask.util.NonBlockingBuffer; /** * A unit test of the NativeIO, FlexotaskWaitSet and NonBlockingBuffer utilities @@ -30,7 +40,9 @@ static Throwable badSender = null; /* Main setup */ - public static void main(String[] args) throws IOException { + public static void main(String[] args) throws IOException, SAXException, ParserConfigurationException, + FlexotaskValidationException + { /* Check environment ... no point in running when only simulating */ if (NativeIO.isSimulated()) { System.err.println("NativeIO test not run since native support not present"); @@ -52,9 +64,7 @@ /* Run sender, which will wait for receiver to connect */ sender.start(); /* Run receiver */ - receiverRun(); - /* Clean up sender */ - try { sender.join(); } catch (InterruptedException e) {} + receiverRun(sender); /* Handle any sender exception */ if (badSender != null) { if (badSender instanceof RuntimeException) { @@ -68,7 +78,9 @@ } /* The receiver loop */ - static void receiverRun() throws IOException { + static void receiverRun(Thread sender) + throws IOException, SAXException, ParserConfigurationException, FlexotaskValidationException + { /* Wait 1 second for sender to fire up */ try { Thread.sleep(1000); } catch (InterruptedException e) {} /* Connect to sender */ @@ -76,31 +88,24 @@ if (fd < 0) { throw new IllegalStateException("Connect rc=" + fd); } - /* Do a few blocking reads */ - readAndCheck(fd, true, 0); - readAndCheck(fd, true, 1); - readAndCheck(fd, true, 2); - /* Now do some non-blocking ones */ - readAndCheck(fd, false, 3); - readAndCheck(fd, false, 4); - readAndCheck(fd, false, 5); - /* Now do some non-blocking ones with a WaitSet */ - FlexotaskFileDescriptorState state = new FlexotaskFileDescriptorState(fd, FlexotaskFileDescriptorState.READ); - FlexotaskWaitSet waitSet = new FlexotaskWaitSet(new FlexotaskFileDescriptorState[] {state}); - readWithWaitSet(fd, waitSet, 6); - readWithWaitSet(fd, waitSet, 7); - readWithWaitSet(fd, waitSet, 8); - /* Now read remaining contents non-blockingly using NonBlockingBuffer */ - NonBlockingBuffer toRead = new NonBlockingBuffer(102); - int rc = toRead.read(fd); - while (rc >= 0 && rc < 102) { - try { Thread.sleep(200); } catch (InterruptedException e) {} - System.err.print(rc + " "); - rc = toRead.read(fd); + /* Set up the Flexotask Graph */ + InputStream stream = Main.class.getResourceAsStream("Reactive.ftg"); + FlexotaskTemplate template = FlexotaskXMLParser.parseStream(stream); + Map<String,Object> initMap = new HashMap<String,Object>(); + initMap.put("Reader", new FileDescriptor(fd)); + boolean[] stopflag = new boolean[1]; + initMap.put("Process", stopflag); + FlexotaskGraph graph = template.validate("ReactiveScheduler", initMap); + /* Run the Flexotask Graph */ + graph.getRunner().start(); + /* Clean up sender */ + try { sender.join(); } catch (InterruptedException e) {} + /* Wait some additional time to be sure graph is finished */ + while (!stopflag[0]) { + try {Thread.sleep(2); } catch (InterruptedException e) {} } - if (rc < 0) { - throw new IllegalStateException("NonBlockingBuffer.read() rc=" + fd); - } + ESystem.err.println("Shutting down"); + graph.getRunner().shutdown(); } /* The sender loop */ @@ -128,54 +133,4 @@ try { Thread.sleep(500); } catch (InterruptedException e) {} } } - - /** - * Read a file descriptor and check the value - * @param fd the fd to read - * @param blocking true if a blocking read should be used from the start, false if a non-blocking read should - * be done first before blocking - * @param check the value to check - */ - private static void readAndCheck(int fd, boolean blocking, int check) { - byte[] buffer = new byte[2]; - int rc = NativeIO.read(fd, buffer, 0, 2, blocking); - if (blocking) { - postCheck(check, buffer, rc); - } else if (rc != NativeIO.getBlockingCode()) { - throw new IllegalStateException("Non-blocking read " + check + " should have returned " + NativeIO.getBlockingCode() - + " but returned " + rc); - } else { - readAndCheck(fd, true, check); - } - } - - /** - * Subroutine to check a buffer against a value and a return code - * @param check the value that should be there - * @param buffer the buffer - * @param rc the return code - */ - private static void postCheck(int check, byte[] buffer, int rc) { - if (rc != 2) { - /* Assumes it is impossible for a two-byte write to break up ... is that true? */ - throw new IllegalStateException("Read " + check + " rc=" + rc); - } - int compare = (buffer[0] << 8) | buffer[1]; - if (compare != check) { - throw new IllegalStateException("Read got " + compare + ", should be " + check); - } - } - - /** - * Read a file descriptor non-blockingly using a WaitSet to wait for it and then check the value - * @param fd the fd to read - * @param waitSet the WaitSet to use - * @param check the value to check - */ - private static void readWithWaitSet(int fd, FlexotaskWaitSet waitSet, int check) { - byte[] buffer = new byte[2]; - waitSet.wait(-1, null); - int rc = NativeIO.read(fd, buffer, 0, 2, false); - postCheck(check, buffer, rc); - } } Added: trunk/flexotask-functiontest/src/nativeio/Reactive.ftg =================================================================== --- trunk/flexotask-functiontest/src/nativeio/Reactive.ftg (rev 0) +++ trunk/flexotask-functiontest/src/nativeio/Reactive.ftg 2009-02-16 21:06:02 UTC (rev 138) @@ -0,0 +1,22 @@ +<FlexotaskTemplate> + <TimingProvider kind='reactive' parser='com.ibm.realtime.flexotask.timing.reactive.ReactiveTimingDataParser' graphics='85 60 362 43'/> + <Task id='Process' implementation='nativeio.Reporter' isolation='weak' graphics='60 60 495 213'> + <Input id='in0' type='java.lang.Long' isBuffered='false'/> + <Input id='in1' type='java.lang.String' isBuffered='false'/> + </Task> + <Task id='Clock' implementation='com.ibm.realtime.flexotask.ClockTask' isolation='strong' graphics='60 60 139 154'> + <Output id='out0' type='java.lang.Long' isBuffered='false'/> + <Timing period='2s'/> + </Task> + <Task id='Reader' implementation='nativeio.TestReader' isolation='strong' graphics='60 60 134 258'> + <Output id='out0' type='java.lang.String' isBuffered='false'/> + </Task> + <Connection id='Clock_Process' source='Clock' target='Process' mode='deepclone'> + </Connection> + <Connection id='Reader_Process' source='Reader' target='Process' targetPort='in1' mode='deepclone'> + </Connection> + <Allocation allow='true'></Allocation> + <Synchronization allow='true'></Synchronization> + <Stable mode='default'> + </Stable> +</FlexotaskTemplate> Added: trunk/flexotask-functiontest/src/nativeio/Reporter.java =================================================================== --- trunk/flexotask-functiontest/src/nativeio/Reporter.java (rev 0) +++ trunk/flexotask-functiontest/src/nativeio/Reporter.java 2009-02-16 21:06:02 UTC (rev 138) @@ -0,0 +1,63 @@ +/* + * 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 nativeio; + +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 Reporter implements Flexotask +{ + private FlexotaskInputPort<java.lang.Long> in0; + private FlexotaskInputPort<java.lang.String> in1; + private long timebase; + private boolean[] stopflag; + + /* (non-Javadoc) + * @see com.ibm.realtime.flexotask.Flexotask#initialize(com.ibm.realtime.flexotask.FlexotaskInputPort[], com.ibm.realtime.flexotask.FlexotaskOutputPort[], java.lang.Object) + */ + @SuppressWarnings("unchecked") + public void initialize(FlexotaskInputPort[] inputs, FlexotaskOutputPort[] outputs, Object parameter) + { + in0 = inputs[0]; + in1 = inputs[1]; + stopflag = (boolean[]) parameter; + } + + /* (non-Javadoc) + * @see com.ibm.realtime.flexotask.Flexotask#execute() + */ + public void execute() + { + Long timeObj = in0.getValue(); + String msg = in1.getValue(); + if (timeObj != null) { + long time = timeObj / 1000000; + if (timebase == 0) { + timebase = time; + } + ESystem.err.println("New time: " + (time - timebase)); + } + if (msg != null) { + ESystem.err.println(msg); + if ("Done".equals(msg)) { + stopflag[0] = true; + } + } + if (msg == null && timeObj == null) { + ESystem.err.println("Nothing to do!"); + } + } +} Property changes on: trunk/flexotask-functiontest/src/nativeio/Reporter.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + native Added: trunk/flexotask-functiontest/src/nativeio/TestReader.java =================================================================== --- trunk/flexotask-functiontest/src/nativeio/TestReader.java (rev 0) +++ trunk/flexotask-functiontest/src/nativeio/TestReader.java 2009-02-16 21:06:02 UTC (rev 138) @@ -0,0 +1,128 @@ +/* + * 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 nativeio; + +import com.ibm.realtime.flexotask.FileDescriptor; +import com.ibm.realtime.flexotask.Flexotask; +import com.ibm.realtime.flexotask.FlexotaskInputPort; +import com.ibm.realtime.flexotask.FlexotaskOutputPort; +import com.ibm.realtime.flexotask.scheduling.FlexotaskFileDescriptorState; +import com.ibm.realtime.flexotask.scheduling.FlexotaskWaitSet; +import com.ibm.realtime.flexotask.util.NativeIO; +import com.ibm.realtime.flexotask.util.NonBlockingBuffer; + +public class TestReader implements Flexotask +{ + private int fd; + private FlexotaskOutputPort<java.lang.String> out0; + NonBlockingBuffer buffer; + + /* (non-Javadoc) + * @see com.ibm.realtime.flexotask.Flexotask#initialize(com.ibm.realtime.flexotask.FlexotaskInputPort[], com.ibm.realtime.flexotask.FlexotaskOutputPort[], java.lang.Object) + */ + @SuppressWarnings("unchecked") + public void initialize(FlexotaskInputPort[] inputs, FlexotaskOutputPort[] outputs, Object parameter) + { + fd = ((FileDescriptor) parameter).getFileDescriptor(); + out0 = outputs[0]; + } + + /* (non-Javadoc) + * @see com.ibm.realtime.flexotask.Flexotask#execute() + */ + public void execute() + { + /* Do "rapid" tests first (these require that there be no pauses) */ + if (buffer == null) { + /* Do a few blocking reads */ + readAndCheck(fd, true, 0); + readAndCheck(fd, true, 1); + readAndCheck(fd, true, 2); + readAndCheck(fd, false, 3); + readAndCheck(fd, false, 4); + readAndCheck(fd, false, 5); + /* Now do some non-blocking ones with a WaitSet */ + FlexotaskFileDescriptorState states = new FlexotaskFileDescriptorState(fd, FlexotaskFileDescriptorState.READ); + FlexotaskWaitSet waitSet = new FlexotaskWaitSet(new FlexotaskFileDescriptorState[] {states}); + readWithWaitSet(fd, waitSet, 6); + re... [truncated message content] |