Skip to content
Snippets Groups Projects
Commit b2a6ac55 authored by Nelson Tavares de Sousa's avatar Nelson Tavares de Sousa
Browse files

added IterableProducer, which was not needed in the end, but could be

helpful in the future
added test, to validate signalhandling in interthread pipes
parent 8ac3ab4b
No related branches found
No related tags found
No related merge requests found
package teetime.stage;
import teetime.framework.ProducerStage;
public class IterableProducer<O extends Iterable<T>, T> extends ProducerStage<T> {
private O iter = null;
public IterableProducer(final O iter) {
this.iter = iter;
}
@Override
protected void execute() {
for (T i : iter) {
this.send(this.outputPort, i);
}
}
}
package teetime.examples.pipe;
import teetime.framework.AnalysisConfiguration;
import teetime.framework.ConsumerStage;
import teetime.framework.ProducerStage;
import teetime.framework.pipe.PipeFactoryRegistry.PipeOrdering;
import teetime.framework.pipe.PipeFactoryRegistry.ThreadCommunication;
import teetime.framework.pipe.SpScPipe;
import teetime.stage.Cache;
import teetime.stage.Clock;
public class SignalQueueConfiguration extends AnalysisConfiguration {
public SpScPipe pipe;
public SignalQueueConfiguration() {
ProducerStage<Long> first = new Clock();
ConsumerStage<Long> second = new Cache<Long>();
pipe = (SpScPipe) PIPE_FACTORY_REGISTRY.getPipeFactory(ThreadCommunication.INTER, PipeOrdering.QUEUE_BASED, false)
.create(first.getOutputPort(), second.getInputPort());
}
}
package teetime.examples.pipe;
import java.util.ArrayList;
import org.junit.Assert;
import org.junit.Test;
import teetime.framework.pipe.SpScPipe;
import teetime.framework.signal.ISignal;
import teetime.framework.signal.StartingSignal;
import teetime.framework.signal.TerminatingSignal;
import teetime.framework.signal.ValidatingSignal;
public class SignalQueueTest {
@Test
public void executeTest() {
ArrayList<ISignal> list = new ArrayList<ISignal>();
list.add(new StartingSignal());
list.add(new TerminatingSignal());
list.add(new ValidatingSignal());
list.add(new StartingSignal());
list.add(new TerminatingSignal());
list.add(new ValidatingSignal());
list.add(new StartingSignal());
list.add(new TerminatingSignal());
list.add(new ValidatingSignal());
SpScPipe pipe = new SignalQueueConfiguration().pipe;
for (ISignal s : list) {
pipe.setSignal(s);
}
ArrayList<ISignal> secondList = new ArrayList<ISignal>();
while (true) {
ISignal temp = pipe.getSignal();
if (temp == null) {
break;
}
secondList.add(temp);
}
Assert.assertEquals(list, secondList);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment