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

[JBIDE-21590] Add project cache to handle connection refresh issues #950

Conversation

jcantrill
Copy link
Contributor

@fbricon
Copy link
Member

fbricon commented Feb 4, 2016

Unit tests?

@scabanovich
Copy link
Contributor

May singleton instance of OpenShiftProjectCache be needed for other clients than only content provider? Then OpenShiftProjectCacheSingleton might be of use as ConnectionsRegistrySingleton is for ConnectionsRegistry.

@scabanovich
Copy link
Contributor

When removing IProjectAdapter, it should be disposed by a dispose() method that would destroy deployment resource mapper and remove listener from connections registry.

@scabanovich
Copy link
Contributor

ServerSettingsViewModel gets from connection projects and builds new DeploymentResourceMapper, could it instead reuse this new cache singleton?

@jcantrill jcantrill force-pushed the 21590_connection_not_refreshed branch from dcffe0a to 642937a Compare February 4, 2016 21:28
@jcantrill
Copy link
Contributor Author

@fbricon I was already on it. Added unit tests for the cache.

@jcantrill
Copy link
Contributor Author

@scabanovich I have not fully thought through the places where one could utilize this cache other then the contentprovider, but one think to note is it is currently impl to only provide UI adapter classes. I would think we would want to keep this out of the ConnectionRegistry. @adietish and I have spoken of a complete resource cache but I think we are still in baby steps before we could fully provide such a solution. I think this is a start towards that goal.

@jcantrill
Copy link
Contributor Author

@scabanovich I'm not sure I fully grasp your 'dispose' suggestion but welcome examples are additional suggestions.

synchronized (listeners) {
try {
for (IProjectAdapter a : adapters) {
listeners.forEach(l->l.handleRemoveFromCache(this, a));
Copy link
Contributor

Choose a reason for hiding this comment

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

@jcantrill Cache listeners are notified of removed IProjectAdapter and they are already removed from 'cache' map. That is fine. However, DeploymentResourceMapper is still a listener to ConnectionsRegistry, so that it cannot be handled by garbage collector together with all maps that it built. I suggest

public void IProjectAdapter.dispose() {
    mapper.dispose();
}

public void DeploymentResourceMapper.dispose() {
    ConnectionsRegistrySingleton.getInstance().removeListener(connectionListener);
    cache.dispose();
    //clean maps for faster memory cleaning.
}

public void ObservableResourceCache.dispose() {
    //clean maps and collections for faster memory cleaning.
}

Copy link
Contributor

Choose a reason for hiding this comment

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

@jcantrill , I forgot to add that I suggest to call a.dispose() at this point, after listeners are notified that adapter is removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

@jcantrill jcantrill force-pushed the 21590_connection_not_refreshed branch from 642937a to 29f7df9 Compare February 5, 2016 21:19
@jcantrill
Copy link
Contributor Author

@scabanovich @fbricon updated per comments

@scabanovich
Copy link
Contributor

@jcantrill , I have a comment that may be not quite related to this issue, but it may be not so a big deal to open a new one.
I looked into the way of computing resource property name :

  • From kind of resource in ResourcesUIModel

    private static String getProperty(String kind) {
    return StringUtils.pluralize(kind.toLowerCase());
    }

  • From tab id in OpenShiftResourcePropertySection.setInput :

    String property = org.apache.commons.lang.StringUtils.right(id, id.length() - id.lastIndexOf(".") - 1);
    

Maybe, there are more places that transform something to property name, I am not aware of them yet. But, imho, even if they are only 2 places and no other will appear, they are too much related to be hidden in the depth of implementation. I suggest a utility that will encapsulate all manipulations with resource property names, (being in an internal package it may have public methods without getting into API), and describe in Java docs in details how it works. Tests for this utility may help to find early if some modification breaks consistency of related names.

@scabanovich
Copy link
Contributor

One more comment, summarizing our discussion in XChat. I focused on method in ResourcesUIModel

public void setBuildConfigs(Collection<IResourceUIModel> buildConfigs) {
    firePropertyChange(PROP_BUILD_CONFIGS, resources.get(ResourceKind.BUILD_CONFIG), resources.put(ResourceKind.BUILD_CONFIG, new ArrayList<>(buildConfigs)));
}

asserting that it will not notify correctly (and other similar setters). That I believe is true. But now I see that actually changes go through methods ResourcesUIModel.add, ResourcesUIModel.remove, ResourcesUIModel.update that have correct notification.
So, if other setters may be ever used, they better be fixed, for instance this way :

public void setBuildConfigs(Collection<IResourceUIModel> buildConfigs) {
    setResourcesForKind(buildConfigs, ResourceKind.BUILD_CONFIG);
}

private void setResourcesForKind(Collection<IResourceUIModel> list, String kind) {
    List<IResourceUIModel> oldList = resources.get(kind);
    List<IResourceUIModel> newList = new ArrayList<IResourceUIModel>(list);
    resources.put(kind, newList);
    firePropertyChange(getProperty(kind), oldList, newList);
}

and with use of private setResourcesForKind all other setters will remain one-liners.

@jcantrill
Copy link
Contributor Author

@scabanovich please open a separate issue regarding your observations. I will merge this PR as is unless there are objections from @fbricon or @adietish

@jcantrill jcantrill force-pushed the 21590_connection_not_refreshed branch 3 times, most recently from bd702f9 to f46cb95 Compare February 8, 2016 19:19
@jcantrill jcantrill force-pushed the 21590_connection_not_refreshed branch from f46cb95 to 2da48ac Compare February 8, 2016 20:06
@jcantrill jcantrill merged commit 2da48ac into jbosstools:jbosstools-4.3.x Feb 8, 2016
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.

None yet

3 participants