Github user hanm commented on a diff in the pull request: https://github.com/apache/zookeeper/pull/179#discussion_r101877413 --- Diff: src/java/main/org/apache/zookeeper/server/command/FourLetterCommands.java --- @@ -153,11 +159,69 @@ */ public final static int telnetCloseCmd = 0xfff4fffd; - final static HashMap<Integer, String> cmd2String = - new HashMap<Integer, String>(); + private static final String ZOOKEEPER_4LW_COMMANDS_WHITELIST = "zookeeper.4lw.commands.whitelist"; + + private static final Logger LOG = LoggerFactory.getLogger(FourLetterCommands.class); + + private static final Map<Integer, String> cmd2String = new HashMap<Integer, String>(); + + private static final Set<String> whiteListedCommands = new HashSet<String>(); + + private static boolean whiteListInitialized = false; + + // @VisibleForTesting + public static void resetWhiteList() { + whiteListInitialized = false; + whiteListedCommands.clear(); + } + + /** + * Return the string representation of the specified command code. + */ + public static String getCommandString(int command) { + return cmd2String.get(command); + } + + /** + * Check if the specified command code is from a known command. + * + * @param command The integer code of command. + * @return true if the specified command is known, false otherwise. + */ + public static boolean isKnown(int command) { + return cmd2String.containsKey(command); + } - public static Map<Integer, String> getCmdMapView() { --- End diff -- While I am on this, this legacy method can be optimized as a boolean query instead of returning a collection, so did the change for this as well (in addition to the white list collection.).
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---