Search in sources :

Example 1 with ThreadId

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);
}
Also used : ThreadId(com.walmartlabs.concord.svm.ThreadId) State(com.walmartlabs.concord.svm.State)

Example 2 with ThreadId

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);
}
Also used : ThreadId(com.walmartlabs.concord.svm.ThreadId) State(com.walmartlabs.concord.svm.State)

Example 3 with ThreadId

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);
}
Also used : ThreadId(com.walmartlabs.concord.svm.ThreadId) State(com.walmartlabs.concord.svm.State)

Example 4 with 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"));
}
Also used : Frame(com.walmartlabs.concord.svm.Frame) ThreadId(com.walmartlabs.concord.svm.ThreadId) State(com.walmartlabs.concord.svm.State) InMemoryState(com.walmartlabs.concord.svm.InMemoryState) InMemoryState(com.walmartlabs.concord.svm.InMemoryState) Test(org.junit.jupiter.api.Test)

Example 5 with ThreadId

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;
}
Also used : Frame(com.walmartlabs.concord.svm.Frame) Serializable(java.io.Serializable) ThreadId(com.walmartlabs.concord.svm.ThreadId) State(com.walmartlabs.concord.svm.State)

Aggregations

State (com.walmartlabs.concord.svm.State)6 ThreadId (com.walmartlabs.concord.svm.ThreadId)6 Frame (com.walmartlabs.concord.svm.Frame)2 TaskProviders (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskProviders)1 InMemoryState (com.walmartlabs.concord.svm.InMemoryState)1 Serializable (java.io.Serializable)1 Test (org.junit.jupiter.api.Test)1