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 java.io.IOException;
12 import org.jolokia.jvmagent.JolokiaServer;
13 import org.jolokia.jvmagent.JvmAgentConfig;
15 public class JolokiaHelper {
16 private static JolokiaServer jolokiaServer;
19 * Bind to port 17777. By convention, ports above 10000 are used for testing
20 * and < 10000 for production
22 * @return url that can be passed to new J4pClient(url)
24 public static String startTestingJolokia() {
25 return startJolokia("localhost", 17777);
29 * @return url that can be passed to new J4pClient(url)
32 public static String startJolokia(String host, int port) {
33 String agentArgs = "host=" + host + ",port=" + port;
34 JvmAgentConfig config = new JvmAgentConfig(agentArgs);
35 Exception lastException = null;
36 for (int i = 0; i < 10; i++) {
38 jolokiaServer = new JolokiaServer(config, false);
39 jolokiaServer.start();
40 return "http://" + host + ":" + port + "/jolokia/";
41 } catch (Exception e) {
45 } catch (InterruptedException ie) {
50 throw new RuntimeException(lastException);
53 public static void stopJolokia() {