-
Notifications
You must be signed in to change notification settings - Fork 6
[NAE-2182] Clearing actions cache #348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: release/7.0.0-rev9
Are you sure you want to change the base?
Changes from all commits
dd58002
5b98ca4
e917f76
bd719b5
e976081
8323adb
f9796d6
a002636
e6e8dac
d2227d0
6e09ba1
790659b
dd80913
7dc7947
eb56f99
93921f9
cf3dc8c
cb1505f
fc76808
b5bd5b5
9059bec
dfd7afd
e8441cb
0c1c914
53fb4e6
1cdfbc4
47ba662
7e0c9b8
4670f33
cf0651a
48e1411
b30c884
d7705b2
2654b7d
d457145
61f9b2e
289de0f
e9ef494
2274d62
39da22c
d82fc67
174c7ee
faa99d7
44c6ed7
fc637ee
6d84f5b
c18561f
f7b61be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package com.netgrif.application.engine.configuration; | ||
|
|
||
| public final class CacheMapKeys { | ||
| private CacheMapKeys() {} | ||
| public static final String ACTIONS = "actions"; | ||
| public static final String FUNCTIONS = "functions"; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| package com.netgrif.application.engine.configuration; | ||
|
|
||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.jetbrains.annotations.NotNull; | ||
| import org.springframework.cache.Cache; | ||
| import org.springframework.cache.support.SimpleValueWrapper; | ||
|
|
||
| import java.util.Map; | ||
| import java.util.concurrent.Callable; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
| import java.util.concurrent.atomic.AtomicReference; | ||
|
|
||
| @Slf4j | ||
| public class GenericMapCache<V> implements Cache { | ||
| private final String name; | ||
| private final Class<V> valueType; | ||
| private final java.util.function.Supplier<Map<String, V>> mapFactory; | ||
| private final AtomicReference<Map<String, V>> atomicMapRef; | ||
|
|
||
| private final ConcurrentHashMap<String, Object> locks = new ConcurrentHashMap<>(); | ||
|
|
||
| public GenericMapCache(String name, Class<V> valueType, java.util.function.Supplier<Map<String, V>> mapFactory) { | ||
| this.name = name; | ||
| this.valueType = valueType; | ||
| this.mapFactory = mapFactory; | ||
| this.atomicMapRef = new AtomicReference<>(mapFactory.get()); | ||
| } | ||
|
|
||
| @Override public @NotNull String getName() { return name; } | ||
|
|
||
| @Override public @NotNull Object getNativeCache() { return Map.copyOf(map()); } | ||
|
|
||
| @Override | ||
| public <T> T get(Object key, Callable<T> loader) { | ||
| final String stringKey = String.valueOf(key); | ||
|
|
||
| Object mapValue = map().get(stringKey); | ||
| if (mapValue != null) { | ||
| return (T) mapValue; | ||
| } | ||
|
|
||
| Object lock = locks.computeIfAbsent(stringKey, lockKey -> new Object()); | ||
| try { | ||
| synchronized (lock) { | ||
| Object mapLockValue = map().get(stringKey); | ||
| if (mapLockValue != null) { | ||
| return (T) mapLockValue; | ||
| } | ||
|
|
||
| T computed = loader.call(); | ||
| if (computed == null) { | ||
| return null; | ||
| } | ||
|
|
||
| V value = safeCast(computed); | ||
| map().put(stringKey, value); | ||
| return (T) value; | ||
| } | ||
| } catch (Exception ex) { | ||
| throw new Cache.ValueRetrievalException(stringKey, loader, ex); | ||
| } finally { | ||
| locks.remove(stringKey, lock); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public ValueWrapper get(Object key) { | ||
| String stringKey = String.valueOf(key); | ||
| Object valueObject = map().get(stringKey); | ||
| return valueObject != null ? new SimpleValueWrapper(valueObject) : null; | ||
| } | ||
|
|
||
| @Override | ||
| public synchronized <T> T get(Object key, Class<T> type) { | ||
| String stringKey = String.valueOf(key); | ||
| Object valueObject = map().get(stringKey); | ||
| return valueObject != null ? type.cast(valueObject) : null; | ||
| } | ||
|
|
||
| @Override | ||
| public synchronized void put(Object key, Object value) { | ||
| map().put(String.valueOf(key), safeCast(value)); | ||
| } | ||
|
|
||
| @Override | ||
| public synchronized void evict(Object key) { | ||
| map().remove(String.valueOf(key)); | ||
| } | ||
|
|
||
| @Override | ||
| public synchronized void clear() { | ||
| this.atomicMapRef.set(mapFactory.get()); | ||
| } | ||
|
Comment on lines
+73
to
+93
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Mixed synchronization strategy creates potential inconsistencies. The class uses three different synchronization mechanisms:
This mix can lead to visibility issues. For example, a thread calling Consider using a consistent approach: either use |
||
|
|
||
| private Map<String, V> map() { | ||
| return atomicMapRef.get(); | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| private V safeCast(Object object) { | ||
| if (object == null) { | ||
| return null; | ||
| } | ||
|
|
||
| if (!valueType.isInstance(object)) { | ||
| throw new ClassCastException("Expected " + valueType.getName() + " but was " + object.getClass().getName()); | ||
| } | ||
|
|
||
| return (V) object; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -56,7 +56,7 @@ public static class FieldRunnerProperties { | |||||||||||||||||||
| /** | ||||||||||||||||||||
| * The size of the cache used for maintaining field runner namespaces. | ||||||||||||||||||||
| */ | ||||||||||||||||||||
| private int namespaceCacheSize = 500; | ||||||||||||||||||||
| private int globalFunctionsCacheSize = 500; | ||||||||||||||||||||
|
Comment on lines
56
to
+59
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update Javadoc to match the renamed field. The Javadoc on line 57 still references "maintaining field runner namespaces," but the field has been renamed to 🔎 Apply this diff to fix the Javadoc: /**
- * The size of the cache used for maintaining field runner namespaces.
+ * The size of the cache used for managing global field runner functions.
*/
private int globalFunctionsCacheSize = 500;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| /** | ||||||||||||||||||||
|
|
||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| package com.netgrif.application.engine.importer.service; | ||
|
|
||
| import com.netgrif.application.engine.objects.importer.model.Scope; | ||
| import com.netgrif.application.engine.objects.petrinet.domain.Function; | ||
| import com.netgrif.application.engine.objects.petrinet.domain.FunctionScope; | ||
| import lombok.extern.slf4j.Slf4j; | ||
|
|
@@ -9,7 +10,10 @@ | |
| @Slf4j | ||
| public final class FunctionFactory { | ||
|
|
||
| private static final String NAMESPACE = "namespace"; | ||
|
|
||
| public Function getFunction(com.netgrif.application.engine.objects.importer.model.Function function) { | ||
| checkDeprecatedAttributes(function); | ||
| Function function1 = new Function(); | ||
|
|
||
| function1.setDefinition(function.getValue()); | ||
|
|
@@ -18,4 +22,11 @@ public Function getFunction(com.netgrif.application.engine.objects.importer.mode | |
|
|
||
| return function1; | ||
| } | ||
|
|
||
| private void checkDeprecatedAttributes(com.netgrif.application.engine.objects.importer.model.Function function) { | ||
| if (function.getScope() != null && function.getScope().value().equals(NAMESPACE)) { | ||
| log.warn("Function scope [NAMESPACE] is deprecated. Replacing with [GLOBAL].]"); | ||
| function.setScope(Scope.GLOBAL); | ||
| } | ||
| } | ||
|
Comment on lines
+26
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: find . -type f -name "Scope.java" | head -20Repository: netgrif/application-engine Length of output: 52 🏁 Script executed: #!/bin/bash
# Search for enum Scope definition
rg "enum\s+Scope" -A 10 --type javaRepository: netgrif/application-engine Length of output: 52 🏁 Script executed: #!/bin/bash
# Search for Scope class/interface definition
rg "^(class|interface|enum)\s+Scope\b" --type java -A 15Repository: netgrif/application-engine Length of output: 52 🏁 Script executed: #!/bin/bash
# Read the FunctionFactory.java file to see imports and the actual method
cat application-engine/src/main/java/com/netgrif/application/engine/importer/service/FunctionFactory.java | head -50Repository: netgrif/application-engine Length of output: 1320 🏁 Script executed: #!/bin/bash
# Search for Scope enum in the objects.importer.model package
find . -type f -path "*/objects/importer/model/*" -name "*.java" | xargs ls -laRepository: netgrif/application-engine Length of output: 1212 🏁 Script executed: #!/bin/bash
# Find all Java files in objects/importer/model path
find . -path "*/objects/importer/model/*.java" -type fRepository: netgrif/application-engine Length of output: 52 🏁 Script executed: #!/bin/bash
# Search for Scope.java file anywhere in the objects directory
find . -path "*/objects/*" -name "Scope.java" -type fRepository: netgrif/application-engine Length of output: 52 🏁 Script executed: #!/bin/bash
# Broad search for where Scope is defined
rg "class Scope|interface Scope" --type java -B 2 -A 10Repository: netgrif/application-engine Length of output: 52 🏁 Script executed: #!/bin/bash
# Search for GLOBAL constant in the codebase
rg "GLOBAL" --type java | head -20Repository: netgrif/application-engine Length of output: 2792 🏁 Script executed: #!/bin/bash
# Search for Scope in nae-object-library or find the importer model package
find . -path "*/importer/model/*" -name "*.java" -type fRepository: netgrif/application-engine Length of output: 52 🏁 Script executed: #!/bin/bash
# List all directories in nae-object-library
find ./nae-object-library -type d -name "importer"Repository: netgrif/application-engine Length of output: 52 🏁 Script executed: #!/bin/bash
# Search all Java files for "Scope.GLOBAL"
rg "Scope\." --type java -B 2 -A 2 | head -40Repository: netgrif/application-engine Length of output: 3040 🏁 Script executed: #!/bin/bash
# Search for all imports of Scope in FunctionFactory and related files
rg "import.*Scope" --type java | grep -v "FunctionScope"Repository: netgrif/application-engine Length of output: 742 🏁 Script executed: #!/bin/bash
# Find the Scope class in the objects.importer.model package
find . -path "*/objects/importer/model/Scope.java" -o -path "*/objects/importer/model/Scope.class"Repository: netgrif/application-engine Length of output: 52 🏁 Script executed: #!/bin/bash
# List all files in the objects/importer/model directory
find . -type d -path "*/objects/importer/model" -exec ls -la {} \;Repository: netgrif/application-engine Length of output: 52 🏁 Script executed: #!/bin/bash
# Search for where the importer model package is defined
find . -type d -name "importer"Repository: netgrif/application-engine Length of output: 351 Critical: Fix compilation error - The code on line 29 attempts to use Verify the correct import path for the Scope enum and ensure the constant exists, or refactor to use an alternative approach (such as directly setting an appropriate value on the importer model function). 🧰 Tools🪛 GitHub Actions: Pull Request[error] 29-29: Compilation error: cannot find symbol 'GLOBAL' in Scope used by FunctionFactory.java. 🤖 Prompt for AI Agents |
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.