📄 serverchild.java
字号:
// send this error to the client too sendError(e.toString()); // throws a ServerChildException which will exit the loop // of user requests and the connection will be closed throw new ServerChildException(e.toString()); } try { dbconf.verifyPasswordForUser(user, password); this.user = user; // mark the owner of the connection // mark the user as being logged on dbconf.markLogged(user); sendOK(); } catch (DBConfigException e) { sendError(e.toString()); } } /* * Mining */ private void mine(String db, String alg, float minSupport, float minConfidence) throws IOException { try { AlgorithmManager algman = new AlgorithmManager(); results = algman.mine(user, db, alg, minSupport, minConfidence); index = 0; // reset the pointer at the beginning of the data log(results.size() + " association rules were mined."); // prepare BATCH_SIZE association rules from results // or less if there are not enough association rules Vector results_to_send = new Vector(BATCH_SIZE); for (int i = 0; (i < BATCH_SIZE) && (index < results.size()); i++) results_to_send.add((AssociationRule)results.get(index++)); sendOK(); // send first BATCH_SIZE association rules out.writeObject(results_to_send); out.flush(); } catch (Exception e) { sendError(e.toString()); } } // sorts the entire vector v according to the criteria // criteria can be AssociationRule.ANTECEDENT_SIZE, // AssociationRule.CONSEQUENT_SIZE, AssociationRule.SUPPORT // or AssociationRule.CONFIDENCE // type can be ASC or DESC private void sort(int criteria, int type) throws IOException { if (results.size() == 0) sendError("There are no results available"); // reset index in the results vector index = 0; heapSort(results, criteria, type); // prepare BATCH_SIZE association rules from results // or less if there are not enough association rules Vector results_to_send = new Vector(BATCH_SIZE); for (int i = 0; (i < BATCH_SIZE) && (index < results.size()); i++) results_to_send.add((AssociationRule)results.get(index++)); sendOK(); // send first BATCH_SIZE association rules out.writeObject(results_to_send); out.flush(); } // exchanges the values at index i and j in the vector v private static void exchange(Vector v, int i, int j) { Object temp = v.get(i); v.set(i, v.get(j)); v.set(j, temp); } // helper method for HeapSort // criteria can be AssociationRule.ANTECEDENT_SIZE, // AssociationRule.CONSEQUENT_SIZE, AssociationRule.SUPPORT // or AssociationRule.CONFIDENCE // type can be ASC or DESC private static void siftDown(Vector v, int i, int n, int criteria, int type) { AssociationRule value = (AssociationRule)(v.get(i)); // value to sift down if (type == ASC) { for (int j = 2 * i + 1; j <= n; i = j, j = 2 * i + 1) { if (j < n) // determine which child is greater if (((AssociationRule)v.get(j + 1)).compareTo((AssociationRule)v.get(j), criteria) > 0) j++; // break if children are smaller if (((AssociationRule)v.get(j)).compareTo(value, criteria) <= 0) break; // move child up v.set(i, v.get(j)); } } else { for (int j = 2 * i + 1; j <= n; i = j, j = 2 * i + 1) { if (j < n) // determine which child is smaller if (((AssociationRule)v.get(j + 1)).compareTo((AssociationRule)v.get(j), criteria) < 0) j++; // break if children are greater if (((AssociationRule)v.get(j)).compareTo(value, criteria) >= 0) break; // move child up v.set(i, v.get(j)); } } // place value into its final position v.set(i, value); } // heapSort will sort the elements 0 ... size() - 1 of array v // criteria can be AssociationRule.ANTECEDENT_SIZE, // AssociationRule.CONSEQUENT_SIZE, AssociationRule.SUPPORT // or AssociationRule.CONFIDENCE // type can be ASC or DESC private static void heapSort(Vector v, int criteria, int type) { int last = v.size() - 1; // heapify for (int i = (last - 1) / 2; i > 0; i--) siftDown(v, i, last, criteria, type); // the first siftDown call will finish the heapify step // then we will extract the top of the heap, exchange it // with the last element of the heap, decrease the size of // the heap and start over again for (int i = last; i > 0; i--) { siftDown(v, 0, i, criteria, type); exchange(v, 0, i); } } /* * Returns next BATCH_SIZE association rules, or * the rest of association rules if there are less * than BATCH_SIZE or an empty vector if all the association * rules have been already sent * This function does not return an ERROR message to the client */ private void getNext() throws IOException { // prepare BATCH_SIZE association rules from results // or less if there are not enough association rules Vector results_to_send = new Vector(BATCH_SIZE); for (int i = 0; (i < BATCH_SIZE) && (index < results.size()); i++) results_to_send.add((AssociationRule)results.get(index++)); sendOK(); // send next BATCH_SIZE association rules (or less if there are not enough) // results_to_send is an empty vector if index became equal // to results.size() out.writeObject(results_to_send); out.flush(); //log(results_to_send); } /* * Advanced mining */ private void mineAdv(String db, String alg, float minSupport, float minConfidence, Vector inAntecedent, Vector inConsequent, Vector ignored, int maxAntecedent, int minConsequent) throws IOException { try { AlgorithmManager algman = new AlgorithmManager(); results = algman.advMine(user, db, alg, minSupport, minConfidence, inAntecedent, inConsequent, ignored, maxAntecedent, minConsequent); index = 0; // reset the pointer at the beginning of the data // prepare BATCH_SIZE association rules from results // or less if there are not enough association rules Vector results_to_send = new Vector(BATCH_SIZE); for (int i = 0; (i < BATCH_SIZE) && (index < results.size()); i++) results_to_send.add((AssociationRule)results.get(index++)); sendOK(); // send first BATCH_SIZE association rules out.writeObject(results_to_send); out.flush(); //log(results_to_send); } catch (Throwable e) { sendError(e.toString()); } } /* * Deletes a database */ private void delDb(String db) throws IOException { try { dbconf.deleteDatabase(user, db); sendOK(); } catch (DBConfigException e) { sendError(e.toString()); } } /* * Changes the group of the algorithm */ private void chgDbGrp(String db, String newgrp) throws IOException { try { dbconf.changeDatabaseGroup(user, db, newgrp); sendOK(); } catch (DBConfigException e) { sendError(e.toString()); } } /* * Deletes an algorithm */ private void delAlg(String alg) throws IOException { try { dbconf.deleteAlgorithm(user, alg); sendOK(); } catch (DBConfigException e) { sendError(e.toString()); } } /* * Changes the group of the algorithm */ private void chgAlgGrp(String alg, String newgrp) throws IOException { try { dbconf.changeAlgorithmGroup(user, alg, newgrp); sendOK(); } catch (DBConfigException e) { sendError(e.toString()); } } /* * Adds a new group */ private void addGrp(String group, Vector users) throws IOException { try { dbconf.addGroup(user, group, users); sendOK(); } catch (DBConfigWarning w) { sendWarning(w.toString()); } catch (DBConfigException e) { sendError(e.toString()); } } /* * Deletes a group */ private void delGrp(String group) throws IOException { try { dbconf.deleteGroup(user, group); sendOK(); } catch (DBConfigException e) { sendError(e.toString()); } } /* * Changes the name of the group */ private void chgNameGrp(String group, String newName) throws IOException { try { dbconf.changeGroupName(user, group, newName); sendOK(); } catch (DBConfigException e) { sendError(e.toString()); } } /* * Sets new users for a group */ private void setUsrsForGrp(String group, Vector newUsers) throws IOException { try { dbconf.setUsersForGroup(user, group, newUsers); sendOK(); } catch (DBConfigException e) { sendError(e.toString()); } } /* * Sets new groups for an user */ private void setGrpsForUsr(String userName, Vector newGroups) throws IOException { try { dbconf.setGroupsForUser(user, userName, newGroups); sendOK(); } catch (DBConfigException e) { sendError(e.toString()); } } /* * adds a group to each user from a list of users */ private void addGrpToUsrs(String group, Vector users) throws IOException { boolean all = true; try { for (int i = 0; i < users.size(); i++) { try { dbconf.addUserToGroup(user, (String)users.get(i), group); } catch (DBConfigNonexistentUser e1) { all = false; } } // have to see if it is OK or WARNING if (all) sendOK(); else sendWarning("not all specified users are valid"); } catch (DBConfigException e) { sendError(e.toString()); } } /* * deletes a group from the list of users */ private void delGrpFromUsrs(String group, Vector users) throws IOException { boolean all = true; try { for (int i = 0; i < users.size(); i++) { try { dbconf.removeUserFromGroup(user, (String)users.get(i), group); } catch (DBConfigNonexistentUser e1) { all = false; } } // have to see if it is OK or WARNING if (all) sendOK(); else sendWarning("not all specified users are valid"); } catch (DBConfigException e) { sendError(e.toString()); } } /* * adds a user to each group from a list of groups */ private void addUsrToGrps(String userName, Vector groups) throws IOException { boolean all = true; try { for (int i = 0; i < groups.size(); i++) { try { dbconf.addUserToGroup(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."); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -