Package gridool.routing

Examples of gridool.routing.GridNodeSelector


        final BindingVariable bindingVar = mapExpr.getBindingVariable();
        final XQExpression bodyExpr = mapExpr.getBodyExpression();
        final byte[] exprBytes = DispatchQueryExecTask.toBytes(bindingVar, bodyExpr);

        final GridNodeSelector selector = config.getNodeSelector();
        assert (selector != null);

        final Map<GridNode, List<String>> nodeKeysMap = new HashMap<GridNode, List<String>>(numLiveNodes);
        final Map<GridTask, GridNode> map = new IdentityHashMap<GridTask, GridNode>(numLiveNodes);

        for(Map.Entry<String, List<GridNode>> entry : mapping.entrySet()) {
            final String key = entry.getKey();
            final List<GridNode> candidateNodes = entry.getValue();
            assert (!candidateNodes.isEmpty());

            final GridNode node = selector.selectNode(candidateNodes, config);
            candidateNodes.clear(); // let GC do its work

            List<String> mappedKeys = nodeKeysMap.get(node);
            if(mappedKeys == null) {
                mappedKeys = new ArrayList<String>(128);
View Full Code Here


        final GridNodeInfo localNode = config.getLocalNode();
        if(!_excludeNodeList.contains(localNode)) {
            _excludeNodeList.add(localNode);
        }
        final GridNodeSelector nodeSelector = config.getNodeSelector();
        final LockManager lockManager = directory.getLockManager();

        final Map<GridNode, List<String>> assignMap = new HashMap<GridNode, List<String>>(_relativePaths.size());
        final List<Pair<String, Lock>> localExecResources = new ArrayList<Pair<String, Lock>>(_relativePaths.size());

        int totalLocked = 0;
        for(String path : _relativePaths) {
            ReadWriteLock lock = lockManager.obtainLock(path);
            final Lock rlock = lock.readLock();
            if(rlock.tryLock()) {
                localExecResources.add(new Pair<String, Lock>(path, rlock));
            } else {
                totalLocked++;
                final byte[] k = StringUtils.getBytes(path);
                final GridNodeValueCollector collector = new GridNodeValueCollector(_excludeNodeList);
                try {
                    directory.exactSearch(k, collector);
                } catch (DbException e) {
                    String errmsg = "Exception caused while lookup: " + path;
                    LOG.error(errmsg, e);
                    throw new GridException(errmsg, e);
                }
                final List<GridNode> replicatedNodes = collector.getMatched();
                if(replicatedNodes == null || replicatedNodes.isEmpty()) {
                    throw new GridException("No replicated document found for path: " + path);
                }
                // TODO Select a node that least recently used for write requests.
                GridNode node = nodeSelector.selectNode(replicatedNodes, config);
                assert (node != null);
                List<String> mappedPaths = assignMap.get(node);
                if(mappedPaths == null) {
                    mappedPaths = new ArrayList<String>(16);
                    assignMap.put(node, mappedPaths);
View Full Code Here

            return Collections.emptyMap();
        }

        final BindingVariable bindingVar = mapExpr.getBindingVariable();
        final XQExpression bodyExpr = mapExpr.getBodyExpression();
        final GridNodeSelector selector = config.getNodeSelector();
        assert (selector != null);

        final Map<GridNode, List<String>> nodeKeysMap = new HashMap<GridNode, List<String>>(numLiveNodes);
        final Map<GridTask, GridNode> map = new IdentityHashMap<GridTask, GridNode>(numLiveNodes);

        for(Map.Entry<String, List<GridNode>> entry : mapping.entrySet()) {
            final String key = entry.getKey();
            final List<GridNode> candidateNodes = entry.getValue();
            assert (!candidateNodes.isEmpty());

            final GridNode node = selector.selectNode(candidateNodes, null, config);
            candidateNodes.clear(); // let GC do its work

            List<String> mappedKeys = nodeKeysMap.get(node);
            if(mappedKeys == null) {
                mappedKeys = new ArrayList<String>(128);
View Full Code Here

        final GridNodeInfo localNode = GridUtils.getLocalNode(config);
        if(!excludeNodeList.contains(localNode)) {
            excludeNodeList.add(localNode);
        }
        final GridNodeSelector nodeSelector = config.getNodeSelector();
        final LockManager lockManager = directory.getLockManager();

        final Map<GridNode, List<String>> assignMap = new HashMap<GridNode, List<String>>(relativePaths.size());
        final List<Pair<String, Lock>> localExecResources = new ArrayList<Pair<String, Lock>>(relativePaths.size());

        int totalLocked = 0;
        for(String path : relativePaths) {
            ReadWriteLock lock = lockManager.obtainLock(path);
            final Lock rlock = lock.readLock();
            if(rlock.tryLock()) {
                localExecResources.add(new Pair<String, Lock>(path, rlock));
            } else {
                totalLocked++;
                final List<GridNode> replicatedNodes;
                try {
                    replicatedNodes = directory.exactSearch(path, excludeNodeList);
                } catch (DbException e) {
                    LOG.error(e.getMessage());
                    throw new GridException("Exception caused while lookup: " + path, e);
                }
                if(replicatedNodes == null || replicatedNodes.isEmpty()) {
                    throw new GridException("No replicated document found for path: " + path);
                }
                // TODO Select a node that least recently used for write requests.
                GridNode node = nodeSelector.selectNode(replicatedNodes, this, config);
                assert (node != null);
                List<String> mappedPaths = assignMap.get(node);
                if(mappedPaths == null) {
                    mappedPaths = new ArrayList<String>(16);
                    assignMap.put(node, mappedPaths);
View Full Code Here

TOP

Related Classes of gridool.routing.GridNodeSelector

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.