use of java.util.concurrent.Executor in project robovm by robovm.
the class Linker method generateMachineCode.
private void generateMachineCode(final Config config, ModuleBuilder[] mbs, final List<File> objectFiles) throws IOException {
/*
* Make sure the tmpDir exists before we launch the worker threads. This
* is to prevent a race between threads to create this folder. See #631.
*/
config.getTmpDir().mkdirs();
Executor executor = config.getThreads() <= 1 ? AppCompiler.SAME_THREAD_EXECUTOR : Executors.newFixedThreadPool(config.getThreads());
final List<Throwable> errors = Collections.synchronizedList(new ArrayList<Throwable>());
for (int i = 0; i < mbs.length; i++) {
final ModuleBuilder mb = mbs[i];
final int num = i;
executor.execute(new Runnable() {
public void run() {
try {
File linkerO = generateMachineCode(config, mb, num);
synchronized (objectFiles) {
objectFiles.add(linkerO);
}
} catch (Throwable t) {
errors.add(t);
}
}
});
}
// Shutdown the executor and wait for running tasks to complete.
if (executor instanceof ExecutorService) {
ExecutorService executorService = (ExecutorService) executor;
executorService.shutdown();
try {
executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);
} catch (InterruptedException e) {
}
}
if (!errors.isEmpty()) {
Throwable t = errors.get(0);
if (t instanceof IOException) {
throw (IOException) t;
}
if (t instanceof RuntimeException) {
throw (RuntimeException) t;
}
throw new CompilerException(t);
}
}
use of java.util.concurrent.Executor in project jetty.project by eclipse.
the class HttpClientTransportOverHTTP2Test method testExternalServer.
@Ignore
@Test
public void testExternalServer() throws Exception {
HTTP2Client http2Client = new HTTP2Client();
SslContextFactory sslContextFactory = new SslContextFactory();
HttpClient httpClient = new HttpClient(new HttpClientTransportOverHTTP2(http2Client), sslContextFactory);
Executor executor = new QueuedThreadPool();
httpClient.setExecutor(executor);
httpClient.start();
// ContentResponse response = httpClient.GET("https://http2.akamai.com/");
ContentResponse response = httpClient.GET("https://webtide.com/");
Assert.assertEquals(HttpStatus.OK_200, response.getStatus());
httpClient.stop();
}
use of java.util.concurrent.Executor in project jetty.project by eclipse.
the class ProxyServlet method onContinue.
@Override
protected void onContinue(HttpServletRequest clientRequest, Request proxyRequest) {
super.onContinue(clientRequest, proxyRequest);
Runnable action = (Runnable) proxyRequest.getAttributes().get(CONTINUE_ACTION_ATTRIBUTE);
Executor executor = getHttpClient().getExecutor();
executor.execute(action);
}
use of java.util.concurrent.Executor in project elasticsearch by elastic.
the class MockTcpTransport method connectToChannels.
@Override
protected NodeChannels connectToChannels(DiscoveryNode node, ConnectionProfile profile) throws IOException {
final MockChannel[] mockChannels = new MockChannel[1];
// we always use light here
final NodeChannels nodeChannels = new NodeChannels(node, mockChannels, LIGHT_PROFILE);
boolean success = false;
final MockSocket socket = new MockSocket();
try {
Consumer<MockChannel> onClose = (channel) -> {
final NodeChannels connected = connectedNodes.get(node);
if (connected != null && connected.hasChannel(channel)) {
try {
executor.execute(() -> {
disconnectFromNode(node, channel, "channel closed event");
});
} catch (RejectedExecutionException ex) {
logger.debug("failed to run disconnectFromNode - node is shutting down");
}
}
};
final InetSocketAddress address = node.getAddress().address();
// we just use a single connections
configureSocket(socket);
final TimeValue connectTimeout = profile.getConnectTimeout();
try {
socket.connect(address, Math.toIntExact(connectTimeout.millis()));
} catch (SocketTimeoutException ex) {
throw new ConnectTransportException(node, "connect_timeout[" + connectTimeout + "]", ex);
}
MockChannel channel = new MockChannel(socket, address, "none", onClose);
channel.loopRead(executor);
mockChannels[0] = channel;
success = true;
} finally {
if (success == false) {
IOUtils.close(nodeChannels, socket);
}
}
return nodeChannels;
}
use of java.util.concurrent.Executor in project jetty.project by eclipse.
the class HTTP2ClientConnectionFactory method newConnection.
@Override
public Connection newConnection(EndPoint endPoint, Map<String, Object> context) throws IOException {
HTTP2Client client = (HTTP2Client) context.get(CLIENT_CONTEXT_KEY);
ByteBufferPool byteBufferPool = (ByteBufferPool) context.get(BYTE_BUFFER_POOL_CONTEXT_KEY);
Executor executor = (Executor) context.get(EXECUTOR_CONTEXT_KEY);
Scheduler scheduler = (Scheduler) context.get(SCHEDULER_CONTEXT_KEY);
Session.Listener listener = (Session.Listener) context.get(SESSION_LISTENER_CONTEXT_KEY);
@SuppressWarnings("unchecked") Promise<Session> promise = (Promise<Session>) context.get(SESSION_PROMISE_CONTEXT_KEY);
Generator generator = new Generator(byteBufferPool);
FlowControlStrategy flowControl = client.getFlowControlStrategyFactory().newFlowControlStrategy();
HTTP2ClientSession session = new HTTP2ClientSession(scheduler, endPoint, generator, listener, flowControl);
Parser parser = new Parser(byteBufferPool, session, 4096, 8192);
HTTP2ClientConnection connection = new HTTP2ClientConnection(client, byteBufferPool, executor, endPoint, parser, session, client.getInputBufferSize(), promise, listener);
connection.addListener(connectionListener);
return customize(connection, context);
}
Aggregations