Esempio n. 1
0
 private void addDependencies(HashSet<byte[]> deps, CommandData data) {
   for (byte[] dep : data.dependencies) {
     deps.add(dep);
   }
   for (byte[] dep : data.runbundles) {
     deps.add(dep);
   }
 }
Esempio n. 2
0
  /**
   * 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);
  }
 @Test
 public void testIssue508And513() throws Exception {
   HazelcastClient client = getHazelcastClient();
   IMap<String, HashSet<byte[]>> callEventsMap = client.getMap("CALL_EVENTS");
   IMap<String, Long> metaDataMap = client.getMap("CALL_META_DATA");
   IMap<String, byte[]> callStartMap = client.getMap("CALL_START_EVENTS");
   MultiMap<String, String> calls = client.getMultiMap("CALLS");
   calls.lock("1");
   calls.unlock("1");
   byte[] bytes = new byte[10];
   HashSet<byte[]> hashSet = new HashSet<byte[]>();
   hashSet.add(bytes);
   String callId = "1";
   callEventsMap.put(callId, hashSet);
   callStartMap.put(callId, bytes);
   metaDataMap.put(callId, 10L);
   Transaction txn = client.getTransaction();
   txn.begin();
   try {
     // remove the data
     callEventsMap.remove(callId);
     // remove meta data
     metaDataMap.remove(callId);
     // remove call start
     callStartMap.remove(callId);
     calls.put(callId, callId);
     txn.commit();
   } catch (Exception e) {
     fail();
   }
   assertNull(callEventsMap.get(callId));
   assertNull(metaDataMap.get(callId));
   assertNull(callStartMap.get(callId));
   assertEquals(0, callEventsMap.size());
   assertEquals(0, metaDataMap.size());
   assertEquals(0, callStartMap.size());
 }