1 package org.sapia.ubik.rmi.replication; 2 3 import org.sapia.ubik.net.ServerAddress; 4 5 import java.util.Set ; 6 7 8 19 public class ReplicationStrategy { 20 private Set _visited; 21 private Set _targets; 22 private Set _siblings; 23 24 33 public ReplicationStrategy(Set visited, Set targets, Set existing) { 34 _visited = visited; 35 _targets = targets; 36 _siblings = existing; 37 } 38 39 45 public ServerAddress selectNextSibling() { 46 ServerAddress toReturn; 47 48 if (_targets == null) { 49 _siblings.removeAll(_visited); 50 51 if (_siblings.size() == 0) { 52 return null; 53 } 54 55 toReturn = (ServerAddress) _siblings.iterator().next(); 56 } else { 57 _siblings.retainAll(_targets); 58 _siblings.removeAll(_visited); 59 60 if (_siblings.size() == 0) { 61 return null; 62 } 63 64 toReturn = (ServerAddress) _siblings.iterator().next(); 65 } 66 67 _visited.add(toReturn); 68 69 return toReturn; 70 } 71 } 72 | Popular Tags |