use of com.walmartlabs.concord.svm.ThreadId in project concord by walmartlabs.
the class ContextVariables method get.
@Override
public Object get(String key) {
State state = ctx.execution().state();
ThreadId threadId = ctx.execution().currentThreadId();
return VMUtils.getCombinedLocal(state, threadId, key);
}
use of com.walmartlabs.concord.svm.ThreadId in project concord by walmartlabs.
the class ContextVariables method has.
@Override
public boolean has(String key) {
State state = ctx.execution().state();
ThreadId threadId = ctx.execution().currentThreadId();
return VMUtils.hasCombinedLocal(state, threadId, key);
}
use of com.walmartlabs.concord.svm.ThreadId in project concord by walmartlabs.
the class VMUtils method getCombinedLocals.
/**
* @see #getCombinedLocals(State, ThreadId)
*/
public static Map<String, Object> getCombinedLocals(Context ctx) {
ThreadId threadId = ctx.execution().currentThreadId();
State state = ctx.execution().state();
return getCombinedLocals(state, threadId);
}
use of com.walmartlabs.concord.svm.ThreadId in project concord by walmartlabs.
the class VMUtilsTest method testLocals.
@Test
public void testLocals() {
Frame rootFrame = Frame.builder().root().locals(Collections.singletonMap("x", 123)).build();
State state = new InMemoryState(rootFrame);
ThreadId threadId = state.getRootThreadId();
Frame levelOneFrame = Frame.builder().nonRoot().locals(Collections.singletonMap("y", 234)).build();
state.pushFrame(threadId, levelOneFrame);
Frame levelTwoFrame = Frame.builder().nonRoot().locals(Collections.singletonMap("x", 345)).build();
state.pushFrame(threadId, levelTwoFrame);
Map<String, Object> locals = VMUtils.getCombinedLocals(state, threadId);
assertEquals(2, locals.size());
assertEquals(345, locals.get("x"));
assertEquals(234, locals.get("y"));
}
use of com.walmartlabs.concord.svm.ThreadId in project concord by walmartlabs.
the class ContextUtils method getCurrentRetryAttemptNumber.
/**
* Returns the current "retry" attempt number (if applicable).
*
* @param ctx current {@link Context}
* @return the current attemp number of {@code null} if the current call is a retry.
* @see Constants.Runtime#RETRY_ATTEMPT_NUMBER
*/
public static Integer getCurrentRetryAttemptNumber(Context ctx) {
Execution execution = ctx.execution();
State state = execution.state();
ThreadId threadId = execution.currentThreadId();
Frame frame = state.peekFrame(threadId);
Serializable value = frame.getLocal(Constants.Runtime.RETRY_ATTEMPT_NUMBER);
if (value == null) {
return null;
}
if (!(value instanceof Integer)) {
throw new IllegalStateException(String.format("%s is expected to be a number, got: %s. This is most likely a bug", Constants.Runtime.RETRY_ATTEMPT_NUMBER, value.getClass()));
}
return (Integer) value;
}
Aggregations