karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject [2/6] karaf git commit: [KARAF-5355] The scripts triggered with {{scheduler::schedule}} command fail to execute
Date Mon, 11 Sep 2017 21:28:48 GMT
[KARAF-5355] The scripts triggered with {{scheduler::schedule}} command fail to execute


Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/af16cb35
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/af16cb35
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/af16cb35

Branch: refs/heads/master
Commit: af16cb353be58d8c417b8037e30e344e88182a76
Parents: c5d3a88
Author: Guillaume Nodet <gnodet@gmail.com>
Authored: Mon Sep 11 11:15:22 2017 +0200
Committer: Guillaume Nodet <gnodet@gmail.com>
Committed: Mon Sep 11 11:15:22 2017 +0200

----------------------------------------------------------------------
 .../java/org/apache/karaf/scheduler/command/Schedule.java |  6 +++++-
 .../apache/karaf/scheduler/command/support/ScriptJob.java | 10 +++++++---
 2 files changed, 12 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/af16cb35/scheduler/src/main/java/org/apache/karaf/scheduler/command/Schedule.java
----------------------------------------------------------------------
diff --git a/scheduler/src/main/java/org/apache/karaf/scheduler/command/Schedule.java b/scheduler/src/main/java/org/apache/karaf/scheduler/command/Schedule.java
index c17055f..b4c2d2e 100644
--- a/scheduler/src/main/java/org/apache/karaf/scheduler/command/Schedule.java
+++ b/scheduler/src/main/java/org/apache/karaf/scheduler/command/Schedule.java
@@ -31,6 +31,7 @@ import org.apache.karaf.shell.api.action.lifecycle.Reference;
 import org.apache.karaf.shell.api.action.lifecycle.Service;
 import org.apache.karaf.shell.api.console.Function;
 import org.apache.karaf.shell.api.console.Session;
+import org.apache.karaf.shell.api.console.SessionFactory;
 
 @Command(scope = "scheduler", name = "schedule", description = "Schedule a script execution")
 @Service
@@ -63,6 +64,9 @@ public class Schedule implements Action {
     @Reference
     Session session;
 
+    @Reference
+    SessionFactory sessionFactory;
+
     @Override
     public Object execute() throws Exception {
         if (cron != null && (at != null || times != -1 || period != 0)) {
@@ -90,7 +94,7 @@ public class Schedule implements Action {
         if (concurrent) {
             options.canRunConcurrently(concurrent);
         }
-        scheduler.schedule(new ScriptJob(session, script), options);
+        scheduler.schedule(new ScriptJob(sessionFactory, session, script), options);
         return null;
     }
 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/af16cb35/scheduler/src/main/java/org/apache/karaf/scheduler/command/support/ScriptJob.java
----------------------------------------------------------------------
diff --git a/scheduler/src/main/java/org/apache/karaf/scheduler/command/support/ScriptJob.java
b/scheduler/src/main/java/org/apache/karaf/scheduler/command/support/ScriptJob.java
index b0f3341..c62a638 100644
--- a/scheduler/src/main/java/org/apache/karaf/scheduler/command/support/ScriptJob.java
+++ b/scheduler/src/main/java/org/apache/karaf/scheduler/command/support/ScriptJob.java
@@ -16,12 +16,14 @@
  */
 package org.apache.karaf.scheduler.command.support;
 
+import java.io.ByteArrayInputStream;
 import java.util.Collections;
 
 import org.apache.karaf.scheduler.Job;
 import org.apache.karaf.scheduler.JobContext;
 import org.apache.karaf.shell.api.console.Function;
 import org.apache.karaf.shell.api.console.Session;
+import org.apache.karaf.shell.api.console.SessionFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -29,18 +31,20 @@ public class ScriptJob implements Job {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(ScriptJob.class);
 
+    private final SessionFactory sessionFactory;
     private final Session session;
     private final Function script;
 
-    public ScriptJob(Session session, Function script) {
+    public ScriptJob(SessionFactory sessionFactory, Session session, Function script) {
+        this.sessionFactory = sessionFactory;
         this.session = session;
         this.script = script;
     }
 
     @Override
     public void execute(JobContext context) {
-        try {
-            script.execute(session, Collections.singletonList(context));
+        try (Session s = sessionFactory.create(new ByteArrayInputStream(new byte[0]), session.getConsole(),
session.getConsole(), session)) {
+            script.execute(s, Collections.singletonList(context));
         } catch (Exception e) {
             LOGGER.warn("Error executing script", e);
         }


Mime
View raw message