Package com.exedosoft.plat.agent.message

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

package com.exedosoft.plat.agent.message;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import com.exedosoft.plat.agent.Message;

/**
* @author   IBM
*/
public class OutPool {

  private static OutPool aPool;

  private static Map<String,Message> msgs;

  private OutPool() {
   
      msgs = new HashMap<String,Message>();
     Collections.synchronizedMap(msgs);

  }

  public synchronized static OutPool getPool() {
    if (aPool == null) {
      aPool = new OutPool();
    }
    return aPool;
  }

  public synchronized Message getMessage(String cmdID) {
   
    if (cmdID == null) {
      return null;
    }
    Message msg = msgs.get(cmdID);
  //  msgs.remove(cmdID);
    return msg;
  }

 
  public synchronized Message getAndRemoveMessage(String cmdID) {
   
    if (cmdID == null) {
      return null;
    }
    Message msg = msgs.get(cmdID);
    msgs.remove(cmdID);
    return msg;
  }

 

  /*
   * (non-Javadoc)
   *
   * @see com.jbbis.hulft.agent.pool.AgentPool#addMessage(com.jbbis.hulft.agent.Message)
   */
  public synchronized void addMessage(String cmdID,Message aMessage) {
    if (aMessage == null) {
      return;
    }
    msgs.put(cmdID,aMessage);
  }

  /*
   * (non-Javadoc)
   *
   * @see com.jbbis.hulft.agent.pool.AgentPool#removeMessage(com.jbbis.hulft.agent.Message)
   */
  public synchronized void removeMessage(String cmdID) {
    if (cmdID == null) {
      return;
    }
    msgs.remove(cmdID);
  }

 
  public boolean isEmpty() {
    return msgs.isEmpty();
  }

 

}
TOP

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

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.