?? commandclient.java
字號:
package trader.nw;
import java.io.*;
import java.net.*;
import trader.*;
import trader.db.*;
/** AddCommand and DeleteCommand UnitTest 2.
Compile from classes directory
javac -d . ../src/trader/nw/CommandClient.java
In one terminal window start the CommandServer class
java trader.nw.CommandServer
In another terminal window start the CommandClient class
java trader.nw.CommandClient
*/
class CommandClient {
public static void main(String args[]) {
String dbHost = "localhost";
Command cmd;
String id = "333_33_3333";
String symbol="CyAs";
Customer retCust;
Object obj;
System.out.println("CommandClient - AddCommand " +
"DelCommand Unit Test 2");
try {
if (args.length > 0) {
dbHost = args[0];
}
NwClient client = new NwClient(dbHost, 6001);
BrokerModel brokerModel = new BrokerModelDbImpl(dbHost);
Thread.sleep(2000);
while (true){
try {
System.out.println("Adding Customer " + id);
Customer addCust = new Customer("333_33_3333",
"Dough Nut", "Bakery Lane");
Command addCmd = new AddCustomerCommand(addCust);
client.send(addCmd);
Thread.sleep(2000);
cmd = (Command)client.receive();
obj = cmd.getResult();
Thread.sleep(5000);
} catch(Exception e) {
e.printStackTrace();
}
/* try {
System.out.println("Getting Customer " + id);
Command getCmd = new GetCustomerCommand(id);//constructor is wrong
client.send(getCmd);
Thread.sleep(2000);
cmd = (Command)client.receive();
System.out.println("Get Customer " +
(Customer) cmd.getResult());
Thread.sleep(5000);
} catch(Exception e) {
e.printStackTrace();
}*/
//modified by ourteam 051228
//begin
try {
System.out.println("Getting Stock " + symbol);
Command getCmd = new GetStockCommand(symbol);
client.send(getCmd);
Thread.sleep(2000);
cmd = (Command)client.receive();
System.out.println("Get Stock " +
(Stock) cmd.getResult());
Thread.sleep(5000);
} catch(Exception e) {
e.printStackTrace();
}
//end
try {
System.out.println("Deleting Customer " + id);
Customer delCust = new Customer("333_33_3333",
"Dough Nut", "Bakery Lane");
Command delCmd = new DeleteCustomerCommand(delCust);
client.send(delCmd);
Thread.sleep(2000);
cmd = (Command)client.receive();
obj = cmd.getResult();
Thread.sleep(5000);
} catch(Exception e) {
e.printStackTrace();
}
}
} catch(Exception e) {
e.printStackTrace();
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -