You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2018/09/05 11:41:07 UTC
[isis] branch master updated: ISIS-1976: minor polishing
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git
The following commit(s) were added to refs/heads/master by this push:
new 2fcfc93 ISIS-1976: minor polishing
2fcfc93 is described below
commit 2fcfc93647a9a32401951b0f01676e9ed11a14dc
Author: Andi Huber <ah...@apache.org>
AuthorDate: Wed Sep 5 13:40:24 2018 +0200
ISIS-1976: minor polishing
Task-Url: https://issues.apache.org/jira/browse/ISIS-1976
---
.../apache/isis/commons/internal/base/_Lazy.java | 64 ++++++++++------------
.../base/{_Lazy.java => _Lazy_Simple.java} | 38 ++-----------
...{_LazyThreadSafe.java => _Lazy_ThreadSafe.java} | 39 ++-----------
.../persistence/PersistenceSessionFactory4.java | 6 +-
.../system/persistence/PersistenceSession5.java | 2 +-
.../persistence/PersistenceSessionFactory5.java | 6 +-
.../adaptermanager/ObjectAdapterContext.java | 16 ++++--
.../objectstore/jdo/service/RegisterEntities.java | 4 +-
8 files changed, 60 insertions(+), 115 deletions(-)
diff --git a/core/commons/src/main/java/org/apache/isis/commons/internal/base/_Lazy.java b/core/commons/src/main/java/org/apache/isis/commons/internal/base/_Lazy.java
index 18eb150..d105093 100644
--- a/core/commons/src/main/java/org/apache/isis/commons/internal/base/_Lazy.java
+++ b/core/commons/src/main/java/org/apache/isis/commons/internal/base/_Lazy.java
@@ -19,8 +19,6 @@
package org.apache.isis.commons.internal.base;
-import static org.apache.isis.commons.internal.base._With.requires;
-
import java.util.function.Supplier;
/**
@@ -35,54 +33,50 @@ import java.util.function.Supplier;
*
* @since 2.0.0
*/
-public final class _Lazy<T> implements Supplier<T> {
-
- private final Supplier<? extends T> supplier;
- private T value;
- private boolean memoized;
-
- /**
- * Concurrent calls to this lazy's get() method might result in concurrent calls to the
- * specified {@code supplier}.
- * @param supplier
- * @return an (non-thread-safe) instance of _Lacy that initializes with the specified {@code supplier}
- */
- public static <T> _Lazy<T> of(Supplier<? extends T> supplier) {
- return new _Lazy<T>(supplier);
- }
-
- private _Lazy(Supplier<? extends T> supplier) {
- this.supplier = requires(supplier, "supplier");
- }
-
+public interface _Lazy<T> extends Supplier<T> {
+
+ // -- INTERFACE
+
/**
* @return whether this lazy got initialized and holds a memoized value
*/
- public boolean isMemoized() {
- return memoized;
- }
+ public boolean isMemoized();
/**
* Clears the lazy's memoized value. Resets this lazy to its initial state.<br>
* isMemoized() = false;
*
*/
- public void clear() {
- this.memoized = false;
- this.value = null;
- }
+ public void clear();
/**
* Evaluates this lazy value and memoizes it, when called the first time
* after initialization or clear().
*/
@Override
- public T get() {
- if(memoized) {
- return value;
- }
- memoized=true;
- return value = supplier.get();
+ public T get();
+
+ // -- FACTORIES
+
+ /**
+ * Concurrent calls to this lazy's get() method might result in concurrent calls to the
+ * specified {@code supplier}.
+ * @param supplier
+ * @return an (non-thread-safe) instance of _Lacy that initializes with the specified {@code supplier}
+ */
+ public static <T> _Lazy<T> of(Supplier<? extends T> supplier) {
+ return new _Lazy_Simple<T>(supplier);
+ }
+
+ /**
+ * Thread-safe variant to {@link _Lazy#of(Supplier)}.
+ * Concurrent calls to this lazy's get() method will never result in concurrent calls to the
+ * specified {@code supplier}.
+ * @param supplier
+ * @return an (thread-safe) instance of _Lacy that initializes with the specified {@code supplier}
+ */
+ public static <T> _Lazy<T> threadSafe(Supplier<? extends T> supplier) {
+ return new _Lazy_ThreadSafe<T>(supplier);
}
}
diff --git a/core/commons/src/main/java/org/apache/isis/commons/internal/base/_Lazy.java b/core/commons/src/main/java/org/apache/isis/commons/internal/base/_Lazy_Simple.java
similarity index 57%
copy from core/commons/src/main/java/org/apache/isis/commons/internal/base/_Lazy.java
copy to core/commons/src/main/java/org/apache/isis/commons/internal/base/_Lazy_Simple.java
index 18eb150..c8aa2c6 100644
--- a/core/commons/src/main/java/org/apache/isis/commons/internal/base/_Lazy.java
+++ b/core/commons/src/main/java/org/apache/isis/commons/internal/base/_Lazy_Simple.java
@@ -24,58 +24,30 @@ import static org.apache.isis.commons.internal.base._With.requires;
import java.util.function.Supplier;
/**
- * <h1>- internal use only -</h1>
- * <p>
- * (non-thread-safe) Supplier with memoization.
- * </p>
- * <p>
- * <b>WARNING</b>: Do <b>NOT</b> use any of the classes provided by this package! <br/>
- * These may be changed or removed without notice!
- * </p>
- *
+ * package private mixin for _Lazy
* @since 2.0.0
*/
-public final class _Lazy<T> implements Supplier<T> {
+final class _Lazy_Simple<T> implements _Lazy<T> {
private final Supplier<? extends T> supplier;
private T value;
private boolean memoized;
- /**
- * Concurrent calls to this lazy's get() method might result in concurrent calls to the
- * specified {@code supplier}.
- * @param supplier
- * @return an (non-thread-safe) instance of _Lacy that initializes with the specified {@code supplier}
- */
- public static <T> _Lazy<T> of(Supplier<? extends T> supplier) {
- return new _Lazy<T>(supplier);
- }
-
- private _Lazy(Supplier<? extends T> supplier) {
+ _Lazy_Simple(Supplier<? extends T> supplier) {
this.supplier = requires(supplier, "supplier");
}
- /**
- * @return whether this lazy got initialized and holds a memoized value
- */
+ @Override
public boolean isMemoized() {
return memoized;
}
- /**
- * Clears the lazy's memoized value. Resets this lazy to its initial state.<br>
- * isMemoized() = false;
- *
- */
+ @Override
public void clear() {
this.memoized = false;
this.value = null;
}
- /**
- * Evaluates this lazy value and memoizes it, when called the first time
- * after initialization or clear().
- */
@Override
public T get() {
if(memoized) {
diff --git a/core/commons/src/main/java/org/apache/isis/commons/internal/base/_LazyThreadSafe.java b/core/commons/src/main/java/org/apache/isis/commons/internal/base/_Lazy_ThreadSafe.java
similarity index 57%
rename from core/commons/src/main/java/org/apache/isis/commons/internal/base/_LazyThreadSafe.java
rename to core/commons/src/main/java/org/apache/isis/commons/internal/base/_Lazy_ThreadSafe.java
index 436cd36..a426a2b 100644
--- a/core/commons/src/main/java/org/apache/isis/commons/internal/base/_LazyThreadSafe.java
+++ b/core/commons/src/main/java/org/apache/isis/commons/internal/base/_Lazy_ThreadSafe.java
@@ -24,52 +24,27 @@ import static org.apache.isis.commons.internal.base._With.requires;
import java.util.function.Supplier;
/**
- * <h1>- internal use only -</h1>
- * <p>
- * Thread-safe Supplier with memoization.
- * </p>
- * <p>
- * <b>WARNING</b>: Do <b>NOT</b> use any of the classes provided by this package! <br/>
- * These may be changed or removed without notice!
- * </p>
- *
+ * package private mixin for _Lazy
* @since 2.0.0
*/
-public final class _LazyThreadSafe<T> implements Supplier<T> {
+final class _Lazy_ThreadSafe<T> implements _Lazy<T> {
private final Supplier<? extends T> supplier;
private T value;
private boolean memoized;
- /**
- * Thread-safe variant to {@link _Lazy#of(Supplier)}.
- * Concurrent calls to this lazy's get() method will never result in concurrent calls to the
- * specified {@code supplier}.
- * @param supplier
- * @return an (thread-safe) instance of _Lacy that initializes with the specified {@code supplier}
- */
- public static <T> _LazyThreadSafe<T> of(Supplier<? extends T> supplier) {
- return new _LazyThreadSafe<T>(supplier);
- }
-
- private _LazyThreadSafe(Supplier<? extends T> supplier) {
+ _Lazy_ThreadSafe(Supplier<? extends T> supplier) {
this.supplier = requires(supplier, "supplier");
}
- /**
- * @return whether this lazy got initialized and holds a memoized value
- */
+ @Override
public boolean isMemoized() {
synchronized (this) {
return memoized;
}
}
- /**
- * Clears the lazy's memoized value. Resets this lazy to its initial state.<br>
- * isMemoized() = false;
- *
- */
+ @Override
public void clear() {
synchronized (this) {
this.memoized = false;
@@ -77,10 +52,6 @@ public final class _LazyThreadSafe<T> implements Supplier<T> {
}
}
- /**
- * Evaluates this lazy value and memoizes it, when called the first time
- * after initialization or clear().
- */
@Override
public T get() {
synchronized (this) {
diff --git a/core/plugins/jdo-datanucleus-4/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSessionFactory4.java b/core/plugins/jdo-datanucleus-4/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSessionFactory4.java
index 9410b49..004fc50 100644
--- a/core/plugins/jdo-datanucleus-4/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSessionFactory4.java
+++ b/core/plugins/jdo-datanucleus-4/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSessionFactory4.java
@@ -31,7 +31,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.isis.applib.annotation.Programmatic;
-import org.apache.isis.commons.internal.base._LazyThreadSafe;
+import org.apache.isis.commons.internal.base._Lazy;
import org.apache.isis.core.commons.authentication.AuthenticationSession;
import org.apache.isis.core.commons.components.ApplicationScopedComponent;
import org.apache.isis.core.commons.config.IsisConfiguration;
@@ -59,8 +59,8 @@ PersistenceSessionFactory, ApplicationScopedComponent, FixturesInstalledFlag {
public static final String DATANUCLEUS_CONFIG_PREFIX = "isis.persistor.datanucleus.impl"; // reserved for datanucleus' own config props
- private final _LazyThreadSafe<DataNucleusApplicationComponents4> applicationComponents =
- _LazyThreadSafe.of(this::createDataNucleusApplicationComponents);
+ private final _Lazy<DataNucleusApplicationComponents4> applicationComponents =
+ _Lazy.threadSafe(this::createDataNucleusApplicationComponents);
private IsisConfiguration configuration;
diff --git a/core/plugins/jdo-datanucleus-5/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession5.java b/core/plugins/jdo-datanucleus-5/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession5.java
index be0c296..90886dc 100644
--- a/core/plugins/jdo-datanucleus-5/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession5.java
+++ b/core/plugins/jdo-datanucleus-5/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSession5.java
@@ -1134,7 +1134,7 @@ implements IsisLifecycleListener.PersistenceSessionLifecycleManagement {
final RootOid originalOid;
ObjectAdapter adapter = objectAdapterContext.lookupAdapterFor(pojo);
if (adapter != null) {
- ensureRootObject(pojo);
+ ensureRootObject(pojo); //[ahuber] while already mapped has no side-effect
originalOid = (RootOid) adapter.getOid();
final Version originalVersion = adapter.getVersion();
diff --git a/core/plugins/jdo-datanucleus-5/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSessionFactory5.java b/core/plugins/jdo-datanucleus-5/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSessionFactory5.java
index ef489a7..423ba06 100644
--- a/core/plugins/jdo-datanucleus-5/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSessionFactory5.java
+++ b/core/plugins/jdo-datanucleus-5/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSessionFactory5.java
@@ -31,7 +31,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.isis.applib.annotation.Programmatic;
-import org.apache.isis.commons.internal.base._LazyThreadSafe;
+import org.apache.isis.commons.internal.base._Lazy;
import org.apache.isis.core.commons.authentication.AuthenticationSession;
import org.apache.isis.core.commons.components.ApplicationScopedComponent;
import org.apache.isis.core.commons.config.IsisConfiguration;
@@ -59,8 +59,8 @@ implements PersistenceSessionFactory, ApplicationScopedComponent, FixturesInstal
public static final String DATANUCLEUS_CONFIG_PREFIX = "isis.persistor.datanucleus.impl"; // reserved for datanucleus' own config props
- private final _LazyThreadSafe<DataNucleusApplicationComponents5> applicationComponents =
- _LazyThreadSafe.of(this::createDataNucleusApplicationComponents);
+ private final _Lazy<DataNucleusApplicationComponents5> applicationComponents =
+ _Lazy.threadSafe(this::createDataNucleusApplicationComponents);
private IsisConfiguration configuration;
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/adaptermanager/ObjectAdapterContext.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/adaptermanager/ObjectAdapterContext.java
index e01b0df..a01bb45 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/adaptermanager/ObjectAdapterContext.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/adaptermanager/ObjectAdapterContext.java
@@ -128,12 +128,12 @@ public class ObjectAdapterContext {
}
@Deprecated // don't expose caching
- public ObjectAdapter lookupAdapterByPojo(Object pojo) {
+ protected ObjectAdapter lookupAdapterByPojo(Object pojo) {
return pojoAdapterMap.getAdapter(pojo);
}
@Deprecated // don't expose caching
- public ObjectAdapter lookupAdapterById(Oid oid) {
+ protected ObjectAdapter lookupAdapterById(Oid oid) {
return oidAdapterMap.getAdapter(oid);
}
@@ -164,10 +164,12 @@ public class ObjectAdapterContext {
// -- CACHE CONSISTENCY
+ @Deprecated // don't expose caching
public void ensureMapsConsistent(final ObjectAdapter adapter) {
consistencyMixin.ensureMapsConsistent(adapter);
}
+ @Deprecated // don't expose caching
public void ensureMapsConsistent(final Oid oid) {
consistencyMixin.ensureMapsConsistent(oid);
}
@@ -224,32 +226,38 @@ public class ObjectAdapterContext {
// -- ADAPTER MANAGER LEGACY
+ @Deprecated // don't expose caching
public ObjectAdapter addRecreatedPojoToCache(Oid oid, Object recreatedPojo) {
return adapterManagerMixin.addRecreatedPojoToCache(oid, recreatedPojo);
}
+ @Deprecated // don't expose caching
public ObjectAdapter mapAndInjectServices(final ObjectAdapter adapter) {
return adapterManagerMixin.mapAndInjectServices(adapter);
}
+ @Deprecated // don't expose caching
public ObjectAdapter lookupAdapterFor(Object pojo) {
return adapterManagerMixin.lookupAdapterFor(pojo);
}
+ @Deprecated // don't expose caching
public ObjectAdapter lookupAdapterFor(final Oid oid) {
return adapterManagerMixin.lookupAdapterFor(oid);
}
+ @Deprecated // don't expose caching
public void removeAdapterFromCache(final ObjectAdapter adapter) {
adapterManagerMixin.removeAdapterFromCache(adapter);
}
- // -- OBJECT ADAPTER PROVIDER SUPPORT
-
+ @Deprecated // don't expose caching
public ObjectAdapter addPersistentToCache(final Object pojo) {
return objectAdapterProviderMixin.addPersistentToCache(pojo);
}
+ // -- OBJECT ADAPTER PROVIDER SUPPORT
+
public ObjectAdapterProvider getObjectAdapterProvider() {
return objectAdapterProviderMixin;
}
diff --git a/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/service/RegisterEntities.java b/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/service/RegisterEntities.java
index 97c191f..b9b8fd1 100644
--- a/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/service/RegisterEntities.java
+++ b/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/service/RegisterEntities.java
@@ -31,7 +31,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.isis.applib.AppManifest;
-import org.apache.isis.commons.internal.base._LazyThreadSafe;
+import org.apache.isis.commons.internal.base._Lazy;
import org.apache.isis.core.metamodel.JdoMetamodelUtil;
public class RegisterEntities {
@@ -45,7 +45,7 @@ public class RegisterEntities {
@Deprecated
public final static String PACKAGE_PREFIX_KEY = "isis.persistor.datanucleus.RegisterEntities.packagePrefix";
- private final _LazyThreadSafe<Set<String>> entityTypes = _LazyThreadSafe.of(this::findEntityTypes);
+ private final _Lazy<Set<String>> entityTypes = _Lazy.threadSafe(this::findEntityTypes);
public Set<String> getEntityTypes() {
return entityTypes.get();