Search in sources :

Example 56 with Callable

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();
    }
}
Also used : FileWriter(java.io.FileWriter) IOException(java.io.IOException) InferenceExample(edu.cmu.ml.proppr.examples.InferenceExample) Callable(java.util.concurrent.Callable) BufferedWriter(java.io.BufferedWriter) Multithreading(edu.cmu.ml.proppr.util.multithreading.Multithreading) ParamsFile(edu.cmu.ml.proppr.util.ParamsFile) File(java.io.File) InferenceExampleStreamer(edu.cmu.ml.proppr.examples.InferenceExampleStreamer)

Example 57 with Callable

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);
    }
}
Also used : SelectionKey(java.nio.channels.SelectionKey) FutureTask(java.util.concurrent.FutureTask) IOException(java.io.IOException) Callable(java.util.concurrent.Callable) AsynchronousCloseException(java.nio.channels.AsynchronousCloseException) CancelledKeyException(java.nio.channels.CancelledKeyException) ClosedChannelException(java.nio.channels.ClosedChannelException) IOException(java.io.IOException) ClosedByInterruptException(java.nio.channels.ClosedByInterruptException)

Example 58 with Callable

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;
        }
    };
}
Also used : SnapshotTableTask(org.voltdb.SnapshotTableTask) SnapshotDataTarget(org.voltdb.SnapshotDataTarget) SimpleFileSnapshotDataTarget(org.voltdb.SimpleFileSnapshotDataTarget) Callable(java.util.concurrent.Callable)

Example 59 with Callable

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);
}
Also used : EmptyStackException(java.util.EmptyStackException) Callable(java.util.concurrent.Callable) Test(org.junit.Test)

Example 60 with Callable

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);
}
Also used : EmptyStackException(java.util.EmptyStackException) Callable(java.util.concurrent.Callable) Test(org.junit.Test)

Aggregations

Callable (java.util.concurrent.Callable)1946 ArrayList (java.util.ArrayList)664 ExecutorService (java.util.concurrent.ExecutorService)630 Test (org.junit.Test)598 Future (java.util.concurrent.Future)482 IOException (java.io.IOException)255 ExecutionException (java.util.concurrent.ExecutionException)247 List (java.util.List)167 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)158 CountDownLatch (java.util.concurrent.CountDownLatch)157 HashMap (java.util.HashMap)120 Map (java.util.Map)117 File (java.io.File)112 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)105 Ignite (org.apache.ignite.Ignite)87 HashSet (java.util.HashSet)80 Set (java.util.Set)55 TimeoutException (java.util.concurrent.TimeoutException)54 Collectors (java.util.stream.Collectors)53 Transaction (org.apache.ignite.transactions.Transaction)52