Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.fasterxml.clustermate.client.cluster;
  
  
Value class used by com.fasterxml.clustermate.client.NetworkClient to keep track of state of a single cluster node. Instances are mutable to a degree, and properly synchronized to allow thread-safe use.
 
 public class ClusterServerNodeImpl
     implements ClusterServerNode
 {
    
Address (ip number and port) used for communicating with the node. Note that this is resolved end point in case server node has been configured to use "localhost" (resolution can be done since client has remote address for starting points)
 
     private final IpAndPort _address;

    
Reference to the root path of the server node this object represents; used for constructing references to item entry points and node status accessor.
 
     private final RequestPath _pathBase;
     
     private KeyRange _activeRange;
     private KeyRange _passiveRange;
     private KeyRange _totalRange;
     
     protected final AtomicBoolean _disabled = new AtomicBoolean(false);

    
Time when last request was sent specifically for this server node (i.e. not updated when we get indirect updates)
 
     private final AtomicLong _lastRequestSent = new AtomicLong(0L);

    
Time when last request was sent specifically from this server node (i.e. not updated when we get indirect updates)
 
     private final AtomicLong _lastResponseReceived = new AtomicLong(0L);

    
Timestamp of last update for information regarding this node; regardless of whether directly or indirectly.
 
     private long _lastNodeUpdateFetched = 0L;

    
Timestamp of last version of cluster update from this server node (i.e. not applicable for indirect updates)
 
     private long _lastClusterUpdateFetched = 0L;

    
Timestamp of last version of cluster update that this server node might have; received indirectly via one of GET, PUT or DELETE operations.
 
     private final AtomicLong _lastClusterUpdateAvailable = new AtomicLong(1L);
 
     /*
     /**********************************************************************
     /* Entry accessor handling
     /**********************************************************************
      */
     
     protected final ContentPutter<?> _entryPutter;
     protected final ContentGetter<?> _entryGetter;
     protected final ContentHeader<?> _entryHeader;
     protected final ContentDeleter<?> _entryDeleter;
     protected final EntryLister<?> _entryLister;
     
     /*
     /**********************************************************************
     /* Instance creation
     /**********************************************************************
      */
 
    public ClusterServerNodeImpl(RequestPath pathBase,
            IpAndPort addressKeyRange activeRangeKeyRange passiveRange,
            EntryAccessors<?> entryAccessors)
    {
         = pathBase;
         = address;
         = activeRange;
         = passiveRange;
         = entryAccessors.entryPutter(this);
         = entryAccessors.entryGetter(this);
         = entryAccessors.entryHeader(this);
         = entryAccessors.entryDeleter(this);
         = entryAccessors.entryLister(this);
    }
    // only for test usage
    private ClusterServerNodeImpl(RequestPath pathBase,
            IpAndPort addressKeyRange activeRangeKeyRange passiveRange)
    {
         = pathBase;
         = address;
         = activeRange;
         = passiveRange;
         = null;
         = null;
         = null;
         = null;
         = null;
    }
    
    protected static ClusterServerNodeImpl forTesting(KeyRange range) {
        return forTesting(rangerange);
    }
    protected static ClusterServerNodeImpl forTesting(KeyRange rangeActiveKeyRange rangePassive) {
        return new ClusterServerNodeImpl(null// client not needed for kinds of tests
        		new IpAndPort("localhost:"+rangeActive.getStart()),
                rangeActiverangePassive);
    }
    /*
    /**********************************************************************
    /* Mutations
    /**********************************************************************
     */
    
    

Returns:
True if ranges changed
    public boolean updateRanges(KeyRange activeRangeKeyRange passiveRange)
    {
        if (.equals(activeRange) && .equals(passiveRange)) {
            return false;
        }
         = activeRange;
         = passiveRange;
         = activeRange.union(passiveRange);
        return true;
    }

    

Returns:
True if state changed
    public boolean updateDisabled(boolean state) {
        boolean old = .getAndSet(state);
        return (old != state);
    }

    
Method called to update cluster info timestamps, based on header received during regular CRUD operations.

Returns:
True if state changed
    public boolean updateLastClusterUpdateAvailable(long requestTimelong responseTime,
            long timestamp)
    {
        if (.get() < responseTime) {
            .set(requestTime);
            .set(responseTime);
            long old = .getAndSet(timestamp);
            return (old != timestamp);
        }
        return false;
    }
    
    public void setLastRequestSent(long timestamp) {
        .set(timestamp);
    }
    public void setLastResponseReceived(long timestamp) {
        .set(timestamp);
    }
    public void setLastNodeUpdateFetched(long timestamp) {
         = timestamp;
    }
    public void setLastClusterUpdateFetched(long timestamp) {
         = timestamp;
    }
    public void setLastClusterUpdateAvailable(long timestamp) {
        .set(timestamp);
    }
    /*
    /**********************************************************************
    /* ReadOnlyServerNodeState implementation (public accessors)
    /**********************************************************************
     */
    @Override
    public IpAndPort getAddress() { return ; }
    @Override
    public KeyRange getActiveRange() { return ; }
    @Override
    public KeyRange getPassiveRange() { return ; }
    @Override
    public KeyRange getTotalRange() { return ; }
    @Override
    public boolean isDisabled() { return .get(); }
    @Override
    public long getLastRequestSent() { return .get(); }
    @Override
    public long getLastResponseReceived() { return .get(); }
    @Override
    public long getLastNodeUpdateFetched() { return ; }
    @Override
    public long getLastClusterUpdateFetched() { return ; }
    @Override
    public long getLastClusterUpdateAvailable() { return .get(); }
    
    /*
    /**********************************************************************
    /* Advanced accessors
    /**********************************************************************
     */

    
Method for calculating distance metrics to use for sorting server nodes based on distance. In addition to basic clock-wise distance from start point we also consider disabled nodes to be further away than any enabled nodes; this is done by adding full length of key space to basic clock-wise distance. *
    public int calculateSortingDistance(KeyHash keyHash)
    {
        /* 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;
    }
    /*
    /**********************************************************************
    /* Call accessors, paths etc
    /**********************************************************************
     */
    
    /*
    @SuppressWarnings("unchecked")
    @Override
    public <P extends RequestPathBuilder> P resourceEndpoint() {
        return (P) _pathBase.builder();
 
    }
    */
    @Override
    public <B extends RequestPathBuilder<B>> B rootPath() {
        return .builder();
    }
    
    @SuppressWarnings("unchecked")
    @Override
    public <K extends EntryKeyContentPutter<K> entryPutter() {
        return (ContentPutter<K>) ;
    }
    @SuppressWarnings("unchecked")
    @Override
    public <K extends EntryKeyContentGetter<K> entryGetter() {
        return (ContentGetter<K>) ;
    }
    @SuppressWarnings("unchecked")
    @Override
    public <K extends EntryKeyContentHeader<K> entryHeader() {
        return (ContentHeader<K>) ;
    }
    @SuppressWarnings("unchecked")
    @Override
    public <K extends EntryKeyContentDeleter<K> entryDeleter() {
        return (ContentDeleter<K>) ;
    }
    @SuppressWarnings("unchecked")
    @Override
    public <K extends EntryKeyEntryLister<K> entryLister() {
        return (EntryLister<K>) ;
    }
New to GrepCode? Check out our FAQ X