1/*-
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 2002,2008 Oracle.  All rights reserved.
5 *
6 * $Id: ReplicationConfig.java,v 12.13 2008/04/23 17:20:53 bschmeck Exp $
7 */
8
9package com.sleepycat.db;
10
11import com.sleepycat.db.internal.DbConstants;
12
13/**
14Settings that configure Berkeley DB replication.  Used in the {@link
15Environment#setReplicationConfig} method.
16*/
17public final class ReplicationConfig implements Cloneable {
18    /**
19    The replication master should send groups of records to the clients in a
20    single network transfer.
21    **/
22    public static final ReplicationConfig BULK =
23        new ReplicationConfig("BULK", DbConstants.DB_REP_CONF_BULK);
24
25    /**
26    The client should delay synchronizing to a newly declared master
27    (defaults to off).  Clients configured in this way will remain
28    unsynchronized until the application calls the
29    {@link Environment#syncReplication} method.
30    **/
31    public static final ReplicationConfig DELAYCLIENT =
32      new ReplicationConfig("DELAYCLIENT", DbConstants.DB_REP_CONF_DELAYCLIENT);
33
34    /**
35    The replication master should not automatically re-initialize outdated
36    clients.
37    **/
38    public static final ReplicationConfig NOAUTOINIT =
39        new ReplicationConfig("NOAUTOINIT", DbConstants.DB_REP_CONF_NOAUTOINIT);
40
41    /**
42    Berkeley DB method calls that would normally block while clients are in
43    recovery should return errors immediately.
44    **/
45    public static final ReplicationConfig NOWAIT =
46        new ReplicationConfig("NOWAIT", DbConstants.DB_REP_CONF_NOWAIT);
47
48    /**
49    Replication Manager observes the strict "majority" rule in managing
50    elections, even in a group with only 2 sites.  This means the client in a
51    2-site group will be unable to take over as master if the original master
52    fails or becomes disconnected.  (See the
53    <a href="{@docRoot}/../ref/rep/elect.html" target="_top">Elections</a>
54    section in the Berkeley DB Reference Guide for more information.)  Both sites
55    in the replication group should have the same value for this parameter.
56    **/
57    public static final ReplicationConfig STRICT_2SITE =
58        new ReplicationConfig("STRICT_2SITE",
59                              DbConstants.DB_REPMGR_CONF_2SITE_STRICT);
60
61    /**
62    Master leases will be used for this site.
63    <p>
64    Configuring this option may result in the {@link Database#get Database.get()}
65    and {@link Cursor Cursor.get*()} methods throwing a
66    {@link DatabaseException} when attempting to read entries from a database
67    after the site's master lease has expired.
68    <p>
69    Once this option is turned on, it may never be turned off.
70    */
71    public static final ReplicationConfig LEASE =
72	new ReplicationConfig("LEASE", DbConstants.DB_REP_CONF_LEASE);
73
74    /* package */
75    static ReplicationConfig fromInt(int which) {
76        switch(which) {
77        case DbConstants.DB_REP_CONF_BULK:
78            return BULK;
79        case DbConstants.DB_REP_CONF_DELAYCLIENT:
80            return DELAYCLIENT;
81        case DbConstants.DB_REP_CONF_NOAUTOINIT:
82            return NOAUTOINIT;
83        case DbConstants.DB_REP_CONF_NOWAIT:
84            return NOWAIT;
85        case DbConstants.DB_REPMGR_CONF_2SITE_STRICT:
86            return STRICT_2SITE;
87	case DbConstants.DB_REP_CONF_LEASE:
88	    return LEASE;
89        default:
90            throw new IllegalArgumentException(
91                "Unknown replication config: " + which);
92        }
93    }
94
95    private String configName;
96    private int flag;
97
98    private ReplicationConfig(final String configName, final int flag) {
99        this.configName = configName;
100        this.flag = flag;
101    }
102
103    /* package */
104    int getFlag() {
105        return flag;
106    }
107
108    /** {@inheritDoc} */
109    public String toString() {
110        return "ReplicationConfig." + configName;
111    }
112}
113