producer2.java

来自「SRI international 发布的OAA框架软件」· Java 代码 · 共 70 行

JAVA
70
字号
/*
 * Created on Jan 5, 2004
 *
 */
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.IclTerm;
import com.sri.oaa2.lib.LibOaa;
import com.sri.oaa2.lib.OAAEventListener;

/**
 * @author agno
 *
 */
public class Producer2
{
  private LibOaa oaa_;
  
  public void init()
  {
    LibCom com = new LibCom(new LibComTcpProtocol(), null);
    oaa_ = new LibOaa(com);
    if(!oaa_.getComLib().comConnect("parent", IclTerm.fromString(true, "tcp(Host,Port)"), new IclList())) {
      throw new RuntimeException("Could not connect to parent");
    }

    System.out.println("Registering callback");

    oaa_.oaaRegisterCallback("oaa_AppDoEvent",
        new OAAEventListener() {
      public boolean doOAAEvent(IclTerm goal,
          IclList params,
          IclList answers) 
      {
        return(processMessage(goal, params, answers));
      }
    }
    );

    System.out.println("Registering solvables");
    
    if(!oaa_.oaaRegister("parent", "Producer2", new IclList(IclTerm.fromString(true, "real_echo(X,Y,Z)")), new IclList())) {
      throw new RuntimeException("Could not register echo solvable");
    }

    System.out.println("All set");
    
    oaa_.oaaReady(true);
  }
  
  public boolean processMessage(IclTerm goal, IclList params, IclList answers)
  {
    System.out.println("Got goal " + goal.toString());
    answers.add(goal);
    return true;
  }
  
  public static void main(String[] args) throws InterruptedException
  {
    Producer2 es = new Producer2();
    es.init();
    while(true) {
      Thread.sleep(10000);
    }
  }
}

⌨️ 快捷键说明

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