Search in sources :

Example 26 with HashSet

use of java.util.HashSet in project groovy by apache.

the class GeneralUtils method getInterfacesAndSuperInterfaces.

public static Set<ClassNode> getInterfacesAndSuperInterfaces(ClassNode type) {
    Set<ClassNode> res = new HashSet<ClassNode>();
    if (type.isInterface()) {
        res.add(type);
        return res;
    }
    ClassNode next = type;
    while (next != null) {
        res.addAll(next.getAllInterfaces());
        next = next.getSuperClass();
    }
    return res;
}
Also used : ClassNode(org.codehaus.groovy.ast.ClassNode) HashSet(java.util.HashSet)

Example 27 with HashSet

use of java.util.HashSet in project hadoop by apache.

the class LdapGroupsMapping method lookupGroup.

/**
   * Perform the second query to get the groups of the user.
   *
   * If posixGroups is enabled, use use posix gid/uid to find.
   * Otherwise, use the general group member attribute to find it.
   *
   * @param result the result object returned from the prior user lookup.
   * @param c the context object of the LDAP connection.
   * @return a list of strings representing group names of the user.
   * @throws NamingException if unable to find group names
   */
private List<String> lookupGroup(SearchResult result, DirContext c, int goUpHierarchy) throws NamingException {
    List<String> groups = new ArrayList<String>();
    Set<String> groupDNs = new HashSet<String>();
    NamingEnumeration<SearchResult> groupResults = null;
    // perform the second LDAP query
    if (isPosix) {
        groupResults = lookupPosixGroup(result, c);
    } else {
        String userDn = result.getNameInNamespace();
        groupResults = c.search(baseDN, "(&" + groupSearchFilter + "(" + groupMemberAttr + "={0}))", new Object[] { userDn }, SEARCH_CONTROLS);
    }
    // returned. Get group names from the returned objects.
    if (groupResults != null) {
        while (groupResults.hasMoreElements()) {
            SearchResult groupResult = groupResults.nextElement();
            getGroupNames(groupResult, groups, groupDNs, goUpHierarchy > 0);
        }
        if (goUpHierarchy > 0 && !isPosix) {
            // convert groups to a set to ensure uniqueness
            Set<String> groupset = new HashSet<String>(groups);
            goUpGroupHierarchy(groupDNs, goUpHierarchy, groupset);
            // convert set back to list for compatibility
            groups = new ArrayList<String>(groupset);
        }
    }
    return groups;
}
Also used : ArrayList(java.util.ArrayList) SearchResult(javax.naming.directory.SearchResult) HashSet(java.util.HashSet)

Example 28 with HashSet

use of java.util.HashSet in project flink by apache.

the class NFACompiler method compileFactory.

/**
	 * Compiles the given pattern into a {@link NFAFactory}. The NFA factory can be used to create
	 * multiple NFAs.
	 *
	 * @param pattern Definition of sequence pattern
	 * @param inputTypeSerializer Serializer for the input type
	 * @param timeoutHandling True if the NFA shall return timed out event patterns
	 * @param <T> Type of the input events
	 * @return Factory for NFAs corresponding to the given pattern
	 */
@SuppressWarnings("unchecked")
public static <T> NFAFactory<T> compileFactory(Pattern<T, ?> pattern, TypeSerializer<T> inputTypeSerializer, boolean timeoutHandling) {
    if (pattern == null) {
        // return a factory for empty NFAs
        return new NFAFactoryImpl<T>(inputTypeSerializer, 0, Collections.<State<T>>emptyList(), timeoutHandling);
    } else {
        // set of all generated states
        Map<String, State<T>> states = new HashMap<>();
        long windowTime;
        // this is used to enforse pattern name uniqueness.
        Set<String> patternNames = new HashSet<>();
        Pattern<T, ?> succeedingPattern;
        State<T> succeedingState;
        Pattern<T, ?> currentPattern = pattern;
        // we're traversing the pattern from the end to the beginning --> the first state is the final state
        State<T> currentState = new State<>(currentPattern.getName(), State.StateType.Final);
        patternNames.add(currentPattern.getName());
        states.put(currentPattern.getName(), currentState);
        windowTime = currentPattern.getWindowTime() != null ? currentPattern.getWindowTime().toMilliseconds() : 0L;
        while (currentPattern.getPrevious() != null) {
            succeedingPattern = currentPattern;
            succeedingState = currentState;
            currentPattern = currentPattern.getPrevious();
            if (!patternNames.add(currentPattern.getName())) {
                throw new MalformedPatternException("Duplicate pattern name: " + currentPattern.getName() + ". " + "Pattern names must be unique.");
            }
            Time currentWindowTime = currentPattern.getWindowTime();
            if (currentWindowTime != null && currentWindowTime.toMilliseconds() < windowTime) {
                // the window time is the global minimum of all window times of each state
                windowTime = currentWindowTime.toMilliseconds();
            }
            if (states.containsKey(currentPattern.getName())) {
                currentState = states.get(currentPattern.getName());
            } else {
                currentState = new State<>(currentPattern.getName(), State.StateType.Normal);
                states.put(currentState.getName(), currentState);
            }
            currentState.addStateTransition(new StateTransition<T>(StateTransitionAction.TAKE, succeedingState, (FilterFunction<T>) succeedingPattern.getFilterFunction()));
            if (succeedingPattern instanceof FollowedByPattern) {
                // the followed by pattern entails a reflexive ignore transition
                currentState.addStateTransition(new StateTransition<T>(StateTransitionAction.IGNORE, currentState, null));
            }
        }
        // add the beginning state
        final State<T> beginningState;
        if (states.containsKey(BEGINNING_STATE_NAME)) {
            beginningState = states.get(BEGINNING_STATE_NAME);
        } else {
            beginningState = new State<>(BEGINNING_STATE_NAME, State.StateType.Start);
            states.put(BEGINNING_STATE_NAME, beginningState);
        }
        beginningState.addStateTransition(new StateTransition<T>(StateTransitionAction.TAKE, currentState, (FilterFunction<T>) currentPattern.getFilterFunction()));
        return new NFAFactoryImpl<T>(inputTypeSerializer, windowTime, new HashSet<>(states.values()), timeoutHandling);
    }
}
Also used : FilterFunction(org.apache.flink.api.common.functions.FilterFunction) HashMap(java.util.HashMap) Time(org.apache.flink.streaming.api.windowing.time.Time) FollowedByPattern(org.apache.flink.cep.pattern.FollowedByPattern) State(org.apache.flink.cep.nfa.State) HashSet(java.util.HashSet)

Example 29 with HashSet

use of java.util.HashSet in project flink by apache.

the class FlinkResourceManager method jobManagerLeaderConnected.

/**
	 * Callback when we're informed about a new leading JobManager.
	 * @param newJobManagerLeader The ActorRef of the new jobManager
	 * @param workers The existing workers the JobManager has registered.
	 */
private void jobManagerLeaderConnected(ActorRef newJobManagerLeader, Collection<ResourceID> workers) {
    if (jobManager == null) {
        LOG.info("Resource Manager associating with leading JobManager {} - leader session {}", newJobManagerLeader, leaderSessionID);
        jobManager = newJobManagerLeader;
        if (workers.size() > 0) {
            LOG.info("Received TaskManagers that were registered at the leader JobManager. " + "Trying to consolidate.");
            // keep track of which TaskManagers are not handled
            Set<ResourceID> toHandle = new HashSet<>(workers.size());
            toHandle.addAll(workers);
            try {
                // ask the framework to tell us which ones we should keep for now
                Collection<WorkerType> consolidated = reacceptRegisteredWorkers(workers);
                LOG.info("Consolidated {} TaskManagers", consolidated.size());
                // put the consolidated TaskManagers into our bookkeeping
                for (WorkerType worker : consolidated) {
                    ResourceID resourceID = worker.getResourceID();
                    startedWorkers.put(resourceID, worker);
                    toHandle.remove(resourceID);
                }
            } catch (Throwable t) {
                LOG.error("Error during consolidation of known TaskManagers", t);
                // the framework should release the remaining unclear resources
                for (ResourceID id : toHandle) {
                    releasePendingWorker(id);
                }
            }
        }
        // trigger initial check for requesting new workers
        checkWorkersPool();
    } else {
        String msg = "Attempting to associate with new JobManager leader " + newJobManagerLeader + " without previously disassociating from current leader " + jobManager;
        fatalError(msg, new Exception(msg));
    }
}
Also used : ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) HashSet(java.util.HashSet)

Example 30 with HashSet

use of java.util.HashSet in project flink by apache.

the class HeapListStateTest method testMerging.

@Test
public void testMerging() throws Exception {
    final ListStateDescriptor<Long> stateDescr = new ListStateDescriptor<>("my-state", Long.class);
    stateDescr.initializeSerializerUnlessSet(new ExecutionConfig());
    final Integer namespace1 = 1;
    final Integer namespace2 = 2;
    final Integer namespace3 = 3;
    final Set<Long> expectedResult = new HashSet<>(asList(11L, 22L, 33L, 44L, 55L));
    final HeapKeyedStateBackend<String> keyedBackend = createKeyedBackend();
    try {
        InternalListState<Integer, Long> state = keyedBackend.createListState(IntSerializer.INSTANCE, stateDescr);
        // populate the different namespaces
        //  - abc spreads the values over three namespaces
        //  - def spreads teh values over two namespaces (one empty)
        //  - ghi is empty
        //  - jkl has all elements already in the target namespace
        //  - mno has all elements already in one source namespace
        keyedBackend.setCurrentKey("abc");
        state.setCurrentNamespace(namespace1);
        state.add(33L);
        state.add(55L);
        state.setCurrentNamespace(namespace2);
        state.add(22L);
        state.add(11L);
        state.setCurrentNamespace(namespace3);
        state.add(44L);
        keyedBackend.setCurrentKey("def");
        state.setCurrentNamespace(namespace1);
        state.add(11L);
        state.add(44L);
        state.setCurrentNamespace(namespace3);
        state.add(22L);
        state.add(55L);
        state.add(33L);
        keyedBackend.setCurrentKey("jkl");
        state.setCurrentNamespace(namespace1);
        state.add(11L);
        state.add(22L);
        state.add(33L);
        state.add(44L);
        state.add(55L);
        keyedBackend.setCurrentKey("mno");
        state.setCurrentNamespace(namespace3);
        state.add(11L);
        state.add(22L);
        state.add(33L);
        state.add(44L);
        state.add(55L);
        keyedBackend.setCurrentKey("abc");
        state.mergeNamespaces(namespace1, asList(namespace2, namespace3));
        state.setCurrentNamespace(namespace1);
        validateResult(state.get(), expectedResult);
        keyedBackend.setCurrentKey("def");
        state.mergeNamespaces(namespace1, asList(namespace2, namespace3));
        state.setCurrentNamespace(namespace1);
        validateResult(state.get(), expectedResult);
        keyedBackend.setCurrentKey("ghi");
        state.mergeNamespaces(namespace1, asList(namespace2, namespace3));
        state.setCurrentNamespace(namespace1);
        assertNull(state.get());
        keyedBackend.setCurrentKey("jkl");
        state.mergeNamespaces(namespace1, asList(namespace2, namespace3));
        state.setCurrentNamespace(namespace1);
        validateResult(state.get(), expectedResult);
        keyedBackend.setCurrentKey("mno");
        state.mergeNamespaces(namespace1, asList(namespace2, namespace3));
        state.setCurrentNamespace(namespace1);
        validateResult(state.get(), expectedResult);
        // make sure all lists / maps are cleared
        keyedBackend.setCurrentKey("abc");
        state.setCurrentNamespace(namespace1);
        state.clear();
        keyedBackend.setCurrentKey("def");
        state.setCurrentNamespace(namespace1);
        state.clear();
        keyedBackend.setCurrentKey("ghi");
        state.setCurrentNamespace(namespace1);
        state.clear();
        keyedBackend.setCurrentKey("jkl");
        state.setCurrentNamespace(namespace1);
        state.clear();
        keyedBackend.setCurrentKey("mno");
        state.setCurrentNamespace(namespace1);
        state.clear();
        StateTable<String, Integer, ArrayList<Long>> stateTable = ((HeapListState<String, Integer, Long>) state).stateTable;
        assertTrue(stateTable.isEmpty());
    } finally {
        keyedBackend.close();
        keyedBackend.dispose();
    }
}
Also used : ListStateDescriptor(org.apache.flink.api.common.state.ListStateDescriptor) ArrayList(java.util.ArrayList) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

HashSet (java.util.HashSet)12137 Set (java.util.Set)2609 ArrayList (java.util.ArrayList)2318 HashMap (java.util.HashMap)2096 Test (org.junit.Test)2060 Map (java.util.Map)1198 Iterator (java.util.Iterator)979 IOException (java.io.IOException)934 List (java.util.List)911 File (java.io.File)607 LinkedHashSet (java.util.LinkedHashSet)460 Test (org.testng.annotations.Test)460 TreeSet (java.util.TreeSet)271 Collection (java.util.Collection)233 LinkedList (java.util.LinkedList)224 Region (org.apache.geode.cache.Region)202 SSOException (com.iplanet.sso.SSOException)188 Date (java.util.Date)180 LinkedHashMap (java.util.LinkedHashMap)169 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)166