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);
}
}
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;
}
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);
}
}
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);
}
}
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);
}
}
Aggregations