001: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
002:
003: This file is part of the db4o open source object database.
004:
005: db4o is free software; you can redistribute it and/or modify it under
006: the terms of version 2 of the GNU General Public License as published
007: by the Free Software Foundation and as clarified by db4objects' GPL
008: interpretation policy, available at
009: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011: Suite 350, San Mateo, CA 94403, USA.
012:
013: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014: WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: for more details.
017:
018: You should have received a copy of the GNU General Public License along
019: with this program; if not, write to the Free Software Foundation, Inc.,
020: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
021: package com.db4o;
022:
023: import com.db4o.foundation.*;
024: import com.db4o.internal.*;
025: import com.db4o.internal.marshall.*;
026: import com.db4o.marshall.*;
027:
028: /**
029: * @exclude
030: */
031: public abstract class Debug extends Debug4 {
032:
033: /**
034: * indexes all fields
035: */
036: public static final boolean indexAllFields = false;
037:
038: /**
039: * prints query graph information to the console
040: */
041: public static final boolean queries = false;
042:
043: /**
044: * prints more stack traces
045: */
046: public static final boolean atHome = false;
047:
048: /**
049: * makes C/S timeouts longer, so C/S does not time out in the debugger
050: */
051: public static final boolean longTimeOuts = false;
052:
053: /**
054: * turns freespace debuggin on
055: */
056: public static final boolean freespace = Deploy.debug;
057:
058: /**
059: * fills deleted slots with 'X' and overrides any configured
060: * freespace filler
061: */
062: public static final boolean xbytes = freespace;
063:
064: /**
065: * checks monitor conditions to make sure only the thread
066: * with the global monitor is allowed entry to the core
067: */
068: public static final boolean checkSychronization = false;
069:
070: /**
071: * makes sure a configuration entry is generated for each persistent
072: * class
073: */
074: public static final boolean configureAllClasses = indexAllFields;
075:
076: /**
077: * makes sure a configuration entry is generated for each persistent
078: * field
079: */
080: public static final boolean configureAllFields = indexAllFields;
081:
082: /**
083: * allows turning weak references off
084: */
085: public static final boolean weakReferences = true;
086:
087: /**
088: * prints all communicated messages to the console
089: */
090: public static final boolean messages = false;
091:
092: /**
093: * allows turning NIO off on Java
094: */
095: public static final boolean nio = true;
096:
097: /**
098: * allows overriding the file locking mechanism to turn it off
099: */
100: public static final boolean lockFile = true;
101:
102: /**
103: * allows faking the Db4oDatabase identity object, so the first
104: * stored object in the debugger is the actually persisted object
105: */
106: public static final boolean staticIdentity = false;
107:
108: /**
109: * turn to false, to prevent reading old PBootRecord object
110: * for debugging updating database files.
111: */
112: public static final boolean readBootRecord = true;
113:
114: public static void expect(boolean cond) {
115: if (!cond) {
116: throw new RuntimeException("Should never happen");
117: }
118: }
119:
120: public static void ensureLock(Object obj) {
121: if (atHome) {
122: try {
123: obj.wait(1);
124: } catch (IllegalMonitorStateException imse) {
125: System.err.println("No Lock Alarm.");
126: imse.printStackTrace();
127: } catch (Exception e) {
128: e.printStackTrace();
129: }
130: }
131: }
132:
133: public static boolean exceedsMaximumBlockSize(int a_length) {
134: if (a_length > Const4.MAXIMUM_BLOCK_SIZE) {
135: if (atHome) {
136: System.err.println("Maximum block size exceeded!!!");
137: new Exception().printStackTrace();
138: }
139: return true;
140: }
141: return false;
142: }
143:
144: public static boolean exceedsMaximumArrayEntries(int a_entries,
145: boolean a_primitive) {
146: if (a_entries > (a_primitive ? Const4.MAXIMUM_ARRAY_ENTRIES_PRIMITIVE
147: : Const4.MAXIMUM_ARRAY_ENTRIES)) {
148: if (atHome) {
149: System.err
150: .println("Maximum array elements exceeded!!!");
151: new Exception().printStackTrace();
152: }
153: return true;
154: }
155: return false;
156: }
157:
158: public static final void readBegin(ReadBuffer buffer,
159: byte identifier) {
160: if (Deploy.debug) {
161: if (Deploy.brackets) {
162: if (buffer.readByte() != Const4.YAPBEGIN) {
163: throw new RuntimeException(
164: "Debug.readBegin() YAPBEGIN expected.");
165: }
166: }
167: if (Deploy.identifiers) {
168: byte readB = buffer.readByte();
169: if (readB != identifier) {
170: throw new RuntimeException(
171: "Debug.readBegin() wrong identifier: "
172: + (char) readB);
173: }
174: }
175: }
176:
177: }
178:
179: public static final void readEnd(ReadBuffer buffer) {
180: if (Deploy.debug && Deploy.brackets) {
181: if (buffer.readByte() != Const4.YAPEND) {
182: throw new RuntimeException(
183: "Debug.readEnd() YAPEND expected");
184: }
185: }
186: }
187:
188: public static final void writeBegin(WriteBuffer buffer,
189: byte identifier) {
190: if (Deploy.debug) {
191: if (buffer instanceof MarshallingContext) {
192: Buffer prepend = new Buffer(2);
193: if (Deploy.brackets) {
194: prepend.writeByte(Const4.YAPBEGIN);
195: }
196: if (Deploy.identifiers) {
197: prepend.writeByte(identifier);
198: }
199: ((MarshallingContext) buffer)
200: .debugPrependNextWrite(prepend);
201: return;
202: }
203: if (Deploy.brackets) {
204: buffer.writeByte(Const4.YAPBEGIN);
205: }
206: if (Deploy.identifiers) {
207: buffer.writeByte(identifier);
208: }
209: }
210: }
211:
212: public static final void writeEnd(WriteBuffer buffer) {
213: if (Deploy.debug && Deploy.brackets) {
214: if (buffer instanceof MarshallingContext) {
215: ((MarshallingContext) buffer)
216: .debugWriteEnd(Const4.YAPEND);
217: return;
218: }
219: buffer.writeByte(Const4.YAPEND);
220: }
221: }
222: }
|