Exemplo n.º 1
0
  /**
   * Means to process PDUs received from the SMSC. This method is called by the <code>Receiver
   * </code> whenever a PDU is received from the SMSC.
   *
   * @param request the request received from the SMSC.
   */
  public void handleEvent(ServerPDUEvent event) {
    PDU pdu = event.getPDU();
    // System.out.println("pdu.ServerPDUEvent()" + pdu.debugString());
    if (pdu.isValid()) {
      if (pdu.isRequest()) {
        // Logger.println("==> " + pdu.debugString());

        // Make default response
        Response response = ((Request) pdu).getResponse();
        this.toSMSC.enqueue(response);
        if (pdu.getCommandId() != Data.ENQUIRE_LINK) {
          this.processRequest(pdu);
        }

      } else if (pdu.isResponse()) {
        // System.out.println("pdu.getCommandId()" +
        // pdu.getCommandId());
        // System.out.println("Data.ENQUIRE_LINK_RESP" +
        // Data.ENQUIRE_LINK_RESP);
        if (pdu.getCommandId() != Data.ENQUIRE_LINK_RESP) this.responseQueue.enqueue(pdu);
        // Gateway.util.log(this.getClass().getName(),"{Respond for
        // MT}{MessageId=" + pdu.getSequenceNumber() +"}");
      } else {
        // System.out
        //		.println("pdu of unknown class (not request nor response) "
        //				+ "received; Discarding " + pdu.debugString());

        DBTools.ALERT(
            "PDUEventListener",
            "PDUEventListener",
            Constants.ALERT_WARN,
            "pdu of unknown class (not request nor response) "
                + "received; Discarding "
                + pdu.debugString(),
            Preference.ALERT_CONTACT);
      }
    } else {
      // System.out.println("Received an invalid pdu!");

      DBTools.ALERT(
          "PDUEventListener",
          "PDUEventListener",
          Constants.ALERT_WARN,
          "Received an invalid pdu!",
          Preference.ALERT_CONTACT);
    }
  }
Exemplo n.º 2
0
  public void run() {
    // ///////////////////////////
    Gateway.addLiveThread(this);
    // ///////////////////////////
    while (Gateway.running) {
      try {
        pdud = (PDUData) fromSMSC.dequeue(); // blocks until having
        // an item
        // pdu = (PDU) fromSMSC.dequeue(); //blocks until having an item
        pdu = (PDU) pdud.getPDU();
        if (pdu.isRequest()) {
          this.RequestID = pdud.getRequestID();
          processRequest(pdu);
        }
      } catch (DBException ex) { // when lost connection to db
        Logger.error(this.getClass().getName(), "DBException: " + ex.getMessage());
        DBTools.ALERT(
            "RequestProcessor",
            "RequestProcessor",
            Constants.ALERT_WARN,
            Preference.Channel + "DBException: " + ex.getMessage(),
            Preference.ALERT_CONTACT);
        Logger.error(this.getClass().getName(), "Alert2YM DBException: " + ex.getMessage());
      } catch (Exception e) {
        Logger.error(this.getClass().getName(), "Exception: " + e.getMessage());

        DBTools.ALERT(
            "RequestProcessor",
            "RequestProcessor",
            Constants.ALERT_WARN,
            Preference.Channel + "Exception: " + e.getMessage(),
            Preference.ALERT_CONTACT);
      }

      try {
        Thread.sleep(50);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
    }
    // /////////////////////////////
    Logger.info(this.getClass().getName(), "{" + this.getClass().getName() + " stopped}");
    this.destroy();
    // /////////////////////////////
  }