/// <exception cref="Org.Apache.Hadoop.Security.Token.SecretManager.InvalidToken"/>
        private BlockReader GetBlockReaderLocal()
        {
            if (Log.IsTraceEnabled())
            {
                Log.Trace(this + ": trying to construct a BlockReaderLocal " + "for short-circuit reads."
                          );
            }
            if (pathInfo == null)
            {
                pathInfo = clientContext.GetDomainSocketFactory().GetPathInfo(inetSocketAddress,
                                                                              conf);
            }
            if (!pathInfo.GetPathState().GetUsableForShortCircuit())
            {
                PerformanceAdvisory.Log.Debug(this + ": " + pathInfo + " is not " + "usable for short circuit; giving up on BlockReaderLocal."
                                              );
                return(null);
            }
            ShortCircuitCache cache = clientContext.GetShortCircuitCache();
            ExtendedBlockId   key   = new ExtendedBlockId(block.GetBlockId(), block.GetBlockPoolId
                                                              ());
            ShortCircuitReplicaInfo info = cache.FetchOrCreate(key, this);

            SecretManager.InvalidToken exc = info.GetInvalidTokenException();
            if (exc != null)
            {
                if (Log.IsTraceEnabled())
                {
                    Log.Trace(this + ": got InvalidToken exception while trying to " + "construct BlockReaderLocal via "
                              + pathInfo.GetPath());
                }
                throw exc;
            }
            if (info.GetReplica() == null)
            {
                if (Log.IsTraceEnabled())
                {
                    PerformanceAdvisory.Log.Debug(this + ": failed to get " + "ShortCircuitReplica. Cannot construct "
                                                  + "BlockReaderLocal via " + pathInfo.GetPath());
                }
                return(null);
            }
            return(new BlockReaderLocal.Builder(conf).SetFilename(fileName).SetBlock(block).SetStartOffset
                       (startOffset).SetShortCircuitReplica(info.GetReplica()).SetVerifyChecksum(verifyChecksum
                                                                                                 ).SetCachingStrategy(cachingStrategy).SetStorageType(storageType).Build());
        }
 /// <summary>Get a RemoteBlockReader that communicates over a UNIX domain socket.</summary>
 /// <returns>
 /// The new BlockReader, or null if we failed to create the block
 /// reader.
 /// </returns>
 /// <exception cref="Org.Apache.Hadoop.Security.Token.SecretManager.InvalidToken">
 /// If the block token was invalid.
 /// Potentially other security-related execptions.
 /// </exception>
 /// <exception cref="System.IO.IOException"/>
 private BlockReader GetRemoteBlockReaderFromDomain()
 {
     if (pathInfo == null)
     {
         pathInfo = clientContext.GetDomainSocketFactory().GetPathInfo(inetSocketAddress,
                                                                       conf);
     }
     if (!pathInfo.GetPathState().GetUsableForDataTransfer())
     {
         PerformanceAdvisory.Log.Debug(this + ": not trying to create a " + "remote block reader because the UNIX domain socket at "
                                       + pathInfo + " is not usable.");
         return(null);
     }
     if (Log.IsTraceEnabled())
     {
         Log.Trace(this + ": trying to create a remote block reader from the " + "UNIX domain socket at "
                   + pathInfo.GetPath());
     }
     while (true)
     {
         BlockReaderFactory.BlockReaderPeer curPeer = NextDomainPeer();
         if (curPeer == null)
         {
             break;
         }
         if (curPeer.fromCache)
         {
             remainingCacheTries--;
         }
         DomainPeer  peer        = (DomainPeer)curPeer.peer;
         BlockReader blockReader = null;
         try
         {
             blockReader = GetRemoteBlockReader(peer);
             return(blockReader);
         }
         catch (IOException ioe)
         {
             IOUtils.Cleanup(Log, peer);
             if (IsSecurityException(ioe))
             {
                 if (Log.IsTraceEnabled())
                 {
                     Log.Trace(this + ": got security exception while constructing " + "a remote block reader from the unix domain socket at "
                               + pathInfo.GetPath(), ioe);
                 }
                 throw;
             }
             if (curPeer.fromCache)
             {
                 // Handle an I/O error we got when using a cached peer.  These are
                 // considered less serious, because the underlying socket may be stale.
                 if (Log.IsDebugEnabled())
                 {
                     Log.Debug("Closed potentially stale domain peer " + peer, ioe);
                 }
             }
             else
             {
                 // Handle an I/O error we got when using a newly created domain peer.
                 // We temporarily disable the domain socket path for a few minutes in
                 // this case, to prevent wasting more time on it.
                 Log.Warn("I/O error constructing remote block reader.  Disabling " + "domain socket "
                          + peer.GetDomainSocket(), ioe);
                 clientContext.GetDomainSocketFactory().DisableDomainSocketPath(pathInfo.GetPath()
                                                                                );
                 return(null);
             }
         }
         finally
         {
             if (blockReader == null)
             {
                 IOUtils.Cleanup(Log, peer);
             }
         }
     }
     return(null);
 }