コード例 #1
0
 @Override
 public void handleRequest(
     final DataInput input,
     final ActiveOperation.ResultHandler<Void> resultHandler,
     final ManagementRequestContext<Void> context)
     throws IOException {
   byte param = input.readByte();
   // If it failed
   if (param != DomainControllerProtocol.PARAM_OK) {
     final byte errorCode = input.readByte();
     final String message = input.readUTF();
     resultHandler.failed(
         new SlaveRegistrationException(
             SlaveRegistrationException.ErrorCode.parseCode(errorCode), message));
     return;
   }
   final ModelNode extensions = new ModelNode();
   extensions.readExternal(input);
   context.executeAsync(
       new ManagementRequestContext.AsyncTask<Void>() {
         @Override
         public void execute(ManagementRequestContext<Void> voidManagementRequestContext)
             throws Exception {
           //
           final ModelNode subsystems = resolveSubsystemVersions(extensions);
           channelHandler.executeRequest(
               context.getOperationId(), new RegisterSubsystemsRequest(subsystems));
         }
       });
 }
 @Override
 public void handleRequest(
     final DataInput input,
     final ResultHandler<Void> resultHandler,
     final ManagementRequestContext<ServerInventory> context)
     throws IOException {
   expectHeader(input, DomainServerProtocol.PARAM_SERVER_NAME);
   final String serverName = input.readUTF();
   if (this.serverProcessName.equals(serverName)) {
     context.getAttachment().serverStarted(serverName);
   } else {
     throw new IOException("illegal server name " + serverName);
   }
 }
コード例 #3
0
 @Override
 public void handleRequest(
     final DataInput input,
     final ActiveOperation.ResultHandler<Void> resultHandler,
     final ManagementRequestContext<Void> context)
     throws IOException {
   byte param = input.readByte();
   // If it failed
   if (param != DomainControllerProtocol.PARAM_OK) {
     final byte errorCode = input.readByte();
     final String message = input.readUTF();
     resultHandler.failed(
         new SlaveRegistrationException(
             SlaveRegistrationException.ErrorCode.parseCode(errorCode), message));
     return;
   }
   final ModelNode domainModel = new ModelNode();
   domainModel.readExternal(input);
   context.executeAsync(
       new ManagementRequestContext.AsyncTask<Void>() {
         @Override
         public void execute(ManagementRequestContext<Void> voidManagementRequestContext)
             throws Exception {
           // Apply the domain model
           final boolean success = applyDomainModel(domainModel);
           if (success) {
             channelHandler.executeRequest(
                 context.getOperationId(),
                 new CompleteRegistrationRequest(DomainControllerProtocol.PARAM_OK));
           } else {
             channelHandler.executeRequest(
                 context.getOperationId(),
                 new CompleteRegistrationRequest(DomainControllerProtocol.PARAM_ERROR));
             resultHandler.failed(
                 new SlaveRegistrationException(
                     SlaveRegistrationException.ErrorCode.UNKNOWN, ""));
           }
         }
       });
 }
    @Override
    protected ModelNode internalExecute(
        final ModelNode operation,
        final ManagementRequestContext<?> context,
        final OperationMessageHandler messageHandler,
        final ProxyOperationControl control,
        OperationAttachments attachments) {

      final OperationStepHandler handler;
      final String operationName = operation.require(OP).asString();
      if (operationName.equals(PullDownDataForServerConfigOnSlaveHandler.OPERATION_NAME)) {
        handler =
            new PullDownDataForServerConfigOnSlaveHandler(
                SlaveChannelAttachments.getHostName(context.getChannel()),
                SlaveChannelAttachments.getTransformers(context.getChannel()),
                runtimeIgnoreTransformationRegistry);
      } else {
        throw HostControllerLogger.ROOT_LOGGER.cannotExecuteTransactionalOperationFromSlave(
            operationName);
      }

      Integer domainControllerLockId;
      if (operation
          .get(OPERATION_HEADERS)
          .hasDefined(DomainControllerLockIdUtils.DOMAIN_CONTROLLER_LOCK_ID)) {
        domainControllerLockId =
            operation
                .get(OPERATION_HEADERS, DomainControllerLockIdUtils.DOMAIN_CONTROLLER_LOCK_ID)
                .asInt();
      } else {
        domainControllerLockId = null;
      }

      final Integer slaveLockId =
          operation
              .get(OPERATION_HEADERS, DomainControllerLockIdUtils.SLAVE_CONTROLLER_LOCK_ID)
              .asInt();
      if (domainControllerLockId == null) {
        synchronized (this) {
          SlaveRequest slaveRequest = this.activeSlaveRequest;
          if (slaveRequest != null) {
            domainControllerLockId = slaveRequest.domainId;
            slaveRequest.refCount.incrementAndGet();
          }
        }
        // TODO https://issues.jboss.org/browse/AS7-6809 If there are many slaves calling back many
        // of these threads will be blocked, and I
        // believe they are a finite resource
      }

      try {
        if (domainControllerLockId != null) {
          return executor.joinActiveOperation(
              operation, messageHandler, control, attachments, handler, domainControllerLockId);
        } else {
          ModelNode result =
              executor.executeAndAttemptLock(
                  operation,
                  messageHandler,
                  control,
                  attachments,
                  new OperationStepHandler() {
                    @Override
                    public void execute(OperationContext context, ModelNode operation)
                        throws OperationFailedException {
                      // Grab the lock id and store it
                      Integer domainControllerLockId =
                          CurrentOperationIdHolder.getCurrentOperationID();
                      synchronized (this) {
                        activeSlaveRequest = new SlaveRequest(domainControllerLockId);
                      }
                      context.addStep(operation, handler, OperationContext.Stage.MODEL);
                      context.stepCompleted();
                    }
                  });
          return result;
        }
      } finally {
        synchronized (this) {
          SlaveRequest slaveRequest = this.activeSlaveRequest;
          if (slaveRequest != null) {
            int refcount = slaveRequest.refCount.decrementAndGet();
            if (refcount == 0) {
              activeSlaveRequest = null;
            }
          }
        }
      }
    }