Aradhana
New Creator

While getting context i am getting Class cast exception

Below is my code that gives me class cast exeption inside init method. i am pasting my code here and also attaching the screen shot of servre configuration ,i just want jobAgent refernce so that i can call the jobAgent interface method to check other active running jobs. Please help me!!

public class CleanHangedJobsExecutable implements Executable {

private static final Class<?> LOGGER = CleanHangedJobsExecutable.class;

private ScheduleTaskExecutionContext context;

@Override
public Object execute(Map<String, Object> map) {
this.init(map);
if(context instanceof ScheduleTaskExecutionContext)
{
Logging.logInfo("inside context line"+context, LOGGER);
JobAgent agent = context.requireSpecialist(JobAgent.TYPE);
Logging.logInfo("inside first line"+agent, LOGGER);
String path=agent.getFolderPath();
Logging.logInfo("check folder path==="+path, LOGGER);

}
Logging.logInfo("outside context line"+context, LOGGER);
return null;
}

@Override
public Object execute(Map<String, Object> map, Writer writer, Writer writer1) {
return execute(map);
}
private void init(Map<String, Object> map) {
this.context = (ScheduleTaskExecutionContext) map.get("context");
}

}

  i am also pasting log:

INFO 10.10.2022 11:33:12.436 (de.espirit.firstspirit.server.sessionmanagement.SessionManagerImpl): new session (ID=8372838764198674675, user=SYSTEM, userID=0, type=DUMMY) created
INFO 10.10.2022 11:33:12.438 (de.espirit.firstspirit.server.scheduler.ScheduleManagerImpl): starting task 'Clean Hanging Jobs' - schedule entry 'FirstSpirit - Cleanup Hanged Jobs' (id=425254)
INFO 10.10.2022 11:33:12.470 (de.espirit.firstspirit.server.sessionmanagement.SessionManagerImpl): new session (ID=5425365609462237344, user=scriptuser, userID=2813, type=DUMMY) created
INFO 10.10.2022 11:33:12.470 (de.espirit.firstspirit.server.scheduler.ScriptTaskExecutor): Legacy password login for user 'scriptuser' detected (name='FirstSpirit - Cleanup Hanged Jobs',id=425254).
INFO 10.10.2022 11:33:12.470 (de.espirit.firstspirit.server.scheduler.ScriptTaskExecutor): skript connection created: 5425365609462237344, user=scriptuser
INFO 10.10.2022 11:33:12.471 (de.espirit.firstspirit.server.sessionmanagement.SessionManagerImpl): new session (ID=5712107329463626657, user=scriptuser, userID=2813, type=DUMMY) created
ERROR 10.10.2022 11:33:12.472{dNR=} (de.espirit.firstspirit.server.scheduler.ScriptTaskExecutor): error during script execution : java.lang.ClassCastException: class de.espirit.firstspirit.server.scheduler.DelegatingScheduleContext cannot be cast to class de.espirit.firstspirit.scheduling.ScheduleTaskExecutionContext (de.espirit.firstspirit.server.scheduler.DelegatingScheduleContext is in unnamed module of loader de.espirit.common.FactoryRegistry$LibrariesLoader @ea1a8d5; de.espirit.firstspirit.scheduling.ScheduleTaskExecutionContext is in unnamed module of loader 'app')
java.lang.ClassCastException: class de.espirit.firstspirit.server.scheduler.DelegatingScheduleContext cannot be cast to class de.espirit.firstspirit.scheduling.ScheduleTaskExecutionContext (de.espirit.firstspirit.server.scheduler.DelegatingScheduleContext is in unnamed module of loader de.espirit.common.FactoryRegistry$LibrariesLoader @ea1a8d5; de.espirit.firstspirit.scheduling.ScheduleTaskExecutionContext is in unnamed module of loader 'app')
at com.vw.ogp.fs.ums.CleanHangedJobsExecutable.init(CleanHangedJobsExecutable.java:42)
at com.vw.ogp.fs.ums.CleanHangedJobsExecutable.execute(CleanHangedJobsExecutable.java:23)
at com.vw.ogp.fs.ums.CleanHangedJobsExecutable.execute(CleanHangedJobsExecutable.java:39)
at de.espirit.firstspirit.server.script.ClassCallerEngine$ContextLoaderExecutable.execute(ClassCallerEngine.java:110)
at de.espirit.firstspirit.server.script.PermissionsScriptEngine$PermissionsExecutable.lambda$execute$1(PermissionsScriptEngine.java:83)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at de.espirit.firstspirit.server.script.PermissionsScriptEngine$PermissionsExecutable.execute(PermissionsScriptEngine.java:88)
at de.espirit.firstspirit.server.script.PermissionsScriptEngine$PermissionsExecutable.execute(PermissionsScriptEngine.java:83)
at de.espirit.firstspirit.common.ScriptUtil.execute(ScriptUtil.java:109)
at de.espirit.firstspirit.server.scheduler.ScriptTaskExecutor.run(ScriptTaskExecutor.java:162)
at de.espirit.firstspirit.server.scheduler.ScheduleManagerImpl$TaskCallable.executeLocal(ScheduleManagerImpl.java:2664)
at de.espirit.firstspirit.server.scheduler.ScheduleManagerImpl$TaskCallable.executeLocal(ScheduleManagerImpl.java:2647)
at de.espirit.firstspirit.server.scheduler.ScheduleManagerImpl$TaskCallable.call(ScheduleManagerImpl.java:2576)
at de.espirit.firstspirit.server.ExecutionManagerImpl$ExtendedCallable.call(ExecutionManagerImpl.java:629)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at de.espirit.common.util.BoundedExecutorService$RunnableWrapper.run(BoundedExecutorService.java:491)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
at de.espirit.common.util.SuspendableThread.run(SuspendableThread.java:58)
INFO 10.10.2022 11:33:12.472 (de.espirit.firstspirit.server.sessionmanagement.SessionManagerImpl): Session terminated (ID=5712107329463626657, user=scriptuser (Funktionaler User für Skripte)(dummy)), number of sessions now 15
INFO 10.10.2022 11:33:12.472 (de.espirit.firstspirit.server.sessionmanagement.SessionManagerImpl): Close dummy session (ID=5425365609462237344, user=scriptuser)
INFO 10.10.2022 11:33:12.472 (de.espirit.firstspirit.server.scheduler.ScheduleManagerImpl): finished task 'Clean Hanging Jobs' - schedule entry 'FirstSpirit - Cleanup Hanged Jobs' (id=425254)

 

Attaching screen shot of server configuration.there is nothing inside properties tab. it is empty.

 

photo of job that is on serverphoto of job that is on server

0 Kudos
2 Replies
mbergmann
Crownpeak employee

Hi,

when you are using an executable in a schedule entry, the given context is not a ScheduleTaskExecutionContext but a ScheduleContext. A ScheduleTaskExecutionContext (and maybe even JobAgent, but not sure about that) is (IIRC) only used/provided in combination with implementations of own custom schedule task types

Beyond that: Not sure how the JobAgent should help here in the next step, I‘d rather recommend

  • reading the control‘s id via ScheduleContext.getExecutionId() (to have something to distinguish the „current“ schedule from it‘s „brothers“ later)
  • get the ScheduleStorage (via AdminService)
  • use the ScheduleStorage.getRunningEntries() - depending on your use case you will most likely have to do some filtering
  • … or maybe a better alternative depending on your use case: directly get ScheduleEntries for your current project and then filter (if needed) and use ScheduleEntry.getRunningEntries() if it’s just about a special ScheduleEntry in one project
  • however, you end up with a list of ScheduleEntryControl objects. On them you can use their stopExecution() method - but maybe use the remembered id to avoid killing that current entry (your running executable itself) if it’s own control could be among those you have at the end
0 Kudos

Thank you!! for the response i will try with ScheduleEntry.getRunningEntries().

0 Kudos