zoo_app/app/src/main/java/com/example/jhalloran/zoo/ui/manager/ZooContentFragment.java
private void beginLoadingFutures() {

    // Request data on a background thread to allow parallel processing
    ListenableFuture animalsListenableFuture = ZooThreadPoolManager.getBackgroundThreadExecutor()
        .submit(new Callable<List<UUID>>() {
          @Override
          public List<UUID> call() throws Exception {
            return new ArrayList<>(zoo.getAnimalIds());
          }
        });
    // Update view with dataset on UI Thread once Future is complete
    Futures.addCallback(animalsListenableFuture, new FutureCallback<List<UUID>>() {
          @Override
          public void onSuccess(List<UUID> result) {
            animalsFuture.set(result);
          }

          @Override
          public void onFailure(Throwable t) {
            Log.e(TAG, String.format("Unable to load animals from model: %s", t));
          }
        },
        ZooThreadPoolManager.getBackgroundThreadExecutor());

    // Request data on a background thread to allow parallel processing
    ListenableFuture pensListenableFuture = ZooThreadPoolManager.getBackgroundThreadExecutor()
        .submit(new Callable<List<UUID>>() {
          @Override
          public List<UUID> call() throws Exception {
            return new ArrayList<>(zoo.getPenIds());
          }
        });
    // Update view with dataset on UI Thread once Future is complete
    Futures.addCallback(pensListenableFuture, new FutureCallback<List<UUID>>() {
          @Override
          public void onSuccess(List<UUID> result) {
            pensFuture.set(result);
          }

          @Override
          public void onFailure(Throwable t) {
            Log.e(TAG, String.format("Unable to load pens from model: %s", t));
          }
        },
        ZooThreadPoolManager.getBackgroundThreadExecutor());

    // Request data on a background thread to allow parallel processing
    ListenableFuture zookeepersListenableFuture = ZooThreadPoolManager.getBackgroundThreadExecutor()
        .submit(new Callable<List<UUID>>() {
          @Override
          public List<UUID> call() throws Exception {
            return new ArrayList<>(zoo.getZookeeperIds());
          }
        });
    // Update view with dataset on UI Thread once Future is complete
    Futures.addCallback(zookeepersListenableFuture, new FutureCallback<List<UUID>>() {
          @Override
          public void onSuccess(List<UUID> result) {
            zookeepersFuture.set(result);
          }

          @Override
          public void onFailure(Throwable t) {
            Log.e(TAG, String.format("Unable to load zookeepers from model: %s", t));
          }
        },
        ZooThreadPoolManager.getBackgroundThreadExecutor());
  }
// Access model in parallel in preparation for loading data to UI.
Access model in parallel in preparation for loading data to UI.
Access model in parallel in preparation for loading data to UI .
private void beginLoadingFutures() {
    ListenableFuture animalsListenableFuture = ZooThreadPoolManager.getBackgroundThreadExecutor()
        .submit(new Callable<List<UUID>>() {
          @Override
          public List<UUID> call() throws Exception {
            return new ArrayList<>(zoo.getAnimalIds());
          }
        });
    Futures.addCallback(animalsListenableFuture, new FutureCallback<List<UUID>>() {
          @Override
          public void onSuccess(List<UUID> result) {
            animalsFuture.set(result);
          }
          @Override
          public void onFailure(Throwable t) {
            Log.e(TAG, String.format("Unable to load animals from model: %s", t));
          }
        },
        ZooThreadPoolManager.getBackgroundThreadExecutor());
    ListenableFuture pensListenableFuture = ZooThreadPoolManager.getBackgroundThreadExecutor()
        .submit(new Callable<List<UUID>>() {
          @Override
          public List<UUID> call() throws Exception {
            return new ArrayList<>(zoo.getPenIds());
          }
        });
    Futures.addCallback(pensListenableFuture, new FutureCallback<List<UUID>>() {
          @Override
          public void onSuccess(List<UUID> result) {
            pensFuture.set(result);
          }
          @Override
          public void onFailure(Throwable t) {
            Log.e(TAG, String.format("Unable to load pens from model: %s", t));
          }
        },
        ZooThreadPoolManager.getBackgroundThreadExecutor());
    ListenableFuture zookeepersListenableFuture = ZooThreadPoolManager.getBackgroundThreadExecutor()
        .submit(new Callable<List<UUID>>() {
          @Override
          public List<UUID> call() throws Exception {
            return new ArrayList<>(zoo.getZookeeperIds());
          }
        });
    Futures.addCallback(zookeepersListenableFuture, new FutureCallback<List<UUID>>() {
          @Override
          public void onSuccess(List<UUID> result) {
            zookeepersFuture.set(result);
          }
          @Override
          public void onFailure(Throwable t) {
            Log.e(TAG, String.format("Unable to load zookeepers from model: %s", t));
          }
        },
        ZooThreadPoolManager.getBackgroundThreadExecutor());
  }
private void beginLoadingFutures ( ) { ListenableFuture animalsListenableFuture = ZooThreadPoolManager . getBackgroundThreadExecutor ( ) . submit ( new Callable < List < UUID > > ( ) { @ Override public List < UUID > call ( ) throws Exception { return new ArrayList < > ( zoo . getAnimalIds ( ) ) ; } } ) ; Futures . addCallback ( animalsListenableFuture , new FutureCallback < List < UUID > > ( ) { @ Override public void onSuccess ( List < UUID > result ) { animalsFuture . set ( result ) ; } @ Override public void onFailure ( Throwable t ) { Log . e ( TAG , String . format ( "Unable to load animals from model: %s" , t ) ) ; } } , ZooThreadPoolManager . getBackgroundThreadExecutor ( ) ) ; ListenableFuture pensListenableFuture = ZooThreadPoolManager . getBackgroundThreadExecutor ( ) . submit ( new Callable < List < UUID > > ( ) { @ Override public List < UUID > call ( ) throws Exception { return new ArrayList < > ( zoo . getPenIds ( ) ) ; } } ) ; Futures . addCallback ( pensListenableFuture , new FutureCallback < List < UUID > > ( ) { @ Override public void onSuccess ( List < UUID > result ) { pensFuture . set ( result ) ; } @ Override public void onFailure ( Throwable t ) { Log . e ( TAG , String . format ( "Unable to load pens from model: %s" , t ) ) ; } } , ZooThreadPoolManager . getBackgroundThreadExecutor ( ) ) ; ListenableFuture zookeepersListenableFuture = ZooThreadPoolManager . getBackgroundThreadExecutor ( ) . submit ( new Callable < List < UUID > > ( ) { @ Override public List < UUID > call ( ) throws Exception { return new ArrayList < > ( zoo . getZookeeperIds ( ) ) ; } } ) ; Futures . addCallback ( zookeepersListenableFuture , new FutureCallback < List < UUID > > ( ) { @ Override public void onSuccess ( List < UUID > result ) { zookeepersFuture . set ( result ) ; } @ Override public void onFailure ( Throwable t ) { Log . e ( TAG , String . format ( "Unable to load zookeepers from model: %s" , t ) ) ; } } , ZooThreadPoolManager . getBackgroundThreadExecutor ( ) ) ; }
Access model in parallel in preparation for loading data to UI.
Access model in parallel in preparation for loading data to UI .
// Request data on a background thread to allow parallel processing // Update view with dataset on UI Thread once Future is complete // Request data on a background thread to allow parallel processing // Update view with dataset on UI Thread once Future is complete // Request data on a background thread to allow parallel processing // Update view with dataset on UI Thread once Future is complete