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.bytecode;
006:
007: import com.tc.cluster.ClusterEventListener;
008: import com.tc.logging.TCLogger;
009: import com.tc.management.beans.sessions.SessionMonitorMBean;
010: import com.tc.object.ObjectID;
011: import com.tc.object.TCObject;
012: import com.tc.object.event.DmiManager;
013: import com.tc.object.lockmanager.api.LockLevel;
014: import com.tc.properties.TCProperties;
015:
016: import java.lang.reflect.Field;
017:
018: /**
019: * The Manager interface
020: */
021: public interface Manager {
022:
023: /** This class's class path: com/tc/object/bytecode/Manager */
024: public static final String CLASS = "com/tc/object/bytecode/Manager";
025: /** Bytecode type definition for this class */
026: public static final String TYPE = "L" + CLASS + ";";
027:
028: public final static int LOCK_TYPE_READ = LockLevel.READ;
029: public final static int LOCK_TYPE_WRITE = LockLevel.WRITE;
030: public final static int LOCK_TYPE_CONCURRENT = LockLevel.CONCURRENT;
031: public final static int LOCK_TYPE_SYNCHRONOUS_WRITE = LockLevel.SYNCHRONOUS_WRITE;
032:
033: /**
034: * Determine whether this class is physically instrumented
035: *
036: * @param clazz Class
037: * @return True if physically instrumented
038: */
039: public boolean isPhysicallyInstrumented(Class clazz);
040:
041: /**
042: * Deep copy the source object graph
043: *
044: * @param source Source object
045: * @return The copy
046: */
047: public Object deepCopy(Object source);
048:
049: /**
050: * Initialize the Manager
051: */
052: public void init();
053:
054: /**
055: * Stop the manager
056: */
057: public void stop();
058:
059: /**
060: * Look up or create a new root object
061: *
062: * @param name Root name
063: * @param object Root object to use if none exists yet
064: * @return The root object actually used, may or may not == object
065: */
066: public Object lookupOrCreateRoot(String name, Object object);
067:
068: /**
069: * Look up or create a new root object. Objects faulted in to arbitrary depth.
070: *
071: * @param name Root name
072: * @param obj Root object to use if none exists yet
073: * @return The root object actually used, may or may not == object
074: */
075: public Object lookupOrCreateRootNoDepth(String name, Object obj);
076:
077: /**
078: * Create or replace root, typically used for replaceable roots.
079: *
080: * @param rootName Root name
081: * @param object Root object
082: * @return Root object used
083: */
084: public Object createOrReplaceRoot(String rootName, Object object);
085:
086: /**
087: * Begin volatile lock
088: *
089: * @param tcObject TCObject to lock
090: * @param fieldName Field name holding volatile object
091: * @param type Lock type
092: */
093: public void beginVolatile(TCObject tcObject, String fieldName,
094: int type);
095:
096: /**
097: * Begin lock
098: *
099: * @param lockID Lock identifier
100: * @param type Lock type
101: */
102: public void beginLock(String lockID, int type);
103:
104: /**
105: * Try to begin lock
106: *
107: * @param lockID Lock identifier
108: * @param type Lock type
109: * @return True if lock was successful
110: */
111: public boolean tryBeginLock(String lockID, int type);
112:
113: /**
114: * Commit volatile lock
115: *
116: * @param tcObject Volatile object TCObject
117: * @param fieldName Field holding the volatile object
118: */
119: public void commitVolatile(TCObject tcObject, String fieldName);
120:
121: /**
122: * Commit lock
123: *
124: * @param lockName Lock name
125: */
126: public void commitLock(String lockName);
127:
128: /**
129: * Look up object by ID, faulting into the JVM if necessary
130: *
131: * @param id Object identifier
132: * @return The actual object
133: */
134: public Object lookupObject(ObjectID id)
135: throws ClassNotFoundException;
136:
137: /**
138: * Look up object by ID, faulting into the JVM if necessary, This method also passes the parent Object context so that
139: * more intelligent prefetching is possible at the L2.
140: *
141: * @param id Object identifier of the object we are looking up
142: * @param parentContext Object identifier of the parent object
143: * @return The actual object
144: * @throws TCClassNotFoundException If a class is not found during faulting
145: */
146: public Object lookupObject(ObjectID id, ObjectID parentContext)
147: throws ClassNotFoundException;
148:
149: /**
150: * Find managed object, which may be null
151: *
152: * @param obj The object instance
153: * @return The TCObject
154: */
155: public TCObject lookupExistingOrNull(Object obj);
156:
157: /**
158: * Find or create new TCObject
159: *
160: * @param obj The object instance
161: * @return The TCObject
162: */
163: public TCObject lookupOrCreate(Object obj);
164:
165: /**
166: * @param pojo Object instance
167: * @return TCObject for pojo
168: */
169: public TCObject shareObjectIfNecessary(Object pojo);
170:
171: /**
172: * Perform notify on obj
173: *
174: * @param obj Instance
175: */
176: public void objectNotify(Object obj);
177:
178: /**
179: * Perform notifyAll on obj
180: *
181: * @param obj Instance
182: */
183: public void objectNotifyAll(Object obj);
184:
185: /**
186: * Perform untimed wait on obj
187: *
188: * @param obj Instance
189: */
190: public void objectWait0(Object obj) throws InterruptedException;
191:
192: /**
193: * Perform timed wait on obj
194: *
195: * @param obj Instance
196: * @param millis Wait time
197: */
198: public void objectWait1(Object obj, long millis)
199: throws InterruptedException;
200:
201: /**
202: * Perform timed wait on obj
203: *
204: * @param obj Instance
205: * @param millis Wait time
206: * @param nonas More wait time
207: */
208: public void objectWait2(Object obj, long millis, int nanos)
209: throws InterruptedException;
210:
211: /**
212: * Enter synchronized monitor
213: *
214: * @param obj Object
215: * @param type Lock type
216: */
217: public void monitorEnter(Object obj, int type);
218:
219: /**
220: * Exit synchronized monitor
221: *
222: * @param obj Object
223: */
224: public void monitorExit(Object obj);
225:
226: /**
227: * Perform invoke on logical managed object
228: *
229: * @param object The object
230: * @param methodName The method to call
231: * @param params The parameters to the method
232: */
233: public void logicalInvoke(Object object, String methodName,
234: Object[] params);
235:
236: /**
237: * Perform invoke on logical managed object in lock
238: *
239: * @param object The object
240: * @param lockObject The lock object
241: * @param methodName The method to call
242: * @param params The parameters to the method
243: */
244: public void logicalInvokeWithTransaction(Object object,
245: Object lockObject, String methodName, Object[] params);
246:
247: /**
248: * Perform distributed method call
249: *
250: * @param receiver The receiver object
251: * @param method The method to call
252: * @param params The parameter values
253: * @param runOnAllNodes True if should run on all nodes, false just for this node
254: */
255: public boolean distributedMethodCall(Object receiver,
256: String method, Object[] params, boolean runOnAllNodes);
257:
258: /**
259: * Commit DMI call
260: */
261: public void distributedMethodCallCommit();
262:
263: /**
264: * Lookup root by name
265: *
266: * @param name Name of root
267: * @return Root object
268: */
269: public Object lookupRoot(String name);
270:
271: /**
272: * Check whether current context has write access
273: *
274: * @param context Context object
275: * @throws com.tc.object.util.ReadOnlyException If in read-only transaction
276: */
277: public void checkWriteAccess(Object context);
278:
279: /**
280: * Check whether an object is managed
281: *
282: * @param object Instance
283: * @return True if managed
284: */
285: public boolean isManaged(Object object);
286:
287: /**
288: * Check whether an object is shared
289: *
290: * @param object Instance
291: * @return True if shared
292: */
293: public boolean isDsoMonitored(Object obj);
294:
295: /**
296: * Check whether dso MonitorExist is required
297: *
298: * @return True if required
299: */
300: public boolean isDsoMonitorEntered(Object obj);
301:
302: /**
303: * Check whether object is logically instrumented
304: *
305: * @param object Instance
306: * @return True if logically instrumented
307: */
308: public boolean isLogical(Object object);
309:
310: /**
311: * Check whether field is a root
312: *
313: * @param field Field
314: * @return True if root
315: */
316: public boolean isRoot(Field field);
317:
318: /**
319: * Begin an optimistic transaction
320: */
321: public void optimisticBegin();
322:
323: /**
324: * Commit an optimistic transaction
325: *
326: * @throws ClassNotFoundException If class not found while faulting in object
327: */
328: public void optimisticCommit() throws ClassNotFoundException;
329:
330: /**
331: * Rollback an optimistic transaction
332: */
333: public void optimisticRollback();
334:
335: /**
336: * Check whether an object is locked at this lockLevel
337: *
338: * @param obj Lock
339: * @param lockLevel Lock level
340: * @return True if locked at this level
341: * @throws NullPointerException If obj is null
342: */
343: public boolean isLocked(Object obj, int lockLevel);
344:
345: /**
346: * Try to enter monitor for specified object
347: *
348: * @param obj The object monitor
349: * @param timeoutInNanos Timeout in nanoseconds
350: * @param type The lock level
351: * @return True if entered
352: * @throws NullPointerException If obj is null
353: */
354: public boolean tryMonitorEnter(Object obj, long timeoutInNanos,
355: int type);
356:
357: /**
358: * Get number of locks held locally on this object
359: *
360: * @param obj The lock object
361: * @param lockLevel The lock level
362: * @return Lock count
363: * @throws NullPointerException If obj is null
364: */
365: public int localHeldCount(Object obj, int lockLevel);
366:
367: /**
368: * Check whether this lock is held by the current thread
369: *
370: * @param obj The lock
371: * @param lockLevel The lock level
372: * @return True if held by current thread
373: * @throws NullPointerException If obj is null
374: */
375: public boolean isHeldByCurrentThread(Object obj, int lockLevel);
376:
377: /**
378: * Number in queue waiting on this lock
379: *
380: * @param obj The object
381: * @return Number of waiters
382: * @throws NullPointerException If obj is null
383: */
384: public int queueLength(Object obj);
385:
386: /**
387: * Number in queue waiting on this wait()
388: *
389: * @param obj The object
390: * @return Number of waiters
391: * @throws NullPointerException If obj is null
392: */
393: public int waitLength(Object obj);
394:
395: /**
396: * Check whether a creation is in progress. This flag is set on a per-thread basis while hydrating an object from DNA.
397: *
398: * @return True if in progress
399: */
400: public boolean isCreationInProgress();
401:
402: /**
403: * Get JVM Client identifier
404: *
405: * @return Client identifier
406: */
407: public String getClientID();
408:
409: /**
410: * Get the named logger
411: *
412: * @param name Logger name
413: * @return The logger
414: */
415: public TCLogger getLogger(String loggerName);
416:
417: /**
418: * @return Session monitor MBean
419: */
420: public SessionMonitorMBean getSessionMonitorMBean();
421:
422: /**
423: * @return TCProperties
424: */
425: public TCProperties getTCProperites();
426:
427: /**
428: * Add listener for cluster events
429: *
430: * @param cel Listener
431: */
432: public void addClusterEventListener(ClusterEventListener cel);
433:
434: /**
435: * @return DMI manager
436: */
437: public DmiManager getDmiManager();
438:
439: /**
440: * Returns true if the field represented by the offset is a portable field, i.e., not static and not dso transient
441: * @param pojo Object
442: * @param fieldOffset The index
443: * @return true if the field is portable and false otherwise
444: */
445: public boolean isFieldPortableByOffset(Object pojo, long fieldOffset);
446:
447: }
|