[ 
https://issues.apache.org/jira/browse/HDFS-13982?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16644506#comment-16644506
 ] 

Xiang Li commented on HDFS-13982:
---------------------------------

Trying to use some functions of enum to rewrite the switch/case logic.

> convertStorageType() in PBHelperClient is not easy to extend when adding new 
> storage types
> ------------------------------------------------------------------------------------------
>
>                 Key: HDFS-13982
>                 URL: https://issues.apache.org/jira/browse/HDFS-13982
>             Project: Hadoop HDFS
>          Issue Type: Improvement
>          Components: hdfs
>            Reporter: Xiang Li
>            Priority: Minor
>
> In PBHelperClient, there are 2 functions to convert between StorageTypeProto 
> and StorageType, like:
> {code:java}
> public static StorageTypeProto convertStorageType(StorageType type) {
>   switch(type) {
>   case DISK:
>     return StorageTypeProto.DISK;
>   case SSD:
>     return StorageTypeProto.SSD;
>   case ARCHIVE:
>     return StorageTypeProto.ARCHIVE;
>   case RAM_DISK:
>     return StorageTypeProto.RAM_DISK;
>   case PROVIDED:
>     return StorageTypeProto.PROVIDED;
>   default:
>     throw new IllegalStateException(
>         "BUG: StorageType not found, type=" + type);
>   }
> }
> public static StorageType convertStorageType(StorageTypeProto type) {
>   switch(type) {
>   case DISK:
>     return StorageType.DISK;
>   case SSD:
>     return StorageType.SSD;
>   case ARCHIVE:
>     return StorageType.ARCHIVE;
>   case RAM_DISK:
>     return StorageType.RAM_DISK;
>   case PROVIDED:
>     return StorageType.PROVIDED;
>   default:
>     throw new IllegalStateException(
>         "BUG: StorageTypeProto not found, type=" + type);
>   }
> }
> {code}
> When there is a need to add a new storage type, we need to add a "case" 
> clause here. It is not quite convenient. And it is easy to forget changing 
> this file, because the newcomers always focus on the change in 
> StorageType.java (to add new storage types).



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: hdfs-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: hdfs-issues-h...@hadoop.apache.org

Reply via email to