Skip to content

Commit

Permalink
JBPM 4714: fixed UpdateTimerCommand to inherit from ProcessInstanceId…
Browse files Browse the repository at this point in the history
…Command
  • Loading branch information
ibek committed Sep 25, 2015
1 parent ce3b4d6 commit e317490
Showing 1 changed file with 47 additions and 11 deletions.
Expand Up @@ -16,6 +16,12 @@


package org.jbpm.process.instance.command; package org.jbpm.process.instance.command;


import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSchemaType;

import org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession; import org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession;
import org.drools.core.command.impl.GenericCommand; import org.drools.core.command.impl.GenericCommand;
import org.drools.core.command.impl.KnowledgeCommandContext; import org.drools.core.command.impl.KnowledgeCommandContext;
Expand All @@ -28,17 +34,33 @@
import org.kie.api.runtime.KieSession; import org.kie.api.runtime.KieSession;
import org.kie.api.runtime.process.NodeInstance; import org.kie.api.runtime.process.NodeInstance;
import org.kie.internal.command.Context; import org.kie.internal.command.Context;
import org.kie.internal.command.ProcessInstanceIdCommand;


public class UpdateTimerCommand implements GenericCommand<Object> { @XmlRootElement(name = "update-timer-command")
@XmlAccessorType(XmlAccessType.NONE)
public class UpdateTimerCommand implements GenericCommand<Void>, ProcessInstanceIdCommand {


private static final long serialVersionUID = -8252686458877022330L; private static final long serialVersionUID = -8252686458877022330L;


private final long processInstanceId; @XmlElement
private final String timerName; @XmlSchemaType(name = "long")

private long processInstanceId;
private final long delay;
private final long period; @XmlElement
private final int repeatLimit; @XmlSchemaType(name = "string")
private String timerName;

@XmlElement
@XmlSchemaType(name = "long")
private long delay;

@XmlElement
@XmlSchemaType(name = "long")
private long period;

@XmlElement
@XmlSchemaType(name = "int")
private int repeatLimit;


public UpdateTimerCommand(long processInstanceId, String timerName, long delay) { public UpdateTimerCommand(long processInstanceId, String timerName, long delay) {
this(processInstanceId, timerName, delay, 0, 0); this(processInstanceId, timerName, delay, 0, 0);
Expand All @@ -57,7 +79,7 @@ public UpdateTimerCommand(long processInstanceId, String timerName, long delay,
} }


@Override @Override
public Object execute(Context context) { public Void execute(Context context) {
KieSession kieSession = ((KnowledgeCommandContext) context).getKieSession(); KieSession kieSession = ((KnowledgeCommandContext) context).getKieSession();
TimerManager tm = getTimerManager(kieSession); TimerManager tm = getTimerManager(kieSession);


Expand All @@ -68,10 +90,10 @@ public Object execute(Context context) {
TimerNodeInstance tni = (TimerNodeInstance) nodeInstance; TimerNodeInstance tni = (TimerNodeInstance) nodeInstance;
if (tni.getNodeName().equals(timerName)) { if (tni.getNodeName().equals(timerName)) {
TimerInstance timer = tm.getTimerMap().get(tni.getTimerId()); TimerInstance timer = tm.getTimerMap().get(tni.getTimerId());

tm.cancelTimer(timer.getTimerId()); tm.cancelTimer(timer.getTimerId());
TimerInstance newTimer = new TimerInstance(); TimerInstance newTimer = new TimerInstance();

if (delay != 0) { if (delay != 0) {
long diff = System.currentTimeMillis() - timer.getActivated().getTime(); long diff = System.currentTimeMillis() - timer.getActivated().getTime();
newTimer.setDelay(delay * 1000 - diff); newTimer.setDelay(delay * 1000 - diff);
Expand All @@ -90,6 +112,16 @@ public Object execute(Context context) {
return null; return null;
} }


@Override
public void setProcessInstanceId(Long procInstId) {
this.processInstanceId = procInstId;
}

@Override
public Long getProcessInstanceId() {
return processInstanceId;
}

private TimerManager getTimerManager(KieSession ksession) { private TimerManager getTimerManager(KieSession ksession) {
KieSession internal = ksession; KieSession internal = ksession;
if (ksession instanceof CommandBasedStatefulKnowledgeSession) { if (ksession instanceof CommandBasedStatefulKnowledgeSession) {
Expand All @@ -99,4 +131,8 @@ private TimerManager getTimerManager(KieSession ksession) {
return ((InternalProcessRuntime) ((StatefulKnowledgeSessionImpl) internal).getProcessRuntime()).getTimerManager(); return ((InternalProcessRuntime) ((StatefulKnowledgeSessionImpl) internal).getProcessRuntime()).getTimerManager();
} }


public String toString() {
return "processInstance.updateTimer(" + timerName + ", " + delay + ", " + period + ", " + repeatLimit + ");";
}

} }

0 comments on commit e317490

Please sign in to comment.