Пример #1
0
  public CommandMessage parser(
      OrderRoutingInstance instance, ProductRoute orderRoute, CommandMessage order)
      throws Exception {
    Exception error = null;

    try {
      // check SMS syntax
      if (order.getChannel().equals("SMS")) {
        smsParser(instance, orderRoute, order);
      }

      if (order.getStatus() != Constants.ORDER_STATUS_DENIED) {
        order.setCause(orderRoute.getKeyword());

        order.setStatus(Constants.ORDER_STATUS_APPROVED);

        SubscriberCampaignImpl.createCampaignEvent(
            order.getUserId(),
            order.getUserName(),
            order.getOrderId(),
            order.getOrderDate(),
            order.getSubscriberId(),
            order.getSubProductId(),
            order.getIsdn(),
            order.getSubscriberType(),
            order.getProductId(),
            order.getServiceAddress(),
            order.getKeyword(),
            order.getCampaignId(),
            order.getSegmentId(),
            null,
            Constants.DEFAULT_ID,
            "",
            Constants.ORDER_STATUS_PENDING);
      }
    } catch (Exception e) {
      error = e;
    }

    if (error != null) {
      order.setStatus(Constants.ORDER_STATUS_DENIED);

      if (error instanceof AppException) {
        order.setCause(error.getMessage());
      } else {
        order.setDescription(error.getMessage());
      }
    }

    if ((error != null) && !(error instanceof AppException)) {
      throw error;
    }

    return order;
  }
Пример #2
0
  public CommandMessage sendOrder(Object request, String correlationId, long timeout)
      throws Exception {
    if (timeout <= 0) {
      timeout = 30000;
    }

    long startTime = System.currentTimeMillis();

    QueueSession session = null;
    MessageProducer producer = null;
    Message message = null;
    Message callBack = null;

    CommandMessage response = null;

    if (request instanceof CommandMessage) {
      response = (CommandMessage) request;
    } else {
      response = new CommandMessage();
    }

    try {
      Queue sendQueue = QueueFactory.getQueue(QueueFactory.ORDER_REQUEST_QUEUE);
      session = QueueFactory.getSession();
      message = QueueFactory.createObjectMessage(session, request);
      producer = session.createProducer(sendQueue);

      try {
        long beforeSend = System.currentTimeMillis();
        producer.send(message);
        long afterSend = System.currentTimeMillis();
        log.info(
            "Send:"
                + (afterSend - beforeSend)
                + ((afterSend - beforeSend) > 20 ? "|high" : "|low")
                + "|SessionId:"
                + correlationId);
      } catch (Exception ex) {
        log.info("Send message error");
        throw ex;
      } finally {
        QueueFactory.closeQueue(producer);
        QueueFactory.closeQueue(session);
      }
      if (!correlationId.equals("")) {
        startTime = System.currentTimeMillis();
        long beforeReceive = System.currentTimeMillis();

        QueueFactory.callbackListerner.put(message.getJMSCorrelationID(), message);
        synchronized (message) {
          try {
            message.wait(timeout);
          } catch (Exception e) {

          } finally {
            callBack = (Message) QueueFactory.callbackOrder.remove(message.getJMSCorrelationID());
            QueueFactory.callbackListerner.remove(message.getJMSCorrelationID());
          }
        }

        long afterReceive = System.currentTimeMillis();

        log.info(
            "Receive:"
                + (afterReceive - beforeReceive)
                + ((afterReceive - beforeReceive) > 300 ? "|high " : "|low")
                + "|SessionId:'"
                + correlationId);
      }
      if (callBack == null) {
        throw new AppException("time-out");
      }
      Object content = QueueFactory.getContentMessage(callBack);

      if (content != null) {
        if (content instanceof CommandMessage) {
          response = (CommandMessage) content;
        } else {
          response.setStatus(Constants.ORDER_STATUS_DENIED);
          response.setCause(Constants.ERROR);
        }
      } else {
        response.setStatus(Constants.ORDER_STATUS_DENIED);
        response.setCause(Constants.ERROR_TIMEOUT);
      }

      log.info(
          "Cost time:" + (System.currentTimeMillis() - startTime) + "|sessionId:" + correlationId);
    } catch (Exception e) {
      log.info(e);
      response.setStatus(Constants.ORDER_STATUS_DENIED);
      response.setCause(Constants.ERROR_RESOURCE_BUSY);
      throw e;
    } finally {
    }

    if ((response != null) && (response.getStatus() == Constants.ORDER_STATUS_DENIED)) {
      log.error("sessionId = " + correlationId + ", timeout = " + timeout + " : " + response);
    }

    return response;
  }