Пример #1
0
  public void launchSuperviseSmsSending(final List<SMSBroker> smsMessageList) {
    // use hashCode of smsMessage

    final long now = System.currentTimeMillis();

    final String jobName = "superviseSmsSending" + now;
    final String keyName = SuperviseSmsSending.SUPERVISE_SMS_BROKER_KEY;
    final String groupName = Scheduler.DEFAULT_GROUP;

    try {
      for (SMSBroker smsMessage : smsMessageList) {
        if (logger.isDebugEnabled()) {
          logger.debug(
              "smsMessage in launchSuperviseSmsSending is : "
                  + " - smsMessage id is : "
                  + smsMessage.getId()
                  + " - smsMessage content is : "
                  + smsMessage.getMessage()
                  + " - smsMessage phone is : "
                  + smsMessage.getRecipient());
        }
      }

      // create DataMap
      final JobDataMap jobDataMap = new JobDataMap();
      jobDataMap.put(keyName, smsMessageList);

      // create trigger
      final Trigger trigger = new SimpleTrigger(jobName, groupName);

      trigger.setVolatility(false);
      trigger.setStartTime(new Date(now));

      if (logger.isDebugEnabled()) {
        logger.debug(
            "Launching job with parameter : \n"
                + " - jobName : "
                + jobName
                + "\n"
                + " - groupName : "
                + groupName
                + "\n");
      }

      JobDetail jobDetail = new JobDetail(jobName, groupName, SuperviseSmsSending.class);
      jobDetail.setJobDataMap(jobDataMap);

      scheduler.scheduleJob(jobDetail, trigger);

      if (logger.isDebugEnabled()) {
        logger.debug("Job successfully launched");
      }
    } catch (SchedulerException e) {
      logger.warn(
          "An error occurs launching the job with parameter : \n"
              + " - jobName : "
              + jobName
              + "\n"
              + " - groupName : "
              + groupName
              + "\n");
    }
  }
  public static org.quartz.Trigger convertTriggerToNativeObject(Trigger spagobiTrigger) {
    org.quartz.Trigger quartzTrigger;

    logger.debug("IN");

    quartzTrigger = null;
    try {
      Assert.assertNotNull(spagobiTrigger, "Input parameter [spagobiTrigger] csannot be null");

      if (spagobiTrigger.isRunImmediately()) {

        quartzTrigger = TriggerUtils.makeImmediateTrigger(spagobiTrigger.getName(), 0, 10000);
        quartzTrigger.setJobName(spagobiTrigger.getJob().getName());
        quartzTrigger.setJobGroup(spagobiTrigger.getJob().getGroupName());
        JobDataMap jobDataMap =
            convertParametersToNativeObject(spagobiTrigger.getJob().getParameters());
        quartzTrigger.setJobDataMap(jobDataMap);

      } else {

        if (spagobiTrigger.isSimpleTrigger()) {
          quartzTrigger = new org.quartz.SimpleTrigger();
        } else {
          org.quartz.CronTrigger quartzCronTrigger = new org.quartz.CronTrigger();
          String quartzCronExpression =
              convertCronExpressionToNativeObject(
                  spagobiTrigger.getChronExpression(), spagobiTrigger.getStartTime());
          quartzCronTrigger.setCronExpression(quartzCronExpression);
          quartzTrigger = quartzCronTrigger;
          // dirty trick
          spagobiTrigger
              .getJob()
              .addParameter(
                  SPAGOBI_CRON_EXPRESSION, spagobiTrigger.getChronExpression().getExpression());
        }

        quartzTrigger.setName(spagobiTrigger.getName());
        quartzTrigger.setDescription(spagobiTrigger.getDescription());
        if (spagobiTrigger.getGroupName() == null) {
          quartzTrigger.setGroup(Scheduler.DEFAULT_GROUP);
        } else {
          quartzTrigger.setGroup(spagobiTrigger.getGroupName());
        }

        quartzTrigger.setStartTime(spagobiTrigger.getStartTime());
        if (spagobiTrigger.getEndTime() != null) {
          quartzTrigger.setEndTime(spagobiTrigger.getEndTime());
        }
        quartzTrigger.setJobName(spagobiTrigger.getJob().getName());
        if (spagobiTrigger.getJob().getGroupName() == null) {
          quartzTrigger.setJobGroup(Scheduler.DEFAULT_GROUP);
        } else {
          quartzTrigger.setJobGroup(spagobiTrigger.getJob().getGroupName());
        }

        quartzTrigger.setVolatility(spagobiTrigger.getJob().isVolatile());

        JobDataMap jobDataMap =
            convertParametersToNativeObject(spagobiTrigger.getJob().getParameters());
        quartzTrigger.setJobDataMap(jobDataMap);
      }
    } catch (Throwable t) {
      throw new SpagoBIRuntimeException(
          "An unexpected error occured while converting Trigger to native object", t);
    } finally {
      logger.debug("OUT");
    }

    return quartzTrigger;
  }