Skip to content

Commit

Permalink
Extend quartz-scheduler plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
qtc-de committed Jan 27, 2024
1 parent 9dfb6f5 commit f5365ce
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
8 changes: 7 additions & 1 deletion plugins/quartz-scheduler/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,18 @@
<version>5.1.0</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.3.2</version>
</dependency>

<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz-jobs</artifactId>
<version>2.3.2</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@

import java.rmi.RemoteException;

import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.SchedulerException;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.quartz.core.RemotableQuartzScheduler;
import org.quartz.jobs.NativeJob;

import eu.tneitzel.rmg.internal.ExceptionHandler;
import eu.tneitzel.rmg.io.Logger;
import eu.tneitzel.rmg.utils.RMGUtils;

public class Dispatcher
{
Expand All @@ -15,4 +23,26 @@ public static void dispatchVersion() throws RemoteException

Logger.printlnMixedYellow("Remote Quartz Scheduler version:", version);
}

public static void dispatchScheduleJob() throws RemoteException
{
RemotableQuartzScheduler scheduler = Helpers.getScheduler();
String jobName = String.format("rmg-job-%d", System.currentTimeMillis());

JobDetail myJob = JobBuilder.newJob(NativeJob.class).withIdentity(jobName).build();
Trigger myTrigger = TriggerBuilder.newTrigger().startNow().build();

try
{
scheduler.scheduleJob(myJob, myTrigger);
}

catch (SchedulerException e)
{
Logger.printlnMixedYellow("Caught unexpected", "SchedulerException", "after scheduling the job.");
ExceptionHandler.showStackTrace(e);

RMGUtils.exit();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package eu.tneitzel.rmg.plugin;

import java.rmi.UnmarshalException;

import org.quartz.core.RemotableQuartzScheduler;

import eu.tneitzel.rmg.internal.RMGOption;
import eu.tneitzel.rmg.io.Logger;
import eu.tneitzel.rmg.networking.RMIRegistryEndpoint;
import eu.tneitzel.rmg.operations.RemoteObjectClient;
import eu.tneitzel.rmg.utils.RMGUtils;

public class Helpers
Expand All @@ -25,10 +26,17 @@ public static RemotableQuartzScheduler getScheduler()
String host = RMGOption.TARGET_HOST.getValue();
int port = RMGOption.TARGET_PORT.getValue();

RMIRegistryEndpoint endpoint = new RMIRegistryEndpoint(host, port);
RemoteObjectClient client = new RemoteObjectClient(endpoint, RMGOption.TARGET_BOUND_NAME.<String>getValue());
try
{
RMIRegistryEndpoint endpoint = new RMIRegistryEndpoint(host, port);
scheduler = (RemotableQuartzScheduler)endpoint.lookup(RMGOption.TARGET_BOUND_NAME.<String>getValue());
}

scheduler = client.createProxy(RemotableQuartzScheduler.class);
catch (UnmarshalException e)
{
Logger.printlnMixedYellow("Caught unexpected", "UnmarshalException", "while calling the RMI registry.");
RMGUtils.exit();
}
}

return scheduler;
Expand Down

0 comments on commit f5365ce

Please sign in to comment.