Package com.exedosoft.plat.agent.message

Source Code of com.exedosoft.plat.agent.message.MessageIn

package com.exedosoft.plat.agent.message;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;

import com.exedosoft.plat.agent.Message;
;

public class MessageIn implements Runnable {

  private Socket aSocket;

  public MessageIn(Socket ss) {

    aSocket = ss;
  }

  public void run() {

    try {
      ObjectInputStream serverInputStream = new ObjectInputStream(aSocket
          .getInputStream());
      SimpleMessage sm = (SimpleMessage) serverInputStream.readObject();
     
      if(sm.getMessageType()==Message.MSG_REQ){
       
        outMessage(sm.getCommandID());
        aSocket.close();
        return;
      }
     
      if (ProcessQueue.getPool().isEmpty()) {
        ProcessQueue.getPool().putMessage(sm);
      } else {
        InQueue.getPool().putMessage(sm);
      }
     
      if(sm.getMessageType()==Message.MSG_RES_REQ){
        sm.setASocket(aSocket);
      }else{
        aSocket.close();
      }

    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (ClassNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

  }
  private void outMessage(String aCmdID){
   
    try {
      ObjectOutputStream serverOutputStream = new ObjectOutputStream(
          aSocket.getOutputStream());
      Message msg = OutPool.getPool().getAndRemoveMessage(aCmdID);
      serverOutputStream.writeObject(msg);
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }



}
TOP

Related Classes of com.exedosoft.plat.agent.message.MessageIn

TOP
Copyright © 2018 www.massapi.com. 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.