/** * Copyright (c) 2009-2012 EBM WebSourcing, 2012-2015 Linagora * * This program/library is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 2.1 of the License, or (at your * option) any later version. * * This program/library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program/library; If not, see * for the GNU Lesser General Public License version 2.1. */ package org.ow2.petals.microkernel.communication; import java.util.logging.Logger; import org.objectweb.fractal.fraclet.annotation.annotations.FractalComponent; import org.objectweb.fractal.fraclet.annotation.annotations.Interface; import org.objectweb.fractal.fraclet.annotation.annotations.LifeCycle; import org.objectweb.fractal.fraclet.annotation.annotations.Provides; import org.objectweb.fractal.fraclet.annotation.annotations.Requires; import org.objectweb.fractal.fraclet.annotation.annotations.type.LifeCycleType; import org.ow2.petals.jmx.api.api.JMXClient; import org.ow2.petals.microkernel.api.communication.JMXService; import org.ow2.petals.microkernel.api.util.LoggingUtil; /** * JMX based remote checker. * @author Christophe Hamerling - EBM WebSourcing */ @FractalComponent @Provides(interfaces = @Interface(name = "service", signature = RemoteCheckerClient.class)) public class JMXRemoteCheckerClientImpl implements RemoteCheckerClient { private LoggingUtil log; @Requires(name = "jmx") protected JMXService jmxService; /** * */ @LifeCycle(on = LifeCycleType.START) protected void start() { this.log = new LoggingUtil(Logger.getLogger(Constants.FRACTAL_COMPONENT_LOGGER_NAME)); } /** * */ @LifeCycle(on = LifeCycleType.STOP) protected void stop() { this.log.call(); } /** * {@inheritDoc} */ public boolean ping(String containerName) { this.log.start(); boolean result = true; try { // Retrieve a connection to the JMX server of the container were the // component is deployed final JMXClient server = this.jmxService.getJMXClient(containerName); // Ask the component if it is ok to accept the exchange result = server.getPetalsAdminServiceClient().ping(); } catch (final Exception e) { result = false; } this.log.end("Result : " + result); return result; } }