package com.how_hard_can_it_be.FirebaseAdmin;

import java.io.FileInputStream;

import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;
import com.google.firebase.auth.FirebaseCredentials;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;

/**
 * Hello world!
 *
 */
public class App 
{
   public static void main( String[] args) throws InterruptedException
   {
      try
      {
         FileInputStream serviceAccount = new FileInputStream( "diaspora-dev-firebase-adminsdk-voul2-9fc9e89711.json");

         FirebaseOptions options = new FirebaseOptions.Builder()
               .setCredential( FirebaseCredentials.fromCertificate( serviceAccount))
               .setDatabaseUrl( "https://diaspora-dev.firebaseio.com/").build();

         FirebaseApp.initializeApp( options);

         dumpClusterMetadata();
      }
      catch (Exception exc)
      {
         System.err.println( "Error: " + exc.toString());
      }
      Thread.sleep( 10000);
      System.out.println( "(Firebase admin done.)");
   }

   private static void dumpClusterMetadata()
   {
      System.out.println( "Cluster metadata:");

      DatabaseReference dbRef = FirebaseDatabase.getInstance().getReference();
      DatabaseReference kids = dbRef.child( "/clusters");

      ValueEventListener listener = new ValueEventListener() {

         public void onDataChange( DataSnapshot aSnapshot)
         {
            Object value = aSnapshot.getValue();
            System.out.println( "\tgot value " + value);
         }

         public void onCancelled( DatabaseError aDbError)
         {
            System.err.println( "Cancelled.  " + aDbError);
         }
      };
      kids.addValueEventListener( listener);
   }
}

@@ -71,16 +71,55 @@
 tStream;
+%0Aimport java.util.concurrent.Semaphore;
 %0A%0Aimport
@@ -563,16 +563,79 @@
  App %0A%7B%0A
+   private static Semaphore semaphore = new Semaphore( 0);%0A   %0A
    publi
@@ -1272,27 +1272,26 @@
     
-Thread.sleep( 10000
+semaphore.acquire(
 );%0A 
@@ -1825,16 +1825,49 @@
 value);%0A
+            semaphore.release();%0A
         
@@ -1931,32 +1931,32 @@
 ror)%0A         %7B%0A
-
             Syst
@@ -1999,16 +1999,49 @@
 Error);%0A
+            semaphore.release();%0A
         

Use Semaphore to know when read/write thread is done.