private boolean getResponse() {
   if (retries > 20) {
     close();
   }
   if (!acquireReadBuffer()) {
     retries++;
     return false;
   }
   try {
     // HEADER(1) + DB_VERISON(8)
     buffer.limit(9);
     int read = connection.read();
     log("Get greeting response");
     if (read == 1 || read == 9) {
       buffer.flip();
       byte masterGreeting = buffer.get();
       if (masterGreeting == HeaderConstants.BYE) {
         log("Problem connecting to master " + connection + ". Got BYE.");
         close();
         return true;
       } else if (masterGreeting != HeaderConstants.MASTER_GREETING) {
         log("Got unkown greeting[" + masterGreeting + "] from " + connection);
         close();
       } else if (read != 9) {
         retries++;
         connection.pushBackAllReadData();
         return false;
       }
       masterVersion = buffer.getLong();
       log("Got master version: " + masterVersion);
       if (masterVersion < xaDs.getCurrentLogVersion()) {
         log("Got wrong version [" + masterVersion + "]");
         close();
         return true;
       }
       setNoRequeue();
       setChainJob(new HandleMasterConnection(connection, slave, masterVersion, xaDs));
       return true;
     } else {
       retries++;
       if (read > 0) {
         connection.pushBackAllReadData();
       }
       return false;
     }
   } finally {
     releaseReadBuffer();
   }
 }
 @Test
 public void hasAllXaManagerBeans() {
   for (XaDataSource xaDataSource :
       graphDb.getXaDataSourceManager().getAllRegisteredDataSources()) {
     XaResourceInfo info = getByName(xaDataSource.getName());
     assertEquals(
         "wrong branchid for XA data source " + xaDataSource.getName(),
         XaManagerBean.toHexString(xaDataSource.getBranchId()),
         info.getBranchId());
     assertEquals(
         "wrong log version for XA data source " + xaDataSource.getName(),
         xaDataSource.getCurrentLogVersion(),
         info.getLogVersion());
     assertEquals(
         "wrong last tx ID for XA data source " + xaDataSource.getName(),
         xaDataSource.getLastCommittedTxId(),
         info.getLastTxId());
   }
 }
 private boolean setupGreeting() {
   if (retries > 20) {
     close();
   }
   if (!acquireWriteBuffer()) {
     retries++;
     return false;
   }
   buffer.put(HeaderConstants.SLAVE_GREETING);
   buffer.putLong(xaDs.getRandomIdentifier());
   buffer.putLong(xaDs.getCreationTime());
   buffer.putLong(xaDs.getCurrentLogVersion());
   byte[] bytes = xaDsName.getBytes();
   buffer.putInt(bytes.length);
   buffer.put(bytes);
   buffer.flip();
   log("Setup greeting");
   setStatus(Status.SEND_GREETING);
   retries = 0;
   return true;
 }