forked from empear-analytics/zookeeper
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Factory to create CliCommand classes. Initial Commit.
- Loading branch information
1 parent
3aa922c
commit cc8de49
Showing
2 changed files
with
70 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
zookeeper-server/src/main/java/org/apache/zookeeper/cli/CommandFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package org.apache.zookeeper.cli; | ||
|
||
import org.apache.zookeeper.server.admin.Command; | ||
|
||
import java.util.function.Supplier; | ||
|
||
/** | ||
* Factory class for creating instances of {@code CliCommand}. | ||
*/ | ||
public class CommandFactory { | ||
|
||
/** | ||
* All Cli Commands. | ||
*/ | ||
public enum Command { | ||
CLOSE(CloseCommand::new), | ||
CREATE(CreateCommand::new), | ||
DELETE(DeleteCommand::new), | ||
DELETE_ALL(DeleteAllCommand::new), | ||
SET(SetCommand::new), | ||
GET(GetCommand::new), | ||
LS(LsCommand::new), | ||
GET_ACL(GetAclCommand::new), | ||
SET_ACL(SetAclCommand::new), | ||
STAT(StatCommand::new), | ||
SYNC(SyncCommand::new), | ||
SET_QUOTA(SetQuotaCommand::new), | ||
LIST_QUOTA(ListQuotaCommand::new), | ||
DEL_QUOTA(DelQuotaCommand::new), | ||
ADD_AUTH(AddAuthCommand::new), | ||
RECONFIG(ReconfigCommand::new), | ||
GET_CONFIG(GetConfigCommand::new), | ||
REMOVE_WATCHES(RemoveWatchesCommand::new), | ||
GET_EPHEMERALS(GetEphemeralsCommand::new), | ||
GET_ALL_CHILDREN_NUMBER(GetAllChildrenNumberCommand::new), | ||
VERSION(VersionCommand::new), | ||
ADD_WATCH(AddWatchCommand::new); | ||
|
||
private Supplier<? extends CliCommand> instantiator; | ||
|
||
private CliCommand getInstance() { | ||
return instantiator.get(); | ||
} | ||
|
||
Command(Supplier<? extends CliCommand> instantiator) { | ||
this.instantiator = instantiator; | ||
} | ||
} | ||
|
||
/** | ||
* Creates a new {@Code CliCommand} instance. | ||
* @param command the | ||
* @return the new instance | ||
*/ | ||
public static CliCommand getInstance (Command command) { | ||
return command.getInstance(); | ||
} | ||
} |