static Method[] getOverridableMethods(Class c) { ArrayList<Method> list = new ArrayList<Method>(); HashSet<String> skip = new HashSet<String>(); while (c != null) { Method[] methods = c.getDeclaredMethods(); for (int i = 0; i < methods.length; i++) { String methodKey = methods[i].getName() + getMethodSignature(methods[i], methods[i].getParameterTypes()); if (skip.contains(methodKey)) continue; // skip this method int mods = methods[i].getModifiers(); if (Modifier.isStatic(mods)) continue; if (Modifier.isFinal(mods)) { // Make sure we don't add a final method to the list // of overridable methods. skip.add(methodKey); continue; } if (Modifier.isPublic(mods) || Modifier.isProtected(mods)) { list.add(methods[i]); skip.add(methodKey); } } c = c.getSuperclass(); } return list.toArray(new Method[list.size()]); }
private void addDependencies(HashSet<byte[]> deps, CommandData data) { for (byte[] dep : data.dependencies) { deps.add(dep); } for (byte[] dep : data.runbundles) { deps.add(dep); } }
private synchronized List getJarCodeSigners() { CodeSigner[] signers; if (jarCodeSigners == null) { HashSet set = new HashSet(); set.addAll(signerMap().values()); jarCodeSigners = new ArrayList(); jarCodeSigners.addAll(set); } return jarCodeSigners; }
/** * Garbage collect repository * * @throws Exception */ public void gc() throws Exception { HashSet<byte[]> deps = new HashSet<byte[]>(); // deps.add(SERVICE_JAR_FILE); for (File cmd : commandDir.listFiles()) { CommandData data = getData(CommandData.class, cmd); addDependencies(deps, data); } for (File service : serviceDir.listFiles()) { File dataFile = new File(service, "data"); ServiceData data = getData(ServiceData.class, dataFile); addDependencies(deps, data); } int count = 0; for (File f : repoDir.listFiles()) { String name = f.getName(); if (!deps.contains(name)) { if (!name.endsWith(".json") || !deps.contains(name.substring(0, name.length() - ".json".length()))) { // Remove // json // files // only // if // the // bin // is // going // as // well f.delete(); count++; } else { } } } System.out.format("Garbage collection done (%d file(s) removed)%n", count); }
private static void appendOverridableMethods( Class<?> c, ArrayList<Method> list, HashSet<String> skip) { Method[] methods = c.getDeclaredMethods(); for (int i = 0; i < methods.length; i++) { String methodKey = methods[i].getName() + getMethodSignature(methods[i], methods[i].getParameterTypes()); if (skip.contains(methodKey)) continue; // skip this method int mods = methods[i].getModifiers(); if (Modifier.isStatic(mods)) continue; if (Modifier.isFinal(mods)) { // Make sure we don't add a final method to the list // of overridable methods. skip.add(methodKey); continue; } if (Modifier.isPublic(mods) || Modifier.isProtected(mods)) { list.add(methods[i]); skip.add(methodKey); } } }