All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sapia.ubik.rmi.replication.ReplicationStrategy Maven / Gradle / Ivy

The newest version!
package org.sapia.ubik.rmi.replication;

import org.sapia.ubik.net.ServerAddress;

import java.util.Set;


/**
 * This class implements the logic that selects the next server to which a replicated command
 * should be dispatched.
 *
 * @author Yanick Duchesne
 * 
*
Copyright:
Copyright © 2002-2004 Sapia Open Source Software. All Rights Reserved.
*
License:
Read the license.txt file of the jar or visit the * license page at the Sapia OSS web site
*
*/ public class ReplicationStrategy { private Set _visited; private Set _targets; private Set _siblings; /** * @param visited the Set of ServerAddresses of the hosts * that have already been visited. * @param targets the Set of ServerAddresses corresponding to * targeted hosts - if null, then the strategy assumes that all hosts must * be visited. * @param existing the Set of ServerAddresses corresponding to * the existing hosts. */ public ReplicationStrategy(Set visited, Set targets, Set existing) { _visited = visited; _targets = targets; _siblings = existing; } /** * @return the ServerAddress of the next sibling host to which replication * should be made. null is returned if there is no "next" host to which to * replicate - all hosts have been visited. Note: if not null, the returned address * is added to the set of visited ones. */ public ServerAddress selectNextSibling() { ServerAddress toReturn; if (_targets == null) { _siblings.removeAll(_visited); if (_siblings.size() == 0) { return null; } toReturn = (ServerAddress) _siblings.iterator().next(); } else { _siblings.retainAll(_targets); _siblings.removeAll(_visited); if (_siblings.size() == 0) { return null; } toReturn = (ServerAddress) _siblings.iterator().next(); } _visited.add(toReturn); return toReturn; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy