View Javadoc

1   package org.apache.helix.tools;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.I0Itec.zkclient.IDefaultNameSpace;
23  import org.I0Itec.zkclient.ZkClient;
24  import org.I0Itec.zkclient.ZkServer;
25  
26  /**
27   * Provides ability to start zookeeper locally on a particular port
28   * 
29   * 
30   */
31  public class LocalZKServer
32  {
33    public void start(int port, String dataDir, String logDir) throws Exception
34    {
35  
36      IDefaultNameSpace defaultNameSpace = new IDefaultNameSpace()
37      {
38  
39        @Override
40        public void createDefaultNameSpace(ZkClient zkClient)
41        {
42  
43        }
44      };
45      ZkServer server = new ZkServer(dataDir, logDir, defaultNameSpace, port);
46      server.start();
47      Thread.currentThread().join();
48    }
49  
50    public static void main(String[] args) throws Exception
51    {
52      int port = 2199;
53      String rootDir = System.getProperty("java.io.tmpdir") + "/zk-helix/"
54          + System.currentTimeMillis();
55      String dataDir = rootDir + "/dataDir";
56      String logDir = rootDir + "/logDir";
57  
58      if (args.length > 0)
59      {
60        port = Integer.parseInt(args[0]);
61      }
62      if (args.length > 1)
63      {
64        dataDir = args[1];
65        logDir = args[1];
66      }
67  
68      if (args.length > 2)
69      {
70        logDir = args[2];
71      }
72      System.out.println("Starting Zookeeper locally at port:" + port
73          + " dataDir:" + dataDir + " logDir:" + logDir);
74      LocalZKServer localZKServer = new LocalZKServer();
75      
76      localZKServer.start(port, dataDir, logDir);
77    }
78  }