interface MajorObjectWrapper{ public Object getMajorObject(); } enum Utility implements MajorObjectWrapper { VAULT("Gold"), //... LOCK(new Lock()); @Override public Object getMajorObject(){ return obj; } private Object obj; Utility(Object obj){ this.obj=obj }; } { MajorObjectWrapper wrapper=Utility.VAULT; System.out.println(wrapper.getMajorObject()); // You will get: "Gold"! :) }
protected final int lockConflict (Lock otherLock) { if (txojLogger.logger.isTraceEnabled()) { txojLogger.logger.trace("LockManager::lockConflict(" + otherLock.get_uid() + ")"); } boolean matching = false; Lock heldLock = null; LockListIterator next = new LockListIterator(locksHeld); while ((heldLock = next.iterate()) != null) { if (heldLock.conflictsWith(otherLock)) { if (LockManager.nestedLocking) { if (!isAncestorOf(heldLock)) /* not quite Moss's rules */ return ConflictType.CONFLICT; } else return ConflictType.CONFLICT; } else { if (heldLock.equals(otherLock)) matching = true; } } return (matching ? ConflictType.PRESENT : ConflictType.COMPATIBLE); }
/** * Implementation of Lock conflict check. Returns TRUE if there is conflict * FALSE otherwise. Does not take account of relationship in the atomic * action hierarchy since this is a function of LockManager. * * @return <code>true</code> if this lock conflicts with the parameter, * <code>false</code> otherwise. */ public boolean conflictsWith (Lock otherLock) { if (txojLogger.logger.isTraceEnabled()) { txojLogger.logger.trace("Lock::conflictsWith(" + otherLock + ")\n" + "\tLock 1:\n" + this + "\n" + "\tLock 2:\n" + otherLock); } if (!(getCurrentOwner().equals(otherLock.getCurrentOwner()))) { switch (lMode) { case LockMode.WRITE: return true; /* WRITE conflicts always */ case LockMode.READ: if (otherLock.getLockMode() != LockMode.READ) return true; break; } } return false; /* no conflict between these locks */ }
/** * Overrides Object.toString() */ public String toString () { StringWriter strm = new StringWriter(); strm.write("Lock object : \n"); strm.write("\ttype : "+type()+ "\n"); strm.write("\tunique id is : " + get_uid() + "\n"); strm.write("\tcurrent_status : " + LockStatus.printString(currentStatus)); strm.write("\n\tMode : " + LockMode.stringForm(lMode)); strm.write("\n\tOwner List : \n"); owners.print(new PrintWriter(strm)); return strm.toString(); }
current = new Lock(u); if (current.restore_state(S, ObjectType.ANDPERSISTENT))
toSet.changeHierarchy(ah); else modifyRequired = toSet.modifiesObject();
/** * Overrides Object.equals() */ public boolean equals (Object otherLock) { if (otherLock instanceof Lock) return equals((Lock) otherLock); else return false; }
UidHelper.packInto(current.get_uid(), S); if (!current.save_state(S, ObjectType.ANDPERSISTENT)) txojLogger.i18NLogger.warn_LockManager_11(current.toString()); unloadOk = false;
if (current.getCurrentOwner().equals(from)) current.propagate();
protected final boolean isAncestorOf (Lock heldLock) { if (txojLogger.logger.isTraceEnabled()) { txojLogger.logger.trace("LockManager::isAncestorOf(" + heldLock.getCurrentOwner() + ")"); } BasicAction action = BasicAction.Current(); if (action == null) return false; /* no action no ancestry! */ return action.isAncestor(heldLock.getCurrentOwner()); }
/** * Print information about this instance on the specified * <code>PrintWriter</code>. */ public void print (PrintWriter strm) { LockListIterator next = new LockListIterator(locksHeld); Lock current; strm.println("LocalLockManager for object " + get_uid()); if (!stateLoaded) strm.println("No loaded state"); else if (locksHeld != null) { strm.println("\tCurrently holding : " + locksHeld.entryCount() + " locks"); while ((current = next.iterate()) != null) current.print(strm); } else strm.println("Currently holding : 0 locks"); }
/** * Overrides Object.toString() */ public String toString () { StringWriter strm = new StringWriter(); strm.write("Lock object : \n"); strm.write("\tunique id is : " + get_uid() + "\n"); strm.write("\tcurrent_status : " + LockStatus.printString(currentStatus)); strm.write("\n\tMode : " + LockMode.stringForm(lMode)); strm.write("\n\tOwner List : \n"); owners.print(new PrintWriter(strm)); return strm.toString(); }
if (current.restore_state(S, ObjectType.ANDPERSISTENT))
current = new Lock(u); if (current.restore_state(S, ObjectType.ANDPERSISTENT))
toSet.changeHierarchy(ah); else modifyRequired = toSet.modifiesObject();
/** * Overrides Object.equals() */ public boolean equals (Object otherLock) { if (otherLock instanceof Lock) return equals((Lock) otherLock); else return false; }
UidHelper.packInto(current.get_uid(), S); if (!current.save_state(S, ObjectType.ANDPERSISTENT)) txojLogger.i18NLogger.warn_LockManager_11(current.toString()); unloadOk = false;
if (current.getCurrentOwner().equals(from)) current.propagate();
/** * Overrides Object.toString() */ public String toString () { StringWriter strm = new StringWriter(); strm.write("Lock object : \n"); strm.write("\ttype : "+type()+ "\n"); strm.write("\tunique id is : " + get_uid() + "\n"); strm.write("\tcurrent_status : " + LockStatus.printString(currentStatus)); strm.write("\n\tMode : " + LockMode.stringForm(lMode)); strm.write("\n\tOwner List : \n"); owners.print(new PrintWriter(strm)); return strm.toString(); }
protected final boolean isAncestorOf (Lock heldLock) { if (txojLogger.logger.isTraceEnabled()) { txojLogger.logger.trace("LockManager::isAncestorOf(" + heldLock.getCurrentOwner() + ")"); } BasicAction action = BasicAction.Current(); if (action == null) return false; /* no action no ancestry! */ return action.isAncestor(heldLock.getCurrentOwner()); }