0001: /*
0002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
0003: * notice. All rights reserved.
0004: */
0005: package com.tc.object.bytecode;
0006:
0007: import com.tc.cluster.ClusterEventListener;
0008: import com.tc.exception.TCClassNotFoundException;
0009: import com.tc.logging.TCLogger;
0010: import com.tc.management.beans.sessions.SessionMonitorMBean;
0011: import com.tc.object.ObjectID;
0012: import com.tc.object.TCObject;
0013: import com.tc.object.bytecode.hook.impl.ArrayManager;
0014: import com.tc.object.bytecode.hook.impl.ClassProcessorHelper;
0015: import com.tc.object.lockmanager.api.LockLevel;
0016: import com.tc.properties.TCProperties;
0017:
0018: import java.lang.reflect.Field;
0019:
0020: /**
0021: * A bunch of static methods that make calling Manager method much easier from instrumented classes
0022: */
0023: public class ManagerUtil {
0024:
0025: /** This class name */
0026: public static final String CLASS = "com/tc/object/bytecode/ManagerUtil";
0027: /** This class type */
0028: public static final String TYPE = "L" + CLASS + ";";
0029:
0030: private static final Manager NULL_MANAGER = NullManager
0031: .getInstance();
0032:
0033: private static volatile boolean enabled = false;
0034:
0035: /**
0036: * Called when initialization has proceeded enough that the Manager can be used.
0037: */
0038: public static void enable() {
0039: enabled = true;
0040: }
0041:
0042: public static Manager getManager() {
0043: if (!enabled) {
0044: return NULL_MANAGER;
0045: }
0046:
0047: if (ClassProcessorHelper.USE_GLOBAL_CONTEXT) {
0048: return GlobalManagerHolder.instance;
0049: } else {
0050: ClassLoader loader = Thread.currentThread()
0051: .getContextClassLoader();
0052: Manager rv = ClassProcessorHelper.getManager(loader);
0053: if (rv == null) {
0054: return NULL_MANAGER;
0055: }
0056: return rv;
0057: }
0058: }
0059:
0060: /**
0061: * Get the named logger
0062: *
0063: * @param name Logger name
0064: * @return The logger
0065: */
0066: public static TCLogger getLogger(String loggerName) {
0067: return getManager().getLogger(loggerName);
0068: }
0069:
0070: /**
0071: * Determine whether this class is physically instrumented
0072: *
0073: * @param clazz Class
0074: * @return True if physically instrumented
0075: */
0076: public static boolean isPhysicallyInstrumented(Class clazz) {
0077: return getManager().isPhysicallyInstrumented(clazz);
0078: }
0079:
0080: /**
0081: * Begin an optimistic transaction
0082: */
0083: public static void optimisticBegin() {
0084: getManager().optimisticBegin();
0085: }
0086:
0087: /**
0088: * Commit an optimistic transaction
0089: *
0090: * @throws ClassNotFoundException If class not found while faulting in object
0091: */
0092: public static void optimisticCommit() {
0093: beginLock("test", LockLevel.WRITE);
0094: try {
0095: getManager().optimisticCommit();
0096: } catch (ClassNotFoundException e) {
0097: throw new TCClassNotFoundException(e);
0098: }
0099: commitLock("test");
0100: }
0101:
0102: /**
0103: * Rollback an optimistic transaction
0104: */
0105: public static void optimisticRollback() {
0106: getManager().optimisticRollback();
0107: }
0108:
0109: /**
0110: * Get JVM Client identifier
0111: *
0112: * @return Client identifier
0113: */
0114: public static String getClientID() {
0115: return getManager().getClientID();
0116: }
0117:
0118: /**
0119: * Deep copy the source object graph
0120: *
0121: * @param source Source object
0122: * @return The copy
0123: */
0124: public static Object deepCopy(Object pojo) {
0125: return getManager().deepCopy(pojo);
0126: }
0127:
0128: /**
0129: * Look up or create a new root object
0130: *
0131: * @param name Root name
0132: * @param object Root object to use if none exists yet
0133: * @return The root object actually used, may or may not == object
0134: */
0135: public static Object lookupOrCreateRoot(String name, Object object) {
0136: return getManager().lookupOrCreateRoot(name, object);
0137: }
0138:
0139: /**
0140: * Look up or create a new root object. Objects faulted in to arbitrary depth.
0141: *
0142: * @param name Root name
0143: * @param obj Root object to use if none exists yet
0144: * @return The root object actually used, may or may not == object
0145: */
0146: public static Object lookupOrCreateRootNoDepth(String name,
0147: Object obj) {
0148: return getManager().lookupOrCreateRootNoDepth(name, obj);
0149: }
0150:
0151: /**
0152: * Create or replace root, typically used for replaceable roots.
0153: *
0154: * @param rootName Root name
0155: * @param object Root object
0156: * @return Root object used
0157: */
0158: public static Object createOrReplaceRoot(String rootName,
0159: Object object) {
0160: return getManager().createOrReplaceRoot(rootName, object);
0161: }
0162:
0163: /**
0164: * Begin volatile lock by field offset in the class
0165: *
0166: * @param pojo Instance containing field
0167: * @param fieldOffset Field offset in pojo
0168: * @param type Lock level
0169: */
0170: public static void beginVolatileByOffset(Object pojo,
0171: long fieldOffset, int type) {
0172: TCObject tcObject = lookupExistingOrNull(pojo);
0173: if (tcObject == null) {
0174: throw new NullPointerException(
0175: "beginVolatileByOffset called on a null TCObject");
0176: }
0177:
0178: beginVolatile(tcObject, tcObject
0179: .getFieldNameByOffset(fieldOffset), type);
0180: }
0181:
0182: /**
0183: * Commit volatile lock by field offset in the class
0184: *
0185: * @param pojo Instance containing field
0186: * @param fieldOffset Field offset in pojo
0187: */
0188: public static void commitVolatileByOffset(Object pojo,
0189: long fieldOffset) {
0190: TCObject tcObject = lookupExistingOrNull(pojo);
0191: if (tcObject == null) {
0192: throw new NullPointerException(
0193: "commitVolatileByOffset called on a null TCObject");
0194: }
0195:
0196: commitVolatile(tcObject, tcObject
0197: .getFieldNameByOffset(fieldOffset));
0198: }
0199:
0200: /**
0201: * Begin volatile lock
0202: *
0203: * @param tcObject TCObject to lock
0204: * @param fieldName Field name holding volatile object
0205: * @param type Lock type
0206: */
0207: public static void beginVolatile(TCObject tcObject,
0208: String fieldName, int type) {
0209: getManager().beginVolatile(tcObject, fieldName, type);
0210: }
0211:
0212: /**
0213: * Begin lock
0214: *
0215: * @param lockID Lock identifier
0216: * @param type Lock type
0217: */
0218: public static void beginLock(String lockID, int type) {
0219: getManager().beginLock(lockID, type);
0220: }
0221:
0222: /**
0223: * Try to begin lock
0224: *
0225: * @param lockID Lock identifier
0226: * @param type Lock type
0227: * @return True if lock was successful
0228: */
0229: public static boolean tryBeginLock(String lockID, int type) {
0230: return getManager().tryBeginLock(lockID, type);
0231: }
0232:
0233: /**
0234: * Commit volatile lock
0235: *
0236: * @param tcObject Volatile object TCObject
0237: * @param fieldName Field holding the volatile object
0238: */
0239: public static void commitVolatile(TCObject tcObject,
0240: String fieldName) {
0241: getManager().commitVolatile(tcObject, fieldName);
0242: }
0243:
0244: /**
0245: * Commit lock
0246: *
0247: * @param lockID Lock name
0248: */
0249: public static void commitLock(String lockID) {
0250: getManager().commitLock(lockID);
0251: }
0252:
0253: /**
0254: * Find managed object, which may be null
0255: *
0256: * @param pojo The object instance
0257: * @return The TCObject
0258: */
0259: public static TCObject lookupExistingOrNull(Object pojo) {
0260: return getManager().lookupExistingOrNull(pojo);
0261: }
0262:
0263: /**
0264: * @param pojo Object instance
0265: * @return TCObject for pojo
0266: */
0267: public static TCObject shareObjectIfNecessary(Object pojo) {
0268: return getManager().shareObjectIfNecessary(pojo);
0269: }
0270:
0271: /**
0272: * Perform invoke on logical managed object
0273: *
0274: * @param object The object
0275: * @param methodName The method to call
0276: * @param params The parameters to the method
0277: */
0278: public static void logicalInvoke(Object object, String methodName,
0279: Object[] params) {
0280: getManager().logicalInvoke(object, methodName, params);
0281: }
0282:
0283: /**
0284: * Perform invoke on logical managed object in lock
0285: *
0286: * @param object The object
0287: * @param lockObject The lock object
0288: * @param methodName The method to call
0289: * @param params The parameters to the method
0290: */
0291: public static void logicalInvokeWithTransaction(Object object,
0292: Object lockObject, String methodName, Object[] params) {
0293: getManager().logicalInvokeWithTransaction(object, lockObject,
0294: methodName, params);
0295: }
0296:
0297: /**
0298: * Commit DMI call
0299: */
0300: public static void distributedMethodCallCommit() {
0301: getManager().distributedMethodCallCommit();
0302: }
0303:
0304: /**
0305: * Perform distributed method call on just this node
0306: *
0307: * @param receiver The receiver object
0308: * @param method The method to call
0309: * @param params The parameter values
0310: */
0311: public static boolean prunedDistributedMethodCall(Object receiver,
0312: String method, Object[] params) {
0313: return getManager().distributedMethodCall(receiver, method,
0314: params, false);
0315: }
0316:
0317: /**
0318: * Perform distributed method call on all nodes
0319: *
0320: * @param receiver The receiver object
0321: * @param method The method to call
0322: * @param params The parameter values
0323: */
0324: public static boolean distributedMethodCall(Object receiver,
0325: String method, Object[] params) {
0326: return getManager().distributedMethodCall(receiver, method,
0327: params, true);
0328: }
0329:
0330: /**
0331: * Lookup root by name
0332: *
0333: * @param name Name of root
0334: * @return Root object
0335: */
0336: public static Object lookupRoot(String name) {
0337: return getManager().lookupRoot(name);
0338: }
0339:
0340: /**
0341: * Look up object by ID, faulting into the JVM if necessary
0342: *
0343: * @param id Object identifier
0344: * @return The actual object
0345: * @throws TCClassNotFoundException If a class is not found during faulting
0346: */
0347: public static Object lookupObject(ObjectID id) {
0348: try {
0349: return getManager().lookupObject(id);
0350: } catch (ClassNotFoundException e) {
0351: throw new TCClassNotFoundException(e);
0352: }
0353: }
0354:
0355: /**
0356: * Look up object by ID, faulting into the JVM if necessary, This method also passes the parent Object context so that
0357: * more intelligent prefetching is possible at the L2.
0358: *
0359: * XXX::FIXME:: This method is not called lookupObject() coz ManagerHelperFactory doesn't allow method overloading.
0360: *
0361: * @param id Object identifier of the object we are looking up
0362: * @param parentContext Object identifier of the parent object
0363: * @return The actual object
0364: * @throws TCClassNotFoundException If a class is not found during faulting
0365: */
0366: public static Object lookupObjectWithParentContext(ObjectID id,
0367: ObjectID parentContext) {
0368: try {
0369: return getManager().lookupObject(id, parentContext);
0370: } catch (ClassNotFoundException e) {
0371: throw new TCClassNotFoundException(e);
0372: }
0373: }
0374:
0375: /**
0376: * Find or create new TCObject
0377: *
0378: * @param obj The object instance
0379: * @return The TCObject
0380: */
0381: public static TCObject lookupOrCreate(Object obj) {
0382: return getManager().lookupOrCreate(obj);
0383: }
0384:
0385: /**
0386: * Check whether current context has write access
0387: *
0388: * @param context Context object
0389: * @throws com.tc.object.util.ReadOnlyException If in read-only transaction
0390: */
0391: public static void checkWriteAccess(Object context) {
0392: getManager().checkWriteAccess(context);
0393: }
0394:
0395: /**
0396: * Check whether an object is managed
0397: *
0398: * @param obj Instance
0399: * @return True if managed
0400: */
0401: public static boolean isManaged(Object obj) {
0402: return getManager().isManaged(obj);
0403: }
0404:
0405: /**
0406: * Check whether an object is shared
0407: *
0408: * @param obj Instance
0409: * @return True if shared
0410: */
0411: public static boolean isDsoMonitored(Object obj) {
0412: return getManager().isDsoMonitored(obj);
0413: }
0414:
0415: /**
0416: * Check whether dso MonitorExist is required
0417: *
0418: * @return True if required
0419: */
0420: public static boolean isDsoMonitorEntered(Object obj) {
0421: return getManager().isDsoMonitorEntered(obj);
0422: }
0423:
0424: /**
0425: * Check whether object is logically instrumented
0426: *
0427: * @param obj Instance
0428: * @return True if logically instrumented
0429: */
0430: public static boolean isLogical(Object obj) {
0431: return getManager().isLogical(obj);
0432: }
0433:
0434: /**
0435: * Check whether field is a root
0436: *
0437: * @param field Field
0438: * @return True if root
0439: */
0440: public static boolean isRoot(Field field) {
0441: return getManager().isRoot(field);
0442: }
0443:
0444: /**
0445: * Perform notify on obj
0446: *
0447: * @param obj Instance
0448: */
0449: public static void objectNotify(Object obj) {
0450: getManager().objectNotify(obj);
0451: }
0452:
0453: /**
0454: * Perform notifyAll on obj
0455: *
0456: * @param obj Instance
0457: */
0458: public static void objectNotifyAll(Object obj) {
0459: getManager().objectNotifyAll(obj);
0460: }
0461:
0462: /**
0463: * Perform untimed wait on obj
0464: *
0465: * @param obj Instance
0466: */
0467: public static void objectWait0(Object obj)
0468: throws InterruptedException {
0469: getManager().objectWait0(obj);
0470: }
0471:
0472: /**
0473: * Perform timed wait on obj
0474: *
0475: * @param obj Instance
0476: * @param millis Wait time
0477: */
0478: public static void objectWait1(Object obj, long millis)
0479: throws InterruptedException {
0480: getManager().objectWait1(obj, millis);
0481: }
0482:
0483: /**
0484: * Perform timed wait on obj
0485: *
0486: * @param obj Instance
0487: * @param millis Wait time
0488: * @param nonas More wait time
0489: */
0490: public static void objectWait2(Object obj, long millis, int nanos)
0491: throws InterruptedException {
0492: getManager().objectWait2(obj, millis, nanos);
0493: }
0494:
0495: /**
0496: * Enter synchronized monitor
0497: *
0498: * @param obj Object
0499: * @param type Lock type
0500: */
0501: public static void monitorEnter(Object obj, int type) {
0502: getManager().monitorEnter(obj, type);
0503: }
0504:
0505: /**
0506: * Exit synchronized monitor
0507: *
0508: * @param obj Object
0509: */
0510: public static void monitorExit(Object obj) {
0511: getManager().monitorExit(obj);
0512: }
0513:
0514: /**
0515: * Check whether an object is locked at this lockLevel
0516: *
0517: * @param obj Lock
0518: * @param lockLevel Lock level
0519: * @return True if locked at this level
0520: * @throws NullPointerException If obj is null
0521: */
0522: public static boolean isLocked(Object obj, int lockLevel) {
0523: return getManager().isLocked(obj, lockLevel);
0524: }
0525:
0526: /**
0527: * Try to enter monitor for specified object
0528: *
0529: * @param obj The object monitor
0530: * @param timeoutInNanos Timeout in nanoseconds
0531: * @param type The lock level
0532: * @return True if entered
0533: * @throws NullPointerException If obj is null
0534: */
0535: public static boolean tryMonitorEnter(Object obj,
0536: long timeoutInNanos, int type) {
0537: return getManager().tryMonitorEnter(obj, timeoutInNanos, type);
0538: }
0539:
0540: /**
0541: * Get number of locks held locally on this object
0542: *
0543: * @param obj The lock object
0544: * @param lockLevel The lock level
0545: * @return Lock count
0546: * @throws NullPointerException If obj is null
0547: */
0548: public static int localHeldCount(Object obj, int lockLevel) {
0549: return getManager().localHeldCount(obj, lockLevel);
0550: }
0551:
0552: /**
0553: * Check whether this lock is held by the current thread
0554: *
0555: * @param obj The lock
0556: * @param lockLevel The lock level
0557: * @return True if held by current thread
0558: * @throws NullPointerException If obj is null
0559: */
0560: public static boolean isHeldByCurrentThread(Object obj,
0561: int lockLevel) {
0562: return getManager().isHeldByCurrentThread(obj, lockLevel);
0563: }
0564:
0565: /**
0566: * Number in queue waiting on this lock
0567: *
0568: * @param obj The object
0569: * @return Number of waiters
0570: * @throws NullPointerException If obj is null
0571: */
0572: public static int queueLength(Object obj) {
0573: return getManager().queueLength(obj);
0574: }
0575:
0576: /**
0577: * Number in queue waiting on this wait()
0578: *
0579: * @param obj The object
0580: * @return Number of waiters
0581: * @throws NullPointerException If obj is null
0582: */
0583: public static int waitLength(Object obj) {
0584: return getManager().waitLength(obj);
0585: }
0586:
0587: /**
0588: * Check whether a creation is in progress. This flag is set on a per-thread basis while hydrating an object from DNA.
0589: *
0590: * @return True if in progress
0591: */
0592: public static boolean isCreationInProgress() {
0593: return getManager().isCreationInProgress();
0594: }
0595:
0596: private ManagerUtil() {
0597: // not for public instantiation
0598: }
0599:
0600: private static class GlobalManagerHolder {
0601: static final Manager instance;
0602: static {
0603: instance = ClassProcessorHelper.getGlobalManager();
0604: }
0605: }
0606:
0607: /**
0608: * For java.lang.reflect.Array.get()
0609: *
0610: * @param array The array
0611: * @param index Index into the array
0612: * @return Item in array at index, boxed to Object if primitive array
0613: * @throws NullPointerException If array is null
0614: * @throws IllegalArgumentException If array is not an array type
0615: */
0616: public static Object get(Object array, int index)
0617: throws IllegalArgumentException,
0618: ArrayIndexOutOfBoundsException {
0619: return ArrayManager.get(array, index);
0620: }
0621:
0622: /**
0623: * This method is part of java.lang.reflect.Array and does the same as the set() method in the Sun JDK, the IBM
0624: * version of the set method just adds a series of argument checks and then delegates to the native setImpl version.
0625: *
0626: * @param array Array
0627: * @param index Index in array
0628: * @param value New value
0629: * @throws NullPointerException If array is null
0630: * @throws IllegalArgumentException If array is an unexpected array type
0631: * @throws ArrayIndexOutOfBoundsException If index is not in valid range for array
0632: */
0633: public static void setImpl(Object array, int index, Object value)
0634: throws IllegalArgumentException,
0635: ArrayIndexOutOfBoundsException {
0636: set(array, index, value);
0637: }
0638:
0639: /**
0640: * This method is part of java.lang.reflect.Array and does the same as the set() method in the Sun JDK, the IBM
0641: * version of the set method just adds a series of argument checks and then delegates to the native setImpl version.
0642: *
0643: * @param array Array
0644: * @param index Index in array
0645: * @param value New value
0646: * @throws NullPointerException If array is null
0647: * @throws IllegalArgumentException If array is an unexpected array type
0648: * @throws ArrayIndexOutOfBoundsException If index is not in valid range for array
0649: */
0650: public static void set(Object array, int index, Object value)
0651: throws IllegalArgumentException,
0652: ArrayIndexOutOfBoundsException {
0653: if (array == null)
0654: throw new NullPointerException();
0655:
0656: if (array instanceof Object[]) {
0657: Class componentType = array.getClass().getComponentType();
0658: if (value != null && !componentType.isInstance(value)) {
0659: //
0660: throw new IllegalArgumentException(
0661: "Cannot assign an instance of type "
0662: + value.getClass().getName()
0663: + " to array with component type "
0664: + componentType.getName());
0665: }
0666: ArrayManager.objectArrayChanged((Object[]) array, index,
0667: value);
0668: } else if (value instanceof Byte)
0669: setByte(array, index, ((Byte) value).byteValue());
0670: else if (value instanceof Short)
0671: setShort(array, index, ((Short) value).shortValue());
0672: else if (value instanceof Integer)
0673: setInt(array, index, ((Integer) value).intValue());
0674: else if (value instanceof Long)
0675: setLong(array, index, ((Long) value).longValue());
0676: else if (value instanceof Float)
0677: setFloat(array, index, ((Float) value).floatValue());
0678: else if (value instanceof Double)
0679: setDouble(array, index, ((Double) value).doubleValue());
0680: else if (value instanceof Character)
0681: setChar(array, index, ((Character) value).charValue());
0682: else if (value instanceof Boolean)
0683: setBoolean(array, index, ((Boolean) value).booleanValue());
0684: else
0685: throw new IllegalArgumentException("Not an array type: "
0686: + array.getClass().getName());
0687: }
0688:
0689: /**
0690: * Set boolean value in array
0691: *
0692: * @param array Array
0693: * @param index Index in array
0694: * @param z New boolean value
0695: * @throws NullPointerException If array is null
0696: * @throws IllegalArgumentException If array is an unexpected array type
0697: * @throws ArrayIndexOutOfBoundsException If index is not in valid range for array
0698: */
0699: public static void setBoolean(Object array, int index, boolean z)
0700: throws IllegalArgumentException,
0701: ArrayIndexOutOfBoundsException {
0702: if (array == null)
0703: throw new NullPointerException();
0704:
0705: if (array instanceof boolean[]) {
0706: byte b = z ? (byte) 1 : (byte) 0;
0707:
0708: ArrayManager.byteOrBooleanArrayChanged(array, index, b);
0709: } else
0710: throw new IllegalArgumentException();
0711: }
0712:
0713: /**
0714: * Set byte value in array
0715: *
0716: * @param array Array
0717: * @param index Index in array
0718: * @param b New byte value
0719: * @throws NullPointerException If array is null
0720: * @throws IllegalArgumentException If array is an unexpected array type
0721: * @throws ArrayIndexOutOfBoundsException If index is not in valid range for array
0722: */
0723: public static void setByte(Object array, int index, byte b)
0724: throws IllegalArgumentException,
0725: ArrayIndexOutOfBoundsException {
0726: if (array == null)
0727: throw new NullPointerException();
0728:
0729: if (array instanceof byte[])
0730: ArrayManager.byteOrBooleanArrayChanged(array, index, b);
0731: else
0732: setShort(array, index, b);
0733: }
0734:
0735: /**
0736: * Set int value in array
0737: *
0738: * @param array Array
0739: * @param index Index in array
0740: * @param c New int value
0741: * @throws NullPointerException If array is null
0742: * @throws IllegalArgumentException If array is an unexpected array type
0743: * @throws ArrayIndexOutOfBoundsException If index is not in valid range for array
0744: */
0745: public static void setChar(Object array, int index, char c)
0746: throws IllegalArgumentException,
0747: ArrayIndexOutOfBoundsException {
0748: if (array == null)
0749: throw new NullPointerException();
0750:
0751: if (array instanceof char[])
0752: ArrayManager.charArrayChanged((char[]) array, index, c);
0753: else
0754: setInt(array, index, c);
0755: }
0756:
0757: /**
0758: * Set short value in array
0759: *
0760: * @param array Array
0761: * @param index Index in array
0762: * @param s New short value
0763: * @throws NullPointerException If array is null
0764: * @throws IllegalArgumentException If array is an unexpected array type
0765: * @throws ArrayIndexOutOfBoundsException If index is not in valid range for array
0766: */
0767: public static void setShort(Object array, int index, short s)
0768: throws IllegalArgumentException,
0769: ArrayIndexOutOfBoundsException {
0770: if (array == null)
0771: throw new NullPointerException();
0772:
0773: if (array instanceof short[])
0774: ArrayManager.shortArrayChanged((short[]) array, index, s);
0775: else
0776: setInt(array, index, s);
0777: }
0778:
0779: /**
0780: * Set int value in array
0781: *
0782: * @param array Array
0783: * @param index Index in array
0784: * @param i New int value
0785: * @throws NullPointerException If array is null
0786: * @throws IllegalArgumentException If array is an unexpected array type
0787: * @throws ArrayIndexOutOfBoundsException If index is not in valid range for array
0788: */
0789: public static void setInt(Object array, int index, int i)
0790: throws IllegalArgumentException,
0791: ArrayIndexOutOfBoundsException {
0792: if (array == null)
0793: throw new NullPointerException();
0794:
0795: if (array instanceof int[])
0796: ArrayManager.intArrayChanged((int[]) array, index, i);
0797: else
0798: setLong(array, index, i);
0799: }
0800:
0801: /**
0802: * Set long value in array
0803: *
0804: * @param array Array
0805: * @param index Index in array
0806: * @param l New long value
0807: * @throws NullPointerException If array is null
0808: * @throws IllegalArgumentException If array is an unexpected array type
0809: * @throws ArrayIndexOutOfBoundsException If index is not in valid range for array
0810: */
0811: public static void setLong(Object array, int index, long l)
0812: throws IllegalArgumentException,
0813: ArrayIndexOutOfBoundsException {
0814: if (array == null)
0815: throw new NullPointerException();
0816:
0817: if (array instanceof long[])
0818: ArrayManager.longArrayChanged((long[]) array, index, l);
0819: else
0820: setFloat(array, index, l);
0821: }
0822:
0823: /**
0824: * Set float value in array
0825: *
0826: * @param array Array
0827: * @param index Index in array
0828: * @param f New float value
0829: * @throws NullPointerException If array is null
0830: * @throws IllegalArgumentException If array is an unexpected array type
0831: * @throws ArrayIndexOutOfBoundsException If index is not in valid range for array
0832: */
0833: public static void setFloat(Object array, int index, float f)
0834: throws IllegalArgumentException,
0835: ArrayIndexOutOfBoundsException {
0836: if (array == null)
0837: throw new NullPointerException();
0838:
0839: if (array instanceof float[])
0840: ArrayManager.floatArrayChanged((float[]) array, index, f);
0841: else
0842: setDouble(array, index, f);
0843: }
0844:
0845: /**
0846: * Set double value in array
0847: *
0848: * @param array Array
0849: * @param index Index in array
0850: * @param d New double value
0851: * @throws NullPointerException If array is null
0852: * @throws IllegalArgumentException If array is an unexpected array type
0853: * @throws ArrayIndexOutOfBoundsException If index is not in valid range for array
0854: */
0855: public static void setDouble(Object array, int index, double d)
0856: throws IllegalArgumentException,
0857: ArrayIndexOutOfBoundsException {
0858: if (array == null)
0859: throw new NullPointerException();
0860:
0861: if (array instanceof double[])
0862: ArrayManager.doubleArrayChanged((double[]) array, index, d);
0863: else
0864: throw new IllegalArgumentException();
0865: }
0866:
0867: /**
0868: * Indicate that object in array changed
0869: *
0870: * @param array The array
0871: * @param index The index into array
0872: * @param value The new value
0873: */
0874: public static void objectArrayChanged(Object[] array, int index,
0875: Object value) {
0876: ArrayManager.objectArrayChanged(array, index, value);
0877: }
0878:
0879: /**
0880: * Indicate that short in array changed
0881: *
0882: * @param array The array
0883: * @param index The index into array
0884: * @param value The new value
0885: */
0886: public static void shortArrayChanged(short[] array, int index,
0887: short value) {
0888: ArrayManager.shortArrayChanged(array, index, value);
0889: }
0890:
0891: /**
0892: * Indicate that long in array changed
0893: *
0894: * @param array The array
0895: * @param index The index into array
0896: * @param value The new value
0897: */
0898: public static void longArrayChanged(long[] array, int index,
0899: long value) {
0900: ArrayManager.longArrayChanged(array, index, value);
0901: }
0902:
0903: /**
0904: * Indicate that int in array changed
0905: *
0906: * @param array The array
0907: * @param index The index into array
0908: * @param value The new value
0909: */
0910: public static void intArrayChanged(int[] array, int index, int value) {
0911: ArrayManager.intArrayChanged(array, index, value);
0912: }
0913:
0914: /**
0915: * Indicate that float in array changed
0916: *
0917: * @param array The array
0918: * @param index The index into array
0919: * @param value The new value
0920: */
0921: public static void floatArrayChanged(float[] array, int index,
0922: float value) {
0923: ArrayManager.floatArrayChanged(array, index, value);
0924: }
0925:
0926: /**
0927: * Indicate that double in array changed
0928: *
0929: * @param array The array
0930: * @param index The index into array
0931: * @param value The new value
0932: */
0933: public static void doubleArrayChanged(double[] array, int index,
0934: double value) {
0935: ArrayManager.doubleArrayChanged(array, index, value);
0936: }
0937:
0938: /**
0939: * Indicate that char in array changed
0940: *
0941: * @param array The array
0942: * @param index The index into array
0943: * @param value The new value
0944: */
0945: public static void charArrayChanged(char[] array, int index,
0946: char value) {
0947: ArrayManager.charArrayChanged(array, index, value);
0948: }
0949:
0950: /**
0951: * Indicate that byte or boolean in array changed
0952: *
0953: * @param array The array
0954: * @param index The index into array
0955: * @param value The new value
0956: */
0957: public static void byteOrBooleanArrayChanged(Object array,
0958: int index, byte value) {
0959: ArrayManager.byteOrBooleanArrayChanged(array, index, value);
0960: }
0961:
0962: /**
0963: * Handle System.arraycopy() semantics with managed arrays
0964: *
0965: * @param src Source array
0966: * @param srcPos Start index in source
0967: * @param dest Destination array
0968: * @param destPos Destination start index
0969: * @param length Number of items to copy
0970: * @throws NullPointerException If src or dest is null
0971: */
0972: public static void arraycopy(Object src, int srcPos, Object dest,
0973: int destPos, int length) {
0974: ArrayManager.arraycopy(src, srcPos, dest, destPos, length);
0975: }
0976:
0977: /**
0978: * Get the TCO for an array
0979: *
0980: * @param array The array instance
0981: * @return The TCObject
0982: */
0983: public static TCObject getObject(Object array) {
0984: return ArrayManager.getObject(array);
0985: }
0986:
0987: /**
0988: * Copy char[]
0989: *
0990: * @param src Source array
0991: * @param srcPos Start in src
0992: * @param dest Destination array
0993: * @param destPos Start in dest
0994: * @param length Number of items to copy
0995: * @param tcDest TCObject for dest array
0996: *
0997: */
0998: public static void charArrayCopy(char[] src, int srcPos,
0999: char[] dest, int destPos, int length, TCObject tco) {
1000: ArrayManager.charArrayCopy(src, srcPos, dest, destPos, length,
1001: tco);
1002: }
1003:
1004: /**
1005: * Register an array with its TCO. It is an error to register an array that has already been registered.
1006: *
1007: * @param array Array
1008: * @param tco TCObject
1009: * @throws NullPointerException if array or tco are null
1010: */
1011: public static void register(Object pojo, TCObject obj) {
1012: ArrayManager.register(pojo, obj);
1013: }
1014:
1015: /**
1016: * @return Session monitor MBean
1017: */
1018: public static SessionMonitorMBean getSessionMonitorMBean() {
1019: return getManager().getSessionMonitorMBean();
1020: }
1021:
1022: /**
1023: * @return TCProperties
1024: */
1025: public static TCProperties getTCProperties() {
1026: return getManager().getTCProperites();
1027: }
1028:
1029: /**
1030: * Add listener for cluster events
1031: *
1032: * @param cel Listener
1033: */
1034: public static void addClusterEventListener(ClusterEventListener cel) {
1035: getManager().addClusterEventListener(cel);
1036: }
1037:
1038: /**
1039: * Get session lock type for the specified app (usually WRITE or SYNCHRONOUS_WRITE)
1040: *
1041: * @param appName Web app name
1042: * @return Lock type
1043: */
1044: public static int getSessionLockType(String appName) {
1045: return ClassProcessorHelper.getSessionLockType(appName);
1046: }
1047:
1048: /**
1049: * Returns true if the field represented by the offset is a portable field, i.e., not static and not dso transient
1050: * @param pojo Object
1051: * @param fieldOffset The index
1052: * @return true if the field is portable and false otherwise
1053: */
1054: public static boolean isFieldPortableByOffset(Object pojo,
1055: long fieldOffset) {
1056: return getManager().isFieldPortableByOffset(pojo, fieldOffset);
1057: }
1058:
1059: }
|