org.quartz.jobs.ee.jmx.JMXInvokerJob Maven / Gradle / Ivy
/*
* Copyright 2004-2005 OpenSymphony
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
*/
/*
* Previously Copyright (c) 2001-2004 James House
*/
package org.quartz.jobs.ee.jmx;
import java.util.LinkedList;
import java.util.StringTokenizer;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.ObjectName;
import com.google.appengine.repackaged.org.apache.commons.logging.Log;
import com.google.appengine.repackaged.org.apache.commons.logging.LogFactory;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
/**
* Generic JMX invoker Job. It supports any number or type of parameters
* to the JMX bean.
*
* The required parameters are as follows (case doesn't matter):
*
* - JMX_OBJECTNAME
*
- This is the fully qualifed name of the object (ie in JBoss to lookup
* the log4j jmx bean you would specify "jboss.system:type=Log4jService,service=Logging"
*
- JMX_METHOD
*
- This is the method to invoke on the specified JMX Bean. (ie in JBoss to
* change the log level you would specify "setLoggerLevel"
*
- JMX_PARAMDEFS
*
- This is a definition of the parameters to be passed to the specified method
* and their corresponding java types. Each parameter definition is comma seperated
* and has the following parts:
:. Type is the java type for the parameter.
* The following types are supported:
* i - is for int
* l - is for long
* f - is for float
* d - is for double
* s - is for String
* b - is for boolean
* For ilfdb use lower for native type and upper for object wrapper. The name portion
* of the definition is the name of the parameter holding the string value. (ie
* s:fname,s:lname would require 2 parameters of the name fname and lname and
* would be passed in that order to the method.
*
* @author James Nelson ([email protected]) -- Provident Solutions LLC
*
*/
public class JMXInvokerJob implements Job {
public void execute(JobExecutionContext context) throws JobExecutionException {
try {
Object[] params=null;
String[] types=null;
String objName = null;
String objMethod = null;
String[] keys = context.getJobDetail().getJobDataMap().getKeys();
for (int i = 0; i < keys.length; i++) {
String value = context.getJobDetail().getJobDataMap().getString(keys[i]);
if ("JMX_OBJECTNAME".equalsIgnoreCase(keys[i])) {
objName = value;
} else if ("JMX_METHOD".equalsIgnoreCase(keys[i])) {
objMethod = value;
} else if("JMX_PARAMDEFS".equalsIgnoreCase(keys[i])) {
String[] paramdefs=split(value, ",");
params=new Object[paramdefs.length];
types=new String[paramdefs.length];
for(int k=0;k