Java Code Examples for org.apache.nifi.components.state.Scope#LOCAL

The following examples show how to use org.apache.nifi.components.state.Scope#LOCAL . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MockStateManager.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
public MockStateManager(final Object component) {
    final Stateful stateful = component.getClass().getAnnotation(Stateful.class);
    if (stateful == null) {
        usesLocalState = false;
        usesClusterState = false;
    } else {
        final Scope[] scopes = stateful.scopes();
        boolean local = false;
        boolean cluster = false;

        for (final Scope scope : scopes) {
            if (scope == Scope.LOCAL) {
                local = true;
            } else if (scope == Scope.CLUSTER) {
                cluster = true;
            }
        }

        usesLocalState = local;
        usesClusterState = cluster;
    }
}
 
Example 2
Source File: MockStateManager.java    From nifi with Apache License 2.0 6 votes vote down vote up
public MockStateManager(final Object component) {
    final Stateful stateful = component.getClass().getAnnotation(Stateful.class);
    if (stateful == null) {
        usesLocalState = false;
        usesClusterState = false;
    } else {
        final Scope[] scopes = stateful.scopes();
        boolean local = false;
        boolean cluster = false;

        for (final Scope scope : scopes) {
            if (scope == Scope.LOCAL) {
                local = true;
            } else if (scope == Scope.CLUSTER) {
                cluster = true;
            }
        }

        usesLocalState = local;
        usesClusterState = cluster;
    }
}
 
Example 3
Source File: ListFile.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected Scope getStateScope(final PropertyContext context) {
    final String location = context.getProperty(DIRECTORY_LOCATION).getValue();
    if (LOCATION_REMOTE.getValue().equalsIgnoreCase(location)) {
        return Scope.CLUSTER;
    }

    return Scope.LOCAL;
}
 
Example 4
Source File: MockStateManager.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private void verifyAnnotation(final Scope scope) {
    // ensure that the @Stateful annotation is present with the appropriate Scope
    if ((scope == Scope.LOCAL && !usesLocalState) || (scope == Scope.CLUSTER && !usesClusterState)) {
        Assert.fail("Component is attempting to set or retrieve state with a scope of " + scope + " but does not declare that it will use "
            + scope + " state. A @Stateful annotation should be added to the component with a scope of " + scope);
    }
}
 
Example 5
Source File: TailFile.java    From nifi with Apache License 2.0 5 votes vote down vote up
private Scope getStateScope(final ProcessContext context) {
    final String location = context.getProperty(STATE_LOCATION).getValue();
    if (LOCATION_REMOTE.getValue().equalsIgnoreCase(location)) {
        return Scope.CLUSTER;
    }

    return Scope.LOCAL;
}
 
Example 6
Source File: MockStateManager.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Specifies whether or not the State Manager should throw an IOException when state is retrieved for the given scope.
 *
 * @param scope the scope that should (or should not) fail
 * @param fail whether or not retrieving state should fail
 */
public void setFailOnStateGet(final Scope scope, final boolean fail) {
    if (scope == Scope.LOCAL) {
        failToGetLocalState = fail;
    } else {
        failToGetClusterState = fail;
    }
}
 
Example 7
Source File: TailFile.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private Scope getStateScope(final ProcessContext context) {
    final String location = context.getProperty(STATE_LOCATION).getValue();
    if (LOCATION_REMOTE.getValue().equalsIgnoreCase(location)) {
        return Scope.CLUSTER;
    }

    return Scope.LOCAL;
}
 
Example 8
Source File: ListFile.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected Scope getStateScope(final ProcessContext context) {
    final String location = context.getProperty(DIRECTORY_LOCATION).getValue();
    if (LOCATION_REMOTE.getValue().equalsIgnoreCase(location)) {
        return Scope.CLUSTER;
    }

    return Scope.LOCAL;
}
 
Example 9
Source File: MockStateManager.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Specifies whether or not the State Manager should throw an IOException when state is retrieved for the given scope.
 *
 * @param scope the scope that should (or should not) fail
 * @param fail whether or not retrieving state should fail
 */
public void setFailOnStateGet(final Scope scope, final boolean fail) {
    if (scope == Scope.LOCAL) {
        failToGetLocalState = fail;
    } else {
        failToGetClusterState = fail;
    }
}
 
Example 10
Source File: StandardStateManager.java    From nifi with Apache License 2.0 5 votes vote down vote up
private StateProvider getProvider(final Scope scope) {
    if (scope == Scope.LOCAL || clusterProvider == null || !clusterProvider.isEnabled()) {
        return localProvider;
    }

    return clusterProvider;
}
 
Example 11
Source File: MockStateManager.java    From nifi with Apache License 2.0 5 votes vote down vote up
private void verifyAnnotation(final Scope scope) {
    // ensure that the @Stateful annotation is present with the appropriate Scope
    if ((scope == Scope.LOCAL && !usesLocalState) || (scope == Scope.CLUSTER && !usesClusterState)) {
        Assert.fail("Component is attempting to set or retrieve state with a scope of " + scope + " but does not declare that it will use "
            + scope + " state. A @Stateful annotation should be added to the component with a scope of " + scope);
    }
}
 
Example 12
Source File: WriteAheadLocalStateProvider.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Override
public Scope[] getSupportedScopes() {
    return new Scope[]{Scope.LOCAL};
}
 
Example 13
Source File: NopStateProvider.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Override
public Scope[] getSupportedScopes() {
    return new Scope[] {Scope.LOCAL};
}
 
Example 14
Source File: MockStateManager.java    From nifi with Apache License 2.0 4 votes vote down vote up
private void verifyCanGet(final Scope scope) throws IOException {
    final boolean failToGet = (scope == Scope.LOCAL) ? failToGetLocalState : failToGetClusterState;
    if (failToGet) {
        throw new IOException("Unit Test configured to throw IOException if " + scope + " State is retrieved");
    }
}
 
Example 15
Source File: MockStateManager.java    From nifi with Apache License 2.0 4 votes vote down vote up
private void verifyCanSet(final Scope scope) throws IOException {
    final boolean failToSet = (scope == Scope.LOCAL) ? failToSetLocalState : failToSetClusterState;
    if (failToSet) {
        throw new IOException("Unit Test configured to throw IOException if " + scope + " State is set");
    }
}
 
Example 16
Source File: NopStateProvider.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
@Override
public Scope[] getSupportedScopes() {
    return new Scope[] {Scope.LOCAL};
}
 
Example 17
Source File: MockStateManager.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
private void verifyCanGet(final Scope scope) throws IOException {
    final boolean failToGet = (scope == Scope.LOCAL) ? failToGetLocalState : failToGetClusterState;
    if (failToGet) {
        throw new IOException("Unit Test configured to throw IOException if " + scope + " State is retrieved");
    }
}
 
Example 18
Source File: MockStateManager.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
private void verifyCanSet(final Scope scope) throws IOException {
    final boolean failToSet = (scope == Scope.LOCAL) ? failToSetLocalState : failToSetClusterState;
    if (failToSet) {
        throw new IOException("Unit Test configured to throw IOException if " + scope + " State is set");
    }
}
 
Example 19
Source File: MockStateManager.java    From nifi with Apache License 2.0 3 votes vote down vote up
/**
 * Specifies whether or not the State Manager should throw an IOException when state is set for the given scope.
 * Note that calls to {@link #replace(StateMap, Map, Scope)} will fail only if the state would be set (i.e., if
 * we call replace and the StateMap does not match the old value, it will not fail).
 *
 * Also note that if setting state is set to fail, clearing will also fail, as clearing is thought of as setting the
 * state to empty
 *
 * @param scope the scope that should (or should not) fail
 * @param fail whether or not setting state should fail
 */
public void setFailOnStateSet(final Scope scope, final boolean fail) {
    if (scope == Scope.LOCAL) {
        failToSetLocalState = fail;
    } else {
        failToSetClusterState = fail;
    }
}
 
Example 20
Source File: MockStateManager.java    From localization_nifi with Apache License 2.0 3 votes vote down vote up
/**
 * Specifies whether or not the State Manager should throw an IOException when state is set for the given scope.
 * Note that calls to {@link #replace(StateMap, Map, Scope)} will fail only if the state would be set (i.e., if
 * we call replace and the StateMap does not match the old value, it will not fail).
 *
 * Also note that if setting state is set to fail, clearing will also fail, as clearing is thought of as setting the
 * state to empty
 *
 * @param scope the scope that should (or should not) fail
 * @param fail whether or not setting state should fail
 */
public void setFailOnStateSet(final Scope scope, final boolean fail) {
    if (scope == Scope.LOCAL) {
        failToSetLocalState = fail;
    } else {
        failToSetClusterState = fail;
    }
}