1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002, 2013 Oracle and/or its affiliates.  All rights reserved.
5  *
6  * $Id$
7  */
8 
9 package com.sleepycat.db;
10 
11 import com.sleepycat.db.internal.DbConstants;
12 
13 /**
14 This class provides definitions of the various start policies thatcan be specified when starting a replication client using the{@link com.sleepycat.db.Environment#replicationManagerStart Environment.replicationManagerStart} call.
15 */
16 public final class ReplicationManagerStartPolicy {
17 
18     /**
19     Start as a master site, and do not call for an election. Note there must
20     never be more than a single master in any replication group, and only one
21     site should ever be started with the DB_REP_MASTER flag specified.
22     */
23     public static final ReplicationManagerStartPolicy REP_MASTER =
24         new ReplicationManagerStartPolicy(
25         "REP_MASTER", DbConstants.DB_REP_MASTER);
26 
27     /**
28     Start as a client site, and do not call for an election.
29     */
30     public static final ReplicationManagerStartPolicy REP_CLIENT =
31         new ReplicationManagerStartPolicy(
32         "REP_CLIENT", DbConstants.DB_REP_CLIENT);
33 
34     /**
35     Start as a client, and call for an election if no master is found.
36     */
37     public static final ReplicationManagerStartPolicy REP_ELECTION =
38         new ReplicationManagerStartPolicy(
39         "REP_ELECTION", DbConstants.DB_REP_ELECTION);
40 
41     /* package */
fromInt(int type)42     static ReplicationManagerStartPolicy fromInt(int type) {
43         switch(type) {
44         case DbConstants.DB_REP_MASTER:
45             return REP_MASTER;
46         case DbConstants.DB_REP_CLIENT:
47             return REP_CLIENT;
48         case DbConstants.DB_REP_ELECTION:
49             return REP_ELECTION;
50         default:
51             throw new IllegalArgumentException(
52                 "Unknown rep start policy: " + type);
53         }
54     }
55 
56     private String statusName;
57     private int id;
58 
ReplicationManagerStartPolicy(final String statusName, final int id)59     private ReplicationManagerStartPolicy(final String statusName,
60         final int id) {
61 
62         this.statusName = statusName;
63         this.id = id;
64     }
65 
66     /* package */
getId()67     int getId() {
68         return id;
69     }
70 
71     /** {@inheritDoc} */
toString()72     public String toString() {
73         return "ReplicationManagerStartPolicy." + statusName;
74     }
75 }
76 
77