Hi @pturmel,
Sorry If it was a very trivial question but I don’t understand my mistake in this context.
As you can see below, In my module development I have multiple instance of this abstract ‘Sample’ class.
For each instance, I register my runnable ‘TimeoutManager’ with an uniqueID with an initial delay.
Before the runnable execution, I update an atomic Long with ‘doSomething()’ function. Unfortunately when my runnable ‘TimeoutManager’ run the atomicLong is stay with the initial Value.
The execution manager don’t take the context (variables) during execution runnable.
How can I have the right value of my AtomicLong during TimeoutManager.run()?
import com.inductiveautomation.ignition.common.execution.ExecutionManager;
import com.inductiveautomation.ignition.gateway.model.GatewayContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
public abstract class Sample{
private final Logger logger = LoggerFactory.getLogger(getClass());
private final ExecutionManager execm;
private final TimeoutManager timeoutManager = new TimeoutManager();
private AtomicLong myLastAccessTime = new AtomicLong(System.currentTimeMillis());
public Sample(GatewayContext _context){
this.execm = _context.getExecutionManager();
}
public void registerRun() {
execm.registerWithInitialDelay("UUID", TimeoutManager.class.getName(), timeoutManager, 30000, TimeUnit.MILLISECONDS, 10000);
logger.debug("registerRun()");
}
public void unRegisterRun() {
execm.unRegister("UUID",TimeoutManager.class.getName());
}
public void doSomething(){
//Do something Here
myLastAccessTime.set(System.currentTimeMillis());
logger.debug("doSomething() > LastAccessTime:[{}]",getLastAccessTime());
}
public Long getLastAccessTime(){
return myLastAccessTime.get();
}
private class TimeoutManager implements Runnable{
public TimeoutManager(){
logger.debug("TimeoutManager > LastAccessTime:{}",getLastAccessTime());
}
@Override
public void run() {
long currentTime = System.currentTimeMillis();
long lastCommTime = getLastAccessTime();
if ((currentTime - lastCommTime)> 30000){
logger.debug("TimeoutManager.run()> You haven't done Something() is in timeout Delay:[{}]ms LastAccessTime:[{}]",(currentTime-lastCommTime),lastCommTime);
} else {
logger.debug("TimeoutManager.run()> You have done Something");
}
}
}
}
registerRun()
TimeoutManager > LastAccessTime:1507275293767
doSomething() > LastAccessTime:[1507275293867]
doSomething() > LastAccessTime:[1507275293892]
TimeoutManager.run()> You haven't done Something() is in timeout Delay:[30000]ms LastAccessTime:[1507275293767]
Thanks.