Package ass3.program.core.message

Examples of ass3.program.core.message.Message


    if (logger.isDebugEnabled()) {
      logger.debug(MessageFormat.format("Processing message {0}:{1}",
          received.getClass().getName(), received));
    }
    if (received instanceof Request) {
      Request request = (Request) received;
      try {
        if (request instanceof PublicKeyRequest) {
          serverState.transit(SState.PUBLIC_KEY_SENT);
          clientState.transit(CState.PUBLIC_KEY_RECEIVED);
        }
        if (request instanceof ExchSharedKeyRequest) {
          serverState.transit(SState.SHARED_KEY_RECEIVED);
          clientState.transit(CState.SHARED_KEY_EXCHANGED);
        }
        if (request instanceof SendTextRequest) {
          // Do nothing now
          serverState.verify(SState.SHARED_KEY_RECEIVED);
        }
      } catch (IllegalStateException e) {
        send(request.respondError(Response.ERROR_NO_AUTHORIZED));
        return;
      }
      send(request.respond());
    }
    if (received instanceof Response) {
      // Update State Machine
      Response resp = (Response) received;
      try {
View Full Code Here


      }
      send(request.respond());
    }
    if (received instanceof Response) {
      // Update State Machine
      Response resp = (Response) received;
      try {
        if (resp.getError() != 0) {
          clientState.transit(CState.INIT);
        } else {
          if (received instanceof PublicKeyResponse) {
            clientState.transit(CState.PUBLIC_KEY_RECEIVED);
            serverState.transit(SState.PUBLIC_KEY_SENT);
          }
          if (received instanceof ExchSharedKeyResponse) {
            clientState.transit(CState.SHARED_KEY_EXCHANGED);
            serverState.transit(SState.SHARED_KEY_RECEIVED);
          }
        }
      } catch (IllegalStateException e) {
        // Illegal Transition, ignore the message
        return;
      }
      resp.process();
      // Release the clients that are waiting for the response
      responseReceived(received.getClass());
    }
    // Notify the listener
    MessageListener l = getListener();
View Full Code Here

  @Override
  public void messageReceived(MessageEvent event) {
    Message msg = event.getContent();
    if (msg instanceof SendTextRequest && msg.getFrom().equals(this.target)) {
      // Receive a message
      SendTextRequest str = (SendTextRequest) msg;
      final String text = str.getText();
      SwingUtilities.invokeLater(new Runnable() {
        public void run() {
          attachText(target, text);
        }
      });
View Full Code Here

   */
  @Override
  public synchronized void messageReceived(MessageEvent event) {
    Message message = event.getContent();
    if (message instanceof SendTextRequest) {
      SendTextRequest st = (SendTextRequest) message;
      String target = st.getFrom();
      if (!chatFrames.containsKey(target)) {
        new ChatFrame(target, this);
      }
      chatFrames.get(target).messageReceived(event);
    }
View Full Code Here

          .load("key", "AES_KEY").getBytes()));
      waitForResponse(ExchSharedKeyResponse.class);
      sendText(message);
      break;
    case SHARED_KEY_EXCHANGED:
      send(new SendTextRequest(ck.getA(), ck.getB(), message));
      waitForResponse(SendTextResponse.class);
      // Check self state to determine whether need to resend
      if (!(clientState.getCurrentState() == CState.SHARED_KEY_EXCHANGED)) {
        // Error encountered, Resend
        sendText(message);
View Full Code Here

TOP

Related Classes of ass3.program.core.message.Message

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.