001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003: * notice. All rights reserved.
004: */
005: package com.tc.object;
006:
007: import com.tc.object.cache.Cacheable;
008: import com.tc.object.dna.api.DNA;
009: import com.tc.object.dna.api.DNAWriter;
010:
011: import gnu.trove.TLinkable;
012:
013: /**
014: * Terracotta class attached to each shared instance Object. The TCObject may be a simple
015: * object value or may have TCFields representing internal field values.
016: */
017: public interface TCObject extends Cacheable {
018: /** Indicates null object identifier */
019: public static final Long NULL_OBJECT_ID = new Long(-1);
020:
021: /** Indicates null field index */
022: public static final int NULL_INDEX = -1;
023:
024: /**
025: * For Cacheable interface, set next linked item
026: * @param link Next link
027: */
028: public void setNext(TLinkable link);
029:
030: /**
031: * For Cacheable interface, set previous linked item
032: * @param link Previous link
033: */
034: public void setPrevious(TLinkable link);
035:
036: /**
037: * For Cacheable interface, get next linked item
038: * @return Next link
039: */
040: public TLinkable getNext();
041:
042: /**
043: * For Cacheable interface, get previous linked item
044: * @return Next link
045: */
046: public TLinkable getPrevious();
047:
048: /**
049: * Get the object identifier
050: * @return Object identifier
051: */
052: public ObjectID getObjectID();
053:
054: /**
055: * @return True if shared (pretty much always right now)
056: */
057: public boolean isShared();
058:
059: /**
060: * @return The Object that this TCObject is wrapping. This value will be null if the peer Object is null.
061: */
062: public Object getPeerObject();
063:
064: /**
065: * @return The TCClass for this TCObject. The TCClass is a peer of the Class of the peer Object.
066: */
067: public TCClass getTCClass();
068:
069: /**
070: * Clear memory references up to toClear limit
071: * @param toClear - the number of references to clear atmost
072: * @return - the number of references actually cleared
073: */
074: public int clearReferences(int toClear);
075:
076: /**
077: * Get an object to lock on to modify this object.
078: * @return The lock object
079: */
080: public Object getResolveLock();
081:
082: /**
083: * Indicate that an object field has changed
084: * @param classname The class name
085: * @param fieldname The field name
086: * @param newValue The new value
087: * @param index If an array, the index into the array
088: */
089: public void objectFieldChanged(String classname, String fieldname,
090: Object newValue, int index);
091:
092: /**
093: * Indicate that a boolean field has changed
094: * @param classname The class name
095: * @param fieldname The field name
096: * @param newValue The new value
097: * @param index If an array, the index into the array
098: */
099: public void booleanFieldChanged(String classname, String fieldname,
100: boolean newValue, int index);
101:
102: /**
103: * Indicate that a byte field has changed
104: * @param classname The class name
105: * @param fieldname The field name
106: * @param newValue The new value
107: * @param index If an array, the index into the array
108: */
109: public void byteFieldChanged(String classname, String fieldname,
110: byte newValue, int index);
111:
112: /**
113: * Indicate that a char field has changed
114: * @param classname The class name
115: * @param fieldname The field name
116: * @param newValue The new value
117: * @param index If an array, the index into the array
118: */
119: public void charFieldChanged(String classname, String fieldname,
120: char newValue, int index);
121:
122: /**
123: * Indicate that a double field has changed
124: * @param classname The class name
125: * @param fieldname The field name
126: * @param newValue The new value
127: * @param index If an array, the index into the array
128: */
129: public void doubleFieldChanged(String classname, String fieldname,
130: double newValue, int index);
131:
132: /**
133: * Indicate that a float field has changed
134: * @param classname The class name
135: * @param fieldname The field name
136: * @param newValue The new value
137: * @param index If an array, the index into the array
138: */
139: public void floatFieldChanged(String classname, String fieldname,
140: float newValue, int index);
141:
142: /**
143: * Indicate that an int field has changed
144: * @param classname The class name
145: * @param fieldname The field name
146: * @param newValue The new value
147: * @param index If an array, the index into the array
148: */
149: public void intFieldChanged(String classname, String fieldname,
150: int newValue, int index);
151:
152: /**
153: * Indicate that a long field has changed
154: * @param classname The class name
155: * @param fieldname The field name
156: * @param newValue The new value
157: * @param index If an array, the index into the array
158: */
159: public void longFieldChanged(String classname, String fieldname,
160: long newValue, int index);
161:
162: /**
163: * Indicate that a short field has changed
164: * @param classname The class name
165: * @param fieldname The field name
166: * @param newValue The new value
167: * @param index If an array, the index into the array
168: */
169: public void shortFieldChanged(String classname, String fieldname,
170: short newValue, int index);
171:
172: /**
173: * Indicate that an object array changed
174: * @param startPos The starting position of the change
175: * @param array The changed array
176: * @param length The length of the changed array
177: */
178: public void objectArrayChanged(int startPos, Object[] array,
179: int length);
180:
181: /**
182: * Indicate that primitive array changed
183: * @param startPos The starting position of the change
184: * @param array The changed array
185: * @param length The length of the changed array
186: */
187: public void primitiveArrayChanged(int startPos, Object array,
188: int length);
189:
190: /**
191: * Indicate that a literal value changed
192: * @param oldValue The old value
193: * @param newValue The new value
194: */
195: public void literalValueChanged(Object newValue, Object oldValue);
196:
197: /**
198: * Set new literal value
199: * @param newValue The new value
200: */
201: public void setLiteralValue(Object newValue);
202:
203: /**
204: * Takes a DNA strand and hydrates the object with it.
205: *
206: * @param force true if the DNA should be applied w/o any version checking
207: * @throws ClassNotFoundException If class not found
208: */
209: public void hydrate(DNA from, boolean force)
210: throws ClassNotFoundException;
211:
212: /**
213: * Check whether the specified index is valid
214: * @param index The array index to check
215: * @return An exception if invalid
216: */
217: public ArrayIndexOutOfBoundsException checkArrayIndex(int index);
218:
219: /**
220: * Fault in field object if necessary
221: * @param fieldName Fully-qualified fieldn name
222: */
223: public void resolveReference(String fieldName);
224:
225: /**
226: * Fault in an array reference
227: * @param index Index when the peer object is an array
228: */
229: public void resolveArrayReference(int index);
230:
231: /**
232: * Fault in all references
233: */
234: public void resolveAllReferences();
235:
236: /**
237: * Set a reference for a field in this object
238: * @param fieldName Field in this object
239: * @param id New reference for this field
240: * @returns Old mapping if present
241: */
242: public ObjectID setReference(String fieldName, ObjectID id);
243:
244: /**
245: * Set an array index reference
246: * @param index The index in this array
247: * @param id The new reference for that index
248: */
249: public void setArrayReference(int index, ObjectID id);
250:
251: /**
252: * Clear the reference for the given field
253: * @param fieldName
254: */
255: public void clearReference(String fieldName);
256:
257: /**
258: * Set new value for a field of this object
259: * @param fieldName The field name
260: * @param obj The object to set for this field
261: */
262: public void setValue(String fieldName, Object obj);
263:
264: /**
265: * Get version of this object instance
266: * @return Version
267: */
268: public long getVersion();
269:
270: /**
271: * Set a new version for this object
272: * @param version New version
273: */
274: public void setVersion(long version);
275:
276: /**
277: * Set whether this object is new
278: */
279: public void setIsNew();
280:
281: /**
282: * @return True if new
283: */
284: public boolean isNew();
285:
286: /**
287: * Set a field value change by offset
288: * @param classname Class name
289: * @param fieldOffset The offset into this object's fields
290: * @param newValue New object value
291: * @param index The index if this peer object is an array
292: */
293: public void objectFieldChangedByOffset(String classname,
294: long fieldOffset, Object newValue, int index);
295:
296: /**
297: * Get field name from field offset
298: * @param fieldOffset The offset for the field
299: * @return Field name
300: */
301: public String getFieldNameByOffset(long fieldOffset);
302:
303: /**
304: * Invoke logical method
305: * @param method Method indicator, as defined in {@link com.tc.object.SerializationUtil}
306: * @param methodSignature The signature description
307: * @param params The parameter values
308: */
309: public void logicalInvoke(int method, String methodSignature,
310: Object[] params);
311:
312: /**
313: * Turns off auto locking.
314: */
315: public void disableAutoLocking();
316:
317: /**
318: * @return True if auto locking enabled.
319: */
320: public boolean autoLockingDisabled();
321:
322: /**
323: * Writes all of the object data to the given DNAWriter, iff object is new
324: * @param writer The writer
325: * @return True if written
326: */
327: public boolean dehydrateIfNew(DNAWriter writer);
328:
329: /**
330: * Returns true if the field represented by the offset is a portable field, i.e., not static and not dso transient
331: * @param fieldOffset The index
332: * @return true if the field is portable and false otherwise
333: */
334: public boolean isFieldPortableByOffset(long fieldOffset);
335: }
|