⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 outgoingmessagehandler.java

📁 SRI international 发布的OAA框架软件
💻 JAVA
字号:
package com.sri.oaa2.simplefac;

import com.sri.oaa2.icl.*;
import org.apache.log4j.Logger;
import java.util.*;
import org.apache.log4j.NDC;

/**
 * Default outgoing message handler handles plain text messages
 */
public class OutgoingMessageHandler implements Runnable 
{
  // Logger for this class
  static Logger logger = Logger.getLogger(OutgoingMessageHandler.class.getName());

  // The incoming message
  private IclTerm term;

  // Our connection
  private SimpleFacConnection conn;

  // Ignore ready status?
  private boolean force = false;

  long start, end;

  /**
   * Create handler with term
   */
  public OutgoingMessageHandler(IclTerm t, SimpleFacConnection c) 
  {
    start = (new Date()).getTime();
    setTerm(t);
    setConn(c);
  }

  /**
   * Set/unset force sending, even if not ready
   */
  public final void setForce(boolean f) 
  {
    force = f;
  }
  
  /**
   * Get force send value
   */
  protected final boolean getForce() 
  {
    return force;
  }

  /**
   * Set connection
   */
  protected final void setConn(SimpleFacConnection c) 
  {
    conn = c;
  }
  
  /**
   * Get connection
   */
  protected final SimpleFacConnection getConn() 
  {
    return conn;
  }

  /**
   * Set term to handle
   */
  protected final void setTerm(IclTerm t) 
  {
    term = t;
  }
  
  /**
   * Get term to handle
   */
  protected final IclTerm getTerm() 
  {
    return term;
  }

  /**
   * Translate the outgoing IclTerm into whatever format the 
   * agent on the other side of this connection requires, and
   * pass on the data.
   */
  public void run() 
  {
    if(getConn().getName() != null) {
      NDC.push(getConn().getName().toString());
    }
    if(!getForce()) {
      getConn().waitOutputUntilReady();
    }
    if(logger.isDebugEnabled()) {
      logger.debug("OutgoingMessageHandler.run() sending " + getTerm());
    }
    getConn().getFormatWriter().write(getTerm());
    if(logger.isInfoEnabled()) {
      end = System.currentTimeMillis();
      logger.info("OutgoingMessageHandler.run() time to send = " + (end - start));
    }
    NDC.pop();
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -