Main Page | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Related Pages

ReplicationStatus.java

00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 2002-2005
00005  *      Sleepycat Software.  All rights reserved.
00006  *
00007  * $Id: ReplicationStatus.java,v 12.2 2005/06/16 20:23:03 bostic Exp $
00008  */
00009 
00010 package com.sleepycat.db;
00011 
00012 import com.sleepycat.db.internal.DbConstants;
00013 import com.sleepycat.db.internal.DbEnv;
00014 
00015 public final class ReplicationStatus {
00016     static final ReplicationStatus SUCCESS =
00017         new ReplicationStatus("SUCCESS", 0);
00018 
00019     private int errCode;
00020     private DatabaseEntry cdata;
00021     private int envid;
00022     private LogSequenceNumber lsn;
00023 
00024     /* For toString */
00025     private String statusName;
00026 
00027     private ReplicationStatus(final String statusName,
00028                               final int errCode,
00029                               final DatabaseEntry cdata,
00030                               final int envid,
00031                               final LogSequenceNumber lsn) {
00032         this.statusName = statusName;
00033         this.errCode = errCode;
00034         this.cdata = cdata;
00035         this.envid = envid;
00036         this.lsn = lsn;
00037     }
00038 
00039     private ReplicationStatus(final String statusName, final int errCode) {
00040         this(statusName, errCode, null, 0, null);
00041     }
00042 
00043     public boolean isSuccess() {
00044         return errCode == 0;
00045     }
00046 
00047     public boolean isIgnore() {
00048         return errCode == DbConstants.DB_REP_IGNORE;
00049     }
00050 
00051     public boolean isPermanent() {
00052         return errCode == DbConstants.DB_REP_ISPERM;
00053     }
00054 
00055     public boolean isNewMaster() {
00056         return errCode == DbConstants.DB_REP_NEWMASTER;
00057     }
00058 
00059     public boolean isNewSite() {
00060         return errCode == DbConstants.DB_REP_NEWSITE;
00061     }
00062 
00063     public boolean isNotPermanent() {
00064         return errCode == DbConstants.DB_REP_NOTPERM;
00065     }
00066 
00067     public boolean isStartupDone() {
00068         return errCode == DbConstants.DB_REP_STARTUPDONE;
00069     }
00070 
00071     public DatabaseEntry getCData() {
00072         return cdata;
00073     }
00074 
00075     public int getEnvID() {
00076         return envid;
00077     }
00078 
00079     public LogSequenceNumber getLSN() {
00080         return lsn;
00081     }
00082 
00083     public String toString() {
00084         return "ReplicationStatus." + statusName;
00085     }
00086 
00087     /* package */
00088     static ReplicationStatus getStatus(final int errCode,
00089                                        final DatabaseEntry cdata,
00090                                        final int envid,
00091                                        final LogSequenceNumber lsn) {
00092         switch(errCode) {
00093         case 0:
00094             return SUCCESS;
00095         case DbConstants.DB_REP_IGNORE:
00096             return IGNORE;
00097         case DbConstants.DB_REP_ISPERM:
00098             return new ReplicationStatus("ISPERM", errCode, cdata, envid, lsn);
00099         case DbConstants.DB_REP_NEWMASTER:
00100             return new ReplicationStatus("NEWMASTER", errCode, cdata, envid, lsn);
00101         case DbConstants.DB_REP_NEWSITE:
00102             return new ReplicationStatus("NEWSITE", errCode, cdata, envid, lsn);
00103         case DbConstants.DB_REP_NOTPERM:
00104             return new ReplicationStatus("NOTPERM", errCode, cdata, envid, lsn);
00105         case DbConstants.DB_REP_STARTUPDONE:
00106             return STARTUPDONE;
00107         default:
00108             throw new IllegalArgumentException(
00109                 "Unknown error code: " + DbEnv.strerror(errCode));
00110         }
00111     }
00112 
00113     private static final ReplicationStatus IGNORE =
00114         new ReplicationStatus("IGNORE", DbConstants.DB_REP_STARTUPDONE);
00115     private static final ReplicationStatus STARTUPDONE =
00116         new ReplicationStatus("STARTUPDONE", DbConstants.DB_REP_STARTUPDONE);
00117 }

Generated on Sun Dec 25 12:14:33 2005 for Berkeley DB 4.4.16 by  doxygen 1.4.2