net.aequologica.neo.shakuntala.EventWriterDagImpl Maven / Gradle / Ivy
package net.aequologica.neo.shakuntala;
import java.io.IOException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import net.aequologica.neo.shakuntala.dagr.DagComputer;
@Singleton
@Named(value = "dag")
public class EventWriterDagImpl extends AbstractEventWriter implements EventWriter {
final static String DAG = "dag";
private DagComputer dagComputer = null;
private CountDownLatch latch = null;
@Inject
@Named("application.conf")
private EventSpyConfig config;
@Override
public void init() throws IOException {
super.init(); // must call super to set the shutdownHook
if (config == null) {
throw new RuntimeException();
}
if (!config.isActive(DAG)) {
return;
}
}
@Override
public void write(final Event event) throws IOException {
if (event == null) {
return;
}
if (!config.isActive(DAG)) {
return;
}
if (event.getKey() != null) {
if (event.getKey().equals(DAG)) {
Object object = event.getObject();
if (object instanceof DagComputer) {
dagComputer = (DagComputer)object;
dagComputer.write(config.getDagURI(), config.getProxy());
}
} else {
if (event.getKey().equals("result")) {
if (dagComputer != null) {
latch = new CountDownLatch(1);
dagComputer.writeResult(config.getDagURI(), config.getProxy(), Boolean.valueOf(event.getValue()));
latch.countDown();
}
}
}
}
}
@Override
public void close() throws IOException {
super.close();
if (!config.isActive(DAG)) {
return;
}
if (latch != null) {
try {
latch.await(10, TimeUnit.SECONDS);
} catch (InterruptedException e) {
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy