Skip to content
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

Open
wants to merge 8 commits into
base: egw-upgrade
Choose a base branch
from
Open

Egw upgrade #166

wants to merge 8 commits into from

Conversation

salinda89
Copy link

merge all changes from patch and release branches.

* 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
Copy link
Contributor

@jaadds jaadds Jun 4, 2019

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.

Copy link
Author

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");
Copy link
Contributor

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.

Copy link
Author

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();
Copy link
Contributor

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.

Copy link
Author

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)));
Copy link
Contributor

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?

Copy link
Author

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
Copy link
Contributor

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?

Copy link
Author

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>
Copy link
Contributor

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);
Copy link
Contributor

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.

Copy link
Author

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pass the original exception.

Copy link
Author

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) {
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Author

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)
Copy link
Contributor

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?

…and general cache with loading pattern, This reverts commit c1a3eaa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants