use of java.util.concurrent.TimeUnit in project undertow by undertow-io.
the class UndertowXnioSsl method createSslTcpServer.
@SuppressWarnings("deprecation")
public AcceptingChannel<ConnectedSslStreamChannel> createSslTcpServer(final XnioWorker worker, final InetSocketAddress bindAddress, final ChannelListener<? super AcceptingChannel<ConnectedSslStreamChannel>> acceptListener, final OptionMap optionMap) throws IOException {
final AcceptingChannel<SslConnection> server = createSslConnectionServer(worker, bindAddress, null, optionMap);
final AcceptingChannel<ConnectedSslStreamChannel> acceptingChannel = new AcceptingChannel<ConnectedSslStreamChannel>() {
public ConnectedSslStreamChannel accept() throws IOException {
final SslConnection connection = server.accept();
return connection == null ? null : new AssembledConnectedSslStreamChannel(connection, connection.getSourceChannel(), connection.getSinkChannel());
}
public ChannelListener.Setter<? extends AcceptingChannel<ConnectedSslStreamChannel>> getAcceptSetter() {
return ChannelListeners.getDelegatingSetter(server.getAcceptSetter(), this);
}
public ChannelListener.Setter<? extends AcceptingChannel<ConnectedSslStreamChannel>> getCloseSetter() {
return ChannelListeners.getDelegatingSetter(server.getCloseSetter(), this);
}
public SocketAddress getLocalAddress() {
return server.getLocalAddress();
}
public <A extends SocketAddress> A getLocalAddress(final Class<A> type) {
return server.getLocalAddress(type);
}
public void suspendAccepts() {
server.suspendAccepts();
}
public void resumeAccepts() {
server.resumeAccepts();
}
public boolean isAcceptResumed() {
return server.isAcceptResumed();
}
public void wakeupAccepts() {
server.wakeupAccepts();
}
public void awaitAcceptable() throws IOException {
server.awaitAcceptable();
}
public void awaitAcceptable(final long time, final TimeUnit timeUnit) throws IOException {
server.awaitAcceptable(time, timeUnit);
}
public XnioWorker getWorker() {
return server.getWorker();
}
@Deprecated
public XnioExecutor getAcceptThread() {
return server.getAcceptThread();
}
public XnioIoThread getIoThread() {
return server.getIoThread();
}
public void close() throws IOException {
server.close();
}
public boolean isOpen() {
return server.isOpen();
}
public boolean supportsOption(final Option<?> option) {
return server.supportsOption(option);
}
public <T> T getOption(final Option<T> option) throws IOException {
return server.getOption(option);
}
public <T> T setOption(final Option<T> option, final T value) throws IllegalArgumentException, IOException {
return server.setOption(option, value);
}
};
acceptingChannel.getAcceptSetter().set(acceptListener);
return acceptingChannel;
}
use of java.util.concurrent.TimeUnit in project undertow by undertow-io.
the class HttpContinue method createResponseSender.
/**
* Creates a response sender that can be used to send a HTTP 100-continue response.
*
* @param exchange The exchange
* @return The response sender
*/
public static ContinueResponseSender createResponseSender(final HttpServerExchange exchange) throws IOException {
if (!exchange.isResponseChannelAvailable()) {
throw UndertowMessages.MESSAGES.cannotSendContinueResponse();
}
if (exchange.getAttachment(ALREADY_SENT) != null) {
return new ContinueResponseSender() {
@Override
public boolean send() throws IOException {
return true;
}
@Override
public void awaitWritable() throws IOException {
}
@Override
public void awaitWritable(long time, TimeUnit timeUnit) throws IOException {
}
};
}
HttpServerExchange newExchange = exchange.getConnection().sendOutOfBandResponse(exchange);
exchange.putAttachment(ALREADY_SENT, true);
newExchange.setStatusCode(StatusCodes.CONTINUE);
newExchange.getResponseHeaders().put(Headers.CONTENT_LENGTH, 0);
final StreamSinkChannel responseChannel = newExchange.getResponseChannel();
return new ContinueResponseSender() {
boolean shutdown = false;
@Override
public boolean send() throws IOException {
if (!shutdown) {
shutdown = true;
responseChannel.shutdownWrites();
}
return responseChannel.flush();
}
@Override
public void awaitWritable() throws IOException {
responseChannel.awaitWritable();
}
@Override
public void awaitWritable(final long time, final TimeUnit timeUnit) throws IOException {
responseChannel.awaitWritable(time, timeUnit);
}
};
}
use of java.util.concurrent.TimeUnit in project voldemort by voldemort.
the class BaseStreamingClient method initStreamingSessions.
/**
**
* @param stores - the list of name of the stores to be streamed to
*
*
* @param checkpointCallback - the callback that allows for the user to
* record the progress, up to the last event delivered. This callable
* would be invoked every so often internally.
*
* @param recoveryCallback - the callback that allows the user to rewind the
* upstream to the position recorded by the last complete call on
* checkpointCallback whenever an exception occurs during the
* streaming session.
*
* @param allowMerge - whether to allow for the streaming event to be merged
* with online writes. If not, all online writes since the completion
* of the last streaming session will be lost at the end of the
* current streaming session.
*
* @param blackListedNodes - the list of Nodes not to stream to; we can
* probably recover them later from the replicas
**/
@SuppressWarnings({ "unchecked", "rawtypes" })
public synchronized void initStreamingSessions(List<String> stores, Callable checkpointCallback, Callable recoveryCallback, boolean allowMerge, List<Integer> blackListedNodes) {
logger.info("Initializing a streaming session");
this.checkpointCallback = checkpointCallback;
this.recoveryCallback = recoveryCallback;
this.allowMerge = allowMerge;
streamingresults = Executors.newFixedThreadPool(3);
entriesProcessed = 0;
newBatch = true;
isMultiSession = true;
this.throttler = new EventThrottler(THROTTLE_QPS);
TimeUnit unit = TimeUnit.SECONDS;
Collection<Node> nodesInCluster = adminClient.getAdminClientCluster().getNodes();
if (blackListedNodes != null && blackListedNodes.size() > 0) {
this.blackListedNodes = blackListedNodes;
}
for (Node node : nodesInCluster) {
if (blackListedNodes != null && blackListedNodes.size() > 0) {
if (!blackListedNodes.contains(node.getId())) {
nodesToStream.add(node);
}
} else
nodesToStream.add(node);
}
// socket pool
streamingSocketPool = new SocketPool(adminClient.getAdminClientCluster().getNumberOfNodes() * MAX_STORES_PER_SESSION, (int) unit.toMillis(adminClientConfig.getAdminConnectionTimeoutSec()), (int) unit.toMillis(adminClientConfig.getAdminSocketTimeoutSec()), adminClientConfig.getAdminSocketBufferSize(), adminClientConfig.getAdminSocketKeepAlive());
nodeIdStoreToSocketRequest = new HashMap();
nodeIdStoreToOutputStreamRequest = new HashMap();
nodeIdStoreToInputStreamRequest = new HashMap();
nodeIdStoreInitialized = new HashMap();
storeToRoutingStrategy = new HashMap();
nodeIdStoreToSocketAndStreams = new HashMap();
for (String store : stores) {
addStoreToSession(store);
}
}
use of java.util.concurrent.TimeUnit in project wildfly by wildfly.
the class TransactionAttributeMergingProcessor method timeout.
private static Integer timeout(final ContainerTransactionMetaData containerTransaction) {
final List<TransactionTimeoutMetaData> transactionTimeouts = containerTransaction.getAny(TransactionTimeoutMetaData.class);
if (transactionTimeouts == null || transactionTimeouts.isEmpty())
return null;
final TransactionTimeoutMetaData transactionTimeout = transactionTimeouts.get(0);
final TimeUnit unit = transactionTimeout.getUnit() == null ? TimeUnit.SECONDS : transactionTimeout.getUnit();
return (int) unit.toSeconds(transactionTimeout.getTimeout());
}
use of java.util.concurrent.TimeUnit in project wildfly by wildfly.
the class StatefulTimeoutMergingProcessor method handleDeploymentDescriptor.
@Override
protected void handleDeploymentDescriptor(final DeploymentUnit deploymentUnit, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final StatefulComponentDescription componentConfiguration) throws DeploymentUnitProcessingException {
final SessionBeanMetaData data = componentConfiguration.getDescriptorData();
if (data == null) {
return;
}
if (data instanceof SessionBean31MetaData) {
SessionBean31MetaData sessionBean31MetaData = (SessionBean31MetaData) data;
final StatefulTimeoutMetaData statefulTimeout = sessionBean31MetaData.getStatefulTimeout();
if (statefulTimeout != null) {
TimeUnit unit = TimeUnit.MINUTES;
if (statefulTimeout.getUnit() != null) {
unit = statefulTimeout.getUnit();
}
componentConfiguration.setStatefulTimeout(new StatefulTimeoutInfo(statefulTimeout.getTimeout(), unit));
}
}
}
Aggregations