org.jclarion.clarion.primative.ThreadStateGetter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of clarion-runtime Show documentation
Show all versions of clarion-runtime Show documentation
JClarion runtime environment
package org.jclarion.clarion.primative;
public class ThreadStateGetter extends AbstractStateGetter
{
private AbstractStateFactory factory;
private ActiveThreadMap threadedState;
private AbstractStateGetter state;
public ThreadStateGetter(AbstractStateFactory aFactory,AbstractStateGetter aState)
{
this.factory=aFactory;
this.state=aState;
threadedState=new ActiveThreadMap();
}
@Override
public T get() {
return get(Thread.currentThread());
}
@Override
public T get(Thread t) {
T result;
synchronized(threadedState) {
result=threadedState.get(t);
if (result==null) {
result=factory.cloneState(state.get());
threadedState.put(t,result);
}
}
return result;
}
@Override
public boolean isThreaded() {
return true;
}
@Override
public AbstractStateGetter getLockedGetter(Thread t) {
return new LockedStateGetter(get(t));
}
@Override
public void reset() {
synchronized(threadedState) {
state.reset();
threadedState.clear();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy