Clean all unused and redundant imports in controller.
[controller.git] / opendaylight / config / config-util / src / test / java / org / opendaylight / controller / config / util / JolokiaHelper.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.config.util;
9
10 import org.jolokia.jvmagent.JolokiaServer;
11 import org.jolokia.jvmagent.JvmAgentConfig;
12
13 public class JolokiaHelper {
14     private static JolokiaServer jolokiaServer;
15
16     /**
17      * Bind to port 17777. By convention, ports above 10000 are used for testing
18      * and < 10000 for production
19      *
20      * @return url that can be passed to new J4pClient(url)
21      */
22     public static String startTestingJolokia() {
23         return startJolokia("localhost", 17777);
24     }
25
26     /**
27      * @return url that can be passed to new J4pClient(url)
28      * @throws IOException
29      */
30     public static String startJolokia(String host, int port) {
31         String agentArgs = "host=" + host + ",port=" + port;
32         JvmAgentConfig config = new JvmAgentConfig(agentArgs);
33         Exception lastException = null;
34         for (int i = 0; i < 10; i++) {
35             try {
36                 jolokiaServer = new JolokiaServer(config, false);
37                 jolokiaServer.start();
38                 return "http://" + host + ":" + port + "/jolokia/";
39             } catch (Exception e) {
40                 lastException = e;
41                 try {
42                     Thread.sleep(100);
43                 } catch (InterruptedException ie) {
44                     ie.printStackTrace();
45                 }
46             }
47         }
48         throw new RuntimeException(lastException);
49     }
50
51     public static void stopJolokia() {
52         jolokiaServer.stop();
53     }
54 }