?? agentclient.java
字號:
/*
* Copyright 1999 by dreamBean Software,
* All rights reserved.
*/
package masteringrmi.agent.client;
import java.awt.Label;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.util.Properties;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import masteringrmi.agent.interfaces.AgentHost;
import masteringrmi.agent.interfaces.NoSuchAgentException;
import masteringrmi.agent.agents.HelloAgent;
import masteringrmi.agent.agents.HelloAgentImpl;
import com.dreambean.dynaserver.DynaServer;
/**
* This is the client of the agent host.
*
* @author Rickard 謆erg
* @version $Revision:$
*/
public class AgentClient
{
// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
DynaServer srv;
AgentHost host;
HelloAgent agent;
// Static --------------------------------------------------------
public static void main(String[] args)
throws Exception
{
new AgentClient().talkToAgent();
}
// Constructors --------------------------------------------------
public AgentClient()
throws Exception
{
// Start webserver for dynamic class loading
srv = new DynaServer();
srv.setDebug(true);
srv.addClassLoader(Thread.currentThread().getContextClassLoader());
srv.start();
// Locate host
host = findHost();
// Create agent
agent = new HelloAgentImpl();
// Register agent
agent = (HelloAgent)host.addAgent(agent);
}
public void talkToAgent()
throws IOException, NoSuchAgentException
{
// Say hello
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String name;
while (true)
{
System.out.print("Name:");
System.out.flush();
if ((name = in.readLine()).equals(""))
break;
System.out.println(agent.hello(name));
}
// Remove agent
HelloAgentImpl result = (HelloAgentImpl)host.removeAgent(agent);
System.out.println("The agent was run "+result.getRunCounter() + " times, and was queried "+result.getQueryCounter() + " times");
// Stop class-server
srv.stop();
}
// Public --------------------------------------------------------
public AgentHost findHost()
throws NamingException
{
return (AgentHost)new InitialContext().lookup("agenthost");
}
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
// Private -------------------------------------------------------
// Inner classes -------------------------------------------------
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -