@Override
 public void dispose() {
   this.scheduledExecutorService.shutdown();
   if (this.scheduler != null) {
     try {
       this.scheduler.shutdown(true);
     } catch (final SchedulerException e) {
       log.error("Shutdown quartz scheduler failed", e);
     }
   }
   for (final ConcurrentHashMap<Integer /* partition */, MessageStore> subMap :
       MessageStoreManager.this.stores.values()) {
     if (subMap != null) {
       for (final MessageStore msgStore : subMap.values()) {
         if (msgStore != null) {
           try {
             msgStore.close();
           } catch (final Throwable e) {
             log.error(
                 "Try to run close  "
                     + msgStore.getTopic()
                     + ","
                     + msgStore.getPartition()
                     + " failed",
                 e);
           }
         }
       }
     }
   }
   this.stores.clear();
 }
 private void loadStores(List<Callable<MessageStore>> tasks)
     throws IOException, InterruptedException {
   for (Callable<MessageStore> task : tasks) {
     MessageStore messageStore;
     try {
       messageStore = task.call();
       ConcurrentHashMap<Integer /* partition */, MessageStore> map =
           this.stores.get(messageStore.getTopic());
       if (map == null) {
         map = new ConcurrentHashMap<Integer, MessageStore>();
         this.stores.put(messageStore.getTopic(), map);
       }
       map.put(messageStore.getPartition(), messageStore);
     } catch (IOException e) {
       throw e;
     } catch (InterruptedException e) {
       throw e;
     } catch (Exception e) {
       throw new IllegalStateException(e);
     }
   }
   tasks.clear();
 }
  private void loadStoresInParallel(ExecutorService executor, List<Callable<MessageStore>> tasks)
      throws InterruptedException {
    CompletionService<MessageStore> completionService =
        new ExecutorCompletionService<MessageStore>(executor);
    for (Callable<MessageStore> task : tasks) {
      completionService.submit(task);
    }
    for (int i = 0; i < tasks.size(); i++) {
      try {
        MessageStore messageStore = completionService.take().get();

        ConcurrentHashMap<Integer /* partition */, MessageStore> map =
            this.stores.get(messageStore.getTopic());
        if (map == null) {
          map = new ConcurrentHashMap<Integer, MessageStore>();
          this.stores.put(messageStore.getTopic(), map);
        }
        map.put(messageStore.getPartition(), messageStore);
      } catch (ExecutionException e) {
        throw ThreadUtils.launderThrowable(e);
      }
    }
    tasks.clear();
  }