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