Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*-
   * See the file LICENSE for redistribution information.
   *
   * Copyright (c) 2002, 2013 Oracle and/or its affiliates.  All rights reserved.
   *
   */
  
  package com.sleepycat.je.rep;
  
 
A consistency policy which describes the amount of time the Replica is allowed to lag the Master. The application can use this policy to ensure that this node sees all transactions that were committed on the Master before the lag interval.

Effective use of this policy requires that the clocks on the Master and Replica are synchronized by using a protocol like NTP

Consistency policies are specified at either a per-transaction level through com.sleepycat.je.TransactionConfig.setConsistencyPolicy(com.sleepycat.je.ReplicaConsistencyPolicy) or as an replication node wide default through ReplicationConfig.setConsistencyPolicy(com.sleepycat.je.ReplicaConsistencyPolicy)

See also:
Managing Consistency
 
 public class TimeConsistencyPolicy implements ReplicaConsistencyPolicy {

    
The name: associated with this policy. The name can be used when constructing policy property values for use in je.properties files.
 
     public static final String NAME = "TimeConsistencyPolicy";
 
     private final int permissibleLag;
 
     /* Amount of time to wait (in ms) for the consistency to be reached. */
     private final int timeout;

    
Specifies the amount of time by which the Replica is allowed to lag the master when initiating a transaction. The Replica ensures that all transactions that were committed on the Master before this lag interval are available at the Replica before allowing a transaction to proceed with Environment.beginTransaction. Effective use of this policy requires that the clocks on the Master and Replica are synchronized by using a protocol like NTP.

Parameters:
permissibleLag the time interval by which the Replica may be out of date with respect to the Master when a transaction is initiated on the Replica.
permissibleLagUnit the TimeUnit for the permissibleLag parameter.
timeout the amount of time to wait for the consistency to be reached.
timeoutUnit the TimeUnit for the timeout parameter.
Throws:
java.lang.IllegalArgumentException if the permissibleLagUnit or timeoutUnit is null.
 
     public TimeConsistencyPolicy(long permissibleLag,
                                  TimeUnit permissibleLagUnit,
                                  long timeout,
                                  TimeUnit timeoutUnit) {
         this. = PropUtil.durationToMillis(permissibleLag,
                                                         permissibleLagUnit);
         this. = PropUtil.durationToMillis(timeouttimeoutUnit);
     }

    
Returns the name: NAME, associated with this policy.

See also:
NAME
 
     public String getName() {
         return ;
     }

    
Returns the allowed time lag associated with this policy.

Parameters:
unit the TimeUnit of the returned value.
Returns:
the permissible lag time in the specified unit.
 
     public long getPermissibleLag(TimeUnit unit) {
         return PropUtil.millisToDuration(unit);
     }

    
Returns the consistency timeout associated with this policy.

Parameters:
unit the TimeUnit of the returned value.
Returns:
the consistency timeout in the specified unit.
    public long getTimeout(TimeUnit unit) {
        return PropUtil.millisToDuration(unit);
    }

    

Hidden:
For internal use only. Ensures that the replica has replayed the replication stream to the point identified by the lag period. If it isn't the method waits until the constraint is satisfied by the replica.
    public void ensureConsistency(EnvironmentImpl replicatorImpl)
        throws InterruptedException,
               ReplicaConsistencyException{
        /*
         * Cast is done to preserve replication/non replication code
         * boundaries.
         */
        RepImpl repImpl = (RepImplreplicatorImpl;
        Replica replica = repImpl.getRepNode().replica();
        replica.getConsistencyTracker().lagAwait(this);
    }
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ;
        result = prime * result + ;
        return result;
    }
    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        TimeConsistencyPolicy other =
            (TimeConsistencyPolicyobj;
        if ( != other.permissibleLag) {
            return false;
        }
        if ( != other.timeout) {
            return false;
        }
        return true;
    }
    @Override
    public String toString(){
        return getName() + " permissibleLag=" + ;
    }
New to GrepCode? Check out our FAQ X