Search in sources :

Example 6 with JenaException

use of org.apache.jena.shared.JenaException in project jena by apache.

the class AssemblerHelp method loadClassNamedBy.

private static Class<?> loadClassNamedBy(Statement s) {
    String x = getString(s);
    // Jena2 -> Jena3 transition 
    if (x.startsWith("com.hp.hpl.jena")) {
        String x1 = x.replaceFirst("com.hp.hpl.jena", "org.apache.jena");
        Log.warnOnce(AssemblerHelp.class, "ja:loadClass: Migration to Jena3: Converting " + x + " to " + x1, x);
        x = x1;
    }
    try {
        return Class.forName(x);
    } catch (Exception e) {
        throw new JenaException(e);
    }
}
Also used : JenaException(org.apache.jena.shared.JenaException) BadDescriptionMultipleRootsException(org.apache.jena.shared.BadDescriptionMultipleRootsException) BadDescriptionNoRootException(org.apache.jena.shared.BadDescriptionNoRootException) AmbiguousSpecificTypeException(org.apache.jena.assembler.exceptions.AmbiguousSpecificTypeException) JenaException(org.apache.jena.shared.JenaException)

Example 7 with JenaException

use of org.apache.jena.shared.JenaException in project jena by apache.

the class AssemblerHelp method loadArbitraryClass.

/**
        Load the class named by the object of <code>s</code> if necessary.
        If that class has a static method <code>whenRequiredByAssembler</code>
        with an <code>AssemblerGroup</code> argument, call that method
        passing it <code>ag</code>.
    */
private static Class<?> loadArbitraryClass(AssemblerGroup ag, Statement s) {
    Class<?> loaded = loadClassNamedBy(s);
    try {
        Method m = loaded.getDeclaredMethod("whenRequiredByAssembler", new Class[] { AssemblerGroup.class });
        m.invoke(null, ag);
    } catch (NoSuchMethodException e) {
    /* that's OK */
    } catch (Exception e) {
        throw new JenaException(e);
    }
    return loaded;
}
Also used : JenaException(org.apache.jena.shared.JenaException) Method(java.lang.reflect.Method) BadDescriptionMultipleRootsException(org.apache.jena.shared.BadDescriptionMultipleRootsException) BadDescriptionNoRootException(org.apache.jena.shared.BadDescriptionNoRootException) AmbiguousSpecificTypeException(org.apache.jena.assembler.exceptions.AmbiguousSpecificTypeException) JenaException(org.apache.jena.shared.JenaException)

Example 8 with JenaException

use of org.apache.jena.shared.JenaException in project jena by apache.

the class TransactionHandlerBase method calculate.

/**
     * Execute the supplier <code>action</code> within a transaction. If it completes normally,
     * commit the transaction and return the result, otherwise abort the transaction.
     */
@Override
public <T> T calculate(Supplier<T> action) {
    begin();
    try {
        T result = action.get();
        commit();
        return result;
    } catch (JenaException e) {
        abort(e);
        throw e;
    } catch (Throwable e) {
        abort(e);
        throw new JenaException(e);
    }
}
Also used : JenaException(org.apache.jena.shared.JenaException)

Example 9 with JenaException

use of org.apache.jena.shared.JenaException in project jena by apache.

the class TransactionHandlerBase method execute.

/**
     * Execute the runnable <code>action</code> within a transaction. If it completes normally,
     * commit the transaction, otherwise abort the transaction.
     */
@Override
public void execute(Runnable action) {
    begin();
    try {
        action.run();
        commit();
    } catch (JenaException e) {
        abort(e);
        throw e;
    } catch (Throwable e) {
        abort(e);
        throw new JenaException(e);
    }
}
Also used : JenaException(org.apache.jena.shared.JenaException)

Example 10 with JenaException

use of org.apache.jena.shared.JenaException in project jena by apache.

the class ConcurrencyTest method doTestConcurrency.

private void doTestConcurrency(final OntModel model) throws InterruptedException {
    // initialize the model
    final String NS = PrintUtil.egNS;
    model.enterCriticalSection(Lock.WRITE);
    final OntClass Top = model.createClass(NS + "Top");
    for (int i = 0; i < MODEL_SIZE; i++) {
        OntClass C = model.createClass(NS + "C" + i);
        Top.addSubClass(C);
        model.createIndividual(NS + "i" + i, C);
    }
    model.leaveCriticalSection();
    class QueryExecutingRunnable implements Runnable {

        @Override
        @SuppressWarnings("unchecked")
        public void run() {
            // Keep this thread running until the specified duration has expired
            long runStartedAt = System.currentTimeMillis();
            while (System.currentTimeMillis() - runStartedAt < TEST_LENGTH) {
                Thread.yield();
                model.enterCriticalSection(Lock.READ);
                try {
                    // Iterate over all statements
                    StmtIterator it = model.listStatements();
                    while (it.hasNext()) it.nextStatement();
                    it.close();
                    // Check number of instances of Top class
                    int count = 0;
                    ExtendedIterator<OntResource> ei = (ExtendedIterator<OntResource>) Top.listInstances();
                    while (ei.hasNext()) {
                        ei.next();
                        count++;
                    }
                    ei.close();
                    if (MODEL_SIZE != count) {
                        if (FULL_TEST)
                            System.err.println("Failure - found " + count + " instance, expected " + MODEL_SIZE);
                        throw new JenaException("Failure - found " + count + " instance, expected " + MODEL_SIZE);
                    }
                } finally {
                    model.leaveCriticalSection();
                }
            }
        }
    }
    // Start the threads
    ExecutorService executorService = Executors.newFixedThreadPool(NUM_THREADS);
    for (int i = 0; i < NUM_THREADS; ++i) {
        executorService.submit(new QueryExecutingRunnable());
    }
    // Wait for threads to finish
    // this will *not* terminate any threads currently running
    executorService.shutdown();
    Thread.sleep(TEST_LENGTH + 50);
    // Possibly in deadlock, wait a little longer to be sure
    for (int i = 0; i < 50 && !executorService.isTerminated(); i++) {
        Thread.sleep(20);
    }
    if (!executorService.isTerminated()) {
        /* uncomment this block to perform deadlock checking, only on java 1.6 */
        // Check for deadlock
        ThreadMXBean tmx = ManagementFactory.getThreadMXBean();
        long[] ids = tmx.findDeadlockedThreads();
        if (ids != null) {
            ThreadInfo[] infos = tmx.getThreadInfo(ids, true, true);
            System.err.println("*** Deadlocked threads");
            for (ThreadInfo ti : infos) {
                System.err.println("Thread \"" + ti.getThreadName() + "\" id=" + ti.getThreadId() + " " + ti.getThreadState().toString());
                System.err.println("Lock name: " + ti.getLockName() + " owned by \"" + ti.getLockOwnerName() + "\" id=" + ti.getLockOwnerId());
                System.err.println("\nStack trace:");
                for (StackTraceElement st : ti.getStackTrace()) System.err.println("   " + st.getClassName() + "." + st.getMethodName() + " (" + st.getFileName() + ":" + st.getLineNumber() + ")");
                System.err.println();
            }
        }
        Assert.assertTrue("Deadlock detected!", false);
        /* end deadlock block */
        assertTrue("Failed to terminate execution", false);
    }
}
Also used : StmtIterator(org.apache.jena.rdf.model.StmtIterator) ThreadMXBean(java.lang.management.ThreadMXBean) OntResource(org.apache.jena.ontology.OntResource) JenaException(org.apache.jena.shared.JenaException) ThreadInfo(java.lang.management.ThreadInfo) ExtendedIterator(org.apache.jena.util.iterator.ExtendedIterator) ExecutorService(java.util.concurrent.ExecutorService) OntClass(org.apache.jena.ontology.OntClass)

Aggregations

JenaException (org.apache.jena.shared.JenaException)70 Model (org.apache.jena.rdf.model.Model)12 RDFReader (org.apache.jena.rdf.model.RDFReader)8 IOException (java.io.IOException)7 QueryException (org.apache.jena.query.QueryException)5 QueryParseException (org.apache.jena.query.QueryParseException)5 java.io (java.io)4 InputStream (java.io.InputStream)4 Reader (java.io.Reader)4 StringReader (java.io.StringReader)4 Graph (org.apache.jena.graph.Graph)4 ServletOutputStream (javax.servlet.ServletOutputStream)3 CmdException (jena.cmd.CmdException)3 AmbiguousSpecificTypeException (org.apache.jena.assembler.exceptions.AmbiguousSpecificTypeException)3 MediaType (org.apache.jena.atlas.web.MediaType)3 Triple (org.apache.jena.graph.Triple)3 BadDescriptionMultipleRootsException (org.apache.jena.shared.BadDescriptionMultipleRootsException)3 BadDescriptionNoRootException (org.apache.jena.shared.BadDescriptionNoRootException)3 ARQParser (org.apache.jena.sparql.lang.arq.ARQParser)3 FileNotFoundException (java.io.FileNotFoundException)2