support for scheduling

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@907199 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Davies 2010-02-06 09:06:42 +00:00
parent c7c8e5367e
commit 17e0b00327
3 changed files with 113 additions and 19 deletions

View File

@ -17,11 +17,11 @@
package org.apache.activemq.web;
import java.util.Collection;
import org.apache.activemq.broker.jmx.BrokerViewMBean;
import org.apache.activemq.broker.jmx.ConnectionViewMBean;
import org.apache.activemq.broker.jmx.ConnectorViewMBean;
import org.apache.activemq.broker.jmx.DurableSubscriptionViewMBean;
import org.apache.activemq.broker.jmx.JobSchedulerViewMBean;
import org.apache.activemq.broker.jmx.NetworkConnectorViewMBean;
import org.apache.activemq.broker.jmx.QueueViewMBean;
import org.apache.activemq.broker.jmx.SubscriptionViewMBean;
@ -178,4 +178,19 @@ public interface BrokerFacade {
* @throws Exception
*/
TopicViewMBean getTopic(String name) throws Exception;
/**
* Get the JobScheduler MBean
* @return the jobScheduler or null if not configured
* @throws Exception
*/
JobSchedulerViewMBean getJobScheduler() throws Exception;
/**
* Get the JobScheduler MBean
* @return the jobScheduler or null if not configured
* @throws Exception
*/
Collection<JobFacade> getScheduledJobs() throws Exception;
}

View File

@ -16,17 +16,6 @@
*/
package org.apache.activemq.web;
import org.apache.activemq.broker.jmx.BrokerViewMBean;
import org.apache.activemq.broker.jmx.ConnectionViewMBean;
import org.apache.activemq.broker.jmx.ConnectorViewMBean;
import org.apache.activemq.broker.jmx.DestinationViewMBean;
import org.apache.activemq.broker.jmx.DurableSubscriptionViewMBean;
import org.apache.activemq.broker.jmx.ManagementContext;
import org.apache.activemq.broker.jmx.NetworkConnectorViewMBean;
import org.apache.activemq.broker.jmx.QueueViewMBean;
import org.apache.activemq.broker.jmx.SubscriptionViewMBean;
import org.apache.activemq.broker.jmx.TopicViewMBean;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@ -34,6 +23,21 @@ import java.util.Iterator;
import java.util.List;
import java.util.Set;
import javax.management.ObjectName;
import javax.management.openmbean.CompositeData;
import javax.management.openmbean.TabularData;
import org.apache.activemq.broker.jmx.BrokerViewMBean;
import org.apache.activemq.broker.jmx.ConnectionViewMBean;
import org.apache.activemq.broker.jmx.ConnectorViewMBean;
import org.apache.activemq.broker.jmx.DestinationViewMBean;
import org.apache.activemq.broker.jmx.DurableSubscriptionViewMBean;
import org.apache.activemq.broker.jmx.JobSchedulerViewMBean;
import org.apache.activemq.broker.jmx.ManagementContext;
import org.apache.activemq.broker.jmx.NetworkConnectorViewMBean;
import org.apache.activemq.broker.jmx.QueueViewMBean;
import org.apache.activemq.broker.jmx.SubscriptionViewMBean;
import org.apache.activemq.broker.jmx.TopicViewMBean;
import org.springframework.util.StringUtils;
/**
* A useful base class for an implementation of {@link BrokerFacade}
*
@ -102,13 +106,10 @@ public abstract class BrokerFacadeSupport implements BrokerFacade {
return answer;
}
@SuppressWarnings("unchecked")
public Collection<ConnectionViewMBean> getConnections() throws Exception {
String brokerName = getBrokerName();
ObjectName query = new ObjectName("org.apache.activemq:BrokerName=" + brokerName + ",Type=Connection,*");
System.out.println(query);
Set<ObjectName> queryResult = getManagementContext().queryNames(query, null);
return getManagedObjects(queryResult.toArray(new ObjectName[queryResult.size()]), ConnectionViewMBean.class);
}
@ -137,8 +138,8 @@ public abstract class BrokerFacadeSupport implements BrokerFacade {
if (queryResult.size() == 0)
return null;
ObjectName objectName = queryResult.iterator().next();
return (ConnectionViewMBean) getManagementContext().newProxyInstance(objectName,
ConnectionViewMBean.class, true);
return (ConnectionViewMBean) getManagementContext().newProxyInstance(objectName, ConnectionViewMBean.class,
true);
}
@SuppressWarnings("unchecked")
@ -156,8 +157,7 @@ public abstract class BrokerFacadeSupport implements BrokerFacade {
String brokerName = getBrokerName();
ObjectName objectName = new ObjectName("org.apache.activemq:BrokerName=" + brokerName
+ ",Type=Connector,ConnectorName=" + name);
return (ConnectorViewMBean) getManagementContext().newProxyInstance(objectName,
ConnectorViewMBean.class, true);
return (ConnectorViewMBean) getManagementContext().newProxyInstance(objectName, ConnectorViewMBean.class, true);
}
@SuppressWarnings("unchecked")
@ -187,4 +187,21 @@ public abstract class BrokerFacadeSupport implements BrokerFacade {
Set<ObjectName> queryResult = getManagementContext().queryNames(query, null);
return getManagedObjects(queryResult.toArray(new ObjectName[queryResult.size()]), SubscriptionViewMBean.class);
}
public JobSchedulerViewMBean getJobScheduler() throws Exception {
ObjectName name = getBrokerAdmin().getJMSJobScheduler();
return (JobSchedulerViewMBean) getManagementContext().newProxyInstance(name, JobSchedulerViewMBean.class, true);
}
public Collection<JobFacade> getScheduledJobs() throws Exception {
JobSchedulerViewMBean jobScheduler = getJobScheduler();
List<JobFacade> result = new ArrayList<JobFacade>();
TabularData table = jobScheduler.getAllJobs();
for (Object object : table.values()) {
CompositeData cd = (CompositeData) object;
JobFacade jf = new JobFacade(cd);
result.add(jf);
}
return result;
}
}

View File

@ -0,0 +1,62 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
package org.apache.activemq.web;
import javax.management.openmbean.CompositeData;
public class JobFacade {
private final CompositeData data;
public JobFacade(CompositeData data) {
this.data = data;
}
public String getCronEntry() {
return data.get("cronEntry").toString();
}
public String getJobId() {
return toString(data.get("jobId"));
}
public String getNextExecutionTime() {
return toString(data.get("next"));
}
public long getPeriod() {
Long result = (Long) data.get("period");
if (result != null) {
return result.longValue();
}
return 0l;
}
public int getRepeat() {
Integer result = (Integer) data.get("repeat");
if (result != null) {
return result.intValue();
}
return 0;
}
public String getStart() {
return toString(data.get("start"));
}
private String toString(Object object) {
return object != null ? object.toString() : "";
}
}