1/*- 2 * See the file LICENSE for redistribution information. 3 * 4 * Copyright (c) 2001-2009 Oracle. All rights reserved. 5 * 6 * $Id$ 7 */ 8 9package db.repquote; 10 11import java.util.Vector; 12 13import com.sleepycat.db.ReplicationHostAddress; 14import com.sleepycat.db.ReplicationManagerAckPolicy; 15import com.sleepycat.db.ReplicationManagerStartPolicy; 16import com.sleepycat.db.ReplicationManagerSiteInfo; 17 18public class RepConfig 19{ 20 /* Constant values used in the RepQuote application. */ 21 public static final String progname = "RepQuoteExample"; 22 public static final int CACHESIZE = 10 * 1024 * 1024; 23 public static final int SLEEPTIME = 5000; 24 25 /* Member variables containing configuration information. */ 26 public ReplicationManagerAckPolicy ackPolicy; 27 public boolean bulk; /* Whether bulk transfer should be performed. */ 28 public String home; /* The home directory for rep files. */ 29 public Vector otherHosts; /* Stores an optional set of "other" hosts. */ 30 public int priority; /* Priority within the replication group. */ 31 public ReplicationManagerStartPolicy startPolicy; 32 public ReplicationHostAddress thisHost; /* Host address to listen to. */ 33 /* Optional value specifying the # of sites in the replication group. */ 34 public int totalSites; 35 public boolean verbose; 36 37 /* Member variables used internally. */ 38 private int currOtherHost; 39 private boolean gotListenAddress; 40 41 public RepConfig() 42 { 43 startPolicy = ReplicationManagerStartPolicy.REP_ELECTION; 44 home = ""; 45 gotListenAddress = false; 46 totalSites = 0; 47 priority = 100; 48 verbose = false; 49 currOtherHost = 0; 50 thisHost = new ReplicationHostAddress(); 51 otherHosts = new Vector(); 52 ackPolicy = ReplicationManagerAckPolicy.QUORUM; 53 bulk = false; 54 } 55 56 public java.io.File getHome() 57 { 58 return new java.io.File(home); 59 } 60 61 public void setThisHost(String host, int port) 62 { 63 gotListenAddress = true; 64 thisHost.port = port; 65 thisHost.host = host; 66 } 67 68 public ReplicationHostAddress getThisHost() 69 { 70 if (!gotListenAddress) 71 System.err.println("Warning: no host specified, returning default."); 72 return thisHost; 73 } 74 75 public boolean gotListenAddress() { 76 return gotListenAddress; 77 } 78 79 public void addOtherHost(String host, int port, boolean peer) 80 { 81 ReplicationHostAddress newInfo = 82 new ReplicationHostAddress(host, port); 83 RepRemoteHost newHost = new RepRemoteHost(newInfo, peer); 84 otherHosts.add(newHost); 85 } 86 87 public RepRemoteHost getFirstOtherHost() 88 { 89 currOtherHost = 0; 90 if (otherHosts.size() == 0) 91 return null; 92 return (RepRemoteHost)otherHosts.get(currOtherHost); 93 } 94 95 public RepRemoteHost getNextOtherHost() 96 { 97 currOtherHost++; 98 if (currOtherHost >= otherHosts.size()) 99 return null; 100 return (RepRemoteHost)otherHosts.get(currOtherHost); 101 } 102 103 public RepRemoteHost getOtherHost(int i) 104 { 105 if (i >= otherHosts.size()) 106 return null; 107 return (RepRemoteHost)otherHosts.get(i); 108 } 109 110} 111 112