1/*- 2 * See the file LICENSE for redistribution information. 3 * 4 * Copyright (c) 2002,2008 Oracle. All rights reserved. 5 * 6 * $Id: CheckpointConfig.java,v 12.7 2008/01/17 05:04:53 mjc Exp $ 7 */ 8 9package com.sleepycat.db; 10 11import com.sleepycat.db.internal.DbEnv; 12import com.sleepycat.db.internal.DbConstants; 13 14/** 15Specifies the attributes of an application invoked checkpoint operation. 16*/ 17public class CheckpointConfig { 18 /** 19 Default configuration used if null is passed to 20 {@link com.sleepycat.db.Environment#checkpoint Environment.checkpoint}. 21 */ 22 public static final CheckpointConfig DEFAULT = new CheckpointConfig(); 23 24 private boolean force = false; 25 private int kbytes = 0; 26 private int minutes = 0; 27 28 /** 29 An instance created using the default constructor is initialized 30 with the system's default settings. 31 */ 32 public CheckpointConfig() { 33 } 34 35 /* package */ 36 static CheckpointConfig checkNull(CheckpointConfig config) { 37 return (config == null) ? DEFAULT : config; 38 } 39 40 /** 41 Configure the checkpoint log data threshold, in kilobytes. 42 <p> 43 The default is 0 for this class and the database environment. 44 <p> 45 @param kbytes 46 If the kbytes parameter is non-zero, a checkpoint will be performed if more 47 than kbytes of log data have been written since the last checkpoint. 48 */ 49 public void setKBytes(final int kbytes) { 50 this.kbytes = kbytes; 51 } 52 53 /** 54Return the checkpoint log data threshold, in kilobytes. 55<p> 56This method may be called at any time during the life of the application. 57<p> 58@return 59The checkpoint log data threshold, in kilobytes. 60 */ 61 public int getKBytes() { 62 return kbytes; 63 } 64 65 /** 66 Configure the checkpoint time threshold, in minutes. 67 <p> 68 The default is 0 for this class and the database environment. 69 <p> 70 @param minutes 71 If the minutes parameter is non-zero, a checkpoint is performed if more than 72 min minutes have passed since the last checkpoint. 73 */ 74 public void setMinutes(final int minutes) { 75 this.minutes = minutes; 76 } 77 78 /** 79 Return the checkpoint time threshold, in minutes. 80 <p> 81 @return 82 The checkpoint time threshold, in minutes. 83 */ 84 public int getMinutes() { 85 return minutes; 86 } 87 88 /** 89 Configure the checkpoint force option. 90 <p> 91 The default is false for this class and the BDB JE environment. 92 <p> 93 @param force 94 If set to true, force a checkpoint, even if there has been no 95 activity since the last checkpoint. 96 */ 97 public void setForce(final boolean force) { 98 this.force = force; 99 } 100 101 /** 102 Return the configuration of the checkpoint force option. 103 <p> 104 @return 105 The configuration of the checkpoint force option. 106 */ 107 public boolean getForce() { 108 return force; 109 } 110 111 /* package */ 112 void runCheckpoint(final DbEnv dbenv) 113 throws DatabaseException { 114 115 dbenv.txn_checkpoint(kbytes, minutes, force ? DbConstants.DB_FORCE : 0); 116 } 117} 118