当前位置: 首页>>代码示例>>Java>>正文


Java IoUtils.safeClose方法代码示例

本文整理汇总了Java中org.xnio.IoUtils.safeClose方法的典型用法代码示例。如果您正苦于以下问题:Java IoUtils.safeClose方法的具体用法?Java IoUtils.safeClose怎么用?Java IoUtils.safeClose使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.xnio.IoUtils的用法示例。


在下文中一共展示了IoUtils.safeClose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handshakeInternal

import org.xnio.IoUtils; //导入方法依赖的package包/类
@Override
protected void handshakeInternal(final WebSocketHttpExchange exchange) {
    String origin = exchange.getRequestHeader(Headers.ORIGIN_STRING);
    if (origin != null) {
        exchange.setResponseHeader(Headers.ORIGIN_STRING, origin);
    }
    selectSubprotocol(exchange);
    selectExtensions(exchange);
    exchange.setResponseHeader(Headers.SEC_WEB_SOCKET_LOCATION_STRING, getWebSocketLocation(exchange));

    final String key = exchange.getRequestHeader(Headers.SEC_WEB_SOCKET_KEY_STRING);
    try {
        final String solution = solve(key);
        exchange.setResponseHeader(Headers.SEC_WEB_SOCKET_ACCEPT_STRING, solution);
        performUpgrade(exchange);
    } catch (NoSuchAlgorithmException e) {
        IoUtils.safeClose(exchange);
        exchange.endExchange();
        return;
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:22,代码来源:Hybi13Handshake.java

示例2: handleEvent

import org.xnio.IoUtils; //导入方法依赖的package包/类
@Override
public void handleEvent(final StreamSourceChannel channel) {
    Pooled<ByteBuffer> resource = bufferPool.allocate();
    ByteBuffer buffer = resource.getResource();
    try {
        int r = 0;
        do {
            r = channel.read(buffer);
            if (r == 0) {
                return;
            } else if (r == -1) {
                stringDone(string.extract());
                IoUtils.safeClose(channel);
            } else {
                buffer.flip();
                string.write(buffer);
            }
        } while (r > 0);
    } catch (IOException e) {
        error(e);
    } finally {
        resource.free();
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:25,代码来源:StringReadChannelListener.java

示例3: run

import org.xnio.IoUtils; //导入方法依赖的package包/类
@Override
public void run() {
    if(!connection.isOpen()) {
        return;
    }
    handle = null;
    if (expireTime > 0) { //timeout is not active
        long now = System.currentTimeMillis();
        if(expireTime > now) {
            handle = connection.getIoThread().executeAfter(this, (expireTime - now) + FUZZ_FACTOR, TimeUnit.MILLISECONDS);
        } else {
            UndertowLogger.REQUEST_LOGGER.parseRequestTimedOut(connection.getPeerAddress());
            IoUtils.safeClose(connection);
        }
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:ParseTimeoutUpdater.java

示例4: transferFrom

import org.xnio.IoUtils; //导入方法依赖的package包/类
public long transferFrom(final FileChannel src, final long position, final long count) throws IOException {
    try {
        if (state != 0) {
            final Pooled<ByteBuffer> pooled = exchange.getConnection().getBufferPool().allocate();
            ByteBuffer buffer = pooled.getResource();
            try {
                int res = src.read(buffer);
                if (res <= 0) {
                    return res;
                }
                buffer.flip();
                return write(buffer);
            } finally {
                pooled.free();
            }
        } else {
            return next.transferFrom(src, position, count);
        }
    } catch (IOException | RuntimeException e) {
        IoUtils.safeClose(exchange.getConnection());
        throw e;
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:HttpResponseConduit.java

示例5: testHttp2Post

import org.xnio.IoUtils; //导入方法依赖的package包/类
/**
 * This is an example for post request. Please note that you need to set header TRANSFER_ENCODING
 * and pass the request body into the callback function.
 *
 * @throws Exception
 */
public void testHttp2Post() throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);
    final ClientConnection connection = client.connect(new URI("https://localhost:8443"), Http2Client.WORKER, Http2Client.SSL, Http2Client.POOL, OptionMap.create(UndertowOptions.ENABLE_HTTP2, true)).get();
    final AtomicReference<ClientResponse> reference = new AtomicReference<>();
    try {
        final ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath("/post");
        if(securityEnabled) {
            // call OAuth 2.0 provider service to get a JWT access token here and
            // put it into the request header. Optionally, you can put a traceabilityId
            // into the header.

        }
        request.getRequestHeaders().put(Headers.TRANSFER_ENCODING, "chunked");
        connection.sendRequest(request, client.createClientCallback(reference, latch, "post"));
        latch.await(100, TimeUnit.MILLISECONDS);
    } finally {
        IoUtils.safeClose(connection);
    }
    System.out.println("testHttp2Post: statusCode = " + reference.get().getResponseCode() + " body = " + reference.get().getAttachment(Http2Client.RESPONSE_BODY));
}
 
开发者ID:networknt,项目名称:light-example-4j,代码行数:27,代码来源:Http2ClientExample.java

示例6: tearDownServer

import org.xnio.IoUtils; //导入方法依赖的package包/类
@AfterClass
public static void tearDownServer() throws Exception {
    ModelControllerClient client = null;
    try {
        client = containerController.getClient().getControllerClient();
        ModelNode vaultResult = client.execute(Util.createRemoveOperation(PathAddress.pathAddress(VaultResourceDefinition.PATH)));
        ModelNode subsystemResult = client.execute(Util.createRemoveOperation(PathAddress.pathAddress(TestVaultSubsystemResourceDescription.PATH)));
        ModelNode extensionResult = client.execute(Util.createRemoveOperation(PathAddress.pathAddress(ModelDescriptionConstants.EXTENSION, MODULE_NAME)));
        ModelTestUtils.checkOutcome(vaultResult);
        ModelTestUtils.checkOutcome(subsystemResult);
        ModelTestUtils.checkOutcome(extensionResult);

    } finally {
        containerController.stop();
        testModule.remove();
        picketLink.remove();
        IoUtils.safeClose(client);
    }
    containerController.stop();
}
 
开发者ID:wildfly,项目名称:wildfly-core,代码行数:21,代码来源:CustomVaultInModuleTestCase.java

示例7: periodicTask

import org.xnio.IoUtils; //导入方法依赖的package包/类
/**
 * This task is executed periodically to make sure no waiter stay in the queue longer than needed and no stale
 * connection occupies the pool.
 */
private void periodicTask() {
    if (stop) {
        return;
    }
    // Close stale connections and remove them from the pool
    long now = System.currentTimeMillis();
    for (Iterator<PooledConnection> iterator = connections.iterator(); iterator.hasNext(); ) {
        PooledConnection connection = iterator.next();
        if (connection.idle && !connection.canReuse(now)) {
            iterator.remove();
            IoUtils.safeClose(connection);
        }
    }
    removeTimedOutWaiters();
    // Create a connection if pool is not full and some clients are waiting
    if (!waiters.isEmpty() && !isFull()) {
        createConnection();
    }
    // Side job, update metrics
    connectionCount = connections.size();
    waiterCount = waiters.size();
}
 
开发者ID:hawkular,项目名称:hawkular-metrics,代码行数:27,代码来源:TokenAuthenticator.java

示例8: release

import org.xnio.IoUtils; //导入方法依赖的package包/类
private void release(PooledConnection connection) {
    connection.idle = true;
    if (stop) {
        return;
    }
    // Don't keep the connection in the pool if we can't reuse it
    if (!connection.canReuse(System.currentTimeMillis())) {
        connections.remove(connection);
        IoUtils.safeClose(connection);
    }
    removeTimedOutWaiters();
    // Stop here if no client is waiting for a connection
    if (!waiters.isEmpty()) {
        PooledConnection selected = selectIdleConnection();
        if (selected != null) {
            // Got a connection, can poll a waiter now
            PooledConnectionWaiter waiter = waiters.poll();
            waiter.onGet.accept(selected);
        } else if (!isFull()) {
            createConnection();
        }
    }
}
 
开发者ID:hawkular,项目名称:hawkular-metrics,代码行数:24,代码来源:TokenAuthenticator.java

示例9: afterTest

import org.xnio.IoUtils; //导入方法依赖的package包/类
@After
public void afterTest() throws Exception {
    final ModelControllerClient client = container.getClient().getControllerClient();
    IoUtils.safeClose(connector);

    final CompositeOperationBuilder compositeOp = CompositeOperationBuilder.create();
    resetUser(compositeOp);
    compositeOp.addStep(Util.getResourceRemoveOperation(PathAddress.pathAddress(auditLogConfigAddress,
            PathElement.pathElement(HANDLER, HANDLER_NAME))));
    compositeOp.addStep(Util.getResourceRemoveOperation(auditLogConfigAddress));

    try {
        executeForSuccess(client, compositeOp.build());
    } finally {
        Files.deleteIfExists(FILE);
        container.stop();
    }
}
 
开发者ID:wildfly,项目名称:wildfly-core,代码行数:19,代码来源:JmxAuditLogFieldsOfLogTestCase.java

示例10: cancel

import org.xnio.IoUtils; //导入方法依赖的package包/类
void cancel(final HttpServerExchange exchange) {
    final ProxyConnection connectionAttachment = exchange.getAttachment(CONNECTION);
    if (connectionAttachment != null) {
        ClientConnection clientConnection = connectionAttachment.getConnection();
        UndertowLogger.REQUEST_LOGGER.timingOutRequest(clientConnection.getPeerAddress() + "" + exchange.getRequestURI());
        IoUtils.safeClose(clientConnection);
    } else {
        UndertowLogger.REQUEST_LOGGER.timingOutRequest(exchange.getRequestURI());
    }
    if (exchange.isResponseStarted()) {
        IoUtils.safeClose(exchange.getConnection());
    } else {
        exchange.setResponseCode(503);
        exchange.endExchange();
    }
}
 
开发者ID:liveoak-io,项目名称:liveoak,代码行数:17,代码来源:ProxyHandler.java

示例11: handleException

import org.xnio.IoUtils; //导入方法依赖的package包/类
@Override
public void handleException(Channel channel, IOException exception) {
    IoUtils.safeClose(channel);
    if (exchange.isResponseStarted()) {
        IoUtils.safeClose(clientConnection);
        UndertowLogger.REQUEST_IO_LOGGER.debug("Exception reading from target server", exception);
        if (!exchange.isResponseStarted()) {
            exchange.setResponseCode(500);
            exchange.endExchange();
        } else {
            IoUtils.safeClose(exchange.getConnection());
        }
    } else {
        exchange.setResponseCode(500);
        exchange.endExchange();
    }
}
 
开发者ID:liveoak-io,项目名称:liveoak,代码行数:18,代码来源:ProxyHandler.java

示例12: testMultipleHttp2Post

import org.xnio.IoUtils; //导入方法依赖的package包/类
public void testMultipleHttp2Post(int round) throws Exception {
    final Http2Client client = Http2Client.getInstance();
    final List<AtomicReference<ClientResponse>> references = new CopyOnWriteArrayList<>();
    final CountDownLatch latch = new CountDownLatch(round);
    final ClientConnection connection = client.connect(new URI("https://localhost:8443"), Http2Client.WORKER, Http2Client.SSL, Http2Client.POOL, OptionMap.create(UndertowOptions.ENABLE_HTTP2, true)).get();
    try {
        connection.getIoThread().execute(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < round; i++) {
                    AtomicReference<ClientResponse> reference = new AtomicReference<>();
                    references.add(i, reference);
                    final ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath("/post");
                    request.getRequestHeaders().put(Headers.TRANSFER_ENCODING, "chunked");
                    request.getRequestHeaders().put(Headers.HOST, "localhost");
                    connection.sendRequest(request, client.createClientCallback(reference, latch, "post"));
                }
            }
        });
        latch.await(10, TimeUnit.SECONDS);
        /*
        for (final AtomicReference<ClientResponse> reference : references) {
            System.out.println(reference.get().getAttachment(Http2Client.RESPONSE_BODY));
            System.out.println(reference.get().getProtocol().toString());
        }
        */
    } finally {
        IoUtils.safeClose(connection);
    }
}
 
开发者ID:networknt,项目名称:http2client-benchmark,代码行数:31,代码来源:Http2ClientExample.java

示例13: doTerminateWrites

import org.xnio.IoUtils; //导入方法依赖的package包/类
@Override
protected void doTerminateWrites() throws IOException {
    try {
        if (!exchange.isPersistent()) {
            next.terminateWrites();
        }
        state |= FLAG_WRITE_SHUTDOWN;
    } catch (IOException | RuntimeException e) {
        IoUtils.safeClose(exchange.getConnection());
        throw e;
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:13,代码来源:AjpServerResponseConduit.java

示例14: handleError

import org.xnio.IoUtils; //导入方法依赖的package包/类
private void handleError(final IOException e) {
    try {
        ThreadSetupAction.Handle handle = threadSetupAction.setup(servletRequestContext.getExchange());
        try {
            listener.onError(e);
        } finally {
            handle.tearDown();
        }
    } finally {
        IoUtils.safeClose(channel, servletRequestContext.getExchange().getConnection());
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:13,代码来源:ServletOutputStreamImpl.java

示例15: close

import org.xnio.IoUtils; //导入方法依赖的package包/类
@Override
public void close() throws Exception {
    try {
        outputStream.closeBlocking();
    } finally {
        IoUtils.safeClose(inputStream, channel);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:9,代码来源:WebConnectionImpl.java


注:本文中的org.xnio.IoUtils.safeClose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。