public static ObjectStore getInstance() { return INSTANCE; }
- public boolean has(StoreIdentifier sid) {
- StoreContainer stoc = getStoreContainerForSid( sid );
- return ( stoc != null && stoc.has(sid) ) ? true:false;
- }
-
/**
* Method: use
* Description: The ObjectStore tries to find the @see StoreIdentifier sid
return sb.toString();
}
+ /**
+ * Method: invalidate(StorableObject sto)
+ * Description: ObjectStore is notified of change of a @see StorableObject
+ * sto and invalidates all relevant cache entries.
+ */
+
+ public void invalidate(StorableObject sto) {
+ // propagate invalidation to StoreContainer
+ if (sto!=null) {
+ StoreIdentifier sid = sto.getStoreIdentifier();
+ if (sto!=null) {
+ StoreContainer stoc = getStoreContainerForSid(sid);
+ stoc.invalidate(sto);
+ }
+ }
+ }
+
// internal methods for StoreContainer managment
/**
* @return true if yes, otherwise no.
*/
private final static boolean implementsStorableObject(Class aClass) {
- boolean yesno=false;
if (aClass!=null) {
Class[] interfaces = aClass.getInterfaces();
if (interfaces.length>0) {
}
}
}
+ return false;
+ }
- return yesno;
+
+ private boolean has(StoreIdentifier sid) {
+ StoreContainer stoc = getStoreContainerForSid( sid );
+ return ( stoc != null && stoc.has(sid) ) ? true:false;
}
+
/**
* Method: version()
* Description: returns ObjectStore version as String
*
*/
abstract StoreIdentifier getStoreIdentifier();
+
+ /**
+ * Method: notifyOnReleaseSet()
+ * Description: Contains a Set of @see StoreIdentifier which are invalidated
+ * on update/insert/delete of this StorableObject.
+ *
+ * @return Set of StoreIdentifier.
+ */
abstract Set notifyOnReleaseSet();
}
\ No newline at end of file
public class StoreContainer {
- private final static int DEFAULT_SIZE=10;
+ private final static int DEFAULT_SIZE=10;
+ private static Logfile storeLog;
+ private static int uniqueCounter=10000;
private LinkedList container;
private StoreContainerType stocType;
private int maxSize=DEFAULT_SIZE;
- private static Logfile storeLog;
+ private int uniqueId;
private StoreContainer() {};
public StoreContainer(StoreContainerType stoc_type) {
+ this.uniqueId=++uniqueCounter;
this.stocType=stoc_type;
this.container=new LinkedList();
}
this.maxSize=maxSize;
}
- /** @todo methods: release+propagation */
-
public StorableObject use(StoreIdentifier sid) {
// find sid in LinkedList or die
// move sid to head of linked list
}
/**
+ * Method: invalidate(StorableObject sto)
+ * Description: finds @see StorableObject, propagates invalidation to
+ * @see StoreIdentifier and removes StoreIdentifier from
+ * list.
+ */
+ public void invalidate(StorableObject sto) {
+ if (sto!=null) {
+ StoreIdentifier sid = sto.getStoreIdentifier();
+ if (sid!=null) {
+ if ( container.contains(sid) ) {
+ sid.invalidate();
+ container.remove(sid);
+ }
+ }
+ }
+ }
+
+ /**
* Method: setSize
* Description: readjusts StoreContainer size to value.
*
*/
public void setSize(int size) {
- /** @todo check size, if size too big, shrink */
+ if (size <0) return;
+ if ( size<maxSize && size > container.size() ) {
+ // shrink
+ while (size > container.size() ) {
+ StoreIdentifier sid = (StoreIdentifier)container.getLast();
+ sid.release();
+ container.remove(sid);
+ }
+ }
this.maxSize=size;
}
* @return String
*/
public String toString() {
- StringBuffer sb = new StringBuffer("StoreContainer for ");
+ StringBuffer sb = new StringBuffer("StoreContainer id: ");
+ sb.append(uniqueId).append(" for ");
sb.append(stocType.toString()).append("\nCurrent size: ");
sb.append(container.size()).append("\nMaximum size:");
sb.append(maxSize).append("\n");
+ /** @todo list members ? */
return sb.toString();
}
public class StoreIdentifier {
- /** @todo move main stuff to storecontainertype */
+ /** @todo check if invalidating already to avoid deadlocks
+ * what about concurrency? */
private static Logfile storeLog;
private StorableObject reference=null;
private String uniqueIdentifier=null; // id for Entity & sql for EntityList
private long timesUsed;
+ private boolean invalidating=false;
/** @todo initialize logfile */
this.stocType = StoreContainerType.valueOf(reference.getClass(), storeType);
}
+ /**
+ * Method: ivalidate
+ * Description:
+ *
+ * @return
+ */
public void invalidate() {
- Set set = reference.notifyOnReleaseSet();
- /** @todo here we should propagate the invalidation all members of Set
- * @see StoreContainer */
+ // avoid deadlock due to propagation.
+ if (!invalidating) {
+ invalidating=true;
+ Set set = reference.notifyOnReleaseSet();
+ /** @todo here we should propagate the invalidation all members of Set
+ * @see StoreContainer. The set may contain objects of different type.*/
+ release();
+ }
+ }
+ public void release() {
this.reference=null;
this.uniqueIdentifier=null;
this.stocType=null;