karaf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (KARAF-5307) Add SchedulerMBean to mimic scheduler shell commands
Date Tue, 28 Nov 2017 17:04:00 GMT

    [ https://issues.apache.org/jira/browse/KARAF-5307?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16269047#comment-16269047
] 

ASF GitHub Bot commented on KARAF-5307:
---------------------------------------

jbonofre closed pull request #401: [KARAF-5307] Add SchedulerMBean
URL: https://github.com/apache/karaf/pull/401
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/scheduler/src/main/java/org/apache/karaf/scheduler/SchedulerMBean.java b/scheduler/src/main/java/org/apache/karaf/scheduler/SchedulerMBean.java
new file mode 100644
index 0000000000..9248e64b3e
--- /dev/null
+++ b/scheduler/src/main/java/org/apache/karaf/scheduler/SchedulerMBean.java
@@ -0,0 +1,30 @@
+/*
+ * 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.karaf.scheduler;
+
+import javax.management.MBeanException;
+import javax.management.openmbean.TabularData;
+
+public interface SchedulerMBean {
+
+    TabularData getJobs() throws MBeanException;
+
+    void trigger(String name, boolean background) throws MBeanException;
+
+    void unschedule(String name) throws MBeanException;
+
+}
diff --git a/scheduler/src/main/java/org/apache/karaf/scheduler/core/Activator.java b/scheduler/src/main/java/org/apache/karaf/scheduler/core/Activator.java
index f3ef634adb..8271609f79 100644
--- a/scheduler/src/main/java/org/apache/karaf/scheduler/core/Activator.java
+++ b/scheduler/src/main/java/org/apache/karaf/scheduler/core/Activator.java
@@ -36,6 +36,10 @@ protected void doStart() throws Exception {
         scheduler = new QuartzScheduler(threadPool);
         whiteboardHandler = new WhiteboardHandler(bundleContext, scheduler);
         register(Scheduler.class, scheduler);
+
+        SchedulerMBeanImpl mBean = new SchedulerMBeanImpl();
+        mBean.setScheduler(scheduler);
+        registerMBean(mBean, "type=scheduler");
     }
 
     @Override
diff --git a/scheduler/src/main/java/org/apache/karaf/scheduler/core/SchedulerMBeanImpl.java
b/scheduler/src/main/java/org/apache/karaf/scheduler/core/SchedulerMBeanImpl.java
new file mode 100644
index 0000000000..b2081d2936
--- /dev/null
+++ b/scheduler/src/main/java/org/apache/karaf/scheduler/core/SchedulerMBeanImpl.java
@@ -0,0 +1,91 @@
+/*
+ * 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.karaf.scheduler.core;
+
+import org.apache.karaf.scheduler.ScheduleOptions;
+import org.apache.karaf.scheduler.Scheduler;
+import org.apache.karaf.scheduler.SchedulerMBean;
+import org.apache.karaf.scheduler.command.support.TriggerJob;
+
+import javax.management.MBeanException;
+import javax.management.NotCompliantMBeanException;
+import javax.management.StandardMBean;
+import javax.management.openmbean.*;
+import java.util.Map;
+
+public class SchedulerMBeanImpl extends StandardMBean implements SchedulerMBean {
+
+    private Scheduler scheduler;
+
+    public SchedulerMBeanImpl() throws NotCompliantMBeanException {
+        super(SchedulerMBean.class);
+    }
+
+    @Override
+    public TabularData getJobs() throws MBeanException {
+        try {
+            CompositeType jobType = new CompositeType("Job", "Scheduler job",
+                    new String[]{ "Job", "Schedule" },
+                    new String[]{ "Job Name", "Job Scheduling" },
+                    new OpenType[]{ SimpleType.STRING, SimpleType.STRING });
+            TabularType tableType = new TabularType("Jobs", "Tables of all jobs", jobType,
new String[]{ "Job" });
+            TabularData table = new TabularDataSupport(tableType);
+
+            Map<Object, ScheduleOptions> jobs = scheduler.getJobs();
+            for (Map.Entry<Object, ScheduleOptions> entry : jobs.entrySet()) {
+                CompositeData data = new CompositeDataSupport(jobType,
+                        new String[]{ "Job", "Schedule" },
+                        new Object[]{ entry.getValue().name(), entry.getValue().schedule()});
+                table.put(data);
+            }
+            return table;
+        } catch (Exception e) {
+            throw new MBeanException(null, e.toString());
+        }
+    }
+
+    @Override
+    public void trigger(String name, boolean background) throws MBeanException {
+        try {
+            if (background) {
+                scheduler.schedule(new TriggerJob(scheduler, name), scheduler.NOW());
+            } else {
+                scheduler.trigger(name);
+            }
+        } catch (Exception e) {
+            throw new MBeanException(null, e.toString());
+        }
+    }
+
+    @Override
+    public void unschedule(String name) throws MBeanException {
+        try {
+            scheduler.unschedule(name);
+        } catch (Exception e) {
+            throw new MBeanException(null, e.toString());
+        }
+    }
+
+    public Scheduler getScheduler() {
+        return scheduler;
+    }
+
+    public void setScheduler(Scheduler scheduler) {
+        this.scheduler = scheduler;
+    }
+
+}


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> Add SchedulerMBean to mimic scheduler shell commands
> ----------------------------------------------------
>
>                 Key: KARAF-5307
>                 URL: https://issues.apache.org/jira/browse/KARAF-5307
>             Project: Karaf
>          Issue Type: New Feature
>          Components: karaf-management, karaf-scheduler
>            Reporter: Jean-Baptiste Onofré
>            Assignee: Jean-Baptiste Onofré
>             Fix For: 4.1.4, 4.2.0
>
>
> Now, we "control" the Karaf scheduler using the {{scheduler:*}} commands. As we do for
the other parts of Karaf, I will add the corresponding MBean to be able to control the scheduler
via JMX.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message