• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt/router/db-4.8.30/examples_java/src/db/repquote_gsg/
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_gsg;
10
11import java.util.Vector;
12
13import com.sleepycat.db.ReplicationHostAddress;
14import com.sleepycat.db.ReplicationManagerStartPolicy;
15
16public class RepConfig
17{
18    // Constant values used in the RepQuote application.
19    public static final String progname = "RepQuoteExampleGSG";
20    public static final int CACHESIZE = 10 * 1024 * 1024;
21    public static final int SLEEPTIME = 5000;
22
23    // Member variables containing configuration information.
24    // String specifying the home directory for rep files.
25    public String home;
26    // Stores an optional set of "other" hosts.
27    public Vector<ReplicationHostAddress> otherHosts;
28    // Priority within the replication group.
29    public int priority;
30    public ReplicationManagerStartPolicy startPolicy;
31    // The host address to listen to.
32    public ReplicationHostAddress thisHost;
33    // Optional parameter specifying the # of sites in the
34    // replication group.
35    public int totalSites;
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        currOtherHost = 0;
49        thisHost = new ReplicationHostAddress();
50        otherHosts = new Vector<ReplicationHostAddress>();
51    }
52
53    public java.io.File getHome()
54    {
55        return new java.io.File(home);
56    }
57
58    public void setThisHost(String host, int port)
59    {
60        gotListenAddress = true;
61        thisHost.port = port;
62        thisHost.host = host;
63    }
64
65    public ReplicationHostAddress getThisHost()
66    {
67        if (!gotListenAddress)
68            System.err.println("Warning: no host specified, returning default.");
69        return thisHost;
70    }
71
72    public boolean gotListenAddress() {
73        return gotListenAddress;
74    }
75
76    public void addOtherHost(String host, int port)
77    {
78        ReplicationHostAddress newInfo = new ReplicationHostAddress(host, port);
79        otherHosts.add(newInfo);
80    }
81
82    public ReplicationHostAddress getFirstOtherHost()
83    {
84        currOtherHost = 0;
85        if (otherHosts.size() == 0)
86            return null;
87        return (ReplicationHostAddress)otherHosts.get(currOtherHost);
88    }
89
90    public ReplicationHostAddress getNextOtherHost()
91    {
92        currOtherHost++;
93        if (currOtherHost >= otherHosts.size())
94            return null;
95        return (ReplicationHostAddress)otherHosts.get(currOtherHost);
96    }
97
98    public ReplicationHostAddress getOtherHost(int i)
99    {
100        if (i >= otherHosts.size())
101            return null;
102        return (ReplicationHostAddress)otherHosts.get(i);
103    }
104}
105
106