1 4 package org.ofbiz.minerva.pool; 5 6 import java.util.Date ; 7 import java.util.ConcurrentModificationException ; 8 9 14 class ObjectRecord { 15 16 private long created; 17 private long lastUsed; 18 private Object object; 19 private Object clientObject; 20 private boolean inUse; 21 22 27 public ObjectRecord(Object ob) { 28 this(ob, true); 29 } 30 31 35 public ObjectRecord(Object ob, boolean inUse) { 36 created = lastUsed = System.currentTimeMillis(); 37 object = ob; 38 this.inUse = inUse; 39 } 40 41 44 public Date getCreationDate() { 45 return new Date (created); 46 } 47 48 51 public Date getLastUsedDate() { 52 return new Date (lastUsed); 53 } 54 55 58 public long getMillisSinceLastUse() { 59 return System.currentTimeMillis() - lastUsed; 60 } 61 62 67 public boolean isInUse() { 68 return inUse; 69 } 70 71 77 public synchronized void setInUse(boolean inUse) throws ConcurrentModificationException { 78 if (this.inUse == inUse) 79 throw new ConcurrentModificationException (); 80 this.inUse = inUse; 81 lastUsed = System.currentTimeMillis(); 82 if (!inUse) clientObject = null; 83 } 84 85 88 public void setLastUsed() { 89 lastUsed = System.currentTimeMillis(); 90 } 91 92 95 public Object getObject() { 96 return object; 97 } 98 99 102 public void setClientObject(Object o) { 103 clientObject = o; 104 } 105 106 110 public Object getClientObject() { 111 return clientObject == null ? object : clientObject; 112 } 113 114 117 public void close() { 118 object = null; 119 clientObject = null; 120 created = lastUsed = Long.MAX_VALUE; 121 inUse = true; 122 } 123 } 124 | Popular Tags |