[Joafip-svn] SF.net SVN: joafip:[2975] trunk/joafip/src/main/java/net/sf/joafip/store
Brought to you by:
luc_peuvrier
|
From: <luc...@us...> - 2011-11-21 07:14:29
|
Revision: 2975
http://joafip.svn.sourceforge.net/joafip/?rev=2975&view=rev
Author: luc_peuvrier
Date: 2011-11-21 07:14:22 +0000 (Mon, 21 Nov 2011)
Log Message:
-----------
abject acceded management refactoring
Modified Paths:
--------------
trunk/joafip/src/main/java/net/sf/joafip/store/entity/objectio/ObjectAndPersistInfo.java
trunk/joafip/src/main/java/net/sf/joafip/store/entity/objectio/ObjectStateMap.java
trunk/joafip/src/main/java/net/sf/joafip/store/entity/objectio/SerializerModel.java
trunk/joafip/src/main/java/net/sf/joafip/store/entity/saver/StoreSaverSession.java
trunk/joafip/src/main/java/net/sf/joafip/store/service/objectio/manager/ObjectIOManager.java
trunk/joafip/src/main/java/net/sf/joafip/store/service/proxy/ProxyCallBack.java
trunk/joafip/src/main/java/net/sf/joafip/store/service/proxy/ProxyManager2.java
trunk/joafip/src/main/java/net/sf/joafip/store/service/saver/StoreSaver3.java
Modified: trunk/joafip/src/main/java/net/sf/joafip/store/entity/objectio/ObjectAndPersistInfo.java
===================================================================
--- trunk/joafip/src/main/java/net/sf/joafip/store/entity/objectio/ObjectAndPersistInfo.java 2011-11-21 07:11:53 UTC (rev 2974)
+++ trunk/joafip/src/main/java/net/sf/joafip/store/entity/objectio/ObjectAndPersistInfo.java 2011-11-21 07:14:22 UTC (rev 2975)
@@ -136,7 +136,7 @@
// FIXMELUC __why for checkAssertNotNull
public boolean checkAssertNotNull = true;
- public boolean acceded;
+ // public boolean acceded;
/**
* for {@link #NULL} and {@link ObjectAndPersistInfo#NULL_DEFINED }
@@ -411,7 +411,7 @@
// object!=null may be unreferenced object and statemap not already
// cleared
final boolean weaked;
- if (!acceded && weakReference == null && object != null) {
+ if (isNotAcceded() && weakReference == null && object != null) {
weakReference = new ObjectAndPersistInfoWeakReference(object, this,
queue);
clear();// Unreferenced
@@ -422,6 +422,16 @@
return weaked;
}
+ private boolean isNotAcceded() {
+ final boolean isNotAcceded;
+ if (proxyIntanceOrEnhanced) {
+ isNotAcceded = proxyCallBack.getInObjectCount$JOAFIP$() == 0;
+ } else {
+ isNotAcceded = true;
+ }
+ return isNotAcceded;
+ }
+
@Override
protected Object getObjectForEquals() {
final Object result;
@@ -534,30 +544,31 @@
return loadedOrNotAProxy;
}
- public void setIsLoaded() throws ObjectIOException {
- // out of constructor, no more acceded, to do before set is
- // loaded
- acceded = false;
- if (proxyIntanceOrEnhanced) {
- /*
- * set loaded state can call save and object is referenced only by
- * this created persist info object, so must not be unreferenced
- */
- assert assertProxyCallBack(proxyCallBack);
- proxyCallBack.setIsLoaded$JOAFIP$();
- }
- }
+ // public void setIsLoaded() throws ObjectIOException {
+ // // out of constructor, no more acceded, to do before set is
+ // // loaded
+ // acceded = false;
+ // if (proxyIntanceOrEnhanced) {
+ // /*
+ // * set loaded state can call save and object is referenced only by
+ // * this created persist info object, so must not be unreferenced
+ // */
+ // assert assertProxyCallBack(proxyCallBack);
+ // proxyCallBack.setIsLoaded$JOAFIP$();
+ // }
+ // }
- public void newInstanceAndCreatedBySave(final StorageInfo storageInfo)
- throws ObjectIOException {
- unWeakReferenceOnObject();
- setStorageInfo(storageInfo);
- setIsLoaded();
- }
+ // public void newInstanceAndCreatedBySave(final StorageInfo storageInfo)
+ // throws ObjectIOException {
+ // setStorageInfo(storageInfo);
+ // setIsLoaded();
+ // acceded=true;
+ // objectStateMap.objectIsAccessed(this);
+ // }
public void unloadAfterSave() throws ObjectIOException,
ObjectIOInvalidClassException {
- if (proxyIntanceOrEnhanced && !acceded) {
+ if (proxyIntanceOrEnhanced && isNotAcceded()) {
assert assertProxyCallBack(proxyCallBack);
proxyCallBack.unload$JOAFIP$();
}
Modified: trunk/joafip/src/main/java/net/sf/joafip/store/entity/objectio/ObjectStateMap.java
===================================================================
--- trunk/joafip/src/main/java/net/sf/joafip/store/entity/objectio/ObjectStateMap.java 2011-11-21 07:11:53 UTC (rev 2974)
+++ trunk/joafip/src/main/java/net/sf/joafip/store/entity/objectio/ObjectStateMap.java 2011-11-21 07:14:22 UTC (rev 2975)
@@ -18,8 +18,8 @@
import java.lang.ref.ReferenceQueue;
import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -46,7 +46,7 @@
* map between object in memory and persistence information for this object
*/
private final Map<IObjectIdentityKey, ObjectAndPersistInfo> stateMap =
- /**/new HashMap<IObjectIdentityKey, ObjectAndPersistInfo>();
+ /**/new LinkedHashMap<IObjectIdentityKey, ObjectAndPersistInfo>();
/**
* map to obtains object persistence information by data record identifier
@@ -451,7 +451,8 @@
public Collection<ObjectAndPersistInfo> getObjectHavingStateSet() {
synchronized (this) {
- final Collection<ObjectAndPersistInfo> objectHavingStateSet = new HashSet<ObjectAndPersistInfo>();
+ final Collection<ObjectAndPersistInfo> objectHavingStateSet =
+ /**/new LinkedHashSet<ObjectAndPersistInfo>();
// if (exclusiveAccessSession) {
// expunge();
@@ -527,7 +528,7 @@
public Set<ObjectAndPersistInfo> mostAccessedObject(final int quota) {
synchronized (this) {
// expunge();
- final Set<ObjectAndPersistInfo> set = new HashSet<ObjectAndPersistInfo>();
+ final Set<ObjectAndPersistInfo> set = new LinkedHashSet<ObjectAndPersistInfo>();
int count = 0;
ObjectAndPersistInfo current = queueHead;
while (count < quota && current != null) {
Modified: trunk/joafip/src/main/java/net/sf/joafip/store/entity/objectio/SerializerModel.java
===================================================================
--- trunk/joafip/src/main/java/net/sf/joafip/store/entity/objectio/SerializerModel.java 2011-11-21 07:11:53 UTC (rev 2974)
+++ trunk/joafip/src/main/java/net/sf/joafip/store/entity/objectio/SerializerModel.java 2011-11-21 07:14:22 UTC (rev 2975)
@@ -22,7 +22,7 @@
*/
package net.sf.joafip.store.entity.objectio;
-import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.Map;
import java.util.TreeMap;
@@ -49,7 +49,7 @@
* map between object in memory and persistence information for this object
*/
private final Map<IObjectIdentityKey, ObjectAndPersistInfo> stateMap =
- /**/new HashMap<IObjectIdentityKey, ObjectAndPersistInfo>();
+ /**/new LinkedHashMap<IObjectIdentityKey, ObjectAndPersistInfo>();
private final ObjectIdentityKey key = new ObjectIdentityKey();
Modified: trunk/joafip/src/main/java/net/sf/joafip/store/entity/saver/StoreSaverSession.java
===================================================================
--- trunk/joafip/src/main/java/net/sf/joafip/store/entity/saver/StoreSaverSession.java 2011-11-21 07:11:53 UTC (rev 2974)
+++ trunk/joafip/src/main/java/net/sf/joafip/store/entity/saver/StoreSaverSession.java 2011-11-21 07:14:22 UTC (rev 2975)
@@ -18,8 +18,8 @@
import java.util.Collection;
import java.util.Deque;
-import java.util.HashSet;
import java.util.Iterator;
+import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.Set;
import java.util.TreeSet;
@@ -52,7 +52,7 @@
/** visited for saving object set */
private final Set<ObjectAndPersistInfo> visitedForSave =
- /**/new HashSet<ObjectAndPersistInfo>();
+ /**/new LinkedHashSet<ObjectAndPersistInfo>();
/** set of data record identifier of object attached to root */
private final Set<DataRecordIdentifier> attachedToRoot =
Modified: trunk/joafip/src/main/java/net/sf/joafip/store/service/objectio/manager/ObjectIOManager.java
===================================================================
--- trunk/joafip/src/main/java/net/sf/joafip/store/service/objectio/manager/ObjectIOManager.java 2011-11-21 07:11:53 UTC (rev 2974)
+++ trunk/joafip/src/main/java/net/sf/joafip/store/service/objectio/manager/ObjectIOManager.java 2011-11-21 07:14:22 UTC (rev 2975)
@@ -623,7 +623,6 @@
@Override
public void objectIsAccessed(final ObjectAndPersistInfo objectAndPersistInfo) {
- objectAndPersistInfo.acceded = true;
objectIsAccessedDelegate(objectAndPersistInfo);
}
Modified: trunk/joafip/src/main/java/net/sf/joafip/store/service/proxy/ProxyCallBack.java
===================================================================
--- trunk/joafip/src/main/java/net/sf/joafip/store/service/proxy/ProxyCallBack.java 2011-11-21 07:11:53 UTC (rev 2974)
+++ trunk/joafip/src/main/java/net/sf/joafip/store/service/proxy/ProxyCallBack.java 2011-11-21 07:14:22 UTC (rev 2975)
@@ -93,13 +93,15 @@
}
/**
- *
+ * only call by proxy constructor
*/
public ProxyCallBack() {
super();
inObjectCount = 1;
storeMutex = new JoafipMutex();
exclusiveAccessSession = true;
+ autoSaveEnabled = true;
+ loaded = true;
}
/**
@@ -262,11 +264,12 @@
@Override
public void constructorEnd$JOAFIP$() {
inObjectCount--;
+ // if (autoSaveEnabled) {
+ // unLoadAction(getInstance$JOAFIP$());
+ // }
+ toUnload = false;
assert inObjectCount >= 0 : "running in object count can not be negative, is "
+ inObjectCount;
- // if (objectIOManager != null) {
- // objectIsAccessed();
- // }
}
@Override
@@ -279,7 +282,6 @@
assert inObjectCount >= 0 : "running in object count can not be negative, is "
+ inObjectCount + " " + getInstance$JOAFIP$().toString();
if (inObjectCount == 0) {
- instanceAndPersistInfo.acceded = false;
if (autoSaveEnabled) {
if (!wasLoaded && loaded) {
try {
@@ -288,26 +290,28 @@
throw new ProxyInterceptException(exception);
}
}
- if (toUnload) {
- toUnload = false;
- loaded = false;
- assert instanceAndPersistInfo != null;
- try {
- objectIOManager
- .saveAndUnsetProxyObjectState(instanceAndPersistInfo);
- } catch (Exception exception) {
- LOGGER.error("method end interception error",
- exception);
- throw new ProxyInterceptException(
- instanceAndPersistInfo.toString(),
- exception);
- }
- }
+ unLoadAction(instanceAndPersistInfo);
}
}
}
}
+ private void unLoadAction(final ObjectAndPersistInfo instanceAndPersistInfo) {
+ if (toUnload) {
+ toUnload = false;
+ loaded = false;
+ assert instanceAndPersistInfo != null;
+ try {
+ objectIOManager
+ .saveAndUnsetProxyObjectState(instanceAndPersistInfo);
+ } catch (Exception exception) {
+ LOGGER.error("method end interception error", exception);
+ throw new ProxyInterceptException(
+ instanceAndPersistInfo.toString(), exception);
+ }
+ }
+ }
+
@Override
@SuppressWarnings("PMD")
public boolean isLoaded$JOAFIP$() throws ObjectIOException {
@@ -345,11 +349,14 @@
*/
if (loaded) {
if (!loading && (!exclusiveAccessSession || inObjectCount == 0)) {
+ toUnload = false;
loaded = false;
objectIOManager.unsetProxyObjectState(getInstance$JOAFIP$());
} else {
toUnload = true;
}
+ } else {
+ toUnload = false;
}
// }
}
Modified: trunk/joafip/src/main/java/net/sf/joafip/store/service/proxy/ProxyManager2.java
===================================================================
--- trunk/joafip/src/main/java/net/sf/joafip/store/service/proxy/ProxyManager2.java 2011-11-21 07:11:53 UTC (rev 2974)
+++ trunk/joafip/src/main/java/net/sf/joafip/store/service/proxy/ProxyManager2.java 2011-11-21 07:14:22 UTC (rev 2975)
@@ -231,6 +231,7 @@
objectAndPersistInfo = objectIOManager
.getObjectAndPersistInfoOfObject(instanceCreated);
+
if (objectAndPersistInfo == null) {
// not created by save
// FIXMELUC ___seems dataRecordIdentifier always null, see call
@@ -273,16 +274,28 @@
throw new ProxyException(
"data record identifier must not be defined if object not persisted");
}
- objectAndPersistInfo.setStorageInfo(storageInfo);
+ objectAndPersistInfo.setStorageInfo(storageInfo);
if (constructed) {
- assert objectAndPersistInfo.isNotWeak();
- objectAndPersistInfo.setIsLoaded();
+ assert objectAndPersistInfo.isNotWeak() : objectAndPersistInfo
+ .toString();
+ assert objectAndPersistInfo.isLoaded() : objectAndPersistInfo
+ .toString();
+ // objectIOManager.objectIsAccessed(objectAndPersistInfo);
+ // objectAndPersistInfo.setNewObject(true);
+ objectIOManager.newObjectLoaded();
}
} else {
// created by save
assert constructed;
- objectAndPersistInfo.newInstanceAndCreatedBySave(storageInfo);
+ assert objectAndPersistInfo.isNotWeak() : objectAndPersistInfo
+ .toString();
+ assert objectAndPersistInfo.isLoaded() : objectAndPersistInfo
+ .toString();
+ objectAndPersistInfo.setStorageInfo(storageInfo);
+ // objectIOManager.objectIsAccessed(objectAndPersistInfo);
+ // objectAndPersistInfo.setNewObject(true);
+ objectIOManager.newObjectLoaded();
}
return objectAndPersistInfo;
}
@@ -510,46 +523,32 @@
final IProxyCallBackToImplement proxyCallBack,
final boolean exclusiveAccessSession) throws ProxyException {
final Object object = objectAndPersistInfo.getObject();
- if (exclusiveAccessSession) {
- if (useJavaAgent) {
- final IProxyCallBackToImplement existing = StaticProxyCallBack
- .getProxyCallBack(object);
- if (existing == null) {
- StaticProxyCallBack.setProxyCallBack(object, proxyCallBack);
- proxyCallBack.setInstance$JOAFIP$(objectAndPersistInfo);
- objectAndPersistInfo.setProxyCallBack(proxyCallBack);
- } else {
- existing.initialize$JOAFIP$(proxyCallBack);
- existing.setInstance$JOAFIP$(objectAndPersistInfo);
- objectAndPersistInfo.setProxyCallBack(existing);
- objectAndPersistInfo.acceded = true;
- }
- } else {
- final IProxyCallBack proxy = (IProxyCallBack) object;
- final IProxyCallBackToImplement existing = proxy
- .getProxyCallBack$JOAFIP$();
- if (existing == null) {
- proxy.setProxyCallBack$JOAFIP$(proxyCallBack);
- proxyCallBack.setInstance$JOAFIP$(objectAndPersistInfo);
- objectAndPersistInfo.setProxyCallBack(proxyCallBack);
- } else {
- existing.initialize$JOAFIP$(proxyCallBack);
- existing.setInstance$JOAFIP$(objectAndPersistInfo);
- objectAndPersistInfo.setProxyCallBack(existing);
- objectAndPersistInfo.acceded = true;
- }
- }
- } else {
- if (useJavaAgent) {
+ // does not test exclusiveAccessSession because new instance construct
+ // can be called out of exclusive data access session
+ if (useJavaAgent) {
+ final IProxyCallBackToImplement existing = StaticProxyCallBack
+ .getProxyCallBack(object);
+ if (existing == null) {
StaticProxyCallBack.setProxyCallBack(object, proxyCallBack);
proxyCallBack.setInstance$JOAFIP$(objectAndPersistInfo);
objectAndPersistInfo.setProxyCallBack(proxyCallBack);
-
} else {
- final IProxyCallBack proxy = (IProxyCallBack) object;
+ existing.initialize$JOAFIP$(proxyCallBack);
+ existing.setInstance$JOAFIP$(objectAndPersistInfo);
+ objectAndPersistInfo.setProxyCallBack(existing);
+ }
+ } else {
+ final IProxyCallBack proxy = (IProxyCallBack) object;
+ final IProxyCallBackToImplement existing = proxy
+ .getProxyCallBack$JOAFIP$();
+ if (existing == null) {
proxy.setProxyCallBack$JOAFIP$(proxyCallBack);
proxyCallBack.setInstance$JOAFIP$(objectAndPersistInfo);
objectAndPersistInfo.setProxyCallBack(proxyCallBack);
+ } else {
+ existing.initialize$JOAFIP$(proxyCallBack);
+ existing.setInstance$JOAFIP$(objectAndPersistInfo);
+ objectAndPersistInfo.setProxyCallBack(existing);
}
}
}
Modified: trunk/joafip/src/main/java/net/sf/joafip/store/service/saver/StoreSaver3.java
===================================================================
--- trunk/joafip/src/main/java/net/sf/joafip/store/service/saver/StoreSaver3.java 2011-11-21 07:11:53 UTC (rev 2974)
+++ trunk/joafip/src/main/java/net/sf/joafip/store/service/saver/StoreSaver3.java 2011-11-21 07:14:22 UTC (rev 2975)
@@ -18,9 +18,9 @@
import java.io.File;
import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -150,7 +150,7 @@
private final List<String> wroteArrays = new LinkedList<String>();
private final Map<ObjectAndPersistInfo, Set<ObjectAndPersistInfo>> fatherMap =
- /**/new HashMap<ObjectAndPersistInfo, Set<ObjectAndPersistInfo>>();
+ /**/new LinkedHashMap<ObjectAndPersistInfo, Set<ObjectAndPersistInfo>>();
/** root of objects to save */
private Object rootOfObjectsToSave;
@@ -753,7 +753,7 @@
.getObjectAndPersistInfo();
Set<ObjectAndPersistInfo> set = fatherMap.get(sonAndPersistInfo);
if (set == null) {
- set = new HashSet<ObjectAndPersistInfo>();
+ set = new LinkedHashSet<ObjectAndPersistInfo>();
fatherMap.put(sonAndPersistInfo, set);
}
set.add(father);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|