webloaa2wrapper.java

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

JAVA
77
字号
/**
 * The contents of this file are subject to the OAA  Community Research
 * License Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License
 * at http://www.ai.sri.com/~oaa/.  Software distributed under the License
 * is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
 * express or implied. See the License for the specific language governing
 * rights and limitations under the License.  Portions of the software are
 * Copyright (c) SRI International, 1999.  All rights reserved.
 * "OAA" is a registered trademark, and "Open Agent Architecture" is a
 * trademark, of SRI International, a California nonprofit public benefit
 * corporation.
*/

package com.sri.oaa2.agt.webloaa2;

import com.sri.oaa2.lib.*;
import com.sri.oaa2.com.*;
import com.sri.oaa2.icl.*;

import webl.lang.expr.*;
import webl.lang.*;

import java.util.*;

public class WebLOaa2Wrapper extends LibOaa{

  private Machine mMachine;

  private Hashtable mCallbacksTable = new Hashtable();

  public WebLOaa2Wrapper(Machine inMachine) {
    super(new LibCom(new LibComTcpProtocol(), null));
    mMachine = inMachine;
    OaaWebL.printMessage("Creating");
  }
  
  public WebLOaa2Wrapper() {
    this(OaaWebL.getMachine());
  }
  
  public void oaaConnect(String inAgentName, String inSolvables) {
    
    // DEBUG
    //System.out.println("Agent Name " + inAgentName + " Solvables " + inSolvables);
    
    // First, connects to the facilitator
    if (!getComLib().comConnect("parent", IclTerm.fromString(true, "tcp(A,B)"), new IclList())) {
      OaaWebL.printError("Could not connect");
      return;
    }

    // Then, once the connection is established, performs handshaking with the facilitator
    if (!oaaRegister("parent", inAgentName, IclTerm.fromString(true, inSolvables), new IclList())) {
      OaaWebL.printError("Could not register");
      return;
    }
    oaaReady(true);
  }

  public void oaaRegisterCallback(String inCallbackId, FunExpr inCallbackFunction) {  
    WebLOaa2Listener newListener = new WebLOaa2Listener(inCallbackId, inCallbackFunction);
    mCallbacksTable.put(inCallbackId, newListener);
    newListener.mMachine = mMachine;
    oaaRegisterCallback(inCallbackId, newListener);
  }
  
  public void oaaDeclare(String inSolvables) {
    IclTerm solvables = IclTerm.fromString(true, inSolvables);
    // DEBUG
    // System.out.println("Declaring : " + inSolvables.toString());

    oaaDeclare(solvables, new IclList(), new IclList(), new IclList());
  }
  
}

⌨️ 快捷键说明

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