📄 client.java
字号:
/*ARMiner - Association Rules MinerCopyright (C) 2000 UMass/Boston - Computer Science DepartmentThis program is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2 of the License, or (atyour option) any later version.This program is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307USAThe ARMiner Server was written by Dana Cristofor and LaurentiuCristofor.The ARMiner Client was written by Abdelmajid Karatihy, Xiaoyong Kuang,and Lung-Tsung Li.The ARMiner package is currently maintained by Laurentiu Cristofor(laur@cs.umb.edu).*//* This file is a part of the ARMiner project. (P)1999-2000 by ARMiner Client Team: Abdelmajid Karatihy Xiaoyong Kuang Lung-Tsung Li*/import java.net.*;import java.io.*;import java.util.Vector;/* Maintenance log started on November 17th, 2000 by Laurentiu Cristofor Nov. 17th, 2000 - made some style changes - made error messages a little more explicit NOTE: The way errors are dealt with in the client application is intriguing at best but I lack the time to do the right thing. - corrected some errors in dealing with errors in several places, setDBConfig, getDBConfig, and getDBConfig1 being the most important*/ /** Client.java<P> Client encapsulates the communication with the server.<P>*/public class Client{ /** * User's login name. * * @userName */ public static String userName; /** * Database object from server side. * * @dbConfig */ public static DBConfig dbConfig; /** * Output stream to send information from client to server. * * @out */ public static ObjectOutputStream out ; /** * input stream to send information from client to server. * * @in */ public static ObjectInputStream in ; /** * array to control the sort direction for mining result. * * @order */ public static int[] order = {0, 0, 0, 0}; private static String status; private static Vector response; private static final String strOK = "OK"; private static final String strERROR = "ERROR"; private static final String strWARNING = "WARNING"; /** * Static method to initiate the static class when * the class is first called. * */ static { userName = ""; } /** * login to server * * @param name user name * @param password user password */ public static Vector login(String name, String password) { Vector result = new Vector(); Vector login = new Vector(2); login.add(name); login.add(password); try { out.reset(); out.writeObject("LOGIN"); out.writeObject(login); out.flush(); //Get the server response. String response = (String)in.readObject(); result.add(response); if (!response.equals(strOK)) result.add((Vector)in.readObject()); } catch (Exception f) { result = new Vector(); result.add(strERROR); Vector msg = new Vector(); msg.add(f.toString()); result.add(msg); } return result; } public static void clientExit() { try { out.writeObject("EXIT"); reset(); } catch (IOException e) { System.err.println("An error occurred in Client.clientExit():\n\t" + e); } } /** * Static method to reset the static class value. * */ public static void reset() { userName = ""; try { if (in != null) { in.close(); in = null; } if (out != null) { out.close(); out = null; } } catch (Exception e) { System.err.println("An error occurred in Client.reset():\n\t" + e); } } /** * Delete an algorithm from the system. * @exception ClientErrorException The operation can not be completed, * the error message from the server will be thrown. * @param request a vector includes the algorithm's name to be deleted. * @return The messages returned from server. */ public static Vector deleteAlgorithms(Vector request) throws ClientErrorException { try { out.reset(); out.writeObject("DELALG"); //System.out.println("deleteAlgorithms: request: " + request.toString()); out.writeObject(request); out.flush(); status = (String)in.readObject(); //System.out.println("deleteAlgorithms: status: " + status); if (status.equals(strOK)) return null; response = (Vector)in.readObject(); throw new ClientErrorException((String)response.get(0)); } catch (IOException e) { //System.err.println("Client: Delete Algorithms " + e); throw new ClientErrorException(e.toString()); } catch (ClassNotFoundException e) { //System.err.println("Client: Delete Algorithms " + e); throw new ClientErrorException(e.toString()); } } /** * Add a new algorithm to the system. * @exception ClientErrorException The operation can not be completed, * the error message from the server will be thrown. * @param request a vector includes the algorithm's name and its group and number of bytes. * @return The messages returned from server. */ public static Vector addAlgorithms (Vector request, byte[] buff) throws ClientErrorException { try { out.reset(); out.writeObject("ADDALG"); out.writeObject(request); out.flush(); out.write(buff); out.flush(); status = (String)in.readObject(); //System.out.println("addAlgorithms: status: " + status); if (status.equals(strOK)) return null; response = (Vector)in.readObject(); throw new ClientErrorException((String)response.get(0)); } catch (IOException e) { //System.err.println("Client: Add Algorithms " + e); throw new ClientErrorException(e.toString()); } catch (ClassNotFoundException e) { //System.err.println("Client: Add Algorithms " + e); throw new ClientErrorException(e.toString()); } } /** * Modify an algorithm's group access. * @exception ClientErrorException The operation can not be completed, * the error message from the server will be thrown. * @param request a vector includes the algorithm's name and its new group. * @return The messages returned from server. */ public static Vector modifyAlgorithms(Vector request) throws ClientErrorException { try { out.reset(); out.writeObject("CHGALGGRP"); //System.out.println("modifyAlgorithms: request: " + request.toString()); out.writeObject(request); out.flush(); status = (String)in.readObject(); //System.out.println("modifyAlgorithms: status: " + status); if (status.equals(strOK)) return null; response = (Vector)in.readObject(); throw new ClientErrorException((String)response.get(0)); } catch (IOException e) { //System.err.println("Client: Modify Algorithms " + e); throw new ClientErrorException(e.toString()); } catch (ClassNotFoundException e) { //System.err.println("Client: Modify Algorithms " + e); throw new ClientErrorException(e.toString()); } } /** * Add a new group to the system. * @exception ClientErrorException The operation can not be completed, * the error message from the server will be thrown. * @exception ClientWarningException The operation can be completed, * the warning message from the server will be thrown. * @param request a vector includes a group's name and a vector of users. * @return The messages returned from server. */ public static Vector addGroup(Vector request) throws ClientErrorException, ClientWarningException { try { out.reset(); out.writeObject("ADDGRP"); //System.out.println("addGroup: request: " + request.toString()); out.writeObject(request); out.flush(); status = (String)in.readObject(); //System.out.println("addGroup: status: " + status); if (status.equals(strOK)) return null; response = (Vector)in.readObject(); if (status.equals(strERROR)) throw new ClientErrorException((String)response.get(0)); else // if (status.equals(strWARNING)) throw new ClientWarningException((String)response.get(0)); } catch (IOException e) { //System.err.println("Client: Add Group " + e); throw new ClientErrorException(e.toString()); } catch (ClassNotFoundException e) { //System.err.println("Client: Add Group " + e); throw new ClientErrorException(e.toString()); } } /** * Delete a group from the system. * @exception ClientErrorException The operation can not be completed, * the error message from the server will be thrown. * @param request a vector includes a group's name to be removed. * @return The messages returned from server. */ public static Vector deleteGroup(Vector request) throws ClientErrorException { try { out.reset(); out.writeObject("DELGRP"); //System.out.println("deleteGroup: request: " + request.toString()); out.writeObject(request); out.flush(); status = (String)in.readObject(); //System.out.println("deleteGroup: status: " + status); if (status.equals(strOK)) return null; response = (Vector)in.readObject(); throw new ClientErrorException((String)response.get(0)); } catch (IOException e) { //System.err.println("Client: Delete Group " + e); throw new ClientErrorException(e.toString()); } catch (ClassNotFoundException e) { //System.err.println("Client: Delete Group " + e); throw new ClientErrorException(e.toString()); } } /** * Modify a group's name. * @exception ClientErrorException The operation can not be completed, * the error message from the server will be thrown. * @param request a vector includes a group's name and its new name. * @return The messages returned from server. */ public static Vector modifyGroupName(Vector request) throws ClientErrorException { try { out.reset(); out.writeObject("CHGNAMEGRP"); //System.out.println("modifyGroupName: request: " + request.toString()); out.writeObject(request); out.flush(); status = (String)in.readObject(); //System.out.println("modifyGroupName: status: " + status); if (status.equals(strOK)) return null; response = (Vector)in.readObject(); throw new ClientErrorException((String)response.get(0)); } catch (IOException e) { //System.err.println("Client: Modify Group " + e); throw new ClientErrorException(e.toString()); } catch (ClassNotFoundException e) { //System.err.println("Client: Modify Group " + e); throw new ClientErrorException(e.toString()); } } /** * Add groups for an user. * @exception ClientErrorException The operation can not be completed, * the error message from the server will be thrown. * @exception ClientWarningException The operation can be completed,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -