
org.objectweb.petals.ant.AbstractJBIAntTask Maven / Gradle / Ivy
The newest version!
/**
* PETALS - PETALS Services Platform.
* Copyright (c) 2005 EBM Websourcing, http://www.ebmwebsourcing.com/
*
* This 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 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 library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* -------------------------------------------------------------------------
* $Id$
* -------------------------------------------------------------------------
*/
package org.objectweb.petals.ant;
import java.io.IOException;
import javax.management.remote.JMXConnector;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
/**
* This class is used to give the main parameters of the Ant tasks
*
* @author ddesjardins chamerling - eBMWebsourcing
*/
public abstract class AbstractJBIAntTask extends Task {
public static final String DEFAULT_JMX_PORT = "7700";
public static final String DEFAULT_JMX_HOST = "localhost";
public static final String DEFAULT_JMX_USER = "";
public static final String DEFAULT_JMX_PWD = "";
/**
* Fail on error
*/
protected boolean failOnError = true;
/**
* Host jmx
*/
protected String host = DEFAULT_JMX_HOST;
/**
* Port jmx
*/
protected String port = DEFAULT_JMX_PORT;
/**
* User name for security
*/
protected String username = DEFAULT_JMX_USER;
/**
* Password for security
*/
protected String password = DEFAULT_JMX_PWD;
/**
*
*/
protected JMXConnector connector;
@Override
public void execute() throws BuildException {
JMXConnector connector = null;
try {
connector = getJMXConnector();
doTask();
} catch (Exception e) {
if (isFailOnError()) {
throw new BuildException(e.getMessage(), e.getCause());
}
} finally {
if (connector != null) {
try {
connector.close();
} catch (Exception e) {
}
}
}
}
/**
* Do the task job
*
* @throws Exception
*/
public abstract void doTask() throws Exception;
/**
* Get a connection to JMX
*
* @return
* @throws IOException
*/
public JMXConnector getJMXConnector() throws IOException {
if (this.connector == null) {
this.connector = JBIJMXConnectorUtil.getConnection(host, port,
username, password);
}
return this.connector;
}
/**
* @return the failOnError
*/
public boolean isFailOnError() {
return failOnError;
}
/**
* @param failOnError
* the failOnError to set
*/
public void setFailOnError(boolean failOnError) {
this.failOnError = failOnError;
}
/**
* @return the host
*/
public String getHost() {
return host;
}
/**
* @param host
* the host to set
*/
public void setHost(String host) {
this.host = host;
}
/**
* @return the password
*/
public String getPassword() {
return password;
}
/**
* @param password
* the password to set
*/
public void setPassword(String password) {
this.password = password;
}
/**
* @return the port
*/
public String getPort() {
return port;
}
/**
* @param port
* the port to set
*/
public void setPort(String port) {
this.port = port;
}
/**
* @return the username
*/
public String getUsername() {
return username;
}
/**
* @param username
* the username to set
*/
public void setUsername(String username) {
this.username = username;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy