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

EnvironmentConfig.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: EnvironmentConfig.java,v 12.11 2005/11/08 11:37:10 mjc 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 class EnvironmentConfig implements Cloneable {
00016     /*
00017      * For internal use, to allow null as a valid value for
00018      * the config parameter.
00019      */
00020     public static final EnvironmentConfig DEFAULT = new EnvironmentConfig();
00021 
00022     /* package */
00023     static EnvironmentConfig checkNull(EnvironmentConfig config) {
00024         return (config == null) ? DEFAULT : config;
00025     }
00026 
00027     /* Parameters */
00028     private int mode = 0644;
00029     private int cacheCount = 0;
00030     private long cacheSize = 0L;
00031     private java.util.Vector dataDirs = new java.util.Vector();
00032     private int envid = 0;
00033     private String errorPrefix = null;
00034     private java.io.OutputStream errorStream = null;
00035     private java.io.OutputStream messageStream = null;
00036     private byte[][] lockConflicts = null;
00037     private LockDetectMode lockDetectMode = LockDetectMode.NONE;
00038     private int maxLocks = 0;
00039     private int maxLockers = 0;
00040     private int maxLockObjects = 0;
00041     private int maxLogFileSize = 0;
00042     private int logBufferSize = 0;
00043     private java.io.File logDirectory = null;
00044     private int logFileMode = 0;
00045     private int logRegionSize = 0;
00046     private int maxMutexes = 0;
00047     private int maxOpenFiles = 0;
00048     private int maxWrite = 0;
00049     private int maxWriteSleep = 0;
00050     private int mutexAlignment = 0;
00051     private int mutexIncrement = 0;
00052     private int mutexTestAndSetSpins = 0;
00053     private long mmapSize = 0L;
00054     private String password = null;
00055     private long replicationLimit = 0L;
00056     private int replicationRequestMin = 0;
00057     private int replicationRequestMax = 0;
00058     private String rpcServer = null;
00059     private long rpcClientTimeout = 0L;
00060     private long rpcServerTimeout = 0L;
00061     private long segmentId = 0L;
00062     private long lockTimeout = 0L;
00063     private int txnMaxActive = 0;
00064     private long txnTimeout = 0L;
00065     private java.util.Date txnTimestamp = null;
00066     private java.io.File temporaryDirectory = null;
00067 
00068     /* Open flags */
00069     private boolean allowCreate = false;
00070     private boolean initializeCache = false;
00071     private boolean initializeCDB = false;
00072     private boolean initializeLocking = false;
00073     private boolean initializeLogging = false;
00074     private boolean initializeReplication = false;
00075     private boolean joinEnvironment = false;
00076     private boolean lockDown = false;
00077     private boolean isPrivate = false;
00078     private boolean register = false;
00079     private boolean runRecovery = false;
00080     private boolean runFatalRecovery = false;
00081     private boolean systemMemory = false;
00082     private boolean threaded = true;  // Handles are threaded by default in Java
00083     private boolean transactional = false;
00084     private boolean useEnvironment = false;
00085     private boolean useEnvironmentRoot = false;
00086 
00087     /* Flags */
00088     private boolean cdbLockAllDatabases = false;
00089     private boolean directDatabaseIO = false;
00090     private boolean directLogIO = false;
00091     private boolean dsyncDatabases = false;
00092     private boolean dsyncLog = false;
00093     private boolean initializeRegions = false;
00094     private boolean logAutoRemove = false;
00095     private boolean logInMemory = false;
00096     private boolean noLocking = false;
00097     private boolean noMMap = false;
00098     private boolean noPanic = false;
00099     private boolean overwrite = false;
00100     private boolean txnNoSync = false;
00101     private boolean txnNotDurable = false;
00102     private boolean txnWriteNoSync = false;
00103     private boolean yieldCPU = false;
00104 
00105     /* Verbose Flags */
00106     private boolean verboseDeadlock = false;
00107     private boolean verboseRecovery = false;
00108     private boolean verboseRegister = false;
00109     private boolean verboseReplication = false;
00110     private boolean verboseWaitsFor = false;
00111 
00112     /* Callbacks */
00113     private ErrorHandler errorHandler = null;
00114     private FeedbackHandler feedbackHandler = null;
00115     private LogRecordHandler logRecordHandler = null;
00116     private MessageHandler messageHandler = null;
00117     private PanicHandler panicHandler = null;
00118     private ReplicationTransport replicationTransport = null;
00119 
00120     public EnvironmentConfig() {
00121     }
00122 
00123     public void setAllowCreate(final boolean allowCreate) {
00124         this.allowCreate = allowCreate;
00125     }
00126 
00127     public boolean getAllowCreate() {
00128         return allowCreate;
00129     }
00130 
00131     public void setCacheSize(final long cacheSize) {
00132         this.cacheSize = cacheSize;
00133     }
00134 
00135     public long getCacheSize() {
00136         return cacheSize;
00137     }
00138 
00139     public void setCacheCount(final int cacheCount) {
00140         this.cacheCount = cacheCount;
00141     }
00142 
00143     public int getCacheCount() {
00144         return cacheCount;
00145     }
00146 
00147     public void setCDBLockAllDatabases(final boolean cdbLockAllDatabases) {
00148         this.cdbLockAllDatabases = cdbLockAllDatabases;
00149     }
00150 
00151     public boolean getCDBLockAllDatabases() {
00152         return cdbLockAllDatabases;
00153     }
00154 
00155     public void addDataDir(final java.io.File dataDir) {
00156         this.dataDirs.add(dataDir);
00157     }
00158 
00159     /* @deprecated */
00160     public void addDataDir(final String dataDir) {
00161         this.addDataDir(new java.io.File(dataDir));
00162     }
00163 
00164     public java.io.File[] getDataDirs() {
00165         final java.io.File[] dirs = new java.io.File[dataDirs.size()];
00166         dataDirs.copyInto(dirs);
00167         return dirs;
00168     }
00169 
00170     public void setDirectDatabaseIO(final boolean directDatabaseIO) {
00171         this.directDatabaseIO = directDatabaseIO;
00172     }
00173 
00174     public boolean getDirectDatabaseIO() {
00175         return directDatabaseIO;
00176     }
00177 
00178     public void setDirectLogIO(final boolean directLogIO) {
00179         this.directLogIO = directLogIO;
00180     }
00181 
00182     public boolean getDirectLogIO() {
00183         return directLogIO;
00184     }
00185 
00186     public void setDsyncDatabases(final boolean dsyncDatabases) {
00187         this.dsyncDatabases = dsyncDatabases;
00188     }
00189 
00190     public boolean getDsyncDatabases() {
00191         return dsyncDatabases;
00192     }
00193 
00194     public void setDsyncLog(final boolean dsyncLog) {
00195         this.dsyncLog = dsyncLog;
00196     }
00197 
00198     public boolean getDsyncLog() {
00199         return dsyncLog;
00200     }
00201 
00202     public void setEncrypted(final String password) {
00203         this.password = password;
00204     }
00205 
00206     public boolean getEncrypted() {
00207         return (password != null);
00208     }
00209 
00210     public void setErrorHandler(final ErrorHandler errorHandler) {
00211         this.errorHandler = errorHandler;
00212     }
00213 
00214     public ErrorHandler getErrorHandler() {
00215         return errorHandler;
00216     }
00217 
00218     public void setErrorPrefix(final String errorPrefix) {
00219         this.errorPrefix = errorPrefix;
00220     }
00221 
00222     public String getErrorPrefix() {
00223         return errorPrefix;
00224     }
00225 
00226     public void setErrorStream(final java.io.OutputStream errorStream) {
00227         this.errorStream = errorStream;
00228     }
00229 
00230     public java.io.OutputStream getErrorStream() {
00231         return errorStream;
00232     }
00233 
00234     public void setFeedbackHandler(final FeedbackHandler feedbackHandler) {
00235         this.feedbackHandler = feedbackHandler;
00236     }
00237 
00238     public FeedbackHandler getFeedbackHandler() {
00239         return feedbackHandler;
00240     }
00241 
00242     public void setInitializeCache(final boolean initializeCache) {
00243         this.initializeCache = initializeCache;
00244     }
00245 
00246     public boolean getInitializeCache() {
00247         return initializeCache;
00248     }
00249 
00250     public void setInitializeCDB(final boolean initializeCDB) {
00251         this.initializeCDB = initializeCDB;
00252     }
00253 
00254     public boolean getInitializeCDB() {
00255         return initializeCDB;
00256     }
00257 
00258     public void setInitializeLocking(final boolean initializeLocking) {
00259         this.initializeLocking = initializeLocking;
00260     }
00261 
00262     public boolean getInitializeLocking() {
00263         return initializeLocking;
00264     }
00265 
00266     public void setInitializeLogging(final boolean initializeLogging) {
00267         this.initializeLogging = initializeLogging;
00268     }
00269 
00270     public boolean getInitializeLogging() {
00271         return initializeLogging;
00272     }
00273 
00274     public void setInitializeRegions(final boolean initializeRegions) {
00275         this.initializeRegions = initializeRegions;
00276     }
00277 
00278     public boolean getInitializeRegions() {
00279         return initializeRegions;
00280     }
00281 
00282     public void setInitializeReplication(final boolean initializeReplication) {
00283         this.initializeReplication = initializeReplication;
00284     }
00285 
00286     public boolean getInitializeReplication() {
00287         return initializeReplication;
00288     }
00289 
00290     public void setJoinEnvironment(final boolean joinEnvironment) {
00291         this.joinEnvironment = joinEnvironment;
00292     }
00293 
00294     public boolean getJoinEnvironment() {
00295         return joinEnvironment;
00296     }
00297 
00298     public void setLockConflicts(final byte[][] lockConflicts) {
00299         this.lockConflicts = lockConflicts;
00300     }
00301 
00302     public byte[][] getLockConflicts() {
00303         return lockConflicts;
00304     }
00305 
00306     public void setLockDetectMode(final LockDetectMode lockDetectMode) {
00307         this.lockDetectMode = lockDetectMode;
00308     }
00309 
00310     public LockDetectMode getLockDetectMode() {
00311         return lockDetectMode;
00312     }
00313 
00314     public void setLockDown(final boolean lockDown) {
00315         this.lockDown = lockDown;
00316     }
00317 
00318     public boolean getLockDown() {
00319         return lockDown;
00320     }
00321 
00322     public void setLockTimeout(final long lockTimeout) {
00323         this.lockTimeout = lockTimeout;
00324     }
00325 
00326     public long getLockTimeout() {
00327         return lockTimeout;
00328     }
00329 
00330     public void setLogAutoRemove(final boolean logAutoRemove) {
00331         this.logAutoRemove = logAutoRemove;
00332     }
00333 
00334     public boolean getLogAutoRemove() {
00335         return logAutoRemove;
00336     }
00337 
00338     public void setLogInMemory(final boolean logInMemory) {
00339         this.logInMemory = logInMemory;
00340     }
00341 
00342     public boolean getLogInMemory() {
00343         return logInMemory;
00344     }
00345 
00346     public void setLogRecordHandler(final LogRecordHandler logRecordHandler) {
00347         this.logRecordHandler = logRecordHandler;
00348     }
00349 
00350     public LogRecordHandler getLogRecordHandler() {
00351         return logRecordHandler;
00352     }
00353 
00354     public void setMaxLocks(final int maxLocks) {
00355         this.maxLocks = maxLocks;
00356     }
00357 
00358     public int getMaxLocks() {
00359         return maxLocks;
00360     }
00361 
00362     public void setMaxLockers(final int maxLockers) {
00363         this.maxLockers = maxLockers;
00364     }
00365 
00366     public int getMaxLockers() {
00367         return maxLockers;
00368     }
00369 
00370     public void setMaxLockObjects(final int maxLockObjects) {
00371         this.maxLockObjects = maxLockObjects;
00372     }
00373 
00374     public int getMaxLockObjects() {
00375         return maxLockObjects;
00376     }
00377 
00378     public void setMaxLogFileSize(final int maxLogFileSize) {
00379         this.maxLogFileSize = maxLogFileSize;
00380     }
00381 
00382     public int getMaxLogFileSize() {
00383         return maxLogFileSize;
00384     }
00385 
00386     public void setLogBufferSize(final int logBufferSize) {
00387         this.logBufferSize = logBufferSize;
00388     }
00389 
00390     public int getLogBufferSize() {
00391         return logBufferSize;
00392     }
00393 
00394     public void setLogDirectory(final java.io.File logDirectory) {
00395         this.logDirectory = logDirectory;
00396     }
00397 
00398     public java.io.File getLogDirectory() {
00399         return logDirectory;
00400     }
00401 
00402     public void setLogFileMode(final int logFileMode) {
00403         this.logFileMode = logFileMode;
00404     }
00405 
00406     public int getLogFileMode() {
00407         return logFileMode;
00408     }
00409 
00410     public void setLogRegionSize(final int logRegionSize) {
00411         this.logRegionSize = logRegionSize;
00412     }
00413 
00414     public int getLogRegionSize() {
00415         return logRegionSize;
00416     }
00417 
00418     public void setMaxOpenFiles(final int maxOpenFiles) {
00419         this.maxOpenFiles = maxOpenFiles;
00420     }
00421 
00422     public int getMaxOpenFiles() {
00423         return maxOpenFiles;
00424     }
00425 
00426     public void setMaxWrite(final int maxWrite, final int maxWriteSleep) {
00427         this.maxWrite = maxWrite;
00428         this.maxWriteSleep = maxWriteSleep;
00429     }
00430 
00431     public int getMaxWrite() {
00432         return maxWrite;
00433     }
00434 
00435     public int getMaxWriteSleep() {
00436         return maxWriteSleep;
00437     }
00438 
00439     public void setMessageHandler(final MessageHandler messageHandler) {
00440         this.messageHandler = messageHandler;
00441     }
00442 
00443     public MessageHandler getMessageHandler() {
00444         return messageHandler;
00445     }
00446 
00447     public void setMessageStream(final java.io.OutputStream messageStream) {
00448         this.messageStream = messageStream;
00449     }
00450 
00451     public java.io.OutputStream getMessageStream() {
00452         return messageStream;
00453     }
00454 
00455     public void setMMapSize(final long mmapSize) {
00456         this.mmapSize = mmapSize;
00457     }
00458 
00459     public long getMMapSize() {
00460         return mmapSize;
00461     }
00462 
00463     public void setMode(final int mode) {
00464         this.mode = mode;
00465     }
00466 
00467     public long getMode() {
00468         return mode;
00469     }
00470 
00471     public void setNoLocking(final boolean noLocking) {
00472         this.noLocking = noLocking;
00473     }
00474 
00475     public boolean getNoLocking() {
00476         return noLocking;
00477     }
00478 
00479     public void setNoMMap(final boolean noMMap) {
00480         this.noMMap = noMMap;
00481     }
00482 
00483     public boolean getNoMMap() {
00484         return noMMap;
00485     }
00486 
00487     public void setNoPanic(final boolean noPanic) {
00488         this.noPanic = noPanic;
00489     }
00490 
00491     public boolean getNoPanic() {
00492         return noPanic;
00493     }
00494 
00495     public void setOverwrite(final boolean overwrite) {
00496         this.overwrite = overwrite;
00497     }
00498 
00499     public boolean getOverwrite() {
00500         return overwrite;
00501     }
00502 
00503     public void setPanicHandler(final PanicHandler panicHandler) {
00504         this.panicHandler = panicHandler;
00505     }
00506 
00507     public PanicHandler getPanicHandler() {
00508         return panicHandler;
00509     }
00510 
00511     public void setPrivate(final boolean isPrivate) {
00512         this.isPrivate = isPrivate;
00513     }
00514 
00515     public boolean getPrivate() {
00516         return isPrivate;
00517     }
00518 
00519     public void setReplicationLimit(final long replicationLimit) {
00520         this.replicationLimit = replicationLimit;
00521     }
00522 
00523     public long getReplicationLimit() {
00524         return replicationLimit;
00525     }
00526 
00527     public void setReplicationRequestMin(final int replicationRequestMin) {
00528         this.replicationRequestMin = replicationRequestMin;
00529     }
00530 
00531     public int getReplicationRequestMin() {
00532         return replicationRequestMin;
00533     }
00534 
00535     public void setReplicationRequestMax(final int replicationRequestMax) {
00536         this.replicationRequestMax = replicationRequestMax;
00537     }
00538 
00539     public int getReplicationRequestMax() {
00540         return replicationRequestMax;
00541     }
00542 
00543     public void setReplicationTransport(final int envid,
00544         final ReplicationTransport replicationTransport) {
00545 
00546         this.envid = envid;
00547         this.replicationTransport = replicationTransport;
00548     }
00549 
00550     public ReplicationTransport getReplicationTransport() {
00551         return replicationTransport;
00552     }
00553 
00554     public void setRegister(final boolean register) {
00555         this.register = register;
00556     }
00557 
00558     public boolean getRegister() {
00559         return register;
00560     }
00561 
00562     public void setRunFatalRecovery(final boolean runFatalRecovery) {
00563         this.runFatalRecovery = runFatalRecovery;
00564     }
00565 
00566     public boolean getRunFatalRecovery() {
00567         return runFatalRecovery;
00568     }
00569 
00570     public void setRunRecovery(final boolean runRecovery) {
00571         this.runRecovery = runRecovery;
00572     }
00573 
00574     public boolean getRunRecovery() {
00575         return runRecovery;
00576     }
00577 
00578     public void setSystemMemory(final boolean systemMemory) {
00579         this.systemMemory = systemMemory;
00580     }
00581 
00582     public boolean getSystemMemory() {
00583         return systemMemory;
00584     }
00585 
00586     public void setRPCServer(final String rpcServer,
00587                              final long rpcClientTimeout,
00588                              final long rpcServerTimeout) {
00589         this.rpcServer = rpcServer;
00590         this.rpcClientTimeout = rpcClientTimeout;
00591         this.rpcServerTimeout = rpcServerTimeout;
00592 
00593         // Turn off threading for RPC client handles.
00594         this.threaded = false;
00595     }
00596 
00597     public void setSegmentId(final long segmentId) {
00598         this.segmentId = segmentId;
00599     }
00600 
00601     public long getSegmentId() {
00602         return segmentId;
00603     }
00604 
00605     public void setTemporaryDirectory(final java.io.File temporaryDirectory) {
00606         this.temporaryDirectory = temporaryDirectory;
00607     }
00608 
00609     /* @deprecated */
00610     public void setTemporaryDirectory(final String temporaryDirectory) {
00611         this.setTemporaryDirectory(new java.io.File(temporaryDirectory));
00612     }
00613 
00614     public java.io.File getTemporaryDirectory() {
00615         return temporaryDirectory;
00616     }
00617 
00618     public void setMutexAlignment(final int mutexAlignment) {
00619         this.mutexAlignment = mutexAlignment;
00620     }
00621 
00622     public int getMutexAlignment() {
00623         return mutexAlignment;
00624     }
00625 
00626     public void setMutexIncrement(final int mutexIncrement) {
00627         this.mutexIncrement = mutexIncrement;
00628     }
00629 
00630     public int getMutexIncrement() {
00631         return mutexIncrement;
00632     }
00633 
00634     public void setMaxMutexes(final int maxMutexes) {
00635         this.maxMutexes = maxMutexes;
00636     }
00637 
00638     public int getMaxMutexes() {
00639         return maxMutexes;
00640     }
00641 
00642     public void setMutexTestAndSetSpins(final int mutexTestAndSetSpins) {
00643         this.mutexTestAndSetSpins = mutexTestAndSetSpins;
00644     }
00645 
00646     public int getMutexTestAndSetSpins() {
00647         return mutexTestAndSetSpins;
00648     }
00649 
00650     /* @deprecated Renamed setMutexTestAndSetSpins */
00651     public void setTestAndSetSpins(final int mutexTestAndSetSpins) {
00652         setMutexTestAndSetSpins(mutexTestAndSetSpins);
00653     }
00654 
00655     /* @deprecated Renamed getMutexTestAndSetSpins */
00656     public int getTestAndSetSpins() {
00657         return getMutexTestAndSetSpins();
00658     }
00659 
00660     public void setThreaded(final boolean threaded) {
00661         this.threaded = threaded;
00662     }
00663 
00664     public boolean getThreaded() {
00665         return threaded;
00666     }
00667 
00668     public void setTransactional(final boolean transactional) {
00669         this.transactional = transactional;
00670     }
00671 
00672     public boolean getTransactional() {
00673         return transactional;
00674     }
00675 
00676     public void setTxnNoSync(final boolean txnNoSync) {
00677         this.txnNoSync = txnNoSync;
00678     }
00679 
00680     public boolean getTxnNoSync() {
00681         return txnNoSync;
00682     }
00683 
00684     public void setTxnNotDurable(final boolean txnNotDurable) {
00685         this.txnNotDurable = txnNotDurable;
00686     }
00687 
00688     public boolean getTxnNotDurable() {
00689         return txnNotDurable;
00690     }
00691 
00692     public void setTxnMaxActive(final int txnMaxActive) {
00693         this.txnMaxActive = txnMaxActive;
00694     }
00695 
00696     public int getTxnMaxActive() {
00697         return txnMaxActive;
00698     }
00699 
00700     public void setTxnTimeout(final long txnTimeout) {
00701         this.txnTimeout = txnTimeout;
00702     }
00703 
00704     public long getTxnTimeout() {
00705         return txnTimeout;
00706     }
00707 
00708     public void setTxnTimestamp(final java.util.Date txnTimestamp) {
00709         this.txnTimestamp = txnTimestamp;
00710     }
00711 
00712     public java.util.Date getTxnTimestamp() {
00713         return txnTimestamp;
00714     }
00715 
00716     public void setTxnWriteNoSync(final boolean txnWriteNoSync) {
00717         this.txnWriteNoSync = txnWriteNoSync;
00718     }
00719 
00720     public boolean getTxnWriteNoSync() {
00721         return txnWriteNoSync;
00722     }
00723 
00724     public void setUseEnvironment(final boolean useEnvironment) {
00725         this.useEnvironment = useEnvironment;
00726     }
00727 
00728     public boolean getUseEnvironment() {
00729         return useEnvironment;
00730     }
00731 
00732     public void setUseEnvironmentRoot(final boolean useEnvironmentRoot) {
00733         this.useEnvironmentRoot = useEnvironmentRoot;
00734     }
00735 
00736     public boolean getUseEnvironmentRoot() {
00737         return useEnvironmentRoot;
00738     }
00739 
00740     public void setVerboseDeadlock(final boolean verboseDeadlock) {
00741         this.verboseDeadlock = verboseDeadlock;
00742     }
00743 
00744     public boolean getVerboseDeadlock() {
00745         return verboseDeadlock;
00746     }
00747 
00748     public void setVerboseRecovery(final boolean verboseRecovery) {
00749         this.verboseRecovery = verboseRecovery;
00750     }
00751 
00752     public boolean getVerboseRecovery() {
00753         return verboseRecovery;
00754     }
00755 
00756     public void setVerboseRegister(final boolean verboseRegister) {
00757         this.verboseRegister = verboseRegister;
00758     }
00759 
00760     public boolean getVerboseRegister() {
00761         return verboseRegister;
00762     }
00763 
00764     public void setVerboseReplication(final boolean verboseReplication) {
00765         this.verboseReplication = verboseReplication;
00766     }
00767 
00768     public boolean getVerboseReplication() {
00769         return verboseReplication;
00770     }
00771 
00772     public void setVerboseWaitsFor(final boolean verboseWaitsFor) {
00773         this.verboseWaitsFor = verboseWaitsFor;
00774     }
00775 
00776     public boolean getVerboseWaitsFor() {
00777         return verboseWaitsFor;
00778     }
00779 
00780     public void setYieldCPU(final boolean yieldCPU) {
00781         this.yieldCPU = yieldCPU;
00782     }
00783 
00784     public boolean getYieldCPU() {
00785         return yieldCPU;
00786     }
00787 
00788     private boolean lockConflictsEqual(byte[][] lc1, byte[][]lc2) {
00789         if (lc1 == lc2)
00790             return true;
00791         if (lc1 == null || lc2 == null || lc1.length != lc2.length)
00792             return false;
00793         for (int i = 0; i < lc1.length; i++) {
00794             if (lc1[i].length != lc2[i].length)
00795                 return false;
00796             for (int j = 0; j < lc1[i].length; j++)
00797                 if (lc1[i][j] != lc2[i][j])
00798                     return false;
00799         }
00800         return true;
00801     }
00802 
00803     /* package */
00804     DbEnv openEnvironment(final java.io.File home)
00805         throws DatabaseException, java.io.FileNotFoundException {
00806 
00807         final DbEnv dbenv = createEnvironment();
00808         int openFlags = 0;
00809 
00810         openFlags |= allowCreate ? DbConstants.DB_CREATE : 0;
00811         openFlags |= initializeCache ? DbConstants.DB_INIT_MPOOL : 0;
00812         openFlags |= initializeCDB ? DbConstants.DB_INIT_CDB : 0;
00813         openFlags |= initializeLocking ? DbConstants.DB_INIT_LOCK : 0;
00814         openFlags |= initializeLogging ? DbConstants.DB_INIT_LOG : 0;
00815         openFlags |= initializeReplication ? DbConstants.DB_INIT_REP : 0;
00816         openFlags |= joinEnvironment ? DbConstants.DB_JOINENV : 0;
00817         openFlags |= lockDown ? DbConstants.DB_LOCKDOWN : 0;
00818         openFlags |= isPrivate ? DbConstants.DB_PRIVATE : 0;
00819         openFlags |= register ? DbConstants.DB_REGISTER : 0;
00820         openFlags |= runRecovery ? DbConstants.DB_RECOVER : 0;
00821         openFlags |= runFatalRecovery ? DbConstants.DB_RECOVER_FATAL : 0;
00822         openFlags |= systemMemory ? DbConstants.DB_SYSTEM_MEM : 0;
00823         openFlags |= threaded ? DbConstants.DB_THREAD : 0;
00824         openFlags |= transactional ? DbConstants.DB_INIT_TXN : 0;
00825         openFlags |= useEnvironment ? DbConstants.DB_USE_ENVIRON : 0;
00826         openFlags |= useEnvironmentRoot ? DbConstants.DB_USE_ENVIRON_ROOT : 0;
00827 
00828         boolean succeeded = false;
00829         try {
00830             dbenv.open((home == null) ? null : home.toString(),
00831                 openFlags, mode);
00832             succeeded = true;
00833             return dbenv;
00834         } finally {
00835             if (!succeeded)
00836                 try {
00837                     dbenv.close(0);
00838                 } catch (Throwable t) {
00839                     // Ignore it -- an exception is already in flight.
00840                 }
00841         }
00842     }
00843 
00844 
00845     /* package */
00846     DbEnv createEnvironment()
00847         throws DatabaseException {
00848 
00849         int createFlags = 0;
00850 
00851         if (rpcServer != null)
00852                 createFlags |= DbConstants.DB_RPCCLIENT;
00853 
00854         final DbEnv dbenv = new DbEnv(createFlags);
00855         configureEnvironment(dbenv, DEFAULT);
00856         return dbenv;
00857     }
00858 
00859     /* package */
00860     void configureEnvironment(final DbEnv dbenv,
00861                               final EnvironmentConfig oldConfig)
00862         throws DatabaseException {
00863 
00864         if (errorHandler != oldConfig.errorHandler)
00865             dbenv.set_errcall(errorHandler);
00866         if (errorPrefix != oldConfig.errorPrefix &&
00867             errorPrefix != null && !errorPrefix.equals(oldConfig.errorPrefix))
00868             dbenv.set_errpfx(errorPrefix);
00869         if (errorStream != oldConfig.errorStream)
00870             dbenv.set_error_stream(errorStream);
00871 
00872         if (rpcServer != oldConfig.rpcServer ||
00873             rpcClientTimeout != oldConfig.rpcClientTimeout ||
00874             rpcServerTimeout != oldConfig.rpcServerTimeout)
00875             dbenv.set_rpc_server(null, rpcServer,
00876                 rpcClientTimeout, rpcServerTimeout, 0);
00877 
00878         // We always set DB_TIME_NOTGRANTED in the Java API, because
00879         // LockNotGrantedException extends DeadlockException, so there's no
00880         // reason why an application would prefer one to the other.
00881         int onFlags = DbConstants.DB_TIME_NOTGRANTED;
00882         int offFlags = 0;
00883 
00884         if (cdbLockAllDatabases && !oldConfig.cdbLockAllDatabases)
00885             onFlags |= DbConstants.DB_CDB_ALLDB;
00886         if (!cdbLockAllDatabases && oldConfig.cdbLockAllDatabases)
00887             offFlags |= DbConstants.DB_CDB_ALLDB;
00888 
00889         if (directDatabaseIO && !oldConfig.directDatabaseIO)
00890             onFlags |= DbConstants.DB_DIRECT_DB;
00891         if (!directDatabaseIO && oldConfig.directDatabaseIO)
00892             offFlags |= DbConstants.DB_DIRECT_DB;
00893 
00894         if (directLogIO && !oldConfig.directLogIO)
00895             onFlags |= DbConstants.DB_DIRECT_LOG;
00896         if (!directLogIO && oldConfig.directLogIO)
00897             offFlags |= DbConstants.DB_DIRECT_LOG;
00898 
00899         if (dsyncDatabases && !oldConfig.dsyncDatabases)
00900             onFlags |= DbConstants.DB_DSYNC_DB;
00901         if (!dsyncDatabases && oldConfig.dsyncDatabases)
00902             offFlags |= DbConstants.DB_DSYNC_DB;
00903 
00904         if (dsyncLog && !oldConfig.dsyncLog)
00905             onFlags |= DbConstants.DB_DSYNC_LOG;
00906         if (!dsyncLog && oldConfig.dsyncLog)
00907             offFlags |= DbConstants.DB_DSYNC_LOG;
00908 
00909         if (initializeRegions && !oldConfig.initializeRegions)
00910             onFlags |= DbConstants.DB_REGION_INIT;
00911         if (!initializeRegions && oldConfig.initializeRegions)
00912             offFlags |= DbConstants.DB_REGION_INIT;
00913 
00914         if (logAutoRemove && !oldConfig.logAutoRemove)
00915             onFlags |= DbConstants.DB_LOG_AUTOREMOVE;
00916         if (!logAutoRemove && oldConfig.logAutoRemove)
00917             offFlags |= DbConstants.DB_LOG_AUTOREMOVE;
00918 
00919         if (logInMemory && !oldConfig.logInMemory)
00920             onFlags |= DbConstants.DB_LOG_INMEMORY;
00921         if (!logInMemory && oldConfig.logInMemory)
00922             offFlags |= DbConstants.DB_LOG_INMEMORY;
00923 
00924         if (noLocking && !oldConfig.noLocking)
00925             onFlags |= DbConstants.DB_NOLOCKING;
00926         if (!noLocking && oldConfig.noLocking)
00927             offFlags |= DbConstants.DB_NOLOCKING;
00928 
00929         if (noMMap && !oldConfig.noMMap)
00930             onFlags |= DbConstants.DB_NOMMAP;
00931         if (!noMMap && oldConfig.noMMap)
00932             offFlags |= DbConstants.DB_NOMMAP;
00933 
00934         if (noPanic && !oldConfig.noPanic)
00935             onFlags |= DbConstants.DB_NOPANIC;
00936         if (!noPanic && oldConfig.noPanic)
00937             offFlags |= DbConstants.DB_NOPANIC;
00938 
00939         if (overwrite && !oldConfig.overwrite)
00940             onFlags |= DbConstants.DB_OVERWRITE;
00941         if (!overwrite && oldConfig.overwrite)
00942             offFlags |= DbConstants.DB_OVERWRITE;
00943 
00944         if (txnNoSync && !oldConfig.txnNoSync)
00945             onFlags |= DbConstants.DB_TXN_NOSYNC;
00946         if (!txnNoSync && oldConfig.txnNoSync)
00947             offFlags |= DbConstants.DB_TXN_NOSYNC;
00948 
00949         if (txnNotDurable && !oldConfig.txnNotDurable)
00950             onFlags |= DbConstants.DB_TXN_NOT_DURABLE;
00951         if (!txnNotDurable && oldConfig.txnNotDurable)
00952             offFlags |= DbConstants.DB_TXN_NOT_DURABLE;
00953 
00954         if (txnWriteNoSync && !oldConfig.txnWriteNoSync)
00955             onFlags |= DbConstants.DB_TXN_WRITE_NOSYNC;
00956         if (!txnWriteNoSync && oldConfig.txnWriteNoSync)
00957             offFlags |= DbConstants.DB_TXN_WRITE_NOSYNC;
00958 
00959         if (yieldCPU && !oldConfig.yieldCPU)
00960             onFlags |= DbConstants.DB_YIELDCPU;
00961         if (!yieldCPU && oldConfig.yieldCPU)
00962             offFlags |= DbConstants.DB_YIELDCPU;
00963 
00964         if (onFlags != 0)
00965             dbenv.set_flags(onFlags, true);
00966         if (offFlags != 0)
00967             dbenv.set_flags(offFlags, false);
00968 
00969         /* Verbose flags */
00970         if (verboseDeadlock && !oldConfig.verboseDeadlock)
00971             dbenv.set_verbose(DbConstants.DB_VERB_DEADLOCK, true);
00972         if (!verboseDeadlock && oldConfig.verboseDeadlock)
00973             dbenv.set_verbose(DbConstants.DB_VERB_DEADLOCK, false);
00974 
00975         if (verboseRecovery && !oldConfig.verboseRecovery)
00976             dbenv.set_verbose(DbConstants.DB_VERB_RECOVERY, true);
00977         if (!verboseRecovery && oldConfig.verboseRecovery)
00978             dbenv.set_verbose(DbConstants.DB_VERB_RECOVERY, false);
00979 
00980         if (verboseRegister && !oldConfig.verboseRegister)
00981             dbenv.set_verbose(DbConstants.DB_VERB_REGISTER, true);
00982         if (!verboseRegister && oldConfig.verboseRegister)
00983             dbenv.set_verbose(DbConstants.DB_VERB_REGISTER, false);
00984 
00985         if (verboseReplication && !oldConfig.verboseReplication)
00986             dbenv.set_verbose(DbConstants.DB_VERB_REPLICATION, true);
00987         if (!verboseReplication && oldConfig.verboseReplication)
00988             dbenv.set_verbose(DbConstants.DB_VERB_REPLICATION, false);
00989 
00990         if (verboseWaitsFor && !oldConfig.verboseWaitsFor)
00991             dbenv.set_verbose(DbConstants.DB_VERB_WAITSFOR, true);
00992         if (!verboseWaitsFor && oldConfig.verboseWaitsFor)
00993             dbenv.set_verbose(DbConstants.DB_VERB_WAITSFOR, false);
00994 
00995         /* Callbacks */
00996         if (feedbackHandler != oldConfig.feedbackHandler)
00997             dbenv.set_feedback(feedbackHandler);
00998         if (logRecordHandler != oldConfig.logRecordHandler)
00999             dbenv.set_app_dispatch(logRecordHandler);
01000         if (messageHandler != oldConfig.messageHandler)
01001             dbenv.set_msgcall(messageHandler);
01002         if (panicHandler != oldConfig.panicHandler)
01003             dbenv.set_paniccall(panicHandler);
01004         if (replicationTransport != oldConfig.replicationTransport)
01005             dbenv.set_rep_transport(envid, replicationTransport);
01006 
01007         /* Other settings */
01008         if (cacheSize != oldConfig.cacheSize ||
01009             cacheCount != oldConfig.cacheCount)
01010             dbenv.set_cachesize(cacheSize, cacheCount);
01011         for (final java.util.Enumeration e = dataDirs.elements();
01012             e.hasMoreElements();) {
01013             final java.io.File dir = (java.io.File)e.nextElement();
01014             if (!oldConfig.dataDirs.contains(dir))
01015                 dbenv.set_data_dir(dir.toString());
01016         }
01017         if (!lockConflictsEqual(lockConflicts, oldConfig.lockConflicts))
01018             dbenv.set_lk_conflicts(lockConflicts);
01019         if (lockDetectMode != oldConfig.lockDetectMode)
01020             dbenv.set_lk_detect(lockDetectMode.getFlag());
01021         if (maxLocks != oldConfig.maxLocks)
01022             dbenv.set_lk_max_locks(maxLocks);
01023         if (maxLockers != oldConfig.maxLockers)
01024             dbenv.set_lk_max_lockers(maxLockers);
01025         if (maxLockObjects != oldConfig.maxLockObjects)
01026             dbenv.set_lk_max_objects(maxLockObjects);
01027         if (maxLogFileSize != oldConfig.maxLogFileSize)
01028             dbenv.set_lg_max(maxLogFileSize);
01029         if (logBufferSize != oldConfig.logBufferSize)
01030             dbenv.set_lg_bsize(logBufferSize);
01031         if (logDirectory != oldConfig.logDirectory && logDirectory != null &&
01032             !logDirectory.equals(oldConfig.logDirectory))
01033             dbenv.set_lg_dir(logDirectory.toString());
01034         if (logFileMode != oldConfig.logFileMode)
01035             dbenv.set_lg_filemode(logFileMode);
01036         if (logRegionSize != oldConfig.logRegionSize)
01037             dbenv.set_lg_regionmax(logRegionSize);
01038         if (maxOpenFiles != oldConfig.maxOpenFiles)
01039             dbenv.set_mp_max_openfd(maxOpenFiles);
01040         if (maxWrite != oldConfig.maxWrite ||
01041             maxWriteSleep != oldConfig.maxWriteSleep)
01042             dbenv.set_mp_max_write(maxWrite, maxWriteSleep);
01043         if (messageStream != oldConfig.messageStream)
01044             dbenv.set_message_stream(messageStream);
01045         if (mmapSize != oldConfig.mmapSize)
01046             dbenv.set_mp_mmapsize(mmapSize);
01047         if (password != null)
01048             dbenv.set_encrypt(password, DbConstants.DB_ENCRYPT_AES);
01049         if (replicationLimit != oldConfig.replicationLimit)
01050             dbenv.set_rep_limit(replicationLimit);
01051         if (replicationRequestMin != oldConfig.replicationRequestMin ||
01052             replicationRequestMax != oldConfig.replicationRequestMax)
01053             dbenv.set_rep_request(replicationRequestMin, replicationRequestMax);
01054         if (segmentId != oldConfig.segmentId)
01055             dbenv.set_shm_key(segmentId);
01056         if (mutexAlignment != oldConfig.mutexAlignment)
01057             dbenv.mutex_set_align(mutexAlignment);
01058         if (mutexIncrement != oldConfig.mutexIncrement)
01059             dbenv.mutex_set_increment(mutexIncrement);
01060         if (maxMutexes != oldConfig.maxMutexes)
01061             dbenv.mutex_set_max(maxMutexes);
01062         if (mutexTestAndSetSpins != oldConfig.mutexTestAndSetSpins)
01063             dbenv.mutex_set_tas_spins(mutexTestAndSetSpins);
01064         if (lockTimeout != oldConfig.lockTimeout)
01065             dbenv.set_timeout(lockTimeout, DbConstants.DB_SET_LOCK_TIMEOUT);
01066         if (txnMaxActive != oldConfig.txnMaxActive)
01067             dbenv.set_tx_max(txnMaxActive);
01068         if (txnTimeout != oldConfig.txnTimeout)
01069             dbenv.set_timeout(txnTimeout, DbConstants.DB_SET_TXN_TIMEOUT);
01070         if (txnTimestamp != oldConfig.txnTimestamp && txnTimestamp != null &&
01071             !txnTimestamp.equals(oldConfig.txnTimestamp))
01072             dbenv.set_tx_timestamp(txnTimestamp);
01073         if (temporaryDirectory != oldConfig.temporaryDirectory &&
01074             temporaryDirectory != null &&
01075             !temporaryDirectory.equals(oldConfig.temporaryDirectory))
01076             dbenv.set_tmp_dir(temporaryDirectory.toString());
01077     }
01078 
01079     /* package */
01080     EnvironmentConfig(final DbEnv dbenv)
01081         throws DatabaseException {
01082 
01083         final int openFlags = dbenv.get_open_flags();
01084 
01085         allowCreate = ((openFlags & DbConstants.DB_CREATE) != 0);
01086         initializeCache = ((openFlags & DbConstants.DB_INIT_MPOOL) != 0);
01087         initializeCDB = ((openFlags & DbConstants.DB_INIT_CDB) != 0);
01088         initializeLocking = ((openFlags & DbConstants.DB_INIT_LOCK) != 0);
01089         initializeLogging = ((openFlags & DbConstants.DB_INIT_LOG) != 0);
01090         initializeReplication = ((openFlags & DbConstants.DB_INIT_REP) != 0);
01091         joinEnvironment = ((openFlags & DbConstants.DB_JOINENV) != 0);
01092         lockDown = ((openFlags & DbConstants.DB_LOCKDOWN) != 0);
01093         isPrivate = ((openFlags & DbConstants.DB_PRIVATE) != 0);
01094         register = ((openFlags & DbConstants.DB_REGISTER) != 0);
01095         runRecovery = ((openFlags & DbConstants.DB_RECOVER) != 0);
01096         runFatalRecovery = ((openFlags & DbConstants.DB_RECOVER_FATAL) != 0);
01097         systemMemory = ((openFlags & DbConstants.DB_SYSTEM_MEM) != 0);
01098         threaded = ((openFlags & DbConstants.DB_THREAD) != 0);
01099         transactional = ((openFlags & DbConstants.DB_INIT_TXN) != 0);
01100         useEnvironment = ((openFlags & DbConstants.DB_USE_ENVIRON) != 0);
01101         useEnvironmentRoot =
01102             ((openFlags & DbConstants.DB_USE_ENVIRON_ROOT) != 0);
01103 
01104         final int envFlags = dbenv.get_flags();
01105 
01106         cdbLockAllDatabases = ((envFlags & DbConstants.DB_CDB_ALLDB) != 0);
01107         directDatabaseIO = ((envFlags & DbConstants.DB_DIRECT_DB) != 0);
01108         directLogIO = ((envFlags & DbConstants.DB_DIRECT_LOG) != 0);
01109         dsyncDatabases = ((envFlags & DbConstants.DB_DSYNC_DB) != 0);
01110         dsyncLog = ((envFlags & DbConstants.DB_DSYNC_LOG) != 0);
01111         initializeRegions = ((envFlags & DbConstants.DB_REGION_INIT) != 0);
01112         logAutoRemove = ((envFlags & DbConstants.DB_LOG_AUTOREMOVE) != 0);
01113         logInMemory = ((envFlags & DbConstants.DB_LOG_INMEMORY) != 0);
01114         noLocking = ((envFlags & DbConstants.DB_NOLOCKING) != 0);
01115         noMMap = ((envFlags & DbConstants.DB_NOMMAP) != 0);
01116         noPanic = ((envFlags & DbConstants.DB_NOPANIC) != 0);
01117         overwrite = ((envFlags & DbConstants.DB_OVERWRITE) != 0);
01118         txnNoSync = ((envFlags & DbConstants.DB_TXN_NOSYNC) != 0);
01119         txnNotDurable = ((envFlags & DbConstants.DB_TXN_NOT_DURABLE) != 0);
01120         txnWriteNoSync = ((envFlags & DbConstants.DB_TXN_WRITE_NOSYNC) != 0);
01121         yieldCPU = ((envFlags & DbConstants.DB_YIELDCPU) != 0);
01122 
01123         /* Verbose flags */
01124         verboseDeadlock = dbenv.get_verbose(DbConstants.DB_VERB_DEADLOCK);
01125         verboseRecovery = dbenv.get_verbose(DbConstants.DB_VERB_RECOVERY);
01126         verboseRegister = dbenv.get_verbose(DbConstants.DB_VERB_REGISTER);
01127         verboseReplication = dbenv.get_verbose(DbConstants.DB_VERB_REPLICATION);
01128         verboseWaitsFor = dbenv.get_verbose(DbConstants.DB_VERB_WAITSFOR);
01129 
01130         /* Callbacks */
01131         errorHandler = dbenv.get_errcall();
01132         feedbackHandler = dbenv.get_feedback();
01133         logRecordHandler = dbenv.get_app_dispatch();
01134         messageHandler = dbenv.get_msgcall();
01135         panicHandler = dbenv.get_paniccall();
01136         // XXX: replicationTransport and envid aren't available?
01137 
01138         /* Other settings */
01139         if (initializeCache) {
01140             cacheSize = dbenv.get_cachesize();
01141             cacheCount = dbenv.get_cachesize_ncache();
01142             mmapSize = dbenv.get_mp_mmapsize();
01143             maxOpenFiles = dbenv.get_mp_max_openfd();
01144             maxWrite = dbenv.get_mp_max_write();
01145             maxWriteSleep = dbenv.get_mp_max_write_sleep();
01146         }
01147 
01148         String[] dataDirArray = dbenv.get_data_dirs();
01149         if (dataDirArray == null)
01150             dataDirArray = new String[0];
01151         dataDirs = new java.util.Vector(dataDirArray.length);
01152         dataDirs.setSize(dataDirArray.length);
01153         for (int i = 0; i < dataDirArray.length; i++)
01154             dataDirs.set(i, new java.io.File(dataDirArray[i]));
01155 
01156         errorPrefix = dbenv.get_errpfx();
01157         errorStream = dbenv.get_error_stream();
01158 
01159         if (initializeLocking) {
01160             lockConflicts = dbenv.get_lk_conflicts();
01161             lockDetectMode = LockDetectMode.fromFlag(dbenv.get_lk_detect());
01162             lockTimeout = dbenv.get_timeout(DbConstants.DB_SET_LOCK_TIMEOUT);
01163             maxLocks = dbenv.get_lk_max_locks();
01164             maxLockers = dbenv.get_lk_max_lockers();
01165             maxLockObjects = dbenv.get_lk_max_objects();
01166             txnTimeout = dbenv.get_timeout(DbConstants.DB_SET_TXN_TIMEOUT);
01167         } else {
01168             lockConflicts = null;
01169             lockDetectMode = LockDetectMode.NONE;
01170             lockTimeout = 0L;
01171             maxLocks = 0;
01172             maxLockers = 0;
01173             maxLockObjects = 0;
01174             txnTimeout = 0L;
01175         }
01176         if (initializeLogging) {
01177             maxLogFileSize = dbenv.get_lg_max();
01178             logBufferSize = dbenv.get_lg_bsize();
01179             logDirectory = (dbenv.get_lg_dir() == null) ? null :
01180                 new java.io.File(dbenv.get_lg_dir());
01181             logFileMode = dbenv.get_lg_filemode();
01182             logRegionSize = dbenv.get_lg_regionmax();
01183         } else {
01184             maxLogFileSize = 0;
01185             logBufferSize = 0;
01186             logDirectory = null;
01187             logRegionSize = 0;
01188         }
01189         messageStream = dbenv.get_message_stream();
01190 
01191         // XXX: intentional information loss?
01192         password = (dbenv.get_encrypt_flags() == 0) ? null : "";
01193 
01194         if (initializeReplication) {
01195             replicationLimit = dbenv.get_rep_limit();
01196             // XXX: no way to find out replicationRequest{Min,Max}
01197         } else {
01198             replicationLimit = 0L;
01199             replicationRequestMin = 0;
01200             replicationRequestMax = 0;
01201         }
01202 
01203         // XXX: no way to find RPC server?
01204         rpcServer = null;
01205         rpcClientTimeout = 0;
01206         rpcServerTimeout = 0;
01207 
01208         segmentId = dbenv.get_shm_key();
01209         mutexAlignment = dbenv.mutex_get_align();
01210         mutexIncrement = dbenv.mutex_get_increment();
01211         maxMutexes = dbenv.mutex_get_max();
01212         mutexTestAndSetSpins = dbenv.mutex_get_tas_spins();
01213         if (transactional) {
01214             txnMaxActive = dbenv.get_tx_max();
01215             final long txnTimestampSeconds = dbenv.get_tx_timestamp();
01216             if (txnTimestampSeconds != 0L)
01217                 txnTimestamp = new java.util.Date(txnTimestampSeconds * 1000);
01218             else
01219                 txnTimestamp = null;
01220         } else {
01221             txnMaxActive = 0;
01222             txnTimestamp = null;
01223         }
01224         temporaryDirectory = new java.io.File(dbenv.get_tmp_dir());
01225     }
01226 }

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