serverproactivecommand.java.svn-base
来自「cqME :java framework for TCK test.」· SVN-BASE 代码 · 共 143 行
SVN-BASE
143 行
/* * $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.server;import com.sun.tck.j2me.execution.baseclient.ExecutionRequest;import java.io.DataInputStream;import java.util.Random;/** * This class represents the proactive command on the server side. It * supports automatic ID creation and waiting methods for the waiting * of the results from agent. * <p> * The proactive commands are commands being sent from the server side * to the client time. The client does not listens these commands * permanently. Neither the client do not implements the popping of * the commands from the server on the separate channel. But the * server can't send the commands as response on the any commands from * the agent, which expect response. When the agent receives proactive * commands as response on a request, the agent should execute these * commands and resend the the request to the server. Current * implementation supports sending of the proactive commands on the * getNextTests(), register and and update registration requests. * <p> * On server side the commands might be sent to already registered * agent using agent ID, or a agent requesting registration. The * sending of the proactive commands is supported by * {@link RegistrationHandler RegistrationHandler}. If proactive * command can be sent to a agent via * {@link RegistrationHandler#dispatchProactiveCommand(String, ServerProactiveCommand) * dispatchProactiveCommand() method}. The {@link RegistrationHandler} * defines special * {@link RegistrationHandler#REGISTRATION REGISTRATION} id for * sending of the commands to the agents requesting registration. * These commands are not removed from the list and they are sent to * each agent prior registration. */public class ServerProactiveCommand extends ExecutionRequest { private static long count = 0; private static String salt = createSalt(ServerProactiveCommand.class); private boolean isReceived = false; private boolean isUnsupported = false; private DataInputStream response; /** * Creates a instance of ServerProactiveCommand with the given * name, arguments and expectData. Note that ID is calculated * automatically and mapArgs and isRemote are set to false and * true accordingly. */ public ServerProactiveCommand( String name, String[] args, boolean expectData) { super(salt + (++count), name, args, false, true, expectData); } private static String createSalt(Class cl) { ClassLoader loader = cl.getClassLoader(); String loaderSalt = ((loader == null) ? "System:" : Long.toHexString(loader.hashCode())); Long salt = new Random(System.currentTimeMillis()).nextLong(); StringBuffer retVal = new StringBuffer(loaderSalt); retVal.append(':'); retVal.append(Long.toHexString(salt)); retVal.append(':'); return retVal.toString(); } /** * Waits when the result of command execution is received from the agent. * @throws UnsupportedOperationException if command does not * expectData or agent does not support proactive commands. * @return DataOutputStream, which represents the result of * command execution. */ public DataInputStream waitResponse() throws InterruptedException, UnsupportedOperationException { if (!expectsData()) { throw new UnsupportedOperationException( "Command does not expect data"); } synchronized (this) { while (!isReceived) { this.wait(); } if (isUnsupported) { throw new UnsupportedOperationException( "Proactive commands are not supported by the client."); } return response; } } /** * Notifies that response is received from the agent. */ public void complete(DataInputStream response) { synchronized (this) { isReceived = true; this.response = response; notifyAll(); } } /** * Notifies that the agent does not support proactive commands. */ public void notSupported() { synchronized (this) { isReceived = true; isUnsupported = true; notifyAll(); } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?