示例#1
0
  public void deploy(
      String name,
      String jobParameters,
      String dateFormat,
      String numberFormat,
      Boolean makeUnique) {
    Assert.hasText(name, "name cannot be blank or null");
    JobDefinition definition = getDefinitionRepository().findOne(name);
    if (definition == null) {
      throwNoSuchDefinitionException(name);
    }
    List<ModuleDeploymentRequest> requests = parse(name, definition.getDefinition());
    // If the job definition has trigger then, check if the trigger exists
    // TODO: should we do this at the parser?
    // but currently the parser has reference to StreamDefinitionRepository only.
    if (requests != null
        && requests.get(0).getParameters().containsKey(ModuleType.TRIGGER.getTypeName())) {
      String triggerName = requests.get(0).getParameters().get(ModuleType.TRIGGER.getTypeName());
      if (triggerDefinitionRepository.findOne(triggerName) == null) {
        throwNoSuchDefinitionException(triggerName, ModuleType.TRIGGER.getTypeName());
      }
    }

    for (ModuleDeploymentRequest request : requests) {
      if ("job".equals(request.getType())) {
        if (jobParameters != null) {
          request.setParameter("jobParameters", jobParameters);
        }
        if (dateFormat != null) {
          request.setParameter("dateFormat", dateFormat);
        }
        if (numberFormat != null) {
          request.setParameter("numberFormat", numberFormat);
        }
        if (makeUnique != null) {
          request.setParameter("makeUnique", String.valueOf(makeUnique));
        }
      }
    }

    try {
      sendDeploymentRequests(name, requests);
    } catch (MessageHandlingException mhe) {
      Throwable cause = mhe.getCause();
      if (cause == null) {
        throw mhe;
      }
      String exceptionClassName = cause.getClass().getName();
      if (exceptionClassName.equals(BEAN_CREATION_EXCEPTION)
          || exceptionClassName.equals(BEAN_DEFINITION_EXEPTION)) {
        throw new MissingRequiredDefinitionException(definition.getName(), cause.getMessage());
      } else {
        throw mhe;
      }
    }
  }
 /**
  * Writes the message payload to the underlying socket, using the specified message format.
  *
  * @see
  *     org.springframework.integration.core.MessageHandler#handleMessage(org.springframework.integration.Message)
  */
 @Override
 public void handleMessageInternal(final Message<?> message) throws MessageHandlingException {
   if (this.serverConnectionFactory != null) {
     // We don't own the connection, we are asynchronously replying
     Object connectionId = message.getHeaders().get(IpHeaders.CONNECTION_ID);
     TcpConnection connection = null;
     if (connectionId != null) {
       connection = connections.get(connectionId);
     }
     if (connection != null) {
       try {
         connection.send(message);
       } catch (Exception e) {
         logger.error("Error sending message", e);
         connection.close();
         if (e instanceof MessageHandlingException) {
           throw (MessageHandlingException) e;
         } else {
           throw new MessageHandlingException(message, "Error sending message", e);
         }
       }
     } else {
       logger.error("Unable to find outbound socket for " + message);
       throw new MessageHandlingException(message, "Unable to find outbound socket");
     }
     return;
   } else {
     // we own the connection
     try {
       doWrite(message);
     } catch (MessageHandlingException e) {
       // retry - socket may have closed
       if (e.getCause() instanceof IOException) {
         if (logger.isDebugEnabled()) {
           logger.debug("Fail on first write attempt", e);
         }
         doWrite(message);
       } else {
         throw e;
       }
     }
   }
 }
 public void sendDeploymentRequests(String name, List<ModuleDeploymentRequest> requests) {
   this.addDeployment(name, requests);
   for (ModuleDeploymentRequest request : requests) {
     Message<?> message = MessageBuilder.withPayload(request.toString()).build();
     if (request.isRemove()) {
       this.undeployChannel.send(message);
     } else {
       try {
         this.deployChannel.send(message);
       } catch (MessageHandlingException e) {
         if (e.getCause() instanceof ApplicationContextException
             && e.getCause().getCause() instanceof ChannelException) {
           throw new MessageHandlingException(
               e.getFailedMessage(),
               e.getCause().getCause().getMessage() + ". Possibly the port is already in use.",
               e);
         }
         throw e;
       }
     }
   }
   ;
 }