client.java

来自「分布式数据库原形代码 可以支持个用户同时登陆到数据库中查询需要的资源」· Java 代码 · 共 70 行

JAVA
70
字号
package transaction;import java.rmi.*;/**  * A client of the Distributed Travel Reservation System. *  */public class Client {        public static void main(String args[]) {	String rmiName = System.getProperty("rmiName");	if (rmiName == null || rmiName.equals("")) {	    rmiName = ResourceManager.DefaultRMIName;	}	String rmiRegPort = System.getProperty("rmiRegPort");	if (rmiRegPort != null && !rmiRegPort.equals("")) {	    rmiName = "//:" + rmiRegPort + "/" + rmiName;	}	ResourceManager rm = null;	try {	    rm = (ResourceManager)Naming.lookup(rmiName);	    System.out.println("Bound to RM");	} 	catch (Exception e) {	    System.err.println("Cannot bind to RM:" + e);	    System.exit(1);	}	try {	    int xid = rm.start();	    if (!rm.addFlight(xid, "347", 230, 999)) {		System.err.println("Add flight failed");	    }	    if (!rm.addRooms(xid, "SFO", 500, 150)) {		System.err.println("Add room failed");	    }	    	    System.out.println("Flight 347 has " +			       rm.queryFlight(xid, "347") +			       " seats.");	    if (!rm.reserveFlight(xid, "John", "347")) {		System.err.println("Reserve flight failed");	    }	    System.out.println("Flight 347 now has " +			       rm.queryFlight(xid, "347") +			       " seats.");	    if (!rm.commit(xid)) {		System.err.println("Commit failed");	    }	    /*	    if (!rm.shutdown()) {		System.err.println("Shutdown failed");	    }	    */	} 	catch (Exception e) {	    System.err.println("Received exception:" + e);	    System.exit(1);	}    }}

⌨️ 快捷键说明

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