1 21 package net.sf.hajdbc.balancer; 22 23 import java.util.ArrayList ; 24 import java.util.Collection ; 25 import java.util.Collections ; 26 import java.util.List ; 27 28 import net.sf.hajdbc.Balancer; 29 import net.sf.hajdbc.Database; 30 31 37 public abstract class AbstractBalancer implements Balancer 38 { 39 42 public void beforeOperation(Database database) 43 { 44 } 46 47 50 public void afterOperation(Database database) 51 { 52 } 54 55 58 public synchronized boolean remove(Database database) 59 { 60 return this.getDatabases().remove(database); 61 } 62 63 66 public synchronized boolean add(Database database) 67 { 68 return this.getDatabases().contains(database) ? false : this.getDatabases().add(database); 69 } 70 71 74 public synchronized boolean contains(Database database) 75 { 76 return this.getDatabases().contains(database); 77 } 78 79 82 public synchronized Database first() 83 { 84 return this.getDatabases().iterator().next(); 85 } 86 87 90 public synchronized List <Database> list() 91 { 92 List <Database> list = new ArrayList <Database>(this.getDatabases()); 93 94 Collections.sort(list); 95 96 return Collections.unmodifiableList(list); 97 } 98 99 103 protected abstract Collection <Database> getDatabases(); 104 } 105 | Popular Tags |