📄 simpleclient.java
字号:
/******************************************************************************* * Copyright (C) 2002, 2003 * ingenieurbuero fuer innovative informationstechnik (iiit) * Dipl.-Ing. Joerg Beckmann, Dortmund, Germany * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * or look at http://www.gnu.org/copleft/lesser.html. * * version $Id: SimpleClient.java,v 1.8 2003/04/13 21:13:38 joerg Exp $ ******************************************************************************/package de.iiit.access.client;import de.iiit.access.common.api.*;import de.iiit.access.common.rmi.*;import java.io.*;import java.rmi.*;import java.rmi.registry.LocateRegistry;import java.rmi.registry.Registry;/** This a demonstration for the RMI client * @version $Revision: 1.8 $ $Date: 2003/04/13 21:13:38 $ */public class SimpleClient{ /** CVS Version Tag */ private static final String vcid = "$Id: SimpleClient.java,v 1.8 2003/04/13 21:13:38 joerg Exp $"; /** Creates a new instance of SimpleClient */ private SimpleClient() { } private static void expr(RMIClient client, String[] parts) { if (parts.length < 2) System.out.println("Syntax error: at least 1 Argument expected."); else { String expr = parts[1]; for (int i = 2; i < parts.length; i++) expr = expr + " " + parts[i]; try { long t = System.currentTimeMillis(); boolean result = client.resolveExpr(expr); t = System.currentTimeMillis() - t; System.out.println("Remote request done within " + t + " ms, Result = <" + result + ">"); } catch (RMIClientException rce) { System.out.println("Client error while sending request"); rce.printStackTrace(); } catch (ParserException rpe) { System.out.println("Parser error"); rpe.printStackTrace(); } } } /** This is the main method of the simple client demonstration program. * It connects to the AccessServer running on localhost and using the default port * 54322. After the connection is established it waits for commands. * @param args the command line arguments */ public static void main(String[] args) { String[] server = { "localhost:54322" }; RMIClient.initLogSystem("INFO", null); RMIClient.initialize(server, 1800, 1800, 10); InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr); RMIClient client = null; boolean loop = true; while(loop) { try { System.out.flush(); System.out.print("Command > "); String line = br.readLine().trim(); if (! line.equals("")) { String[] parts = line.split("\\s");// System.out.print("Line =");// for (int i = 0; i < parts.length; i++)// System.out.print(" <" + parts[i] + ">");//// System.out.println(""); if (parts[0].equalsIgnoreCase("setuser")) { client = RMIClient.getSession(parts[1]); if (client == null) System.out.println("Unknown user <" + parts[1] + ">"); } else if (parts[0].equalsIgnoreCase("expr")) expr(client, parts); else if (parts[0].equalsIgnoreCase("quit")) loop = false; else System.out.println("Unknown command <" + parts[0] + ">"); } } catch(Exception e) { e.printStackTrace(System.err); } } RMIClient.shutdown(); System.out.println("Finished."); } }/** * $Log: SimpleClient.java,v $ * Revision 1.8 2003/04/13 21:13:38 joerg * Copyright statements changed to LGPL * * Revision 1.7 2003/04/13 21:09:56 joerg * Package structure modified * * Revision 1.6 2003/04/13 20:16:41 joerg * Package structure modified * * Revision 1.5 2003/04/07 20:15:33 joerg * Adopted to changes in RMIClient * * Revision 1.4 2003/04/07 20:08:49 joerg * Improved JavaDoc. * * Revision 1.3 2003/04/07 17:13:50 joerg * RMIParserException is now catched. * * Revision 1.2 2003/04/06 20:45:00 joerg * GPL statement and some comments included. * */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -