⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 serverchild.java

📁 数据挖掘的工具代码(包含fp-tree,appriory
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    catch (DBConfigException e)      {	sendError(e.toString());      }  }  /*   * deletes a user from the list of groups   */  private void delUsrFromGrps(String userName, Vector groups)    throws IOException  {    boolean all = true;    try      {	for (int i = 0; i < groups.size(); i++)	  {	    try	      {		dbconf.removeUserFromGroup(user, userName, 					   (String)groups.get(i));	      }	    catch (DBConfigNonexistentGroup e1)	      {		all = false;	      }	  }	  	// have to see if it is OK or WARNING	if (all)	  sendOK();	else	  sendWarning("not all specified groups are valid ");      }    catch (DBConfigException e)      {	sendError(e.toString());      }  }  /*   * Adds a new user   */  private void addUsr(String userName, String password,		      long permissions, Vector groups)    throws IOException  {    try      {	dbconf.addUser(user, userName, password, permissions, groups);	sendOK();      }    catch (DBConfigWarning w)      {	sendWarning(w.toString());      }    catch (DBConfigException e)      {	sendError(e.toString());      }  }  /*   * Deletes the user   */  private void delUsr(String userName)    throws IOException  {    try      {	dbconf.deleteUser(user, userName);	sendOK();      }    catch (DBConfigException e)      {	sendError(e.toString());      }  }  /*   * Changes the name for user   */  private void chgNameUsr(String userName, String newName)    throws IOException  {    try      {	dbconf.changeUserName(user, userName, newName);	sendOK();      }    catch (DBConfigException e)      {	sendError(e.toString());      }  }  /*   * Changes the password for user   */  private void chgPassw(String userName, String password)    throws IOException  {    try      {	dbconf.changePassword(user, userName, password);	sendOK();      }    catch (DBConfigException e)      {	sendError(e.toString());      }  }  /*   * Changes the permissions for user   */  private void chgPerm(String userName, long permissions)    throws IOException  {    try      {	dbconf.changePermissions(user, userName, permissions);	sendOK();      }    catch (DBConfigException e)      {	sendError(e.toString());      }  }  /*   * Sends the results of the benchmark process   */  private void benchmark(Vector dbs, Vector algs, Vector supps)    throws IOException  {        try      {	AlgorithmManager algman = new AlgorithmManager();	Vector results_to_send = algman.benchmark(user, dbs, algs, supps);	sendOK();	// send the vector containing the results of the minings	out.writeObject(results_to_send);	out.flush();	//log(results_to_send);      }    catch (DBConfigException e)      {	sendError(e.toString());      }  }  /*   * Sends a copy of the configuration object   */  private void getDBConfig()    throws IOException  {    try      {	sendOK();	DBConfig.sendUpdate(out);	// out.flush() is done inside sendUpdate      }    catch (DBConfigException e)      {	sendError(e.toString());      }  }  /*   * Sends to the client the list of columns associated with the    * database from the Vector dbs; in this version dbs will   * contain only one element, the name of the database;    * in the future it might contain several   */  private void getColumns(Vector dbs)    throws IOException  {    try      {	// find the path to the database	String dbPath = dbconf.getPathDatabase((String)dbs.get(0));	// create a DBReader for this database	DBReader dbReader = new DBReader(dbPath);	// ask a DBReader to return the columns for the database	Vector dbCols = dbReader.getColumnNames();	dbReader.close();		sendOK();	// send the result to the client	out.writeObject(dbCols);	out.flush();      }    catch (DBConfigException e)      {	sendError(e.toString());      }  }  /*   * Adds a new database   */  private void addDb(Vector info)    throws IOException, ClassNotFoundException   {    Vector info1;    String dbname = (String)info.get(0);    try      {	dbconf.addDatabase(user, dbname, (String)info.get(1));      }    catch (DBConfigException e)      {	sendError(e.toString());      }    try      {	// find the directory of the database	String dirName = dbconf.getDirDatabase(dbname);	// find the path to the database	String dbPath = dbconf.getPathDatabase(dbname);		File dir = new File(dirName);	    	if (dir.mkdir() != true)	  throw new IOException("Could not create database directory!");	// create a DBWriter	DBWriter dbw = new DBWriter(dbPath);	    	dbw.setColumnNames((Vector)info.get(2));	dbw.setDescription((String)info.get(3));	sendOK();	    	// get the Itemsets	while ((info1 = (Vector)in.readObject()).size() > 0)	  {	    //log("Another round saved to file");	    //log(info1);	    for (int i = 0; i < info1.size(); i++)	      dbw.addRow((Itemset)info1.get(i));	  }	dbw.close();	sendOK();      }    catch (Throwable e)      {	try	  {	    dbconf.deleteDatabase(user, dbname);	    sendError(e.toString());	  }	catch (DBConfigException e2) 	  {	    sendError(e.toString() + " and " + e2.toString());	  }      }  }  /*   * Adds a new synthetic database   */  private void genDB(String dbname, String group,		     long num_transactions, int avg_transaction_size, 		     int num_large_itemsets, int avg_large_itemset_size,		     int num_items,		     double correlation_mean, double corruption_mean)    throws IOException, ClassNotFoundException   {    try      {	dbconf.addDatabase(user, dbname, group);      }    catch (DBConfigException e)      {	sendError(e.toString());      }	    try      {	// find the directory of the database	String dirName = dbconf.getDirDatabase(dbname);	// find the path to the database	String dbPath = dbconf.getPathDatabase(dbname);	File dir = new File(dirName);	    	if (dir.mkdir() != true)	  throw new IOException("Could not create database directory!");	// create a synthetic data generator	SyntheticDataGenerator syngen =	  new SyntheticDataGenerator(num_transactions,				     avg_transaction_size,				     num_large_itemsets,				     avg_large_itemset_size,				     num_items,				     correlation_mean,				     corruption_mean);		// create a DBWriter	DBWriter dbw = new DBWriter(dbPath);	    	// generate the column names C1, C2, ...	Vector columnNames = new Vector();	for (int i = 1; i <= num_items; i++)	  columnNames.add("C" + i);	    	dbw.setColumnNames(columnNames);	String description = "Synthetic database: " 	  + "number of transactions=" + num_transactions 	  + "; average transaction size=" + avg_transaction_size 	  + "; number of large itemsets=" + num_large_itemsets 	  + "; average large itemset size=" + avg_large_itemset_size 	  + "; number of items=" + num_items 	  + "; correlation=" + correlation_mean 	  + "; corruption=" + corruption_mean;	    	dbw.setDescription(description);	// get the Itemsets	while (syngen.hasMoreTransactions())	  {	    Itemset is = syngen.getNextTransaction();	    dbw.addRow(is);	    //log(is);	  }	dbw.close();	sendOK();      }    catch (Throwable e)      {	try	  {	    dbconf.deleteDatabase(user, dbname);	    sendError(e.toString());	  }	catch (DBConfigException e2) 	  {	    sendError(e.toString() + " and " + e2.toString());	  }      }  }  /*   * Adds a new algorithm   */  private void addAlg(Vector info)    throws IOException   {    String algname = (String)info.get(0);    String grpname = (String)info.get(1);    // get the number of bytes in the file    int dim = ((Integer)info.get(2)).intValue();     byte[] buf = new byte[dim];    try      {	// read the next byte[] from the socket in order to 	// save the information into a jar file        int bytes_read = 0;        while (bytes_read != dim)	  {	    int r = in.read(buf, bytes_read, dim - bytes_read);	    if (r < 0)	      break;	    bytes_read += r;	  }        if (bytes_read != dim)          throw new DBConfigException("Cannot read algorithm from socket");	// we don't want to overwrite some file!	File algjar = new File(algname + ".jar");	if (algjar.exists())	  throw new DBConfigException("File " + algname 				      + ".jar already exists!");	dbconf.addAlgorithm(user, algname, grpname);      }    catch (Throwable e)      {	sendError(e.toString());      }      try      {	// write the bytes in the file	BufferedOutputStream alg_writer = 	  new BufferedOutputStream(new FileOutputStream(algname							+ ".jar"));		alg_writer.write(buf, 0, dim);	alg_writer.close();	// send OK	sendOK();      }    catch (Throwable e)      {	try	  {	    dbconf.deleteAlgorithm(user, algname);	    sendError(e.toString());	  }	catch (DBConfigException e2) 	  {	    sendError(e.toString() + " and " + e2.toString());	  }      }  }  /*   * Sends an OK message   */  private void sendOK()    throws IOException  {    out.writeObject("OK");    out.flush();    log("Sent OK");  }  /*   * Sends a warning message   */  private void sendWarning(String msg)    throws IOException  {    Vector err = new Vector(1);    err.add(msg);    out.writeObject("WARNING");    out.flush();    out.writeObject(err);    out.flush();    log("Sent warning: " + err);  }  /*   * Sends an error message   */  private void sendError(String msg)    throws IOException  {    Vector err = new Vector(1);    err.add(msg);    out.writeObject("ERROR");    out.flush();    out.writeObject(err);    out.flush();    log("Sent error: " + err);  }  /*   * Prints to System.out the connection id and a dump of data.   */  private void log(Object data)  {    System.out.println("<" + connectionID + "> " + data.toString());  }}

⌨️ 快捷键说明

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