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

finished new instatiation method and removed obsolete class

parent d2004b4a
No related branches found
No related tags found
No related merge requests found
......@@ -38,7 +38,6 @@ import teetime.framework.pipe.UnboundedSpScPipeFactory;
import teetime.framework.signal.InitializingSignal;
import teetime.framework.signal.ValidatingSignal;
import teetime.framework.validation.AnalysisNotValidException;
import teetime.util.Connection;
import teetime.util.Pair;
/**
......@@ -198,22 +197,18 @@ public final class Analysis<T extends AnalysisConfiguration> implements Uncaught
Set<Stage> threadableStageJobs = configuration.getThreadableStageJobs();
for (Stage threadableStage : threadableStageJobs) {
i++;
colors.put(threadableStage, i); // Markiere den threadHead
colors.put(threadableStage, i);
colorAndConnectStages(i, colors, threadableStage);
}
// if (configuration.getConnections().size() != createdConnections) {
// throw new IllegalStateException("Remaining " + (configuration.getConnections().size() - createdConnections) + " connection(s)");
// }
LOGGER.debug("Created " + createdConnections + "connections");
}
public void colorAndConnectStages(final Integer i, final Map<Stage, Integer> colors, final Stage threadableStage) {
Set<Stage> threadableStageJobs = configuration.getThreadableStageJobs();
for (OutputPort outputPort : threadableStage.getOutputPorts()) {
if (outputPort.pipe != null) {
InstantiationPipe pipe;
if (outputPort.pipe instanceof InstantiationPipe) {
pipe = (InstantiationPipe) outputPort.pipe;
Connection connection = new Connection(outputPort, pipe.getTargetPort(), pipe.getCapacity());
InstantiationPipe pipe = (InstantiationPipe) outputPort.pipe;
Stage targetStage = pipe.getTargetPort().getOwningStage();
Integer targetColor = new Integer(0);
if (colors.containsKey(targetStage)) {
......@@ -221,9 +216,9 @@ public final class Analysis<T extends AnalysisConfiguration> implements Uncaught
}
if (threadableStageJobs.contains(targetStage) && targetColor.compareTo(i) != 0) {
if (pipe.getCapacity() != 0) {
interBoundedThreadPipeFactory.create(connection.getSourcePort(), connection.getTargetPort(), connection.getCapacity());
interBoundedThreadPipeFactory.create(outputPort, pipe.getTarget(), pipe.getCapacity());
} else {
interUnboundedThreadPipeFactory.create(connection.getSourcePort(), connection.getTargetPort(), 4);
interUnboundedThreadPipeFactory.create(outputPort, pipe.getTarget(), 4);
}
} else {
if (colors.containsKey(targetStage)) {
......@@ -231,7 +226,7 @@ public final class Analysis<T extends AnalysisConfiguration> implements Uncaught
throw new IllegalStateException("Crossing threads"); // One stage is connected to a stage of another thread (but not its "headstage")
}
}
intraThreadPipeFactory.create(connection.getSourcePort(), connection.getTargetPort());
intraThreadPipeFactory.create(outputPort, pipe.getTarget());
colors.put(targetStage, i);
colorAndConnectStages(i, colors, targetStage);
}
......
......@@ -24,7 +24,6 @@ import teetime.framework.pipe.InstantiationPipe;
import teetime.framework.pipe.PipeFactoryRegistry;
import teetime.framework.pipe.PipeFactoryRegistry.PipeOrdering;
import teetime.framework.pipe.PipeFactoryRegistry.ThreadCommunication;
import teetime.util.Connection;
/**
* Represents a configuration of connected stages, which is needed to run a analysis.
......@@ -33,7 +32,6 @@ import teetime.util.Connection;
public abstract class AnalysisConfiguration {
private final Set<Stage> threadableStageJobs = new HashSet<Stage>();
private final Set<Connection<?>> connections = new HashSet<Connection<?>>();
@SuppressWarnings("deprecation")
private static final PipeFactoryRegistry PIPE_FACTORY_REGISTRY = PipeFactoryRegistry.INSTANCE;
......@@ -73,7 +71,6 @@ public abstract class AnalysisConfiguration {
*/
protected void addThreadableStage(final AbstractCompositeStage stage) {
this.threadableStageJobs.add(stage.getFirstStage());
this.connections.addAll(stage.getConnections());
for (Stage threadableStage : stage.getThreadableStageJobs()) {
this.addThreadableStage(threadableStage);
}
......@@ -183,13 +180,4 @@ public abstract class AnalysisConfiguration {
// connections.add(new Connection<T>(sourcePort, targetPort, capacity));
}
/**
* Returns a list of pairs, which describe the connections among all stages.
*
* @return a list of pairs of Out- and InputPorts, which are connected
*/
protected Set<Connection<?>> getConnections() {
return connections;
}
}
/**
* Copyright (C) 2015 Christian Wulf, Nelson Tavares de Sousa (http://teetime.sourceforge.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package teetime.util;
import teetime.framework.InputPort;
import teetime.framework.OutputPort;
public class Connection<T> {
private final OutputPort<? extends T> sourcePort;
private final InputPort<T> targetPort;
private final int capacity;
public Connection(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort) {
this(sourcePort, targetPort, 4);
}
public Connection(final OutputPort<? extends T> sourcePort, final InputPort<T> targetPort, final int capacity) {
this.sourcePort = sourcePort;
this.targetPort = targetPort;
this.capacity = capacity;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((sourcePort == null) ? 0 : sourcePort.hashCode());
result = prime * result + ((targetPort == null) ? 0 : targetPort.hashCode());
return result;
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
Connection<?> other = (Connection<?>) obj;
if (sourcePort == null) {
if (other.sourcePort != null) {
return false;
}
} else if (!sourcePort.equals(other.sourcePort)) {
return false;
}
if (targetPort == null) {
if (other.targetPort != null) {
return false;
}
} else if (!targetPort.equals(other.targetPort)) {
return false;
}
return true;
}
public int getCapacity() {
return capacity;
}
public OutputPort<? extends T> getSourcePort() {
return sourcePort;
}
public InputPort<T> getTargetPort() {
return targetPort;
}
}
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