2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.config.util;
10 import org.jolokia.jvmagent.JolokiaServer;
11 import org.jolokia.jvmagent.JvmAgentConfig;
13 public class JolokiaHelper {
14 private static JolokiaServer jolokiaServer;
17 * Bind to port 17777. By convention, ports above 10000 are used for testing
18 * and < 10000 for production
20 * @return url that can be passed to new J4pClient(url)
22 public static String startTestingJolokia() {
23 return startJolokia("localhost", 17777);
27 * @return url that can be passed to new J4pClient(url)
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++) {
36 jolokiaServer = new JolokiaServer(config, false);
37 jolokiaServer.start();
38 return "http://" + host + ":" + port + "/jolokia/";
39 } catch (Exception e) {
43 } catch (InterruptedException ie) {
48 throw new RuntimeException(lastException);
51 public static void stopJolokia() {