Beispiel #1
0
  public void startUpQueueManager() throws Exception {

    QueueServer qServer = null;

    QueueConfig bpQueue = new QueueConfig();
    bpQueue.setMaxRetry(0);
    bpQueue.setMaxSize(50);
    bpQueue.setQueueId("ANYPAY");
    bpQueue.setTerminable(false);
    log.info("ANYPAY Queue config:" + bpQueue);
    int maxdeQueue = 0;
    try {
      SimInfoDao simInfoDao = new SimInfoDao();
      List<SimInfo> simInfos = simInfoDao.selectAll();

      if (simInfos != null) maxdeQueue = simInfos.size();
      if (maxdeQueue == 0) throw new Exception("No Sim info configured");
    } catch (Exception e) {
      throw e;
    }
    bpQueue.setDequeue(maxdeQueue);
    log.info("ANYPAY Queue config:" + bpQueue);
    qServer = new QueueServer(bpQueue);
    qServer.startQueueServer();
    queues.put(bpQueue.getQueueId(), qServer);
  }
Beispiel #2
0
  public ContextBase process(ContextBase context) {

    if (log.isDebugEnabled()) {
      log.debug("Receive request. |context-" + context.toString());
    }

    String errCode = null;
    QueueRequest request = null;
    ContextBase result = new ContextBase();
    if (StringUtils.isEmpty(context.get(Attributes.ATTR_ERROR_CODE)))
      context.put(Attributes.ATTR_ERROR_CODE, ErrorCode.SUCCESS);

    try {

      if (shutdownFlag.get()) {
        log.warn("Queue Manager is shuting down.");
        result.put(Attributes.ATTR_ERROR_CODE, ErrorCode.QUEUE_SHUTINGDOWN);
        return result;
      }

      errCode = validate(context);
      context.put(Attributes.ATTR_QUEUE_REQUEST_ID, context.get(Attributes.ATTR_TRANSACTION_ID));

      if (!ErrorCode.SUCCESS.equals(errCode)) {
        result.put(Attributes.ATTR_ERROR_CODE, errCode);
        return result;
      }

      request = RequestDbFactory.getInstance().insert(context);

      if (request == null) {
        errCode = ErrorCode.DATABASE_EXCEPTION;
        result.put(Attributes.ATTR_ERROR_CODE, errCode);
        log.error(
            "Fail to insert context to queue db. | ErrorCode-" + errCode + " | context-" + context);
        return result;
      }

      QueueServer qServer = queues.get(request.getQueueId());
      if (qServer == null) result.setErrorCode(ErrorCode.QUEUE_NOT_EXISTED);
      else result = qServer.process(request);

      if (!ErrorCode.SUCCESS.equals(result.getErrorCode())) {
        RequestDbFactory.getInstance().delete(request);
        log.error("Process put request to Queue failed. | result-" + result);
      } else {
        log.info("Process put request to Queue successful. | result-" + result);
      }

      return result;
    } catch (Exception e) {
      log.error(
          "Exception while processing received context. | context-"
              + context.toString()
              + " | ErrorMessage-"
              + e.getMessage(),
          e);
      result.put(Attributes.ATTR_ERROR_CODE, ErrorCode.SYS_INTERNAL_ERROR);
      return result;
    }
  }