Commit 281780ef authored by Christian Wulf's avatar Christian Wulf

added PipeFactoryLoader

parent 364f39b3
......@@ -19,10 +19,11 @@ appender("CONSOLE", ConsoleAppender) {
}
}
//root WARN, ["CONSOLE"]
root WARN
root WARN, ["CONSOLE"]
//logger "teetime.variant.methodcallWithPorts.stage", DEBUG, ["CONSOLE"]
logger "teetime.variant.methodcallWithPorts.stage", INFO
logger "teetime.variant.methodcallWithPorts.examples.kiekerdays.TimingsReader", TRACE, ["CONSOLE", "FILE"]
\ No newline at end of file
logger "teetime.variant.methodcallWithPorts.framework.core.pipe", INFO
logger "teetime.variant.methodcallWithPorts.examples.kiekerdays.TimingsReader", TRACE, ["FILE"]
\ No newline at end of file
teetime.variant.methodcallWithPorts.framework.core.pipe.SingleElementPipeFactory
teetime.variant.methodcallWithPorts.framework.core.pipe.OrderedGrowableArrayPipeFactory
teetime.variant.methodcallWithPorts.framework.core.pipe.UnorderedGrowablePipeFactory
teetime.variant.methodcallWithPorts.framework.core.pipe.SpScPipeFactory
package teetime.variant.methodcallWithPorts.framework.core.pipe;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class PipeFactory {
private static final Logger LOGGER = LoggerFactory.getLogger(PipeFactory.class);
public enum ThreadCommunication {
INTER, INTRA
}
......@@ -23,6 +30,17 @@ public class PipeFactory {
private final Map<String, IPipeFactory> pipeFactories = new HashMap<String, IPipeFactory>();
public PipeFactory() {
try {
List<IPipeFactory> pipeFactories = PipeFactoryLoader.loadFromFile("conf/pipe-factories.conf");
for (IPipeFactory pipeFactory : pipeFactories) {
this.register(pipeFactory);
}
} catch (IOException e) {
LOGGER.warn("Could not load pipe factories from file", e);
}
}
/**
* Creates a new FIFO-ordered, growable pipe with an initial capacity of 1. <br>
* <i>This method is suitable for most situations.</i>
......@@ -47,6 +65,7 @@ public class PipeFactory {
public void register(final IPipeFactory pipeFactory) {
String key = this.buildKey(pipeFactory.getThreadCommunication(), pipeFactory.getOrdering(), pipeFactory.isGrowable());
this.pipeFactories.put(key, pipeFactory);
LOGGER.info("Registered pipe factory: " + pipeFactory.getClass().getCanonicalName());
}
}
package teetime.variant.methodcallWithPorts.framework.core.pipe;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class PipeFactoryLoader {
private static final Logger LOGGER = LoggerFactory.getLogger(PipeFactoryLoader.class);
private PipeFactoryLoader() {
// utility class
}
public static List<IPipeFactory> loadFromFile(final String fileName) throws IOException {
List<IPipeFactory> pipeFactories = new LinkedList<IPipeFactory>();
BufferedReader bufferedReader = new BufferedReader(new FileReader(fileName));
try {
String line;
while (null != (line = bufferedReader.readLine())) {
try {
line = line.trim();
if (!line.isEmpty()) {
Class<?> clazz = Class.forName(line);
Class<? extends IPipeFactory> pipeFactoryClass = clazz.asSubclass(IPipeFactory.class);
IPipeFactory pipeFactory = pipeFactoryClass.newInstance();
pipeFactories.add(pipeFactory);
}
} catch (ClassNotFoundException e) {
LOGGER.warn("Could not find class: " + line, e);
} catch (InstantiationException e) {
LOGGER.warn("Could not instantiate pipe factory", e);
} catch (IllegalAccessException e) {
LOGGER.warn("Could not instantiate pipe factory", e);
}
}
} finally {
bufferedReader.close();
}
return pipeFactories;
}
}
......@@ -23,14 +23,10 @@ import teetime.variant.methodcallWithPorts.framework.core.Configuration;
import teetime.variant.methodcallWithPorts.framework.core.Pipeline;
import teetime.variant.methodcallWithPorts.framework.core.StageWithPort;
import teetime.variant.methodcallWithPorts.framework.core.pipe.IPipe;
import teetime.variant.methodcallWithPorts.framework.core.pipe.OrderedGrowableArrayPipeFactory;
import teetime.variant.methodcallWithPorts.framework.core.pipe.PipeFactory;
import teetime.variant.methodcallWithPorts.framework.core.pipe.PipeFactory.PipeOrdering;
import teetime.variant.methodcallWithPorts.framework.core.pipe.PipeFactory.ThreadCommunication;
import teetime.variant.methodcallWithPorts.framework.core.pipe.SingleElementPipeFactory;
import teetime.variant.methodcallWithPorts.framework.core.pipe.SpScPipe;
import teetime.variant.methodcallWithPorts.framework.core.pipe.SpScPipeFactory;
import teetime.variant.methodcallWithPorts.framework.core.pipe.UnorderedGrowablePipeFactory;
import teetime.variant.methodcallWithPorts.stage.CollectorSink;
import teetime.variant.methodcallWithPorts.stage.kieker.Dir2RecordsFilter;
import teetime.variant.methodcallWithPorts.stage.kieker.className.ClassNameRegistryRepository;
......@@ -48,12 +44,7 @@ public class RecordReaderConfiguration extends Configuration {
private final PipeFactory pipeFactory;
public RecordReaderConfiguration() {
// BETTER instantiate one single pipe factory for all analyzes and register all available pipe implementations once
this.pipeFactory = new PipeFactory();
this.pipeFactory.register(new SingleElementPipeFactory());
this.pipeFactory.register(new OrderedGrowableArrayPipeFactory());
this.pipeFactory.register(new UnorderedGrowablePipeFactory());
this.pipeFactory.register(new SpScPipeFactory());
}
public void buildConfiguration() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment