genericagentcommand.java.svn-base

来自「cqME :java framework for TCK test.」· SVN-BASE 代码 · 共 167 行

SVN-BASE
167
字号
/* * $Id$ * * Copyright 1996-2007 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License version 2 for more details (a copy is * included at /legal/license.txt). * * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 or visit www.sun.com if you need additional * information or have any questions. * */package com.sun.tck.j2me.execution.javatest;import java.io.PrintWriter;import java.util.HashMap;import com.sun.javatest.Command;import com.sun.javatest.Status;import com.sun.tck.j2me.execution.baseclient.ExecutionRequest;import com.sun.tck.j2me.execution.queue.DefaultTestInfo;import com.sun.tck.j2me.execution.queue.Request;import com.sun.tck.j2me.execution.queue.RequestImpl;import com.sun.tck.j2me.execution.server.DefaultExecDataCreator;import com.sun.tck.j2me.services.LifeCycleAware;/** * This command works with the ExecutionRequestQueue. It creates request and * put it into current ExecutionRequestQueue, waits until the request is * executed and returns status. * <p> * The command uses the following parameters, which should be specified prior * test class and test parameters. * <ul> *   <li><code>-m</code> or <code>-mapArgs</code> specifies that parameters *   should be mapped on the agent side using map file</li> *   <li><code>-loadRemote</code> specifies that classes should be loaded *   remotely from the JavaTest. The class file binary representation are *   resolved as resources by ResourceProvider</li> * </ul> */public class GenericAgentCommand extends Command {    public static final Status INTERRUPTED = Status.error(            "Command has been interrupted");    /**     * Returns LifeCycleAware for managing of the lifecycle of the execution     * service. Note that this service should be registered after     * {@link com.sun.tck.j2me.services.commService.CommTestSuiteService     * CommTestSuiteService}.     */    public static LifeCycleAware getExecutionService() {        return AgentQueue.getInstance().services;    }    private static class NotifiedTestInfo extends DefaultTestInfo {        private Object monitor = new Object();        private boolean isCompleted = false;        public NotifiedTestInfo(String testUrl, PrintWriter log,                                PrintWriter ref) {            super(testUrl, log, ref);        }        public Status waitUntilDone(String commandName) throws InterruptedException {            while (!isCompleted) {                synchronized (monitor) {                    monitor.wait();                }            }            return statuses.get(commandName);        }        @Override        public void completed() {            super.completed();            synchronized (monitor) {                isCompleted = true;                monitor.notifyAll();            }        }    }    private static int count = 1;    private synchronized int getNextRequestID() {        return count++;    }    @Override    public Status run(String[] args, PrintWriter log, PrintWriter ref) {        boolean loadRemote = false;        boolean mapArgs = false;        String classpath = null;        int i = 0;/// TODO Next Release//        String queueName = ExecutionRequestQueue.DEFAULT_QUEUE;        String testUrl = "file:///UnknownTest/" + getNextRequestID();        for (; i < args.length && args[i].startsWith("-"); i++) {            if (args[i].equals("-loadRemote")) {                loadRemote = true;// TODO Next Release//            } else if (args[i].equals("-queue") && (i < args.length - 1)) {//                queueName = args[++i];            } else if (args[i].equals("-m") || args[i].equals("-mapArgs")) {                mapArgs = true;            } else if (args[i].equals("-testURL") && (i < args.length - 1)) {                testUrl = args[++i];            } else if (args[i].equals("-classpath") && (i < args.length - 1)) {                classpath = args[++i];            } else {                return Status.error("Unrecognized option: " + args[i]);            }        }        if (i == args.length) {            return Status.error("No command specified");        }        String cmdClass = args[i++];        String[] cmdArgs = new String[args.length - i];        System.arraycopy(args, i, cmdArgs, 0, cmdArgs.length);// TODO Next Release//        ExecutionRequestQueue queue = ExecutionRequestQueue.getInstance(queueName);        HashMap<String, Object> map = new HashMap<String, Object>();        map.put(DefaultExecDataCreator.EXECUTION_REQUEST_PREFIX + testUrl,                new ExecutionRequest(testUrl, cmdClass, cmdArgs, mapArgs, loadRemote, false));        NotifiedTestInfo info = new NotifiedTestInfo(testUrl, log,ref);        Request request = new RequestImpl(map, info);        AgentQueue agents = AgentQueue.getInstance();        if (classpath != null) {            agents.setClassPath(classpath);        }        try {            agents.putRequest(request);            return info.waitUntilDone("execute");        } catch (InterruptedException e) {            agents.removeRequest(request);            return INTERRUPTED;        } catch (Exception e) {            agents.removeRequest(request);            return Status.error("Unexpected exception:" + e);        }        // TODO: move agents.removeRequest() to finally block?    }}

⌨️ 快捷键说明

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