[Joafip-svn] SF.net SVN: joafip:[2936] trunk/joafip/src
Brought to you by:
luc_peuvrier
|
From: <luc...@us...> - 2011-10-23 11:38:03
|
Revision: 2936
http://joafip.svn.sourceforge.net/joafip/?rev=2936&view=rev
Author: luc_peuvrier
Date: 2011-10-23 11:37:55 +0000 (Sun, 23 Oct 2011)
Log Message:
-----------
auto save now ok
Modified Paths:
--------------
trunk/joafip/src/main/java/net/sf/joafip/service/IFilePersistence.java
trunk/joafip/src/main/java/net/sf/joafip/store/service/Store.java
trunk/joafip/src/main/java/net/sf/joafip/store/service/bytecode/proxy/EnhanceCodeGenerator.java
trunk/joafip/src/main/java/net/sf/joafip/store/service/objectio/manager/AbstractObjectIOManagerDelegatingToStateMap.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/DetachedProxyCallBack.java
trunk/joafip/src/main/java/net/sf/joafip/store/service/proxy/IProxyCallBackProxyDelegation.java
trunk/joafip/src/main/java/net/sf/joafip/store/service/proxy/IProxyCallBackToImplement.java
trunk/joafip/src/main/java/net/sf/joafip/store/service/proxy/NullProxyCallBack.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/proxy/StaticProxyCallBack.java
trunk/joafip/src/test/java/net/sf/joafip/service/TestTreeListIteratorIntercept.java
trunk/joafip/src/test/java/net/sf/joafip/service/sync/TestSynchronizedCollection.java
trunk/joafip/src/test/java/net/sf/joafip/store/service/copier/AbstractTestDeepCopier.java
trunk/joafip/src/test/java/net/sf/joafip/store/service/proxy/AbstractObjectIoManagerForProxyTest.java
trunk/joafip/src/test/java/net/sf/joafip/store/service/proxy/ProxyCallBackForTest.java
trunk/joafip/src/test/java/net/sf/joafip/store/service/proxy/TestProxyCreation.java
Modified: trunk/joafip/src/main/java/net/sf/joafip/service/IFilePersistence.java
===================================================================
--- trunk/joafip/src/main/java/net/sf/joafip/service/IFilePersistence.java 2011-10-22 03:38:16 UTC (rev 2935)
+++ trunk/joafip/src/main/java/net/sf/joafip/service/IFilePersistence.java 2011-10-23 11:37:55 UTC (rev 2936)
@@ -1195,12 +1195,22 @@
void keptInMemory(final String key, final Object object)
throws FilePersistenceException;
- // FIXMELUC _______________javadoc
+ /**
+ * instance referenced by static field of class are kept in memory
+ *
+ * @param classHavingStaticFieldReferenced
+ * @throws FilePersistenceException
+ */
void referencedByPesistedStaticField(
Class<?> classHavingStaticFieldReferenced)
throws FilePersistenceException;
- // FIXMELUC _______________javadoc
+ /**
+ * instance referenced by static field of classes are kept in memory
+ *
+ * @param classHavingStaticFieldReferenced
+ * @throws FilePersistenceException
+ */
void referencedByPesistedStaticField(
Class<?>[] classHavingStaticFieldReferenced)
throws FilePersistenceException;
Modified: trunk/joafip/src/main/java/net/sf/joafip/store/service/Store.java
===================================================================
--- trunk/joafip/src/main/java/net/sf/joafip/store/service/Store.java 2011-10-22 03:38:16 UTC (rev 2935)
+++ trunk/joafip/src/main/java/net/sf/joafip/store/service/Store.java 2011-10-23 11:37:55 UTC (rev 2936)
@@ -1024,23 +1024,18 @@
ObjectIOClassNotFoundException, ObjectIOInvalidClassException,
ObjectIODataCorruptedException, ObjectIONotSerializableException {
- try {
- proxyManager2.setCreateEntryinObjectMap(false);
- final Map<EnumKey, Enum<?>> storeRootEnumMap = getStoredEnumMap();
- if (storeRootEnumMap != null) {
- final Collection<Enum<?>> values = storeRootEnumMap.values();
- final Iterator<Enum<?>> iterator = values.iterator();
- while (iterator.hasNext()) {
- final Enum<?> enumValue = iterator.next();
- /* just to force state setting of persisted value */
- if (enumValue != null) {
- // not null, not a no more existing enum
- objectIOManager.reInitializeEnum(enumValue);
- }
+ final Map<EnumKey, Enum<?>> storeRootEnumMap = getStoredEnumMap();
+ if (storeRootEnumMap != null) {
+ final Collection<Enum<?>> values = storeRootEnumMap.values();
+ final Iterator<Enum<?>> iterator = values.iterator();
+ while (iterator.hasNext()) {
+ final Enum<?> enumValue = iterator.next();
+ /* just to force state setting of persisted value */
+ if (enumValue != null) {
+ // not null, not a no more existing enum
+ objectIOManager.reInitializeEnum(enumValue);
}
}
- } finally {
- proxyManager2.setCreateEntryinObjectMap(true);
}
}
Modified: trunk/joafip/src/main/java/net/sf/joafip/store/service/bytecode/proxy/EnhanceCodeGenerator.java
===================================================================
--- trunk/joafip/src/main/java/net/sf/joafip/store/service/bytecode/proxy/EnhanceCodeGenerator.java 2011-10-22 03:38:16 UTC (rev 2935)
+++ trunk/joafip/src/main/java/net/sf/joafip/store/service/bytecode/proxy/EnhanceCodeGenerator.java 2011-10-23 11:37:55 UTC (rev 2936)
@@ -40,7 +40,7 @@
import net.sf.joafip.store.service.proxy.IProxyCallBackProxyDelegation;
import net.sf.joafip.store.service.proxy.IProxyCallBackToImplement;
import net.sf.joafip.store.service.proxy.IProxyInternal;
-import net.sf.joafip.store.service.proxy.NullProxyCallBack;
+import net.sf.joafip.store.service.proxy.ProxyCallBack;
/**
* generate enhancement byte code
@@ -85,11 +85,6 @@
private String forceLoadMethodDesc;
- private static final String SET_IN_CONSTRUCTION_METHOD_NAME =
- /**/"setInConstruction$JOAFIP$";
-
- private String setInConstructionMethodDesc;
-
private static final String[] FORCE_LOAD_EXCEPTION = new String[] {
/**/Type.getInternalName(ObjectIOException.class),
/**/Type.getInternalName(ObjectIODataRecordNotFoundException.class),
@@ -117,6 +112,11 @@
private String methodEndMethodDesc;
+ private static final String CONSTRUCTOR_END_METHOD_NAME =
+ /**/"constructorEnd$JOAFIP$";
+
+ private String constructorEndMethodDesc;
+
private static final String SET_PROXY_CALL_BACK_METHOD_NAME =
/**/"setProxyCallBack$JOAFIP$";
@@ -146,6 +146,11 @@
private static final String I_PROXY_CALL_BACK_DELEGATION_DESC =
/**/Type.getDescriptor(IProxyCallBackProxyDelegation.class);
+ private static final String PROXY_CALL_BACK =
+ /**/Type.getInternalName(ProxyCallBack.class);
+
+ private String proxyCallBackConstructorDesc;
+
private final static String[] INTERFACES = new String[] {
/**/Type.getInternalName(IProxyCallBack.class) };
@@ -156,12 +161,6 @@
private final static EnhanceCodeGenerator INSTANCE =
/**/new EnhanceCodeGenerator();
- private static final String NULL_PROXY_CALL_BACK_INTERNAL_NAME =
- /**/Type.getInternalName(NullProxyCallBack.class);
-
- private static final String NULL_PROXY_CALL_BACK_INTERNAL_DESC =
- /**/Type.getDescriptor(NullProxyCallBack.class);
-
public static EnhanceCodeGenerator getInstance() {
return INSTANCE;
}
@@ -194,11 +193,6 @@
forceLoadMethodDesc = Type.getMethodDescriptor(method);
method = IProxyCallBack.class.getMethod(
- /**/SET_IN_CONSTRUCTION_METHOD_NAME,
- /**/new Class[] { boolean.class });
- setInConstructionMethodDesc = Type.getMethodDescriptor(method);
-
- method = IProxyCallBack.class.getMethod(
/**/UNLOAD_METHOD_NAME,
/**/NO_PARAMETERS);
unloadMethodDesc = Type.getMethodDescriptor(method);
@@ -214,6 +208,11 @@
methodEndMethodDesc = Type.getMethodDescriptor(method);
method = IProxyCallBack.class.getMethod(
+ /**/CONSTRUCTOR_END_METHOD_NAME,
+ /**/NO_PARAMETERS);
+ constructorEndMethodDesc = Type.getMethodDescriptor(method);
+
+ method = IProxyCallBack.class.getMethod(
/**/IS_LOADED_METHOD_NAME,
/**/NO_PARAMETERS);
isLoadedMethodDesc = Type.getMethodDescriptor(method);
@@ -244,6 +243,11 @@
/**/NO_PARAMETERS);
getInstanceMethodDesc = Type.getMethodDescriptor(method);
+ final Constructor<ProxyCallBack> constructor = ProxyCallBack.class
+ .getConstructor(NO_PARAMETERS);
+ proxyCallBackConstructorDesc = Type
+ .getConstructorDescriptor(constructor);
+
initialized = true;
} catch (Exception exception) {
@@ -336,12 +340,13 @@
methodVisitor.visitCode();
methodVisitor.visitVarInsn(ALOAD, 0);
+
+ methodVisitor.visitTypeInsn(NEW, PROXY_CALL_BACK);
+ methodVisitor.visitInsn(DUP);
+ methodVisitor.visitMethodInsn(INVOKESPECIAL, PROXY_CALL_BACK,
+ INIT_METHOD_NAME, proxyCallBackConstructorDesc);
+
methodVisitor.visitFieldInsn(
- /**/GETSTATIC,
- /**/NULL_PROXY_CALL_BACK_INTERNAL_NAME,
- /**/"INSTANCE",
- /**/NULL_PROXY_CALL_BACK_INTERNAL_DESC);
- methodVisitor.visitFieldInsn(
/**/PUTFIELD,/* opcode */
/**/classInternalName,/* owner */
/**/PROXY_CALL_BACK_FIELD_NAME,/* name */
@@ -364,6 +369,13 @@
/**/INIT_METHOD_NAME,
/**/desc);
+ methodVisitor.visitVarInsn(ALOAD, 0);
+ methodVisitor.visitMethodInsn(
+ /**/INVOKEVIRTUAL,
+ /**/classInternalName,
+ /**/CONSTRUCTOR_END_METHOD_NAME,
+ /**/constructorEndMethodDesc);
+
methodVisitor.visitInsn(RETURN);
// FIXMELUC _visitmaxs call needed ?
@@ -466,44 +478,44 @@
methodVisitor.visitEnd();
/*
- * setInConstruction
+ * unload
*/
-
methodVisitor = classWriter.visitMethod(
/**/ACC_PUBLIC,
- /**/SET_IN_CONSTRUCTION_METHOD_NAME,
- /**/setInConstructionMethodDesc,
+ /**/UNLOAD_METHOD_NAME,
+ /**/unloadMethodDesc,
/**/null,
- /**/null);
+ /**/UNLOAD_EXCEPTION);
+
methodVisitor.visitCode();
+
methodVisitor.visitVarInsn(ALOAD, 0);
methodVisitor.visitFieldInsn(
/**/GETFIELD,
/**/classInternalName,
- /**/PROXY_CALL_BACK_FIELD_NAME, I_PROXY_CALL_BACK_DELEGATION_DESC);
- methodVisitor.visitVarInsn(ILOAD, 1);
+ /**/PROXY_CALL_BACK_FIELD_NAME,
+ /**/I_PROXY_CALL_BACK_DELEGATION_DESC);
methodVisitor.visitMethodInsn(
/**/INVOKEINTERFACE,
/**/I_PROXY_CALL_BACK_INTERFACE,
- /**/SET_IN_CONSTRUCTION_METHOD_NAME,
- /**/setInConstructionMethodDesc);
+ /**/UNLOAD_METHOD_NAME,
+ /**/unloadMethodDesc);
methodVisitor.visitInsn(RETURN);
+
// FIXMELUC _visitmaxs call needed ?
methodVisitor.visitMaxs(0, 0);
methodVisitor.visitEnd();
/*
- * unload
+ * intercept
*/
methodVisitor = classWriter.visitMethod(
/**/ACC_PUBLIC,
- /**/UNLOAD_METHOD_NAME,
- /**/unloadMethodDesc,
+ /**/INTERCEPT_METHOD_NAME,
+ /**/interceptMethodDesc,
/**/null,
- /**/UNLOAD_EXCEPTION);
-
+ /**/null);
methodVisitor.visitCode();
-
methodVisitor.visitVarInsn(ALOAD, 0);
methodVisitor.visitFieldInsn(
/**/GETFIELD,
@@ -513,21 +525,21 @@
methodVisitor.visitMethodInsn(
/**/INVOKEINTERFACE,
/**/I_PROXY_CALL_BACK_INTERFACE,
- /**/UNLOAD_METHOD_NAME,
- /**/unloadMethodDesc);
+ /**/INTERCEPT_METHOD_NAME,
+ /**/interceptMethodDesc);
methodVisitor.visitInsn(RETURN);
-
// FIXMELUC _visitmaxs call needed ?
methodVisitor.visitMaxs(0, 0);
methodVisitor.visitEnd();
/*
- * intercept
+ * constructor end
*/
+
methodVisitor = classWriter.visitMethod(
/**/ACC_PUBLIC,
- /**/INTERCEPT_METHOD_NAME,
- /**/interceptMethodDesc,
+ /**/CONSTRUCTOR_END_METHOD_NAME,
+ /**/constructorEndMethodDesc,
/**/null,
/**/null);
methodVisitor.visitCode();
@@ -540,8 +552,8 @@
methodVisitor.visitMethodInsn(
/**/INVOKEINTERFACE,
/**/I_PROXY_CALL_BACK_INTERFACE,
- /**/INTERCEPT_METHOD_NAME,
- /**/interceptMethodDesc);
+ /**/CONSTRUCTOR_END_METHOD_NAME,
+ /**/constructorEndMethodDesc);
methodVisitor.visitInsn(RETURN);
// FIXMELUC _visitmaxs call needed ?
methodVisitor.visitMaxs(0, 0);
Modified: trunk/joafip/src/main/java/net/sf/joafip/store/service/objectio/manager/AbstractObjectIOManagerDelegatingToStateMap.java
===================================================================
--- trunk/joafip/src/main/java/net/sf/joafip/store/service/objectio/manager/AbstractObjectIOManagerDelegatingToStateMap.java 2011-10-22 03:38:16 UTC (rev 2935)
+++ trunk/joafip/src/main/java/net/sf/joafip/store/service/objectio/manager/AbstractObjectIOManagerDelegatingToStateMap.java 2011-10-23 11:37:55 UTC (rev 2936)
@@ -47,6 +47,9 @@
private final ObjectStateMgr objectStateMgr = new ObjectStateMgr();
+ /** true if exclusive data access session */
+ private boolean exclusiveAccessSession;
+
public AbstractObjectIOManagerDelegatingToStateMap(
final int currentDataModelIdentifier,
final IClassNameManager classNameManager, final boolean proxyMode,
@@ -81,10 +84,11 @@
IProxyCallBackToImplement proxyCallBack;
try {
proxyCallBack = new ProxyCallBack(this);
+ ProxyManager2.setProxyCallBack(objectAndPersistInfo,
+ proxyCallBack, exclusiveAccessSession);
} catch (ProxyException exception) {
throw new ObjectIOException(exception);
}
- ProxyManager2.setProxyCallBack(objectAndPersistInfo, proxyCallBack);
} else {
assert !ProxyManager2.isProxyOrEnhanced(object);
}
@@ -188,8 +192,14 @@
protected void setExclusiveAccessSessionDelegate(
final boolean exclusiveAccessSession) {
objectStateMgr.setExclusiveAccessSession(exclusiveAccessSession);
+ this.exclusiveAccessSession = exclusiveAccessSession;
}
+ @Override
+ public boolean isExclusiveAccessSession() {
+ return exclusiveAccessSession;
+ }
+
protected void setMaintainedInMemoryQuotaDelegate(
final int maintainedInMemoryQuota) {
objectStateMgr.setMaintainedInMemoryQuota(maintainedInMemoryQuota);
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-10-22 03:38:16 UTC (rev 2935)
+++ trunk/joafip/src/main/java/net/sf/joafip/store/service/objectio/manager/ObjectIOManager.java 2011-10-23 11:37:55 UTC (rev 2936)
@@ -120,9 +120,6 @@
/** file output stream to write change */
private FileOutputStream changeFileOutputStream;
- /** true if exclusive data access session */
- private boolean exclusiveAccessSession;
-
/** true if proxy notify object access */
// FIXMELUC ___no more needed ?
private boolean maintainInMemoryEnabled;// NOPMD
@@ -604,7 +601,6 @@
}
public void setExclusiveAccessSession(final boolean exclusiveAccessSession) {
- this.exclusiveAccessSession = exclusiveAccessSession;
super.setExclusiveAccessSessionDelegate(exclusiveAccessSession);
}
@@ -621,11 +617,6 @@
}
@Override
- public boolean isExclusiveAccessSession() {
- return exclusiveAccessSession;
- }
-
- @Override
public boolean isMaintainInMemoryEnabled() {
return maintainInMemoryEnabled;
}
Modified: trunk/joafip/src/main/java/net/sf/joafip/store/service/proxy/DetachedProxyCallBack.java
===================================================================
--- trunk/joafip/src/main/java/net/sf/joafip/store/service/proxy/DetachedProxyCallBack.java 2011-10-22 03:38:16 UTC (rev 2935)
+++ trunk/joafip/src/main/java/net/sf/joafip/store/service/proxy/DetachedProxyCallBack.java 2011-10-23 11:37:55 UTC (rev 2936)
@@ -66,6 +66,12 @@
@SuppressWarnings("PMD")
@Override
+ public void constructorEnd$JOAFIP$() {
+ // no implementation
+ }
+
+ @SuppressWarnings("PMD")
+ @Override
public void methodEnd$JOAFIP$() {
// no implementation
}
@@ -121,10 +127,4 @@
public IObjectIOManagerForProxyObjectIO getObjectIOManager$JOAFIP$() {
throw new UnsupportedOperationException();
}
-
- @SuppressWarnings("PMD")
- @Override
- public void setInConstruction$JOAFIP$(final boolean inConstruction) {
- throw new UnsupportedOperationException();
- }
}
Modified: trunk/joafip/src/main/java/net/sf/joafip/store/service/proxy/IProxyCallBackProxyDelegation.java
===================================================================
--- trunk/joafip/src/main/java/net/sf/joafip/store/service/proxy/IProxyCallBackProxyDelegation.java 2011-10-22 03:38:16 UTC (rev 2935)
+++ trunk/joafip/src/main/java/net/sf/joafip/store/service/proxy/IProxyCallBackProxyDelegation.java 2011-10-23 11:37:55 UTC (rev 2936)
@@ -46,6 +46,12 @@
void intercept$JOAFIP$();
/**
+ * constructor execution end
+ */
+ @SuppressWarnings("PMD")
+ void constructorEnd$JOAFIP$();
+
+ /**
* method execution end
*/
@SuppressWarnings("PMD")
@@ -110,7 +116,4 @@
@SuppressWarnings("PMD")
ObjectAndPersistInfo getInstance$JOAFIP$();
-
- @SuppressWarnings("PMD")
- void setInConstruction$JOAFIP$(boolean inConstruction);
}
Modified: trunk/joafip/src/main/java/net/sf/joafip/store/service/proxy/IProxyCallBackToImplement.java
===================================================================
--- trunk/joafip/src/main/java/net/sf/joafip/store/service/proxy/IProxyCallBackToImplement.java 2011-10-22 03:38:16 UTC (rev 2935)
+++ trunk/joafip/src/main/java/net/sf/joafip/store/service/proxy/IProxyCallBackToImplement.java 2011-10-23 11:37:55 UTC (rev 2936)
@@ -51,8 +51,8 @@
IObjectIOManagerForProxyObjectIO objectIOManager)
throws ProxyException;
- @Fortest
@SuppressWarnings("PMD")
+ @Override
IObjectIOManagerForProxyObjectIO getObjectIOManager$JOAFIP$();
// @Fortest
@@ -69,4 +69,8 @@
@SuppressWarnings("PMD")
boolean isAutoSaveEnabled$JOAFIP$();
+
+ @SuppressWarnings("PMD")
+ void initialize$JOAFIP$(IProxyCallBackToImplement proxyCallBack)
+ throws ProxyException;
}
Modified: trunk/joafip/src/main/java/net/sf/joafip/store/service/proxy/NullProxyCallBack.java
===================================================================
--- trunk/joafip/src/main/java/net/sf/joafip/store/service/proxy/NullProxyCallBack.java 2011-10-22 03:38:16 UTC (rev 2935)
+++ trunk/joafip/src/main/java/net/sf/joafip/store/service/proxy/NullProxyCallBack.java 2011-10-23 11:37:55 UTC (rev 2936)
@@ -48,6 +48,13 @@
}
@Override
+ @SuppressWarnings("PMD")
+ public void initialize$JOAFIP$(IProxyCallBackToImplement proxyCallBack)
+ throws ProxyException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
public void initializeFileAccessSessionIdentifier(
final IObjectIOManagerForProxyObjectIO objectIOManager) {
throw new UnsupportedOperationException();
@@ -63,7 +70,13 @@
// do nothing
}
+ @SuppressWarnings("PMD")
@Override
+ public void constructorEnd$JOAFIP$() {
+ // no implementation
+ }
+
+ @Override
@SuppressWarnings("PMD")
public void methodEnd$JOAFIP$() {
// FIXMELUC ___call when proxied construct, construct not need
@@ -185,10 +198,4 @@
public boolean isAutoSaveEnabled$JOAFIP$() {
throw new UnsupportedOperationException();
}
-
- @Override
- @SuppressWarnings("PMD")
- public void setInConstruction$JOAFIP$(final boolean inConstruction) {
- throw new UnsupportedOperationException();
- }
}
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-10-22 03:38:16 UTC (rev 2935)
+++ trunk/joafip/src/main/java/net/sf/joafip/store/service/proxy/ProxyCallBack.java 2011-10-23 11:37:55 UTC (rev 2936)
@@ -49,8 +49,14 @@
private static boolean useJavaAgent;
/** mutex for storage file access */
- private final JoafipMutex storeMutex;
+ private/* final */JoafipMutex storeMutex;
+ private/* final */IObjectIOManagerForProxyObjectIO objectIOManager;
+
+ private/* final */boolean exclusiveAccessSession;
+
+ private/* final */boolean autoSaveEnabled;
+
/** true if object loaded */
private boolean loaded = false;
@@ -61,8 +67,6 @@
private boolean toUnload;
- private final IObjectIOManagerForProxyObjectIO objectIOManager;
-
/**
* the proxy instance and persistence information for which is this proxy
* callback
@@ -81,20 +85,24 @@
*/
private long myFileAccessSessionIdentifier;
- private final boolean exclusiveAccessSession;
-
/** count number of entry in object code */
private int inObjectCount;
- private final boolean autoSaveEnabled;
-
- private boolean inConstruction;
-
public static void setUseJavaAgent(final boolean useJavaAgent) {
ProxyCallBack.useJavaAgent = useJavaAgent;
}
/**
+ *
+ */
+ public ProxyCallBack() {
+ super();
+ inObjectCount = 1;
+ storeMutex = new JoafipMutex();
+ exclusiveAccessSession = true;
+ }
+
+ /**
* at construction set the proxied object class, the object input/output
* manager for state reading from file, and get the mutex for file access
*
@@ -107,8 +115,19 @@
this.objectIOManager = objectIOManager;
autoSaveEnabled = objectIOManager.isAutoSaveEnabled();
storeMutex = objectIOManager.getStoreMutex();
+ exclusiveAccessSession = objectIOManager.isExclusiveAccessSession();
initializeFileAccessSessionIdentifier(objectIOManager);
+ }
+
+ @SuppressWarnings("PMD")
+ @Override
+ public void initialize$JOAFIP$(final IProxyCallBackToImplement proxyCallBack)
+ throws ProxyException {
+ this.objectIOManager = proxyCallBack.getObjectIOManager$JOAFIP$();
+ autoSaveEnabled = objectIOManager.isAutoSaveEnabled();
+ storeMutex = objectIOManager.getStoreMutex();
exclusiveAccessSession = objectIOManager.isExclusiveAccessSession();
+ initializeFileAccessSessionIdentifier(objectIOManager);
}
@SuppressWarnings("PMD")
@@ -175,17 +194,6 @@
return result;
}
- // FIXMELUC _________________________for test
- // private boolean in() {
- // final StackTraceElement[] stackTraceElements = new Exception()
- // .getStackTrace();
- // final StackTraceElement stackTraceElement = stackTraceElements[3];
- // final String className = stackTraceElement.getClassName();
- // final String methodName = stackTraceElement.getMethodName();
- // return className.contains("MultiMap")
- // && methodName.contains("addKeyDefinition");
- // }
-
@Override
@SuppressWarnings("PMD")
public void intercept$JOAFIP$() {
@@ -193,98 +201,99 @@
if (exclusiveAccessSession) {
inObjectCount++;
}
- // FIXMELUC _________________________for test
- // if (in()) {
- // System.out.println("intercept " + inObjectCount + " "
- // + proxyObjectAndPersistInfo);
- // }
- // end for test
- if (exclusiveAccessSession) {
- try {
- objectIOManager.objectIsAccessed(getInstance$JOAFIP$());
- } catch (Exception exception) {
- LOGGER.error("method begin interception error", exception);
- throw new ProxyInterceptException(getInstance$JOAFIP$()
- .toString(), exception);
+ if (!exclusiveAccessSession || inObjectCount == 1) {
+ if (exclusiveAccessSession) {
+ try {
+ objectIOManager.objectIsAccessed(getInstance$JOAFIP$());
+ } catch (Exception exception) {
+ LOGGER.error("method begin interception error",
+ exception);
+ throw new ProxyInterceptException(getInstance$JOAFIP$()
+ .toString(), exception);
+ }
}
- }
- /*
- * No loading operation twice. A nested call can happen when
- * invoking serialization method while loading
- */
- if (!loading) {
- loading = true;
-
/*
- * do not force load if finalizer thread
+ * No loading operation twice. A nested call can happen when
+ * invoking serialization method while loading
*/
- if (autoSaveEnabled && inObjectCount == 1) {
- wasLoaded = loaded;
- }
+ if (!loading) {
+ loading = true;
- if (!loaded
- && !inConstruction
- && !FINALIZER_THREAD_NAME.equals(Thread.currentThread()
- .getName())) {
+ if (autoSaveEnabled) {
+ wasLoaded = loaded;
+ }
+
/*
- * since object can be manipulated outside store method call
- * by another thread, need to be synchronized
+ * do not force load if finalizer thread
*/
- /* must be loaded before invoke method */
- try {
- load();
- } catch (Exception exception) {
- LOGGER.error("method begin interception error",
- exception);
- throw new ProxyInterceptException(getInstance$JOAFIP$()
- .toString(), exception);
+ if (!loaded
+ && !FINALIZER_THREAD_NAME.equals(Thread
+ .currentThread().getName())) {
+ /*
+ * since object can be manipulated outside store method
+ * call by another thread, need to be synchronized
+ */
+ /* must be loaded before invoke method */
+ try {
+ load();
+ } catch (Exception exception) {
+ LOGGER.error("method begin interception error",
+ exception);
+ final ObjectAndPersistInfo instance = getInstance$JOAFIP$();
+ final String instanceToString = instance == null ? "no instance"
+ : instance.toString();
+ throw new ProxyInterceptException(instanceToString,
+ exception);
+ }
}
+ loading = false;
}
-
- loading = false;
}
}
}
+ @SuppressWarnings("PMD")
@Override
+ public void constructorEnd$JOAFIP$() {
+ inObjectCount--;
+ assert inObjectCount >= 0 : "running in object count can not be negative, is "
+ + inObjectCount;
+ }
+
+ @Override
@SuppressWarnings("PMD")
public void methodEnd$JOAFIP$() {
- // FIXMELUC _________________________for test
- // if (in()) {
- // System.out.println("methodEnd " + inObjectCount + " "
- // + proxyObjectAndPersistInfo);
- // }
- // end for test
synchronized (storeMutex) {
final ObjectAndPersistInfo instanceAndPersistInfo = getInstance$JOAFIP$();
- if (--inObjectCount == 0) {
+ inObjectCount--;
+ // ASSERTX
+ assert inObjectCount >= 0 : "running in object count can not be negative, is "
+ + inObjectCount + " " + getInstance$JOAFIP$().toString();
+ if (inObjectCount == 0) {
instanceAndPersistInfo.acceded = false;
- }
- if (autoSaveEnabled) {
- // ASSERTX
- assert inObjectCount >= 0 : "running in object count can not be negative, is "
- + inObjectCount
- + " "
- + getInstance$JOAFIP$().toString();
- if (!wasLoaded && loaded && inObjectCount == 0) {
- try {
- objectIOManager.newObjectLoaded();
- } catch (ObjectIOException exception) {
- throw new ProxyInterceptException(exception);
+ if (autoSaveEnabled) {
+ if (!wasLoaded && loaded) {
+ try {
+ objectIOManager.newObjectLoaded();
+ } catch (ObjectIOException exception) {
+ throw new ProxyInterceptException(exception);
+ }
}
- }
- if (toUnload && inObjectCount == 0) {
- 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);
+ 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);
+ }
}
}
}
@@ -307,7 +316,7 @@
ObjectIOClassNotFoundException, ObjectIODataCorruptedException,
ObjectIONotSerializableException {
synchronized (storeMutex) {
- if (!loading && !inConstruction) {
+ if (!loading) {
loading = true;
if (!loaded) {
load();
@@ -326,8 +335,8 @@
/*
* inObjectCount==0 because can not unload object when running its code
*/
- if (loaded && !inConstruction) {
- if (!loading && inObjectCount == 0) {
+ if (loaded) {
+ if (!loading && (!exclusiveAccessSession || inObjectCount == 0)) {
loaded = false;
objectIOManager.unsetProxyObjectState(getInstance$JOAFIP$());
} else {
@@ -407,12 +416,6 @@
@Override
@SuppressWarnings("PMD")
- public void setInConstruction$JOAFIP$(final boolean inConstruction) {
- this.inConstruction = inConstruction;
- }
-
- @Override
- @SuppressWarnings("PMD")
public boolean isAutoSaveEnabled$JOAFIP$() {
return autoSaveEnabled;
}
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-10-22 03:38:16 UTC (rev 2935)
+++ trunk/joafip/src/main/java/net/sf/joafip/store/service/proxy/ProxyManager2.java 2011-10-23 11:37:55 UTC (rev 2936)
@@ -65,8 +65,6 @@
private int persistenceId;
- private boolean createEntryinObjectMap = true;
-
/**
*
* @param classLoaderProvider
@@ -158,11 +156,9 @@
objectIOManager.isExclusiveAccessSession());
instanceCreated = reflectNewInstanceDefaultConstructor(enhancedClass);
}
- if (createEntryinObjectMap) {
- objectAndPersistInfoOfCreatedInstance(objectClassInfo,
- storageInfo, objectIOManager, dataRecordIdentifier,
- persisted, instanceCreated, true);
- }
+ objectAndPersistInfoOfCreatedInstance(objectClassInfo, storageInfo,
+ objectIOManager, dataRecordIdentifier, persisted,
+ instanceCreated, true);
} catch (ReflectException exception) {
throw new ProxyException(exception);
} catch (EnhanceException exception) {
@@ -203,11 +199,9 @@
instanceCreated = reflectNewInstanceConstruct(enhancedClass,
parameterTypes, initargs);
}
- if (createEntryinObjectMap) {
- objectAndPersistInfoOfCreatedInstance(objectClassInfo,
- storageInfo, objectIOManager, dataRecordIdentifier,
- persisted, instanceCreated, true);
- }
+ objectAndPersistInfoOfCreatedInstance(objectClassInfo, storageInfo,
+ objectIOManager, dataRecordIdentifier, persisted,
+ instanceCreated, true);
} catch (ReflectException exception) {
throw new ProxyException(exception);
} catch (EnhanceException exception) {
@@ -228,10 +222,6 @@
initargs);
}
- public void setCreateEntryinObjectMap(final boolean createEntryinObjectMap) {
- this.createEntryinObjectMap = createEntryinObjectMap;
- }
-
private ObjectAndPersistInfo objectAndPersistInfoOfCreatedInstance(
final ClassInfo objectClassInfo, final StorageInfo storageInfo,
final IObjectIOManagerForProxyObjectIO objectIOManager,
@@ -290,7 +280,6 @@
if (constructed) {
assert getProxyCallBack(instanceCreated) != NULL_PROXY_CALL_BACK_INSTANCE;
- setNotInConstruction(instanceCreated);
// set is loaded last for auto save
objectAndPersistInfo.setIsLoaded();
}
@@ -307,8 +296,6 @@
* objectAndPersistInfo.setIsLoaded() should be good to, may be
* better
*/
- // objectAndPersistInfo.getProxyCallBackOfObject().setInConstruction$JOAFIP$(false);
- setNotInConstruction(instanceCreated);
// set is loaded last for auto save
setIsLoaded(instanceCreated);
}
@@ -400,15 +387,6 @@
}
}
- private void setNotInConstruction(final Object object) {
- if (useJavaAgent) {
- StaticProxyCallBack.setInConstruction(object, false);
- } else if (isProxy(object)) {
- ((IProxyCallBackProxyDelegation) object)
- .setInConstruction$JOAFIP$(false);
- }
- }
-
public static void setIsLoadedNoSave(final Object object)
throws ProxyException {
try {
@@ -543,37 +521,49 @@
public static void setProxyCallBack(
final ObjectAndPersistInfo objectAndPersistInfo,
- final IProxyCallBackToImplement proxyCallBack) {
+ final IProxyCallBackToImplement proxyCallBack,
+ final boolean exclusiveAccessSession) throws ProxyException {
final Object object = objectAndPersistInfo.getObject();
- if (useJavaAgent) {
- // ASSERTX
- assert StaticProxyCallBack.getProxyCallBack(object) == null
- || StaticProxyCallBack.getProxyCallBack(object) == NULL_PROXY_CALL_BACK_INSTANCE : "can not set twice the proxy callback of "
- + object.getClass().getName()
- + "@"
- + System.identityHashCode(object);
- StaticProxyCallBack.setProxyCallBack(object, proxyCallBack);
+ 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);
+ }
+ } 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);
+ }
+ }
} else {
- final IProxyCallBack proxy = (IProxyCallBack) object;
- // ASSERTX
- assert proxy.getProxyCallBack$JOAFIP$() == null
- || proxy.getProxyCallBack$JOAFIP$() == NULL_PROXY_CALL_BACK_INSTANCE : "can not set twice the proxy callback of "
- + object.getClass().getName()
- + "@"
- + System.identityHashCode(object);
- // FIXMELUC _______________________old proxy call back
- // FIXMELUC _______________________only for autosave
- // if(proxyCallBack.isAutoSaveEnabled$JOAFIP$())
- final IProxyCallBackToImplement oldProxyCallBack = proxy
- .getProxyCallBack$JOAFIP$();
- if (oldProxyCallBack == NULL_PROXY_CALL_BACK_INSTANCE) {// NOPMD
- // in construction
- proxyCallBack.setInConstruction$JOAFIP$(true);
+ if (useJavaAgent) {
+ StaticProxyCallBack.setProxyCallBack(object, proxyCallBack);
+ proxyCallBack.setInstance$JOAFIP$(objectAndPersistInfo);
+ objectAndPersistInfo.setProxyCallBack(proxyCallBack);
+
+ } else {
+ final IProxyCallBack proxy = (IProxyCallBack) object;
+ proxy.setProxyCallBack$JOAFIP$(proxyCallBack);
+ proxyCallBack.setInstance$JOAFIP$(objectAndPersistInfo);
+ objectAndPersistInfo.setProxyCallBack(proxyCallBack);
}
- proxy.setProxyCallBack$JOAFIP$(proxyCallBack);
}
- proxyCallBack.setInstance$JOAFIP$(objectAndPersistInfo);
- objectAndPersistInfo.setProxyCallBack(proxyCallBack);
}
public static void changeProxyCallBack(
Modified: trunk/joafip/src/main/java/net/sf/joafip/store/service/proxy/StaticProxyCallBack.java
===================================================================
--- trunk/joafip/src/main/java/net/sf/joafip/store/service/proxy/StaticProxyCallBack.java 2011-10-22 03:38:16 UTC (rev 2935)
+++ trunk/joafip/src/main/java/net/sf/joafip/store/service/proxy/StaticProxyCallBack.java 2011-10-23 11:37:55 UTC (rev 2936)
@@ -141,17 +141,6 @@
}
}
- public static void setInConstruction(final Object object,
- final boolean inConstruction) {
- final IProxyCallBackProxyDelegation proxyCallBack;
- synchronized (StaticProxyCallBack.class) {
- proxyCallBack = proxyCallBackOfObject(object);
- }
- if (proxyCallBack != null) {
- proxyCallBack.setInConstruction$JOAFIP$(inConstruction);
- }
- }
-
public static void setIsLoadedNoSave(final Object object)
throws ObjectIOException {
final IProxyCallBackProxyDelegation proxyCallBack;
Modified: trunk/joafip/src/test/java/net/sf/joafip/service/TestTreeListIteratorIntercept.java
===================================================================
--- trunk/joafip/src/test/java/net/sf/joafip/service/TestTreeListIteratorIntercept.java 2011-10-22 03:38:16 UTC (rev 2935)
+++ trunk/joafip/src/test/java/net/sf/joafip/service/TestTreeListIteratorIntercept.java 2011-10-23 11:37:55 UTC (rev 2936)
@@ -50,7 +50,14 @@
}
}
+ @SuppressWarnings("PMD")
@Override
+ public void initialize$JOAFIP$(IProxyCallBackToImplement proxyCallBack)
+ throws ProxyException {
+ // no implementation
+ }
+
+ @Override
@SuppressWarnings("PMD")
public void intercept$JOAFIP$() {
intercepted = true;
@@ -88,7 +95,13 @@
return false;
}
+ @SuppressWarnings("PMD")
@Override
+ public void constructorEnd$JOAFIP$() {
+ // no implementation
+ }
+
+ @Override
@SuppressWarnings("PMD")
public void methodEnd$JOAFIP$() {
}
@@ -144,9 +157,4 @@
// no implementation
return false;
}
-
- @Override
- public void setInConstruction$JOAFIP$(final boolean inConstruction) {// NOPMD
- // no implementation
- }
}
Modified: trunk/joafip/src/test/java/net/sf/joafip/service/sync/TestSynchronizedCollection.java
===================================================================
--- trunk/joafip/src/test/java/net/sf/joafip/service/sync/TestSynchronizedCollection.java 2011-10-22 03:38:16 UTC (rev 2935)
+++ trunk/joafip/src/test/java/net/sf/joafip/service/sync/TestSynchronizedCollection.java 2011-10-23 11:37:55 UTC (rev 2936)
@@ -4,6 +4,8 @@
import java.util.Map;
import net.sf.joafip.AbstractDeleteFileTestCase;
+import net.sf.joafip.NotStorableClass;
+import net.sf.joafip.StorableAccess;
import net.sf.joafip.TestException;
import net.sf.joafip.entity.EnumFilePersistenceCloseAction;
import net.sf.joafip.java.util.PTreeMap;
@@ -17,8 +19,11 @@
import net.sf.joafip.service.IDataAccessSession;
import net.sf.joafip.service.IFilePersistence;
+@NotStorableClass
+@StorableAccess
public class TestSynchronizedCollection extends AbstractDeleteFileTestCase {
+ private static final String KEY = "key";
private IFilePersistence filePersistence;
public TestSynchronizedCollection() throws TestException {
@@ -54,7 +59,7 @@
super.tearDown();
}
- @SuppressWarnings({ "PMD", "unchecked" })
+ @SuppressWarnings("unchecked")
public void testSynchronizedMap() throws FilePersistenceException,
FilePersistenceClassNotFoundException,
FilePersistenceInvalidClassException,
@@ -70,15 +75,16 @@
.createDataAccessSession();
PTreeMap<String, String> map = new PTreeMap<String, String>();
Map<String, String> smap = Collections.synchronizedMap(map);
- smap.put("key", "value");
+ smap.put(KEY, "value");
session.open();
- session.setObject("key", smap);
+ session.setObject(KEY, smap);
map = null;// NOPMD
smap = null;// NOPMD
session.close(EnumFilePersistenceCloseAction.SAVE);
session.open();
- smap = (Map<String, String>) session.getObject("key");
+ smap = (Map<String, String>) session.getObject(KEY);
+ assertEquals("bad value", "value", smap.get(KEY));
session.close(EnumFilePersistenceCloseAction.SAVE);
}
}
Modified: trunk/joafip/src/test/java/net/sf/joafip/store/service/copier/AbstractTestDeepCopier.java
===================================================================
--- trunk/joafip/src/test/java/net/sf/joafip/store/service/copier/AbstractTestDeepCopier.java 2011-10-22 03:38:16 UTC (rev 2935)
+++ trunk/joafip/src/test/java/net/sf/joafip/store/service/copier/AbstractTestDeepCopier.java 2011-10-23 11:37:55 UTC (rev 2936)
@@ -206,10 +206,11 @@
ProxyCallBack proxyCallBack;
try {
proxyCallBack = new ProxyCallBack(this);
+ ProxyManager2.setProxyCallBack(objectAndPersistInfo,
+ proxyCallBack, isExclusiveAccessSession());
} catch (ProxyException exception) {
throw new ObjectIOException(exception);
}
- ProxyManager2.setProxyCallBack(objectAndPersistInfo, proxyCallBack);
}
return objectAndPersistInfo;
}
Modified: trunk/joafip/src/test/java/net/sf/joafip/store/service/proxy/AbstractObjectIoManagerForProxyTest.java
===================================================================
--- trunk/joafip/src/test/java/net/sf/joafip/store/service/proxy/AbstractObjectIoManagerForProxyTest.java 2011-10-22 03:38:16 UTC (rev 2935)
+++ trunk/joafip/src/test/java/net/sf/joafip/store/service/proxy/AbstractObjectIoManagerForProxyTest.java 2011-10-23 11:37:55 UTC (rev 2936)
@@ -64,7 +64,8 @@
objectAndPersistInfo = new ObjectAndPersistInfo(object,
proxyInstance, objectClassInfo);
final ProxyCallBack proxyCallBack = new ProxyCallBack(this);
- ProxyManager2.setProxyCallBack(objectAndPersistInfo, proxyCallBack);
+ ProxyManager2.setProxyCallBack(objectAndPersistInfo, proxyCallBack,
+ isExclusiveAccessSession());
} catch (ClassInfoException exception) {
throw new ObjectIOException(exception);
} catch (ProxyException exception) {
@@ -118,7 +119,8 @@
objectAndPersistInfo = new ObjectAndPersistInfo(object,
proxyInstance, objectClassInfo);
final ProxyCallBack proxyCallBack = new ProxyCallBack(this);
- ProxyManager2.setProxyCallBack(objectAndPersistInfo, proxyCallBack);
+ ProxyManager2.setProxyCallBack(objectAndPersistInfo, proxyCallBack,
+ isExclusiveAccessSession());
} catch (ClassInfoException exception) {
throw new ObjectIOException(exception);
} catch (ProxyException exception) {
Modified: trunk/joafip/src/test/java/net/sf/joafip/store/service/proxy/ProxyCallBackForTest.java
===================================================================
--- trunk/joafip/src/test/java/net/sf/joafip/store/service/proxy/ProxyCallBackForTest.java 2011-10-22 03:38:16 UTC (rev 2935)
+++ trunk/joafip/src/test/java/net/sf/joafip/store/service/proxy/ProxyCallBackForTest.java 2011-10-23 11:37:55 UTC (rev 2936)
@@ -41,6 +41,13 @@
@Override
@SuppressWarnings("PMD")
+ public void initialize$JOAFIP$(final IProxyCallBackToImplement proxyCallBack)
+ throws ProxyException {
+ // do nothing
+ }
+
+ @Override
+ @SuppressWarnings("PMD")
public ClassInfoFactory getClassInfoFactory$JOAFIP$() {
return classInfoFactory;
}
@@ -87,7 +94,13 @@
// no implementation
}
+ @SuppressWarnings("PMD")
@Override
+ public void constructorEnd$JOAFIP$() {
+ // no implementation
+ }
+
+ @Override
@SuppressWarnings("PMD")
public void methodEnd$JOAFIP$() {
// no implementation
@@ -290,10 +303,4 @@
// no implementation
return false;
}
-
- @SuppressWarnings("PMD")
- @Override
- public void setInConstruction$JOAFIP$(final boolean inConstruction) {
- // no implementation
- }
}
Modified: trunk/joafip/src/test/java/net/sf/joafip/store/service/proxy/TestProxyCreation.java
===================================================================
--- trunk/joafip/src/test/java/net/sf/joafip/store/service/proxy/TestProxyCreation.java 2011-10-22 03:38:16 UTC (rev 2935)
+++ trunk/joafip/src/test/java/net/sf/joafip/store/service/proxy/TestProxyCreation.java 2011-10-23 11:37:55 UTC (rev 2936)
@@ -99,7 +99,7 @@
assertTrue("must be loaded", ProxyManager2.isLoadedOrNotAProxy(object));
assertNotNull("field must be defined", ((Bob1) object).getBob2());
ProxyManager2.unload(object);
- assertFalse("must not be unloaded",
+ assertFalse("must not be unloaded after call of unload",
ProxyManager2.isLoadedOrNotAProxy(object));
assertNull("field must not be defined", getBob2(object));
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|