net.fortytwo.rdfagents.HttpDemo1 Maven / Gradle / Ivy
package net.fortytwo.rdfagents;
import jade.core.AID;
import jade.wrapper.AgentContainer;
import jade.wrapper.AgentController;
import net.fortytwo.rdfagents.data.DatasetFactory;
import net.fortytwo.rdfagents.jade.RDFAgentImpl;
import net.fortytwo.rdfagents.jade.RDFAgentsPlatformImpl;
import net.fortytwo.rdfagents.jade.SailBasedQueryProvider;
import net.fortytwo.rdfagents.model.AgentId;
import net.fortytwo.rdfagents.model.Dataset;
import net.fortytwo.rdfagents.model.RDFAgent;
import net.fortytwo.rdfagents.model.RDFAgentsPlatform;
import net.fortytwo.rdfagents.model.RDFContentLanguage;
import org.openrdf.sail.Sail;
import org.openrdf.sail.memory.MemoryStore;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;
/**
* @author Joshua Shinavier (http://fortytwo.net)
*/
public class HttpDemo1 {
private final Sail sail;
private void run(final Properties config) throws Exception {
RDFAgentsPlatform pf = new RDFAgentsPlatformImpl("demo1", 8888, config);
RDFAgent a1 = new RDFAgentImpl(pf,
new AgentId("provider", "http://192.168.1.136:7778/acc"));
a1.setQueryProvider(new SailBasedQueryProvider(a1, sail));
/*
RDFAgent a2 = new RDFAgentImpl(pf,
new AgentId("urn:x-agent:[email protected]", "http://localhost:8889"));
QueryConsumer qc = new QueryConsumerImpl(a2);
ConsumerCallback callback = new EchoCallback(pf.getDatasetFactory());
qc.submit(new URIImpl("http://example.org/ns#arthur"), a1.getIdentity(), callback);
//*/
AgentContainer c = ((RDFAgentsPlatformImpl) pf).getContainer();
AgentController a = c.getAgent("provider");
System.out.println("a1: " + a);
a.activate();
waitAWhile(60000);
pf.shutDown();
}
private void waitAWhile(final long time) {
Object mutex = "";
synchronized (mutex) {
try {
mutex.wait(time);
} catch (InterruptedException e) {
e.printStackTrace(System.err);
}
}
}
private HttpDemo1() throws Exception {
DatasetFactory datasetFactory = new DatasetFactory();
for (RDFContentLanguage l : RDFContentLanguage.values()) {
datasetFactory.addLanguage(l);
}
Dataset d;
try (InputStream in = RDFAgents.class.getResourceAsStream("dummyData.trig")) {
d = datasetFactory.parse(in, RDFContentLanguage.RDF_TRIG);
}
sail = new MemoryStore();
sail.initialize();
datasetFactory.addToSail(d, sail);
}
public static void main(final String args[]) {
try {
File props;
if (1 == args.length) {
props = new File(args[0]);
} else {
props = new File("rdfagents.props");
//printUsage();
//System.exit(1);
}
Properties config = new Properties();
try (InputStream in = new FileInputStream(props)) {
config.load(in);
}
new HttpDemo1().run(config);
} catch (Throwable t) {
t.printStackTrace(System.err);
System.exit(1);
}
}
private static void printUsage() {
System.out.println("Usage: rdfagents [configuration file]");
System.out.println("For more information, please see:\n"
+ " .");
}
}