Skip to content
Snippets Groups Projects
REFITOrderProtocol.java 1.58 KiB
Newer Older
  • Learn to ignore specific revisions
  • Michael Eischer's avatar
    Michael Eischer committed
    package refit.replica.order;
    
    import refit.config.REFITConfig;
    import refit.replica.REFITReplicaGroups;
    
    
    public abstract class REFITOrderProtocol {
    
    	protected static final boolean[] NO_REPLICA = new boolean[REFITConfig.TOTAL_NR_OF_REPLICAS];
    	protected static final boolean[] ALL_REPLICAS = REFITReplicaGroups.getAllReplicas();
    
    
    	// ####################
    	// # ABSTRACT METHODS #
    	// ####################
    
    	public abstract REFITOrderProtocolInstance createInstance(REFITOrderStageSlot slot);
    
    	public abstract REFITOrderProtocolTransitionInstance createTransitionInstance(REFITOrderStageSlot slot);
    
    	// ###################
    	// # DEFAULT METHODS #
    	// ###################
    
    	public boolean[] getActiveOrderRecipients(int groupID) {
    		// currently active order replicas
    		return REFITOrderGroups.getGroupByID(groupID);
    	}
    
    	public boolean[] getAllOrderRecipients(int groupID) {
    		// full set of order replicas
    		return REFITOrderGroups.getGroupByID(groupID);
    	}
    
    	public boolean[] getUpdateRecipients() {
    		return NO_REPLICA;
    	}
    
    	public boolean[] getCheckpointRecipients() {
    		return ALL_REPLICAS;
    	}
    
    	public boolean useLightweightCheckpoints() {
    		return false;
    	}
    
    
    	// ##################
    	// # HELPER METHODS #
    	// ##################
    
    	public boolean hasCheckpointRecipients() {
    		boolean[] recipients = getCheckpointRecipients();
    		for (boolean recipient : recipients) {
    			if (recipient) return true;
    		}
    		return false;
    	}
    
    	public boolean hasUpdateRecipients() {
    		boolean[] recipients = getUpdateRecipients();
    		for (boolean recipient : recipients) {
    			if (recipient) return true;
    		}
    		return false;
    	}
    
    }