/**
   * @see MessageListener#onMessage(Message)
   *     <p>This method expects a MapMessage containing information about a flight that has been
   *     added to the database. This method will print out the information about the flight.
   */
  public void onMessage(Message message) {
    try {
      if (message instanceof MapMessage) {
        MapMessage msg = (MapMessage) message;

        StringBuffer sb = new StringBuffer();

        sb.append("Flight #: " + msg.getString("flightId") + "\n");
        sb.append("Flight Date: " + msg.getString("flightDate") + "\n");
        sb.append("Departure Airport: " + msg.getString("departureAirport") + "\n");
        sb.append("Destination Airport: " + msg.getString("destinationAirport") + "\n");
        sb.append("Number of Seats: " + msg.getInt("numSeats") + "\n");
        sb.append("Seat Cost: $" + msg.getDouble("cost") + "\n");
        sb.append("Airplane #: " + msg.getString("airplaneId") + "\n");
        sb.append("*************************************************** \n\n");

        System.out.println(
            "\n**" + getClass().getSimpleName() + ": Flight Added!\n" + sb.toString());

      } else {
        System.out.println(
            getClass().getSimpleName()
                + " - Error: The message provided was not of type MapMessage!");
      }
    } catch (JMSException e) {
      System.out.println(
          getClass().getSimpleName() + ": Error occuredwhen attempting to read the MapMessage");
      e.printStackTrace();
    }
  }
Ejemplo n.º 2
0
  public void onMessage(Message message) {

    try {
      boolean accepted = false;

      // Get the data from the message
      MapMessage msg = (MapMessage) message;
      double salary = msg.getDouble("Salary");
      double loanAmt = msg.getDouble("LoanAmount");

      // Determine whether to accept or decline the loan
      if (loanAmt < 200000) {
        accepted = (salary / loanAmt) > .25;
      } else {
        accepted = (salary / loanAmt) > .33;
      }
      System.out.println(
          ""
              + "Percent = "
              + (salary / loanAmt)
              + ", loan is "
              + (accepted ? "Accepted!" : "Declined"));

      // Send the results back to the borrower
      TextMessage tmsg = qSession.createTextMessage();
      tmsg.setText(accepted ? "Accepted!" : "Declined");

      // correlation
      tmsg.setJMSCorrelationID(message.getJMSMessageID());

      // Create the sender and send the message
      qSender = qSession.createSender((Queue) message.getJMSReplyTo());
      qSender.send(tmsg);

      System.out.println("\nWaiting for loan requests...");

    } catch (JMSException jmse) {
      jmse.printStackTrace();
      System.exit(1);
    } catch (Exception jmse) {
      jmse.printStackTrace();
      System.exit(1);
    }
  }
Ejemplo n.º 3
0
  public void onMessage(Message message) {

    try {
      boolean accepted = false;

      // Get the data from the message
      MapMessage msg = (MapMessage) message;
      double salary = msg.getDouble("Salary");
      double expAmt = msg.getDouble("Years’ experience");

      // Determine whether to accept or decline the loan
      if (expAmt < 200000) {
        accepted = (salary / expAmt) > .25;
      } else {
        accepted = (salary / expAmt) > .33;
      }
      if (salary <= 32000) {
        accepted = true;
      } else {
        if (expAmt == 0) accepted = false;
        else accepted = ((double) (expAmt - 32000) / expAmt) < 3000.;
      }
      System.out.println(" Salary proposal is " + (accepted ? "Accepted!" : "Declined"));

      // Send the results back to the borrower
      TextMessage tmsg = qSession.createTextMessage();
      tmsg.setText(accepted ? "Accepted!" : "Declined");
      tmsg.setJMSCorrelationID(message.getJMSMessageID());

      // Create the sender and send the message
      QueueSender qSender = qSession.createSender((Queue) message.getJMSReplyTo());
      qSender.send(tmsg);

      System.out.println("\nWaiting for salary requests...");

    } catch (JMSException jmse) {
      jmse.printStackTrace();
      System.exit(1);
    } catch (Exception jmse) {
      jmse.printStackTrace();
      System.exit(1);
    }
  }
  public void onMessage(Message msg) {

    // TODO Auto-generated method stub
    if (observer != null) {
      MapMessage msg1 = (MapMessage) msg;
      L1Data data = new L1Data();
      try {
        data.symbol_ = msg1.getString("Symbol");
        data.price_ = msg1.getDouble("LastPrice");
      } catch (JMSException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      observer.update(data);
    }
  }