Ejemplo n.º 1
0
  public final void execute(Object input) {
    T row = (T) input;
    String jobDescription = dataToString(row);
    final Serializable jobId = m_jobContext.schedule("Import data: " + jobDescription);

    TransactionTemplate tt = new TransactionTemplate(m_transactionManager);
    try {
      TransactionCallback callback = new JobTransaction(jobId, row);
      tt.execute(callback);
    } catch (UserException e) {
      // ignore user exceptions - just log them
      m_jobContext.failure(jobId, null, e);
    } catch (RuntimeException e) {
      // log and rethrow other exceptions
      m_jobContext.failure(jobId, null, e);
      throw e;
    }
  }
Ejemplo n.º 2
0
  private void reloadXmlWithRetries(Location location) {
    boolean success = false;
    int maxRetries = 3;
    int retry = 0;
    if (!isRunning(location)) {
      // no need to reloadXml if the service is not running at the moment
      return;
    }

    Serializable jobId = m_jobContext.schedule(RELOAD_XML_JOB_TITLE);
    m_jobContext.start(jobId);
    String serviceUri = getServiceUri(location);
    FreeswitchApi api = m_freeswitchApiProvider.getApi(serviceUri);

    while ((retry <= maxRetries) && !success) {
      LOG.debug("reloadXmlWithRetries() while loop retry:" + retry);
      try {
        api.reloadxml();
        success = true;
      } catch (Exception ex) {
        LOG.debug("reloadXmlWithRetries() caught Exception:" + ex);
      } finally {
        if (success) {
          m_jobContext.success(jobId);
        } else {
          LOG.debug("reloadXmlWithRetries() failed at retry " + retry);
          if (retry == maxRetries) { // failed after retry maxRetries so just give up
            LOG.error("reloadXmlWithRetries() gives up after retry " + retry);
            m_jobContext.failure(jobId, null, null);
          } else {
            retry++;
            // retry but sleep for a while
            try {
              Thread.sleep(2000);
            } catch (InterruptedException e) {
              continue;
            }
          }
        }
      }
    }

    LOG.debug("reloadXmlWithRetries() return success at retry " + retry);
  }
Ejemplo n.º 3
0
 private void reloadXml(Location location) {
   if (!isRunning(location)) {
     // no need to reloadXml if the service is not running at the moment
     return;
   }
   boolean success = false;
   Serializable jobId = m_jobContext.schedule(RELOAD_XML_JOB_TITLE);
   try {
     m_jobContext.start(jobId);
     String serviceUri = getServiceUri(location);
     FreeswitchApi api = m_freeswitchApiProvider.getApi(serviceUri);
     api.reloadxml();
     success = true;
   } finally {
     if (success) {
       m_jobContext.success(jobId);
     } else {
       m_jobContext.failure(jobId, null, null);
     }
   }
 }