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

📄 producer1.java

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

import com.sri.oaa2.com.LibCom;
import com.sri.oaa2.com.LibComTcpProtocol;
import com.sri.oaa2.icl.IclList;
import com.sri.oaa2.icl.IclStruct;
import com.sri.oaa2.icl.IclTerm;
import com.sri.oaa2.lib.LibOaa;
import com.sri.oaa2.lib.OAAEventListener;

public class Producer1
{
  private LibOaa oaaLocal_;
  private LibOaa oaaForRequests_ = null;
  private int echoNumber_ = 0;
  
  public void init()
  {
    LibCom com = new LibCom(new LibComTcpProtocol(), null);
    oaaLocal_ = new LibOaa(com);
    if(!oaaLocal_.getComLib().comConnect("parent", IclTerm.fromString(true, "tcp(Host,Port)"), new IclList())) {
      throw new RuntimeException("Could not connect to parent");
    }
    
    oaaLocal_.oaaRegisterCallback("oaa_AppDoEvent",
                             new OAAEventListener() 
                             {
                               public boolean doOAAEvent(IclTerm goal,
                                                         IclList params,
                                                         IclList answers) 
                               {
                                 return processMessage(goal, params, answers);
                               }
                             }
                             );

    if(!oaaLocal_.oaaRegister("parent", "Producer1", IclTerm.fromString(true, "[echo(X,Y,Z)]"), new IclList())) {
      throw new RuntimeException("Could not register empty list of solvables");
    }
    
    oaaLocal_.oaaReady(true);
  }

  public void handoff(IclTerm goal, IclList params, IclList answers) 
  {
    if(this.oaaForRequests_ == null) {
      System.out.println("Making new OAA object to send actual request");
      LibCom com = new LibCom(new LibComTcpProtocol(), null);
      oaaForRequests_ = new LibOaa(com);
      if(!oaaForRequests_.getComLib().comConnect("parent", IclTerm.fromString(true, "tcp(Host,Port)"), new IclList())) {
        throw new RuntimeException("Could not connect to parent");
      }
    
      oaaForRequests_.oaaRegisterCallback("oaa_AppDoEvent",
                                    new OAAEventListener() 
                                    {
                                      public boolean doOAAEvent(IclTerm goal,
                                                                IclList params,
                                                                IclList answers) 
                                      {
                                        return false;
                                      }
                                    }
                                    );

      StringBuffer buf = new StringBuffer("Producer1");
      buf.append(echoNumber_);
      if(!oaaForRequests_.oaaRegister("parent", buf.toString(), new IclList(), new IclList())) {
        throw new RuntimeException("Could not register empty list of solvables");
      }
    
      oaaForRequests_.oaaReady(true);
    }
    System.out.println("Making request with new LibOaa Object");
    this.oaaForRequests_.oaaSolve(goal, params, answers);
  }
  
  public boolean processMessage(IclTerm goal, IclList params, IclList answers)
  {
    System.out.println("Got goal " + goal.toString());
    IclTerm newGoal = new IclStruct("real_echo");
    newGoal.addAll(goal);
    this.handoff(newGoal, params, answers);
    return true;
  }
  
  public static void main(String[] args) throws InterruptedException
  {
    Producer1 es = new Producer1();
    es.init();
    while(true) {
      Thread.sleep(10000);
    }
  }
}

⌨️ 快捷键说明

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