-
Notifications
You must be signed in to change notification settings - Fork 83
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
Egw upgrade #166
base: egw-upgrade
Are you sure you want to change the base?
Egw upgrade #166
Conversation
…al cache with loading pattern
* All the objects stored in the cache will be return without cloning or deep cloning due to improve the cache performance. | ||
* Because of that user should be responsible of the mutability of the stored object. | ||
*/ | ||
public final class AXPCache implements ICache |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Occurred that it "may" be possible to support this implementation through javax.cache, by registering AXP as a separate caching provider. Will find more on this and confirm. Nothing to fix on this yet. This comment is to serve as just a note.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted
purge(); | ||
} | ||
}; | ||
Timer timer = new Timer("Timer"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about replacing this with a ScheduledExecutorService? That way the number of TimerThreads won't increase as the caches grow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@Override | ||
public void run() | ||
{ | ||
purge(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check if this is prone to a ConcurrentModificationException. If that's the case, timer task handling purge operation can stop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved to ScheduledExecutorService. it resolves the problem.
else | ||
{ | ||
long expiryTime = System.currentTimeMillis() + periodInMillis; | ||
cache.put(key, new SoftReference<>(new CacheObject(value, expiryTime))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a SoftReference is fine, but I still think we need to clear HashMap entries using some algorithm. Like an LRU or a LFU algorithm. The reference held by SoftReference which is the CacheObject in this case will be removed, but how about the SoftReference itself?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
implemented another task to clean null references.
*/ | ||
@Override | ||
public <K, V> V getData(final AXPCache axpCache, final IAXPCacheLoader<K, V> cacheLoader, final K cacheKey) throws | ||
Exception |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we create a specific Exception here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to do a proper analysis of the existing exceptions and define a new hierarchy in the framework level. Until that is it safe to keep this as it is?
<dependency> | ||
<groupId>org.wso2.carbon.apimgt</groupId> | ||
<artifactId>org.wso2.carbon.apimgt.rest.api.util</artifactId> | ||
<version>6.0.4</version> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Version should be updated..
userAdminStub._getServiceClient().getOptions().setProperty(HTTPConstants.CONNECTION_TIMEOUT, DEFAULT_CONNECTION_TIMEOUT); | ||
} catch (AxisFault e) { | ||
log.error("", e); | ||
throw new BusinessException(GenaralError.INTERNAL_SERVER_ERROR); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pass the original exception as an argument so that error is traceable in log file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lifted change. will do the correction
|
||
} catch (RemoteException | UserAdminUserAdminException e) { | ||
log.error("UIPermission.build", e); | ||
throw new BusinessException(GenaralError.INTERNAL_SERVER_ERROR); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pass the original exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lifted chnage. will do the correction
} | ||
|
||
public static UserRolePermissionFactory getInstance() { | ||
if (instance == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prone to fail in multi-threaded scenarios. Can you use double-checked locking or eager initialization?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, noticed that this file appears as a change since you have formatted the code. But anyway its better to fix this now, the moment we noticed it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes. these are lifted changes. didnt do any modifications. merged as it is. btw , will fix those
@Override | ||
public long size() | ||
{ | ||
return cache.entrySet().stream().filter(entry -> Optional.ofNullable(entry.getValue()).map(SoftReference::get) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Each call to size would go through all entries to check expiry. Can't we simple return the size without explicitly checking for validity, and letting cleanup task do the eviction?
components/framework-axp/src/main/java/framework/cache/AXPCache.java
Outdated
Show resolved
Hide resolved
…and general cache with loading pattern, This reverts commit c1a3eaa
merge all changes from patch and release branches.