All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.fortytwo.rdfagents.HttpDemo2 Maven / Gradle / Ivy

package net.fortytwo.rdfagents;

import net.fortytwo.rdfagents.jade.QueryConsumerImpl;
import net.fortytwo.rdfagents.jade.RDFAgentImpl;
import net.fortytwo.rdfagents.jade.RDFAgentsPlatformImpl;
import net.fortytwo.rdfagents.jade.testing.EchoCallback;
import net.fortytwo.rdfagents.messaging.ConsumerCallback;
import net.fortytwo.rdfagents.messaging.query.QueryConsumer;
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 org.openrdf.model.Value;
import org.openrdf.model.impl.URIImpl;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;

/**
 * @author Joshua Shinavier (http://fortytwo.net)
 */
public class HttpDemo2 {

    private void run(final Properties config) throws Exception {

        //config.setProperty(RDFAgentsPlatformImpl.HTTP_MTP_OUTPORT, "7779");

        RDFAgentsPlatform pf = new RDFAgentsPlatformImpl("demo2", 8888, config);

        AgentId a1id = new AgentId("provider", "http://192.168.1.136:7778/acc");

        RDFAgent a2 = new RDFAgentImpl(pf,
                new AgentId("consumer", "http://192.168.1.107:7778/acc"));
        QueryConsumer qc = new QueryConsumerImpl(a2);
        ConsumerCallback callback = new EchoCallback(pf.getDatasetFactory());
        qc.submit(new URIImpl("http://example.org/ns#arthur"), a1id, callback);

        waitAWhile(10000);

        pf.shutDown();
    }

    private void waitAWhile(final long time) {
        Object mutex = "";
        synchronized (mutex) {
            try {
                mutex.wait(time);
            } catch (InterruptedException e) {
                e.printStackTrace(System.err);
            }
        }
    }

    private HttpDemo2() throws Exception {
    }

    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 HttpDemo2().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"
                + "  .");
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy