@Override public void run() { try { responseAttachmentSupport.shutdown(); // Shut down new requests to the client request executor, // but don't mess with currently running tasks clientRequestExecutor.shutdown(); } finally { stopContext.complete(); } } };
/** * Closes any registered stream entries that have not yet been consumed */ public final synchronized void shutdown() { // synchronize on 'this' to avoid races with registerStreams stopped = true; // If the cleanup task is running tell it to stop looping, and then remove it from the scheduled executor if (cleanupTaskFuture != null) { cleanupTaskFuture.cancel(false); } // Close remaining streams for (Map.Entry<InputStreamKey, TimedStreamEntry> entry : streamMap.entrySet()) { InputStreamKey key = entry.getKey(); TimedStreamEntry timedStreamEntry = entry.getValue(); //noinspection SynchronizationOnLocalVariableOrMethodParameter synchronized (timedStreamEntry) { // ensure there's no race with a request that got a ref before we removed it closeStreamEntry(timedStreamEntry, key.requestId, key.index); } } }
@Override public void run() { ResponseAttachmentInputStreamSupport.this.gc(); } }
configuration.setConnectionTimeout(SERVER_CONNECTION_TIMEOUT); configuration.setSslContext(sslContextSupplier.get()); this.responseAttachmentSupport = new ResponseAttachmentInputStreamSupport(scheduledExecutorSupplier.get());
ResponseAttachmentInputStreamSupport.handleDomainOperationResponseStreams(context, responseNode, finalResponse.getInputStreams()); } else {
@Override public ManagementRequestHandler<?, ?> resolveHandler(final RequestHandlerChain handlers, final ManagementRequestHeader header) { switch (header.getOperationId()) { case ModelControllerProtocol.EXECUTE_ASYNC_CLIENT_REQUEST: case ModelControllerProtocol.EXECUTE_CLIENT_REQUEST: // initialize the operation ctx before executing the request handler handlers.registerActiveOperation(header.getBatchId(), null); return new ExecuteRequestHandler(); case ModelControllerProtocol.CANCEL_ASYNC_REQUEST: return new CancelAsyncRequestHandler(); case ModelControllerProtocol.GET_CHUNKED_INPUTSTREAM_REQUEST: // initialize the operation ctx before executing the request handler handlers.registerActiveOperation(header.getBatchId(), null); return responseAttachmentSupport.getReadHandler(); case ModelControllerProtocol.CLOSE_INPUTSTREAM_REQUEST: // initialize the operation ctx before executing the request handler handlers.registerActiveOperation(header.getBatchId(), null); return responseAttachmentSupport.getCloseHandler(); } return handlers.resolveNext(); }
OperationResponse response = controller.execute(attachmentsProxy, messageHandlerProxy, transactionControl); responseAttachmentSupport.registerStreams(context.getOperationId(), response.getInputStreams());
/** {@inheritDoc} */ @Override public synchronized void start(StartContext context) throws StartException { MGMT_OP_LOGGER.debugf("Starting operation handler service %s", context.getController().getName()); responseAttachmentSupport = new ResponseAttachmentInputStreamSupport(scheduledExecutor.getValue()); final ThreadFactory threadFactory = doPrivileged(new PrivilegedAction<JBossThreadFactory>() { public JBossThreadFactory run() { return new JBossThreadFactory(new ThreadGroup("management-handler-thread"), Boolean.FALSE, null, "%G - %t", null, null); } }); if (EnhancedQueueExecutor.DISABLE_HINT) { ThreadPoolExecutor executor = new ThreadPoolExecutor(POOL_CORE_SIZE, POOL_MAX_SIZE, 600L, TimeUnit.SECONDS, new LinkedBlockingDeque<>(WORK_QUEUE_SIZE), threadFactory); // Allow the core threads to time out as well executor.allowCoreThreadTimeOut(true); this.clientRequestExecutor = executor; } else { this.clientRequestExecutor = new EnhancedQueueExecutor.Builder() .setCorePoolSize(POOL_CORE_SIZE) .setMaximumPoolSize(POOL_MAX_SIZE) .setKeepAliveTime(600L, TimeUnit.SECONDS) .setMaximumQueueSize(WORK_QUEUE_SIZE) .setThreadFactory(threadFactory) .allowCoreThreadTimeOut(true) .build(); } }
ResponseAttachmentInputStreamSupport.handleDomainOperationResponseStreams(context, responseNode, finalResponse.getInputStreams()); } else {
@Override public ManagementRequestHandler<?, ?> resolveHandler(final RequestHandlerChain handlers, final ManagementRequestHeader header) { switch (header.getOperationId()) { case ModelControllerProtocol.EXECUTE_ASYNC_CLIENT_REQUEST: case ModelControllerProtocol.EXECUTE_CLIENT_REQUEST: // initialize the operation ctx before executing the request handler handlers.registerActiveOperation(header.getBatchId(), null); return new ExecuteRequestHandler(); case ModelControllerProtocol.CANCEL_ASYNC_REQUEST: return new CancelAsyncRequestHandler(); case ModelControllerProtocol.GET_CHUNKED_INPUTSTREAM_REQUEST: // initialize the operation ctx before executing the request handler handlers.registerActiveOperation(header.getBatchId(), null); return responseAttachmentSupport.getReadHandler(); case ModelControllerProtocol.CLOSE_INPUTSTREAM_REQUEST: // initialize the operation ctx before executing the request handler handlers.registerActiveOperation(header.getBatchId(), null); return responseAttachmentSupport.getCloseHandler(); } return handlers.resolveNext(); }
OperationResponse response = controller.execute(attachmentsProxy, messageHandlerProxy, transactionControl); responseAttachmentSupport.registerStreams(context.getOperationId(), response.getInputStreams());
@Override public void run() { try { responseAttachmentSupport.shutdown(); // Shut down new requests to the client request executor, // but don't mess with currently running tasks clientRequestExecutor.shutdown(); } finally { stopContext.complete(); } } };
/** {@inheritDoc} */ @Override public synchronized void start(StartContext context) throws StartException { MGMT_OP_LOGGER.debugf("Starting operation handler service %s", context.getController().getName()); responseAttachmentSupport = new ResponseAttachmentInputStreamSupport(scheduledExecutor.getValue()); final ThreadFactory threadFactory = doPrivileged(new PrivilegedAction<JBossThreadFactory>() { public JBossThreadFactory run() { return new JBossThreadFactory(new ThreadGroup("management-handler-thread"), Boolean.FALSE, null, "%G - %t", null, null); } }); if (EnhancedQueueExecutor.DISABLE_HINT) { ThreadPoolExecutor executor = new ThreadPoolExecutor(POOL_CORE_SIZE, POOL_MAX_SIZE, 600L, TimeUnit.SECONDS, new LinkedBlockingDeque<>(WORK_QUEUE_SIZE), threadFactory); // Allow the core threads to time out as well executor.allowCoreThreadTimeOut(true); this.clientRequestExecutor = executor; } else { this.clientRequestExecutor = new EnhancedQueueExecutor.Builder() .setCorePoolSize(POOL_CORE_SIZE) .setMaximumPoolSize(POOL_MAX_SIZE) .setKeepAliveTime(600L, TimeUnit.SECONDS) .setMaximumQueueSize(WORK_QUEUE_SIZE) .setThreadFactory(threadFactory) .allowCoreThreadTimeOut(true) .build(); } }
ResponseAttachmentInputStreamSupport.handleDomainOperationResponseStreams(context, transformedResult, finalResponse.getInputStreams());
return responseAttachmentSupport.getReadHandler(); return responseAttachmentSupport.getCloseHandler();
/** * Closes any registered stream entries that have not yet been consumed */ public final synchronized void shutdown() { // synchronize on 'this' to avoid races with registerStreams stopped = true; // If the cleanup task is running tell it to stop looping, and then remove it from the scheduled executor if (cleanupTaskFuture != null) { cleanupTaskFuture.cancel(false); } // Close remaining streams for (Map.Entry<InputStreamKey, TimedStreamEntry> entry : streamMap.entrySet()) { InputStreamKey key = entry.getKey(); TimedStreamEntry timedStreamEntry = entry.getValue(); //noinspection SynchronizationOnLocalVariableOrMethodParameter synchronized (timedStreamEntry) { // ensure there's no race with a request that got a ref before we removed it closeStreamEntry(timedStreamEntry, key.requestId, key.index); } } }
/** * Sends the final response to the remote client after the prepare phase has been executed. * This should be called whether the outcome was successful or not. */ synchronized void completed(final OperationResponse response) { assert prepared; if (responseChannel != null) { // Normal case, where a COMPLETE_TX_REQUEST came in after the prepare() call and // established a new responseChannel so the client can correlate the response ControllerLogger.MGMT_OP_LOGGER.tracef("sending completed response %s for %d --- interrupted: %s", response.getResponseNode(), getOperationId(), Thread.currentThread().isInterrupted()); streamSupport.registerStreams(operation.getOperationId(), response.getInputStreams()); try { sendResponse(responseChannel, ModelControllerProtocol.PARAM_OPERATION_COMPLETED, response.getResponseNode()); responseChannel = null; // we've now sent a response to the COMPLETE_TX_REQUEST, so we can't use this one further } catch (IOException e) { ControllerLogger.MGMT_OP_LOGGER.failedSendingCompletedResponse(e, response.getResponseNode(), getOperationId()); } finally { getResultHandler().done(null); } } else { // We were cancelled or somehow failed after sending our prepare() message but before we got a COMPLETE_TX_REQUEST. // The client will not be able to deal with any response until it sends a COMPLETE_TX_REQUEST // (which is why we null out responseChannel in prepare()). So, just cache this response // so we can send it in completeTx when the COMPLETE_TX_REQUEST comes in. assert postPrepareRaceResponse == null; // else we got called twice locally! ControllerLogger.MGMT_OP_LOGGER.tracef("received a post-prepare response for %d but no " + "COMPLETE_TX_REQUEST has been received; caching the response", getOperationId()); postPrepareRaceResponse = response; } }
@Override public void run() { ResponseAttachmentInputStreamSupport.this.gc(); } }
@Override public void run() { try { responseAttachmentSupport.shutdown(); } finally { StreamUtils.safeClose(client); client = null; stopContext.complete(); } } };
configuration.setConnectionTimeout(SERVER_CONNECTION_TIMEOUT); configuration.setSslContext(sslContextSupplier.get()); this.responseAttachmentSupport = new ResponseAttachmentInputStreamSupport(scheduledExecutorInjector.getValue());