2016-07-25 99 views
0

1)有谁能帮我介绍一下“Remoteexception”的概念吗?一般意味着什么?“RemoteException”在HDFS中的含义是什么?

2)又是什么意思unwrapRemoteException?不知道它的意思是“如果这个远程异常包装了lookupTypes之一”

/** 
    * If this remote exception wraps up one of the lookupTypes 
    * then return this exception. 
    * <p> 
    * Unwraps any IOException. 
    * 
    * @param lookupTypes the desired exception class. 
    * @return IOException, which is either the lookupClass exception or this. 
    */ 
    public IOException unwrapRemoteException(Class<?>... lookupTypes) { 
    if(lookupTypes == null) 
     return this; 
    for(Class<?> lookupClass : lookupTypes) { 
     if(!lookupClass.getName().equals(getClassName())) 
     continue; 
     try { 
     return instantiateException(lookupClass.asSubclass(IOException.class)); 
     } catch(Exception e) { 
     // cannot instantiate lookupClass, just return this 
     return this; 
     } 
    } 
    // wrapped up exception is not in lookupTypes, just return this 
    return this; 
    } 

(Hadoop_HDFS_Open_Source:https://github.com/apache/hadoop

提前感谢!任何帮助都感激不尽!

回答

0

1)有谁能帮我一下“Remoteexception”的概念吗?一般意味着什么?

远程异常在服务器端被引发(创建)。服务器抛出这样的异常,因为客户端发送无效请求,或服务器有内部错误或其他。服务器端的RPC服务器序列化该异常,并将其发送到客户端。客户端反序列化异常,并获取异常。

2)又是什么意思unwrapRemoteException?

问题是“为什么我们需要包装异常”。首先,RemoteException是一个包装,不是真正的例外。服务器抛出的真正异常可能是AccessControlException(用户没有预备),FileNotFoundException(无效请求)。我们把它们包装在RemoteException中。但为什么?因为代码更干净,更具可读性。

不知道它的意思是 “如果这个远程异常包装了lookupTypes之一”

例如,在DFSClient.java

public HdfsFileStatus getFileInfo(String src) throws IOException { 
    checkOpen(); 
    try { 
    return namenode.getFileInfo(src); 
    } catch(RemoteException re) { 
    throw re.unwrapRemoteException(AccessControlException.class, 
            FileNotFoundException.class, 
            UnresolvedPathException.class); 
    } 
} 

如果re包装了FileNotFoundException ,那么getFileInfo只返回FileNotFoundException。然后用户可以看到更简洁的异常消息。用户只需要知道文件没有找到,不关心它是否是远程的。

但是,如果re包装SafeModeException或一些未知的例外。这可能是一些服务器的内部错误或配置错误。我们完全抛出re(RemoteException)。因此,用户可以知道错误来自远程(服务器端),即使用户不知道包装的SafeModeException(或某个未知的例外)。用户可以向技术支持寻求帮助。