Skip to content

Commit

Permalink
[RHPAM-4698] Detect creation of timers for notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Alberto Fanjul committed May 5, 2023
1 parent 3e967fb commit 2d5a714
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright 2017 Red Hat, Inc. and/or its affiliates.
*
* Licensed 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.jbpm.process.instance.timer;

/**
*
*/
public interface TimerJobContext {
boolean isNewTimer();
}
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ public void execute(JobContext c) {

}

public static class ProcessJobContext implements JobContext {
public static class ProcessJobContext implements JobContext, TimerJobContext {
private static final long serialVersionUID = 476843895176221627L;

private Long processInstanceId;
Expand Down Expand Up @@ -444,7 +444,8 @@ public void setKnowledgeRuntime(InternalKnowledgeRuntime kruntime) {
public InternalWorkingMemory getWorkingMemory() {
return kruntime instanceof InternalWorkingMemory ? (InternalWorkingMemory)kruntime : null;
}


@Override
public boolean isNewTimer() {
return newTimer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.jbpm.process.core.timer.NamedJobContext;
import org.jbpm.process.core.timer.TimerServiceRegistry;
import org.jbpm.process.core.timer.impl.GlobalTimerService;
import org.jbpm.process.instance.timer.TimerJobContext;
import org.jbpm.services.task.commands.ExecuteDeadlinesCommand;
import org.jbpm.services.task.deadlines.NotificationListener;
import org.jbpm.services.task.utils.ClassUtil;
Expand Down Expand Up @@ -99,7 +100,7 @@ public void schedule(long taskId, long deadlineId, long delay, DeadlineType type
0,
null,
null ) ;
JobHandle handle = timerService.scheduleJob(deadlineJob, new TaskDeadlineJobContext(deadlineJob.getId(), task.getTaskData().getProcessInstanceId(), deploymentId), trigger);
JobHandle handle = timerService.scheduleJob(deadlineJob, new TaskDeadlineJobContext(deadlineJob.getId(), task.getTaskData().getProcessInstanceId(), deploymentId, true), trigger);
jobHandles.put(deadlineJob.getId(), handle);

} else {
Expand Down Expand Up @@ -356,20 +357,30 @@ public String getId() {
}
}

private static class TaskDeadlineJobContext implements NamedJobContext {
private static class TaskDeadlineJobContext implements NamedJobContext, TimerJobContext {

private static final long serialVersionUID = -6838102884655249845L;
private JobHandle jobHandle;
private String jobName;
private Long processInstanceId;
private String deploymentId;
private boolean newTimer;

public TaskDeadlineJobContext(String jobName, Long processInstanceId, String deploymentId) {
this(jobName, processInstanceId, deploymentId, false);
}

public TaskDeadlineJobContext(String jobName, Long processInstanceId, String deploymentId, boolean newTimer) {
this.jobName = jobName;
this.processInstanceId = processInstanceId;
this.deploymentId = deploymentId;
this.newTimer = newTimer;
}

@Override
public boolean isNewTimer() {
return newTimer;
}
@Override
public void setJobHandle(JobHandle jobHandle) {
this.jobHandle = jobHandle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
import org.jbpm.process.core.timer.impl.DelegateSchedulerServiceInterceptor;
import org.jbpm.process.core.timer.impl.GlobalTimerService;
import org.jbpm.process.core.timer.impl.GlobalTimerService.GlobalJobHandle;
import org.jbpm.process.instance.timer.TimerManager.ProcessJobContext;
import org.jbpm.process.instance.timer.TimerJobContext;
import org.jbpm.runtime.manager.impl.jpa.EntityManagerFactoryManager;
import org.jbpm.runtime.manager.impl.jpa.TimerMappingInfo;
import org.kie.internal.runtime.manager.InternalRuntimeManager;
Expand Down Expand Up @@ -267,7 +267,6 @@ protected String getJobName(JobContext ctx, long id) {
}

private boolean isNewTimer(JobContext ctx) {
return ctx instanceof ProcessJobContext && ((ProcessJobContext) ctx).isNewTimer();
return ctx instanceof TimerJobContext && ((TimerJobContext) ctx).isNewTimer();
}

}

0 comments on commit 2d5a714

Please sign in to comment.