airlinea.java
来自「《移动Agent技术》一书的所有章节源代码。」· Java 代码 · 共 220 行
JAVA
220 行
/* AirLineA.java * $Id: AirLineA.java,v 2.4 1997-12-07 14:59:50+09 ht Exp $ * $Name: alpha5_1-release $ * */package com.ibm.acl.kqmlsample.travel;import com.ibm.acl.kqml.*;import com.ibm.acl.kqml.interpreter.*;import com.ibm.acl.facilitator.FacilitatorProperties;import java.lang.*;import java.io.*;import java.net.*;import java.util.*;/** * AirLineA Sample * * @version $Revision: 2.4 $ $Date: 1997-12-07 14:59:50+09 $ * @author Osamu Furusawa * @author Hajime Tsuchtiani */public class AirLineA extends AirLine{ private static final String rcsid = "$Id: AirLineA.java,v 2.4 1997-12-07 14:59:50+09 ht Exp $ $Name: alpha5_1-release $"; public AirLineA() { } /** * Constructor * * @param port socket port number. */ public AirLineA(int port) { super(); this.port = port; FacilitatorProperties fp; try { fp = new FacilitatorProperties(); } catch (IOException ex) { ex.printStackTrace(); return; } facilitator = fp.getOneURL("ktp"); if (facilitator == null) { print(" no ktp facilitator found, system exit!"); System.exit(1); } agentName = new String("JAL"); print("port" + port); try { InetAddress home = InetAddress.getLocalHost(); StringBuffer buf = new StringBuffer("ktp://"); buf.append(home.getHostName() + ":"); buf.append(Integer.toString(port)); localHost = new String(buf.toString()); } catch (UnknownHostException e) { System.err.println("Unknown HostName"); System.exit(1); } // initialize data base flightTable.addElement(new FlightInfo("JAL", "123", "NRT", "JFK", "03/21/97 AM")); flightTable.addElement(new FlightInfo("JAL", "323", "NRT", "CDG", "03/21/97 AM")); flightTable.addElement(new FlightInfo("JAL", "523", "NRT", "LHR", "03/21/97 AM")); flightTable.addElement(new FlightInfo("JAL", "623", "NRT", "SFO", "03/21/97 AM")); if ( -1 != port ) { kManager = new KQMLManager(agentName, "ktp", port); frame = new AirFrame("Airline-A", this); frame.show(); // scenario - (21) call AirLine method setRegisterL(); // scenario - (22) call AirLine method. setRecommendoneInsertY(); // scenario - (24) setInsertY(); // scenario - (26) call AirLine method setAdvertiseBrokerallAskallT(); // scenario - (27) call AirLine method setAdvertiseSubAskallT(); } } /** * AirLineA Insert(yellowpages) * scenario (24) * */ private void setInsertY() { KQML kqml = new KQML(); String rw = new String(kManager.getInitialID()); kqml.setPerformative("insert"); kqml.setParameter(":name", agentName); kqml.setParameter(":sender", localHost); kqml.setParameter(":receiver", receiverAddr); kqml.setParameter(":reply-with", rw); kqml.setParameter(":language", "anACL"); kqml.setParameter(":ontology", "yellowpages"); String content = new String( "(:ProviderName \"Japan Air Line\"" +"\n"+ " :category travel" +"\n"+ " :subCategory airline" +"\n"+ " :class anacl_travel" +"\n"+ " :name JAL" +"\n"+ " :language anACL" +"\n"+ " :ontology travel)" ); kqml.setContent(content); Conversation conv = null; try { conv = (Conversation) kManager.sendMessage(kqml); } catch (SendFailedException ex) { ex.printStackTrace(); } catch (InvalidFormatException ex) { ex.printStackTrace(); } catch (InvalidMessageSequenceException ex) { ex.printStackTrace(); } catch (JKQMLException ex) { ex.printStackTrace(); } conv.getResult().waitFor(45000); Result res = conv.getResult(); if ( res.isAvailable()) { ReturnValue rtn = (ReturnValue)res.getResult(); if (rtn.isOK()) { yellowpageID = new String((String)rtn.getReturnValue()); print("yellowpage: " + yellowpageID); } else { System.err.println("setInsertY() : scenario (24)"); System.err.println((String)rtn.getReturnValue()); System.exit(-1); } } else { System.err.println("setInsertY() :Error Result isn't available"); System.exit(-1); } } /** * print for debug. * * @param msg print message */ private void print(String msg) { if (KQMLManager.debug) { System.err.println("AirLineA." + msg); } } /** * main routine * * @param args[] port number. The default number is 8001. */ public static void main(String args[]) { int port = 8102; String usage = new String("Usage: AirLineA [-trace] [-port <port#>] [-help]"); int argc = args.length; for (int i = 0; i < argc; i++) { try { if (args[i].equals("-trace")) { KQMLManager.debug = true; } else if (args[i].equals("-port")) { port = Integer.parseInt(args[++i]); } else if (args[i].equals("-help")) { System.err.println(usage); System.exit(0); } else { System.err.println(usage); System.exit(1); } } catch (ArrayIndexOutOfBoundsException e) { System.err.println(usage); System.exit(1); } catch (NumberFormatException nfe) { System.err.println(usage); System.exit(1); } } AirLineA app = new AirLineA(port); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?