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

📄 oaatest_t.java

📁 SRI international 发布的OAA框架软件
💻 JAVA
字号:
/* $Id: OaaTest_T.java,v 1.2 2004/02/05 23:28:59 giuli Exp $
 *
 * 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.test.agent;

import com.sri.oaa2.icl.IclList;
import com.sri.oaa2.icl.IclTerm;
import com.sri.oaa2.icl.IclUtils;
import com.sri.oaa2.agentlib.AgentException;

/**
 * OaaTest_T is a common base class for the OAA tests.
 */
public abstract class OaaTest_T extends com.sri.oaa2.agentlib.AgentImpl {
    private IclList nonBlockingAnswers;

    void debug(String msg) {
        System.out.println(msg);
    }

    /**
     * For testing the interpret method is changed to always block.
     */
    public IclList interpret(IclTerm toBeInterpreted, IclList localParams)
            throws com.sri.oaa2.agentlib.AgentException {
        boolean nonBlocking = !getBlocking();

        if ((toBeInterpreted.isStruct() && toBeInterpreted.
                toIdentifyingString().equals("oaa_Solve"))) {
            IclList params = (IclList) toBeInterpreted.getTerm(1);
            IclTerm nbParam = IclUtils.getParamValue(BLOCK_PARAM_NAME, null, params);

            if (nbParam != null && nbParam.toIdentifyingString().equals("false")) {
                nonBlocking = true;
            }
        }

        if (nonBlocking) {
            synchronized (this) {
                super.interpret(toBeInterpreted, localParams);
                debug("Waiting for answers non-blocking...");
                nonBlockingAnswers = new IclList();
                // Wait for the answers. This release the synchronization block
                try {
                    wait();
                } catch (InterruptedException ex) {
                    throw new AgentException("Interrupted while waiting for results!");
                }
                return nonBlockingAnswers;
            }
        } else {
            return super.interpret(toBeInterpreted, localParams);
        }
    }

    public boolean oaaDoEventCallback(IclTerm goal,
                                      IclList params,
                                      IclList answers) {
        if (goal.toIdentifyingString().equals("ev_solved")) {
            synchronized (this) {
                nonBlockingAnswers = (IclList) goal.getTerm(goal.size() - 1);
                notify();
            }

            return true;
        }

        return super.oaaDoEventCallback(goal, params, answers);
    }
}

⌨️ 快捷键说明

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