ServerConfig.java 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright 2008, Yahoo! Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.yahoo.zookeeper.server;
  17. public class ServerConfig {
  18. private int clientPort;
  19. private String dataDir;
  20. private String dataLogDir;
  21. protected ServerConfig(int port, String dataDir,String dataLogDir) {
  22. this.clientPort = port;
  23. this.dataDir = dataDir;
  24. this.dataLogDir=dataLogDir;
  25. }
  26. protected boolean isStandaloneServer(){
  27. return true;
  28. }
  29. public static int getClientPort(){
  30. assert instance!=null;
  31. return instance.clientPort;
  32. }
  33. public static String getDataDir(){
  34. assert instance!=null;
  35. return instance.dataDir;
  36. }
  37. public static String getDataLogDir(){
  38. assert instance!=null;
  39. return instance.dataLogDir;
  40. }
  41. public static boolean isStandalone(){
  42. assert instance!=null;
  43. return instance.isStandaloneServer();
  44. }
  45. protected static ServerConfig instance=null;
  46. public static void parse(String[] args) {
  47. if(instance!=null)
  48. return;
  49. if (args.length != 2) {
  50. System.err.println("USAGE: ZooKeeperServer port datadir\n");
  51. System.exit(2);
  52. }
  53. try {
  54. instance=new ServerConfig(Integer.parseInt(args[0]),args[1],args[1]);
  55. } catch (NumberFormatException e) {
  56. System.err.println(args[0] + " is not a valid port number");
  57. System.exit(2);
  58. }
  59. }
  60. }