Package com.fasterxml.clustermate.api

Examples of com.fasterxml.clustermate.api.KeyRange


    }
   
    protected String _buildNodeStatusUpdateUrl(ClusterViewByServerUpdatable cluster, IpAndPort remote,
            String state)
    {
        final KeyRange syncRange = cluster.getLocalState().totalRange();
        RequestPathBuilder pathBuilder = new JdkHttpClientPathBuilder(remote)
            .addPathSegments(_stuff.getServiceConfig().servicePathRoot);
        pathBuilder = _stuff.getPathStrategy().appendPath(pathBuilder, PathType.NODE_STATUS);
        pathBuilder = pathBuilder.addParameter(ClusterMateConstants.QUERY_PARAM_KEYRANGE_START, String.valueOf(syncRange.getStart()));
        pathBuilder = pathBuilder.addParameter(ClusterMateConstants.QUERY_PARAM_KEYRANGE_LENGTH, String.valueOf(syncRange.getLength()));
        pathBuilder = pathBuilder.addParameter(ClusterMateConstants.QUERY_PARAM_TIMESTAMP,
                String.valueOf(_stuff.getTimeMaster().currentTimeMillis()));
        pathBuilder = pathBuilder.addParameter(ClusterMateConstants.QUERY_PARAM_STATE, state);
        // this will include 'caller' param:
        pathBuilder = cluster.addClusterStateInfo(pathBuilder);
View Full Code Here


        /* Note: while we include things based on passive range, distance
         * should be based on active range; this to make passive range
         * more useful (can catch up with larger passive range; then enable
         * larger range once caught up)
         */
        KeyRange range = getActiveRange();
        int distance = range.clockwiseDistance(keyHash);
        if (isDisabled()) {
            distance += range.getKeyspace().getLength();
        }
        return distance;
    }
View Full Code Here

        try {
            Matcher m = DESC_PATTERN.matcher(ref);
            if (m.matches()) {
                int start = Integer.parseInt(m.group(1));
                int len = Integer.parseInt(m.group(2));
                return new KeyRange(space, start, len);
            }
        } catch (IllegalArgumentException e) { }
        throw new IllegalArgumentException("Invalid KeyRange reference '"+ref+"'");
    }
View Full Code Here

        }
        if (newLength < 0 || newLength > _spaceEnd) {
            throw new IllegalArgumentException("Illegal 'newLength' ("+newLength+"): must be [0, "
                    +_spaceEnd+"]");
        }
        return new KeyRange(_keyspace, _start, newLength);
    }
View Full Code Here

    public boolean equals(Object o)
    {
        if (o == this) return true;
        if (o == null) return false;
        if (o.getClass() != getClass()) return false;
        KeyRange other = (KeyRange) o;
        // should we compare key space directly? No, should be enough to verify space length:
        return (other._start == _start)
                && (other._length == _length)
                && (other._spaceEnd == _spaceEnd);
    }
View Full Code Here

    /**
     * Basic constructor that creates key space with specific length.
     */
    public KeySpace(int length) {
        _length = length;
        _emptyRange = new KeyRange(this, 0, 0);
    }
View Full Code Here

        }
        if (length < 0 || length > _length) {
            throw new IllegalArgumentException("Invalid 'length' argument, "+length+"; must be [0, "
                    +_length+"]");
        }
        return new KeyRange(this, from, length);
    }
View Full Code Here

    /**
     * Factory method for testing
     */
    public KeyRange fullRange() {
        return new KeyRange(this, 0, _length);
    }
View Full Code Here

        /* Note: while we include things based on passive range, distance
         * should be based on active range; this to make passive range
         * more useful (can catch up with larger passive range; then enable
         * larger range once caught up)
         */
        KeyRange range = getActiveRange();
        int distance = range.clockwiseDistance(keyHash);
        if (isDisabled()) {
            distance += range.getKeyspace().getLength();
        }
        return distance;
    }
View Full Code Here

        public BootstrapState() { }

        public RemoteCluster finish(TimeMaster timeMaster, NodeState localState)
        {
            List<RemoteClusterNode> overlapping = new ArrayList<RemoteClusterNode>();
            final KeyRange localRange = localState.totalRange();
            for (RemoteClusterNode node : _nodes.values()) {
                if (localRange.overlapsWith(node.getTotalRange())) {
                    overlapping.add(node);
                }
            }
            if (overlapping.isEmpty()) {
                return null;
            }
            // Also, need to sort in descending order of preference
            Collections.sort(overlapping, new Comparator<RemoteClusterNode>() {
                @Override
                public int compare(RemoteClusterNode c1, RemoteClusterNode c2) {
                    KeyRange r1 = c1.getTotalRange();
                    // First, exact match is the usual way, preferred
                    if (r1.equals(localRange)) {
                        return -1;
                    }
                    KeyRange r2 = c2.getTotalRange();
                    if (r2.equals(localRange)) {
                        return 1;
                    }

                    // If not, let's actually base it on stable clockwise-distance between
                    // starting points, such that we'll try to find range that starts as soon
                    // as possible _after_ local range
                    int dist1 = localRange.clockwiseDistance(r1);
                    int dist2 = localRange.clockwiseDistance(r2);

                    if (dist1 != dist2) {
                        return dist1 - dist2;
                    }
                   
                    // And if this still doesn't resolve, choose one with _smaller_ range; assumption
                    // is that most likely cluster is growing, and smaller range indicates newer
                    // information
                    int diff = r1.getLength() - r2.getLength();
                    if (diff != 0) { // sort from smaller to bigger
                        return diff;
                    }
                   
                    // and otherwise use simple lexicographic (~= alphabetic) ordering of endpoint IP
View Full Code Here

TOP

Related Classes of com.fasterxml.clustermate.api.KeyRange

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.