use of java.util.concurrent.Callable in project ProPPR by TeamCohen.
the class Grounder method groundExamples.
public void groundExamples(File dataFile, File groundedFile, boolean maintainOrder) {
status.start();
try {
if (this.graphKeyFile != null)
this.graphKeyWriter = new BufferedWriter(new FileWriter(this.graphKeyFile));
this.statistics = new GroundingStatistics();
this.empty = 0;
Multithreading<InferenceExample, String> m = new Multithreading<InferenceExample, String>(log, this.status, maintainOrder);
m.executeJob(this.nthreads, new InferenceExampleStreamer(dataFile).stream(), new Transformer<InferenceExample, String>() {
@Override
public Callable<String> transformer(InferenceExample in, int id) {
return new Ground(in, id);
}
}, groundedFile, this.throttle);
reportStatistics(empty);
File indexFile = new File(groundedFile.getParent(), groundedFile.getName() + FEATURE_INDEX_EXTENSION);
serializeFeatures(indexFile, featureTable);
if (this.graphKeyFile != null)
this.graphKeyWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
}
use of java.util.concurrent.Callable in project voltdb by VoltDB.
the class VoltNetwork method registerChannel.
/**
* Register a channel with the selector and create a Connection that will pass incoming events
* to the provided handler.
* @param channel
* @param handler
* @throws IOException
*/
Connection registerChannel(final SocketChannel channel, final InputHandler handler, final int interestOps, final ReverseDNSPolicy dns, final CipherExecutor cipherService, final SSLEngine sslEngine) throws IOException {
synchronized (channel.blockingLock()) {
channel.configureBlocking(false);
channel.socket().setKeepAlive(true);
}
Callable<Connection> registerTask = new Callable<Connection>() {
@Override
public Connection call() throws Exception {
final VoltPort port = VoltPortFactory.createVoltPort(channel, VoltNetwork.this, handler, (InetSocketAddress) channel.socket().getRemoteSocketAddress(), m_pool, cipherService, sslEngine);
port.registering();
/*
* This means we are used by a client. No need to wait then, trigger
* the reverse DNS lookup now.
*/
if (dns != ReverseDNSPolicy.NONE) {
port.resolveHostname(dns == ReverseDNSPolicy.SYNCHRONOUS);
}
try {
SelectionKey key = channel.register(m_selector, interestOps, null);
port.setKey(key);
port.registered();
//Fix a bug witnessed on the mini where the registration lock and the selector wakeup contained
//within was not enough to prevent the selector from returning the port after it was registered,
//but before setKey was called. Suspect a bug in the selector.wakeup() or register() implementation
//on the mac.
//The null check in invokeCallbacks will catch the null attachment, continue, and do the work
//next time through the selection loop
key.attach(port);
return port;
} finally {
m_ports.add(port);
m_numPorts.incrementAndGet();
}
}
};
FutureTask<Connection> ft = new FutureTask<Connection>(registerTask);
m_tasks.offer(ft);
m_selector.wakeup();
try {
return ft.get();
} catch (Exception e) {
throw new IOException(e);
}
}
use of java.util.concurrent.Callable in project voltdb by VoltDB.
the class CSVSnapshotWritePlan method createDeferredSetup.
private Callable<Boolean> createDeferredSetup(final String file_path, final String pathType, final String file_nonce, final Table[] tables, final long txnId, final Map<Integer, Long> partitionTransactionIds, final SystemProcedureExecutionContext context, final ExtensibleSnapshotDigestData extraSnapshotData, final long timestamp, final AtomicInteger numTables, final SnapshotRegistry.Snapshot snapshotRecord, final ArrayList<SnapshotTableTask> partitionedSnapshotTasks, final ArrayList<SnapshotTableTask> replicatedSnapshotTasks) {
return new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
NativeSnapshotWritePlan.createFileBasedCompletionTasks(file_path, pathType, file_nonce, txnId, partitionTransactionIds, context, extraSnapshotData, null, timestamp, context.getNumberOfPartitions(), tables);
for (SnapshotTableTask task : replicatedSnapshotTasks) {
final SnapshotDataTarget target = createDataTargetForTable(file_path, file_nonce, context.getHostId(), numTables, snapshotRecord, task.m_table);
task.setTarget(target);
}
for (SnapshotTableTask task : partitionedSnapshotTasks) {
final SnapshotDataTarget target = createDataTargetForTable(file_path, file_nonce, context.getHostId(), numTables, snapshotRecord, task.m_table);
task.setTarget(target);
}
return true;
}
};
}
use of java.util.concurrent.Callable in project core-java by SpineEventEngine.
the class VerifyShould method pass_assertThrows_if_callable_throws_specified_exception.
@Test
public void pass_assertThrows_if_callable_throws_specified_exception() {
final Callable throwsEmptyStackException = new Callable() {
@Override
public Object call() throws Exception {
throw new EmptyStackException();
}
};
assertThrows(EmptyStackException.class, throwsEmptyStackException);
}
use of java.util.concurrent.Callable in project core-java by SpineEventEngine.
the class VerifyShould method pass_assertThrowsWithCause_if_callable_throws_specified_exception_with_specified_cause.
@Test
public void pass_assertThrowsWithCause_if_callable_throws_specified_exception_with_specified_cause() {
final Throwable cause = new EmptyStackException();
final RuntimeException runtimeException = new RuntimeException(cause);
final Callable throwsRuntimeException = new Callable() {
@Override
public Object call() {
throw runtimeException;
}
};
assertThrowsWithCause(runtimeException.getClass(), cause.getClass(), throwsRuntimeException);
}
Aggregations