/** * Create a transactional protocol request handler. * * @param association the management channel * @param controller the model controller * @return the handler factory */ public static ManagementRequestHandlerFactory createHandler(final ManagementChannelAssociation association, final ModelController controller) { return new TransactionalProtocolOperationHandler(controller, association); }
@Override public synchronized void failed(Exception e) { if(prepared) { final ModelController.OperationTransaction transaction = activeTx; if(transaction != null) { transaction.rollback(); txCompletedLatch.countDown(); } } else if (responseChannel != null) { rollbackOnPrepare = true; // Failed in a step before prepare, send error response final String message = e.getMessage() != null ? e.getMessage() : "failure before rollback " + e.getClass().getName(); final ModelNode response = new ModelNode(); response.get(OUTCOME).set(FAILED); response.get(FAILURE_DESCRIPTION).set(message); try { sendResponse(responseChannel, ModelControllerProtocol.PARAM_OPERATION_FAILED, response); } catch (IOException ignored) { ProtocolLogger.ROOT_LOGGER.debugf(ignored, "failed to process message"); } } }
protected void doExecute(final ModelNode operation, final int attachmentsLength, final ManagementRequestContext<ExecuteRequestContext> context) { final ExecuteRequestContext executeRequestContext = context.getAttachment(); // Set the response information executeRequestContext.initialize(context); final Integer batchId = executeRequestContext.getOperationId(); final OperationMessageHandlerProxy messageHandlerProxy = new OperationMessageHandlerProxy(channelAssociation, batchId); final ProxyOperationControlProxy control = new ProxyOperationControlProxy(executeRequestContext); final OperationAttachmentsProxy attachmentsProxy = OperationAttachmentsProxy.create(channelAssociation, batchId, attachmentsLength); final ModelNode result; try { // Execute the operation result = internalExecute(operation, context, messageHandlerProxy, control, attachmentsProxy); } catch (Exception e) { final ModelNode failure = new ModelNode(); failure.get(OUTCOME).set(FAILED); failure.get(FAILURE_DESCRIPTION).set(e.getClass().getName() + ":" + e.getMessage()); control.operationFailed(failure); attachmentsProxy.shutdown(e); return; } if (result.hasDefined(FAILURE_DESCRIPTION)) { control.operationFailed(result); } else { // controller.execute() will block in OperationControl.prepared until the {@code PoxyController} // sent a CompleteTxRequest, which will either commit or rollback the operation control.operationCompleted(result); } } }
final Boolean readSubject = channelAssociation.getAttachments().getAttachment(TransactionalProtocolClient.SEND_SUBJECT); if (readSubject != null && readSubject) { subject = readSubject(input); } else { subject = new Subject();
try { result = internalExecute(attachmentsProxy, context, messageHandlerProxy, control); } catch (Throwable t) {
/** * Create a transactional protocol request handler. * * @param association the management channel * @param controller the model controller * @return the handler factory */ public static ManagementRequestHandlerFactory createHandler(final ManagementChannelAssociation association, final ModelController controller) { return new TransactionalProtocolOperationHandler(controller, association); }
@Override public synchronized void failed(Exception e) { if(prepared) { final ModelController.OperationTransaction transaction = activeTx; activeTx = null; if(transaction != null) { try { transaction.rollback(); } finally { txCompletedLatch.countDown(); } } } else if (responseChannel != null) { rollbackOnPrepare = true; // Failed in a step before prepare, send error response final String message = e.getMessage() != null ? e.getMessage() : "failure before rollback " + e.getClass().getName(); final ModelNode response = new ModelNode(); response.get(OUTCOME).set(FAILED); response.get(FAILURE_DESCRIPTION).set(message); ControllerLogger.MGMT_OP_LOGGER.tracef("sending pre-prepare failed response for %d --- interrupted: %s", getOperationId(), (Object) Thread.currentThread().isInterrupted()); try { sendResponse(responseChannel, ModelControllerProtocol.PARAM_OPERATION_FAILED, response); responseChannel = null; } catch (IOException ignored) { ControllerLogger.MGMT_OP_LOGGER.failedSendingFailedResponse(ignored, response, getOperationId()); } } }
try { result = internalExecute(attachmentsProxy, context, messageHandlerProxy, control); } catch (Throwable t) {
private void setupHandler() { // Setup the transaction protocol handler handler.addHandlerFactory(new TransactionalProtocolOperationHandler(controller, handler, responseAttachmentSupport)); // Use the existing channel strategy masterProxy = ExistingChannelModelControllerClient.createAndAdd(handler); txMasterProxy = TransactionalProtocolHandlers.createClient(handler); }
@Override public synchronized void failed(Exception e) { if(prepared) { final ModelController.OperationTransaction transaction = activeTx; activeTx = null; if(transaction != null) { try { transaction.rollback(); } finally { txCompletedLatch.countDown(); } } } else if (responseChannel != null) { rollbackOnPrepare = true; // Failed in a step before prepare, send error response final String message = e.getMessage() != null ? e.getMessage() : "failure before rollback " + e.getClass().getName(); final ModelNode response = new ModelNode(); response.get(OUTCOME).set(FAILED); response.get(FAILURE_DESCRIPTION).set(message); ControllerLogger.MGMT_OP_LOGGER.tracef("sending pre-prepare failed response for %d --- interrupted: %s", getOperationId(), (Object) Thread.currentThread().isInterrupted()); try { sendResponse(responseChannel, ModelControllerProtocol.PARAM_OPERATION_FAILED, response); responseChannel = null; } catch (IOException ignored) { ControllerLogger.MGMT_OP_LOGGER.failedSendingFailedResponse(ignored, response, getOperationId()); } } }
private void setupHandler() { // Setup the transaction protocol handler handler.addHandlerFactory(new TransactionalProtocolOperationHandler(controller, handler, responseAttachmentSupport)); // Use the existing channel strategy masterProxy = ExistingChannelModelControllerClient.createAndAdd(handler); txMasterProxy = TransactionalProtocolHandlers.createClient(handler); }
synchronized void completed(final ModelNode response) { assert prepared; assert responseChannel != null; try { // 4) operation-completed (done) sendResponse(responseChannel, ModelControllerProtocol.PARAM_OPERATION_COMPLETED, response); } catch (IOException e) { ProtocolLogger.ROOT_LOGGER.debugf(e, "failed to process message"); } finally { getResultHandler().done(null); } }
/** * Connect to the HC and retrieve the current model updates. * * @param controller the server controller * @param callback the operation completed callback * @return the boot operations * @throws IOException for any error */ synchronized void openConnection(final ModelController controller, final ActiveOperation.CompletedCallback<ModelNode> callback) throws Exception { boolean ok = false; final Connection connection = connectionManager.connect(); try { channelHandler.executeRequest(new ServerRegisterRequest(), null, callback); channelHandler.addHandlerFactory(new TransactionalProtocolOperationHandler(controller, channelHandler)); ok = true; } finally { if(!ok) { connection.close(); } } }
synchronized void completed(final ModelNode response) { assert prepared; assert responseChannel != null; try { // 4) operation-completed (done) sendResponse(responseChannel, ModelControllerProtocol.PARAM_OPERATION_COMPLETED, response); } catch (IOException e) { ProtocolLogger.ROOT_LOGGER.debugf(e, "failed to process message"); } finally { getResultHandler().done(null); } }
handler.addHandlerFactory(new TransactionalProtocolOperationHandler(controller, handler));
synchronized void prepare(final ModelController.OperationTransaction tx, final ModelNode result) { if(rollbackOnPrepare) { try { tx.rollback(); } finally { txCompletedLatch.countDown(); } // TODO send response ? } else { assert !prepared; assert activeTx == null; assert responseChannel != null; try { // 2) send the operation-prepared notification (just clear response info) sendResponse(responseChannel, ModelControllerProtocol.PARAM_OPERATION_PREPARED, result); activeTx = tx; prepared = true; } catch (IOException e) { getResultHandler().failed(e); } finally { responseChannel = null; } } }
/** * Connect to the HC and retrieve the current model updates. * * @param controller the server controller * @param callback the operation completed callback * @return the boot operations * @throws IOException for any error */ synchronized void openConnection(final ModelController controller, final ActiveOperation.CompletedCallback<ModelNode> callback) throws Exception { boolean ok = false; final Connection connection = connectionManager.connect(); try { channelHandler.executeRequest(new ServerRegisterRequest(), null, callback); // HC is the same version, so it will support sending the subject channelHandler.getAttachments().attach(TransactionalProtocolClient.SEND_SUBJECT, Boolean.TRUE); channelHandler.addHandlerFactory(new TransactionalProtocolOperationHandler(controller, channelHandler)); ok = true; } finally { if(!ok) { connection.close(); } } }
synchronized void prepare(final ModelController.OperationTransaction tx, final ModelNode result) { if(rollbackOnPrepare) { try { tx.rollback(); } finally { txCompletedLatch.countDown(); } // TODO send response ? } else { assert !prepared; assert activeTx == null; assert responseChannel != null; try { // 2) send the operation-prepared notification (just clear response info) sendResponse(responseChannel, ModelControllerProtocol.PARAM_OPERATION_PREPARED, result); activeTx = tx; prepared = true; } catch (IOException e) { getResultHandler().failed(e); } finally { responseChannel = null; } } }
/** * Connect to the HC and retrieve the current model updates. * * @param controller the server controller * @param callback the operation completed callback * * @throws IOException for any error */ synchronized void openConnection(final ModelController controller, final ActiveOperation.CompletedCallback<ModelNode> callback) throws Exception { boolean ok = false; final Connection connection = connectionManager.connect(); try { channelHandler.executeRequest(new ServerRegisterRequest(), null, callback); // HC is the same version, so it will support sending the subject channelHandler.getAttachments().attach(TransactionalProtocolClient.SEND_IDENTITY, Boolean.TRUE); channelHandler.getAttachments().attach(TransactionalProtocolClient.SEND_IN_VM, Boolean.TRUE); channelHandler.addHandlerFactory(new TransactionalProtocolOperationHandler(controller, channelHandler, responseAttachmentSupport)); ok = true; } finally { if(!ok) { connection.close(); } } }
/** Signal from ProxyOperationTransactionControl that the operation is prepared */ synchronized void prepare(final ModelController.OperationTransaction tx, final ModelNode result) { assert !prepared; prepared = true; if(rollbackOnPrepare) { try { tx.rollback(); ControllerLogger.MGMT_OP_LOGGER.tracef("rolled back on prepare for %d --- interrupted: %s", getOperationId(), (Object) Thread.currentThread().isInterrupted()); } finally { txCompletedLatch.countDown(); } // no response to remote side here; the response will go out when this thread executing // the now rolled-back op returns in ExecuteRequestHandler.doExecute } else { assert activeTx == null; assert responseChannel != null; activeTx = tx; ControllerLogger.MGMT_OP_LOGGER.tracef("sending prepared response for %d --- interrupted: %s", getOperationId(), (Object) Thread.currentThread().isInterrupted()); try { sendResponse(responseChannel, ModelControllerProtocol.PARAM_OPERATION_PREPARED, result); responseChannel = null; // we've now sent a response to the original request, so we can't use this one further } catch (IOException e) { getResultHandler().failed(e); // this will eventually call back into failed(e) above and roll back the tx } } }