Search in sources :

Example 81 with TimeUnit

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;
}
Also used : SslConnection(org.xnio.ssl.SslConnection) ChannelListener(org.xnio.ChannelListener) TimeUnit(java.util.concurrent.TimeUnit) Option(org.xnio.Option) AssembledConnectedSslStreamChannel(org.xnio.channels.AssembledConnectedSslStreamChannel) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) ConnectedSslStreamChannel(org.xnio.channels.ConnectedSslStreamChannel) AssembledConnectedSslStreamChannel(org.xnio.channels.AssembledConnectedSslStreamChannel) AcceptingChannel(org.xnio.channels.AcceptingChannel)

Example 82 with TimeUnit

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);
        }
    };
}
Also used : HttpServerExchange(io.undertow.server.HttpServerExchange) TimeUnit(java.util.concurrent.TimeUnit) StreamSinkChannel(org.xnio.channels.StreamSinkChannel)

Example 83 with 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);
    }
}
Also used : HashMap(java.util.HashMap) Node(voldemort.cluster.Node) EventThrottler(voldemort.utils.EventThrottler) TimeUnit(java.util.concurrent.TimeUnit)

Example 84 with TimeUnit

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());
}
Also used : TransactionTimeoutMetaData(org.jboss.metadata.ejb.jboss.ejb3.TransactionTimeoutMetaData) TimeUnit(java.util.concurrent.TimeUnit)

Example 85 with TimeUnit

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));
        }
    }
}
Also used : SessionBeanMetaData(org.jboss.metadata.ejb.spec.SessionBeanMetaData) StatefulTimeoutInfo(org.jboss.as.ejb3.component.stateful.StatefulTimeoutInfo) TimeUnit(java.util.concurrent.TimeUnit) StatefulTimeoutMetaData(org.jboss.metadata.ejb.spec.StatefulTimeoutMetaData) SessionBean31MetaData(org.jboss.metadata.ejb.spec.SessionBean31MetaData)

Aggregations

TimeUnit (java.util.concurrent.TimeUnit)190 Test (org.junit.Test)28 ExecutionException (java.util.concurrent.ExecutionException)16 IOException (java.io.IOException)11 TimeoutException (java.util.concurrent.TimeoutException)11 Future (java.util.concurrent.Future)10 HashMap (java.util.HashMap)7 TimeSpec (com.linkedin.thirdeye.api.TimeSpec)6 ArrayList (java.util.ArrayList)6 TimeValue (org.elasticsearch.common.unit.TimeValue)6 DataType (com.linkedin.pinot.common.data.FieldSpec.DataType)5 File (java.io.File)5 HashSet (java.util.HashSet)5 Matcher (java.util.regex.Matcher)5 WaitUntilGatewaySenderFlushedCoordinatorJUnitTest (org.apache.geode.internal.cache.wan.WaitUntilGatewaySenderFlushedCoordinatorJUnitTest)5 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)5 TimeGranularity (com.linkedin.thirdeye.api.TimeGranularity)4 GwtIncompatible (com.google.common.annotations.GwtIncompatible)3 RestException (com.linkedin.r2.message.rest.RestException)3 Map (java.util.Map)3