deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject git commit: DELTASPIKE-549 Scheduler#unwrap
Date Mon, 31 Mar 2014 06:22:47 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master 380b113be -> 18c02618d


DELTASPIKE-549 Scheduler#unwrap


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

Branch: refs/heads/master
Commit: 18c02618da5b30a254afcb8ea741d350a4b95fe4
Parents: 380b113
Author: gpetracek <gpetracek@apache.org>
Authored: Mon Mar 31 08:20:32 2014 +0200
Committer: gpetracek <gpetracek@apache.org>
Committed: Mon Mar 31 08:20:32 2014 +0200

----------------------------------------------------------------------
 .../org/apache/deltaspike/scheduler/spi/Scheduler.java  |  2 ++
 .../deltaspike/scheduler/impl/QuartzScheduler.java      | 12 ++++++++++++
 .../test/scheduler/custom/CustomSchedulerTest.java      | 12 ++++++++++++
 .../test/scheduler/custom/MockedScheduler.java          | 12 ++++++++++++
 4 files changed, 38 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/18c02618/deltaspike/modules/scheduler/api/src/main/java/org/apache/deltaspike/scheduler/spi/Scheduler.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/scheduler/api/src/main/java/org/apache/deltaspike/scheduler/spi/Scheduler.java
b/deltaspike/modules/scheduler/api/src/main/java/org/apache/deltaspike/scheduler/spi/Scheduler.java
index 11560ac..c09a1c3 100644
--- a/deltaspike/modules/scheduler/api/src/main/java/org/apache/deltaspike/scheduler/spi/Scheduler.java
+++ b/deltaspike/modules/scheduler/api/src/main/java/org/apache/deltaspike/scheduler/spi/Scheduler.java
@@ -37,4 +37,6 @@ public interface Scheduler<T> extends Deactivatable
     void registerNewJob(Class<? extends T> jobClass);
 
     void startJobManually(Class<? extends T> jobClass);
+
+    <S> S unwrap(Class<? extends S> schedulerClass);
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/18c02618/deltaspike/modules/scheduler/impl/src/main/java/org/apache/deltaspike/scheduler/impl/QuartzScheduler.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/scheduler/impl/src/main/java/org/apache/deltaspike/scheduler/impl/QuartzScheduler.java
b/deltaspike/modules/scheduler/impl/src/main/java/org/apache/deltaspike/scheduler/impl/QuartzScheduler.java
index 4b83f67..484d6dc 100644
--- a/deltaspike/modules/scheduler/impl/src/main/java/org/apache/deltaspike/scheduler/impl/QuartzScheduler.java
+++ b/deltaspike/modules/scheduler/impl/src/main/java/org/apache/deltaspike/scheduler/impl/QuartzScheduler.java
@@ -330,4 +330,16 @@ public class QuartzScheduler implements Scheduler<Job>
             }
         }
     }
+
+    @Override
+    public <S> S unwrap(Class<? extends S> schedulerClass)
+    {
+        if (schedulerClass.isAssignableFrom(this.scheduler.getClass()))
+        {
+            return (S)this.scheduler;
+        }
+
+        throw new IllegalArgumentException(schedulerClass.getName() +
+            " isn't compatible with " + this.scheduler.getClass().getName());
+    }
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/18c02618/deltaspike/modules/scheduler/impl/src/test/java/org/apache/deltaspike/test/scheduler/custom/CustomSchedulerTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/scheduler/impl/src/test/java/org/apache/deltaspike/test/scheduler/custom/CustomSchedulerTest.java
b/deltaspike/modules/scheduler/impl/src/test/java/org/apache/deltaspike/test/scheduler/custom/CustomSchedulerTest.java
index d97159d..5a5a5a6 100644
--- a/deltaspike/modules/scheduler/impl/src/test/java/org/apache/deltaspike/test/scheduler/custom/CustomSchedulerTest.java
+++ b/deltaspike/modules/scheduler/impl/src/test/java/org/apache/deltaspike/test/scheduler/custom/CustomSchedulerTest.java
@@ -93,4 +93,16 @@ public abstract class CustomSchedulerTest
         this.scheduler.registerNewJob(AutoRegisteredJob.class);
         Assert.assertEquals(1, testJobManager.getRegisteredJobs().size());
     }
+
+    @Test
+    public void unwrap()
+    {
+        Assert.assertEquals(TestJobManager.class, this.scheduler.unwrap(TestJobManager.class).getClass());
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void invalidUnwrap()
+    {
+        this.scheduler.unwrap(MockedScheduler.class);
+    }
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/18c02618/deltaspike/modules/scheduler/impl/src/test/java/org/apache/deltaspike/test/scheduler/custom/MockedScheduler.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/scheduler/impl/src/test/java/org/apache/deltaspike/test/scheduler/custom/MockedScheduler.java
b/deltaspike/modules/scheduler/impl/src/test/java/org/apache/deltaspike/test/scheduler/custom/MockedScheduler.java
index bc152f3..b5d1958 100644
--- a/deltaspike/modules/scheduler/impl/src/test/java/org/apache/deltaspike/test/scheduler/custom/MockedScheduler.java
+++ b/deltaspike/modules/scheduler/impl/src/test/java/org/apache/deltaspike/test/scheduler/custom/MockedScheduler.java
@@ -63,4 +63,16 @@ public class MockedScheduler implements Scheduler<CustomJob>
     {
         TestJobManager.getInstance().startJobManually(jobClass);
     }
+
+    @Override
+    public <S> S unwrap(Class<? extends S> schedulerClass)
+    {
+        if (schedulerClass.isAssignableFrom(TestJobManager.getInstance().getClass()))
+        {
+            return (S)TestJobManager.getInstance();
+        }
+
+        throw new IllegalArgumentException(schedulerClass.getName() +
+            " isn't compatible with " + TestJobManager.getInstance().getClass().getName());
+    }
 }


Mime
View raw message