GitHub PullRequestReviewCommentEvent at 2014-09-17 05:55:58
Repository: hazelcast
Actor: pveentjer
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/hazelcast/hazelcast/pulls/comments/17646982","id":17646982,"diff_hunk":"@@ -37,60 +37,55 @@\n     protected static final ILogger LOGGER = Logger.getLogger(HazelcastCachingProvider.class);\n     protected static volatile HazelcastInstance hazelcastInstance;\n \n-    private WeakHashMap<ClassLoader, HashMap<URI, CacheManager>> cacheManagers;\n+    protected final ClassLoader defaultClassLoader;\n+    protected final URI defaultURI;\n+\n+    private final ConcurrentMap<ClassLoader, ConcurrentMap<URI, CacheManager>> cacheManagers;\n \n     public HazelcastAbstractCachingProvider() {\n-        this.cacheManagers = new WeakHashMap<ClassLoader, HashMap<URI, CacheManager>>();\n+        //we use a concurrent weak HashMap to prevent strong references to a classLoader to avoid memory leak.\n+        this.cacheManagers = new ConcurrentReferenceHashMap<ClassLoader, ConcurrentMap<URI, CacheManager>>();\n+        this.defaultClassLoader = this.getClass().getClassLoader();\n+        try {\n+            defaultURI = new URI(this.getClass().getName());\n+        } catch (URISyntaxException e) {\n+            throw new CacheException(\"Cannot create Default URI\", e);\n+        }\n     }\n \n     @Override\n-    public synchronized CacheManager getCacheManager(URI uri, ClassLoader classLoader, Properties properties) {\n-        URI managerURI = uri == null ? getDefaultURI() : uri;\n-        ClassLoader managerClassLoader = classLoader == null ? getDefaultClassLoader() : classLoader;\n-        Properties managerProperties = properties == null ? new Properties() : properties;\n-\n-        HashMap<URI, CacheManager> cacheManagersByURI = cacheManagers.get(managerClassLoader);\n-        if (cacheManagersByURI == null) {\n-            cacheManagersByURI = new HashMap<URI, CacheManager>();\n+    public CacheManager getCacheManager(URI uri, ClassLoader classLoader, Properties properties) {\n+        final URI managerURI = getManagerUri(uri);\n+        final ClassLoader managerClassLoader = getManagerClassLoader(classLoader);\n+        final Properties managerProperties = properties == null ? new Properties() : properties;\n+\n+        if (cacheManagers.get(managerClassLoader) == null) {\n+            cacheManagers.putIfAbsent(managerClassLoader, new ConcurrentHashMap<URI, CacheManager>());\n         }\n+        final ConcurrentMap<URI, CacheManager> cacheManagersByURI = cacheManagers.get(managerClassLoader);\n         CacheManager cacheManager = cacheManagersByURI.get(managerURI);\n         if (cacheManager == null) {\n             try {\n-                cacheManager = getHazelcastCacheManager(uri, classLoader, managerProperties);\n-                cacheManagersByURI.put(managerURI, cacheManager);\n-            } catch (Throwable t) {\n-                LOGGER.warning(\"Error opening URI\" + managerURI.toString() + \". Caused by :\" + t.getMessage());\n-            }\n-        }\n-        if (!cacheManagers.containsKey(managerClassLoader)) {\n-            cacheManagers.put(managerClassLoader, cacheManagersByURI);\n-        }\n-        return cacheManager;\n-    }\n-\n-    protected HazelcastInstance getHazelcastInstance() {\n-        if (hazelcastInstance == null) {\n-            synchronized (this) {\n-                if (hazelcastInstance == null) {\n-                    hazelcastInstance = initHazelcast();\n+                cacheManager = createHazelcastCacheManager(uri, classLoader, managerProperties);\n+                final CacheManager oldCacheManager = cacheManagersByURI.putIfAbsent(managerURI, cacheManager);\n+                if (oldCacheManager != null) {","path":"hazelcast/src/main/java/com/hazelcast/cache/impl/HazelcastAbstractCachingProvider.java","position":83,"original_position":83,"commit_id":"2ed0640835190da231b65feb6f96b16836248ed3","original_commit_id":"2ed0640835190da231b65feb6f96b16836248ed3","user":{"login":"pveentjer","id":105243,"avatar_url":"https://avatars.githubusercontent.com/u/105243?v=2","gravatar_id":"d8b5cf3679fa7a4f32994df31d6fb180","url":"https://api.github.com/users/pveentjer","html_url":"https://github.com/pveentjer","followers_url":"https://api.github.com/users/pveentjer/followers","following_url":"https://api.github.com/users/pveentjer/following{/other_user}","gists_url":"https://api.github.com/users/pveentjer/gists{/gist_id}","starred_url":"https://api.github.com/users/pveentjer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pveentjer/subscriptions","organizations_url":"https://api.github.com/users/pveentjer/orgs","repos_url":"https://api.github.com/users/pveentjer/repos","events_url":"https://api.github.com/users/pveentjer/events{/privacy}","received_events_url":"https://api.github.com/users/pveentjer/received_events","type":"User","site_admin":false},"body":"In this case potentially you have 2 cacheManagers and one of them you are going to throw away; that is fine.. it is a common technique. But since the cacheManager is a 'big resource', can you add a line of comment stating that it doesn't need to be cleaned up? ","created_at":"2014-09-17T05:55:58Z","updated_at":"2014-09-17T05:55:58Z","html_url":"https://github.com/hazelcast/hazelcast/pull/3578#discussion_r17646982","pull_request_url":"https://api.github.com/repos/hazelcast/hazelcast/pulls/3578","_links":{"self":{"href":"https://api.github.com/repos/hazelcast/hazelcast/pulls/comments/17646982"},"html":{"href":"https://github.com/hazelcast/hazelcast/pull/3578#discussion_r17646982"},"pull_request":{"href":"https://api.github.com/repos/hazelcast/hazelcast/pulls/3578"}}},"pull_request":{"url":"https://api.github.com/repos/hazelcast/hazelcast/pulls/3578","id":21296792,"html_url":"https://github.com/hazelcast/hazelcast/pull/3578","diff_url":"https://github.com/hazelcast/hazelcast/pull/3578.diff","patch_url":"https://github.com/hazelcast/hazelcast/pull/3578.patch","issue_url":"https://api.github.com/repos/hazelcast/hazelcast/issues/3578","number":3578,"state":"open","locked":false,"title":"JCache improved concurrency of CacheManager and CacheProvider impls improved #3564","user":{"login":"asimarslan","id":2497208,"avatar_url":"https://avatars.githubusercontent.com/u/2497208?v=2","gravatar_id":"d7f34189d7fb3eab6eb354e2d23ba2f3","url":"https://api.github.com/users/asimarslan","html_url":"https://github.com/asimarslan","followers_url":"https://api.github.com/users/asimarslan/followers","following_url":"https://api.github.com/users/asimarslan/following{/other_user}","gists_url":"https://api.github.com/users/asimarslan/gists{/gist_id}","starred_url":"https://api.github.com/users/asimarslan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/asimarslan/subscriptions","organizations_url":"https://api.github.com/users/asimarslan/orgs","repos_url":"https://api.github.com/users/asimarslan/repos","events_url":"https://api.github.com/users/asimarslan/events{/privacy}","received_events_url":"https://api.github.com/users/asimarslan/received_events","type":"User","site_admin":false},"body":"This pull request send as separate from #3564 to preserve #3564 comments","created_at":"2014-09-16T13:14:14Z","updated_at":"2014-09-17T05:55:58Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1736f216d87a0d42f821fd85c638f74a95bde025","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/hazelcast/hazelcast/pulls/3578/commits","review_comments_url":"https://api.github.com/repos/hazelcast/hazelcast/pulls/3578/comments","review_comment_url":"https://api.github.com/repos/hazelcast/hazelcast/pulls/comments/{number}","comments_url":"https://api.github.com/repos/hazelcast/hazelcast/issues/3578/comments","statuses_url":"https://api.github.com/repos/hazelcast/hazelcast/statuses/2ed0640835190da231b65feb6f96b16836248ed3","head":{"label":"asimarslan:feature/maintance-3.x/jcache2","ref":"feature/maintance-3.x/jcache2","sha":"2ed0640835190da231b65feb6f96b16836248ed3","user":{"login":"asimarslan","id":2497208,"avatar_url":"https://avatars.githubusercontent.com/u/2497208?v=2","gravatar_id":"d7f34189d7fb3eab6eb354e2d23ba2f3","url":"https://api.github.com/users/asimarslan","html_url":"https://github.com/asimarslan","followers_url":"https://api.github.com/users/asimarslan/followers","following_url":"https://api.github.com/users/asimarslan/following{/other_user}","gists_url":"https://api.github.com/users/asimarslan/gists{/gist_id}","starred_url":"https://api.github.com/users/asimarslan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/asimarslan/subscriptions","organizations_url":"https://api.github.com/users/asimarslan/orgs","repos_url":"https://api.github.com/users/asimarslan/repos","events_url":"https://api.github.com/users/asimarslan/events{/privacy}","received_events_url":"https://api.github.com/users/asimarslan/received_events","type":"User","site_admin":false},"repo":{"id":10238745,"name":"hazelcast","full_name":"asimarslan/hazelcast","owner":{"login":"asimarslan","id":2497208,"avatar_url":"https://avatars.githubusercontent.com/u/2497208?v=2","gravatar_id":"d7f34189d7fb3eab6eb354e2d23ba2f3","url":"https://api.github.com/users/asimarslan","html_url":"https://github.com/asimarslan","followers_url":"https://api.github.com/users/asimarslan/followers","following_url":"https://api.github.com/users/asimarslan/following{/other_user}","gists_url":"https://api.github.com/users/asimarslan/gists{/gist_id}","starred_url":"https://api.github.com/users/asimarslan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/asimarslan/subscriptions","organizations_url":"https://api.github.com/users/asimarslan/orgs","repos_url":"https://api.github.com/users/asimarslan/repos","events_url":"https://api.github.com/users/asimarslan/events{/privacy}","received_events_url":"https://api.github.com/users/asimarslan/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/asimarslan/hazelcast","description":"Open Source In-Memory Data Grid","fork":true,"url":"https://api.github.com/repos/asimarslan/hazelcast","forks_url":"https://api.github.com/repos/asimarslan/hazelcast/forks","keys_url":"https://api.github.com/repos/asimarslan/hazelcast/keys{/key_id}","collaborators_url":"https://api.github.com/repos/asimarslan/hazelcast/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/asimarslan/hazelcast/teams","hooks_url":"https://api.github.com/repos/asimarslan/hazelcast/hooks","issue_events_url":"https://api.github.com/repos/asimarslan/hazelcast/issues/events{/number}","events_url":"https://api.github.com/repos/asimarslan/hazelcast/events","assignees_url":"https://api.github.com/repos/asimarslan/hazelcast/assignees{/user}","branches_url":"https://api.github.com/repos/asimarslan/hazelcast/branches{/branch}","tags_url":"https://api.github.com/repos/asimarslan/hazelcast/tags","blobs_url":"https://api.github.com/repos/asimarslan/hazelcast/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/asimarslan/hazelcast/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/asimarslan/hazelcast/git/refs{/sha}","trees_url":"https://api.github.com/repos/asimarslan/hazelcast/git/trees{/sha}","statuses_url":"https://api.github.com/repos/asimarslan/hazelcast/statuses/{sha}","languages_url":"https://api.github.com/repos/asimarslan/hazelcast/languages","stargazers_url":"https://api.github.com/repos/asimarslan/hazelcast/stargazers","contributors_url":"https://api.github.com/repos/asimarslan/hazelcast/contributors","subscribers_url":"https://api.github.com/repos/asimarslan/hazelcast/subscribers","subscription_url":"https://api.github.com/repos/asimarslan/hazelcast/subscription","commits_url":"https://api.github.com/repos/asimarslan/hazelcast/commits{/sha}","git_commits_url":"https://api.github.com/repos/asimarslan/hazelcast/git/commits{/sha}","comments_url":"https://api.github.com/repos/asimarslan/hazelcast/comments{/number}","issue_comment_url":"https://api.github.com/repos/asimarslan/hazelcast/issues/comments/{number}","contents_url":"https://api.github.com/repos/asimarslan/hazelcast/contents/{+path}","compare_url":"https://api.github.com/repos/asimarslan/hazelcast/compare/{base}...{head}","merges_url":"https://api.github.com/repos/asimarslan/hazelcast/merges","archive_url":"https://api.github.com/repos/asimarslan/hazelcast/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/asimarslan/hazelcast/downloads","issues_url":"https://api.github.com/repos/asimarslan/hazelcast/issues{/number}","pulls_url":"https://api.github.com/repos/asimarslan/hazelcast/pulls{/number}","milestones_url":"https://api.github.com/repos/asimarslan/hazelcast/milestones{/number}","notifications_url":"https://api.github.com/repos/asimarslan/hazelcast/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/asimarslan/hazelcast/labels{/name}","releases_url":"https://api.github.com/repos/asimarslan/hazelcast/releases{/id}","created_at":"2013-05-23T07:56:42Z","updated_at":"2014-06-23T09:06:55Z","pushed_at":"2014-09-16T13:11:28Z","git_url":"git://github.com/asimarslan/hazelcast.git","ssh_url":"git@github.com:asimarslan/hazelcast.git","clone_url":"https://github.com/asimarslan/hazelcast.git","svn_url":"https://github.com/asimarslan/hazelcast","homepage":"www.hazelcast.com","size":50105,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"hazelcast:maintenance-3.x","ref":"maintenance-3.x","sha":"624b7e05d70307ae2881d55c81a707723f377a8b","user":{"login":"hazelcast","id":1453152,"avatar_url":"https://avatars.githubusercontent.com/u/1453152?v=2","gravatar_id":"9bbb2c780bf7972b79c8a54804eb5837","url":"https://api.github.com/users/hazelcast","html_url":"https://github.com/hazelcast","followers_url":"https://api.github.com/users/hazelcast/followers","following_url":"https://api.github.com/users/hazelcast/following{/other_user}","gists_url":"https://api.github.com/users/hazelcast/gists{/gist_id}","starred_url":"https://api.github.com/users/hazelcast/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hazelcast/subscriptions","organizations_url":"https://api.github.com/users/hazelcast/orgs","repos_url":"https://api.github.com/users/hazelcast/repos","events_url":"https://api.github.com/users/hazelcast/events{/privacy}","received_events_url":"https://api.github.com/users/hazelcast/received_events","type":"Organization","site_admin":false},"repo":{"id":3786237,"name":"hazelcast","full_name":"hazelcast/hazelcast","owner":{"login":"hazelcast","id":1453152,"avatar_url":"https://avatars.githubusercontent.com/u/1453152?v=2","gravatar_id":"9bbb2c780bf7972b79c8a54804eb5837","url":"https://api.github.com/users/hazelcast","html_url":"https://github.com/hazelcast","followers_url":"https://api.github.com/users/hazelcast/followers","following_url":"https://api.github.com/users/hazelcast/following{/other_user}","gists_url":"https://api.github.com/users/hazelcast/gists{/gist_id}","starred_url":"https://api.github.com/users/hazelcast/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hazelcast/subscriptions","organizations_url":"https://api.github.com/users/hazelcast/orgs","repos_url":"https://api.github.com/users/hazelcast/repos","events_url":"https://api.github.com/users/hazelcast/events{/privacy}","received_events_url":"https://api.github.com/users/hazelcast/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/hazelcast/hazelcast","description":"Open Source In-Memory Data Grid","fork":false,"url":"https://api.github.com/repos/hazelcast/hazelcast","forks_url":"https://api.github.com/repos/hazelcast/hazelcast/forks","keys_url":"https://api.github.com/repos/hazelcast/hazelcast/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hazelcast/hazelcast/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hazelcast/hazelcast/teams","hooks_url":"https://api.github.com/repos/hazelcast/hazelcast/hooks","issue_events_url":"https://api.github.com/repos/hazelcast/hazelcast/issues/events{/number}","events_url":"https://api.github.com/repos/hazelcast/hazelcast/events","assignees_url":"https://api.github.com/repos/hazelcast/hazelcast/assignees{/user}","branches_url":"https://api.github.com/repos/hazelcast/hazelcast/branches{/branch}","tags_url":"https://api.github.com/repos/hazelcast/hazelcast/tags","blobs_url":"https://api.github.com/repos/hazelcast/hazelcast/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hazelcast/hazelcast/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hazelcast/hazelcast/git/refs{/sha}","trees_url":"https://api.github.com/repos/hazelcast/hazelcast/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hazelcast/hazelcast/statuses/{sha}","languages_url":"https://api.github.com/repos/hazelcast/hazelcast/languages","stargazers_url":"https://api.github.com/repos/hazelcast/hazelcast/stargazers","contributors_url":"https://api.github.com/repos/hazelcast/hazelcast/contributors","subscribers_url":"https://api.github.com/repos/hazelcast/hazelcast/subscribers","subscription_url":"https://api.github.com/repos/hazelcast/hazelcast/subscription","commits_url":"https://api.github.com/repos/hazelcast/hazelcast/commits{/sha}","git_commits_url":"https://api.github.com/repos/hazelcast/hazelcast/git/commits{/sha}","comments_url":"https://api.github.com/repos/hazelcast/hazelcast/comments{/number}","issue_comment_url":"https://api.github.com/repos/hazelcast/hazelcast/issues/comments/{number}","contents_url":"https://api.github.com/repos/hazelcast/hazelcast/contents/{+path}","compare_url":"https://api.github.com/repos/hazelcast/hazelcast/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hazelcast/hazelcast/merges","archive_url":"https://api.github.com/repos/hazelcast/hazelcast/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hazelcast/hazelcast/downloads","issues_url":"https://api.github.com/repos/hazelcast/hazelcast/issues{/number}","pulls_url":"https://api.github.com/repos/hazelcast/hazelcast/pulls{/number}","milestones_url":"https://api.github.com/repos/hazelcast/hazelcast/milestones{/number}","notifications_url":"https://api.github.com/repos/hazelcast/hazelcast/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hazelcast/hazelcast/labels{/name}","releases_url":"https://api.github.com/repos/hazelcast/hazelcast/releases{/id}","created_at":"2012-03-21T12:25:18Z","updated_at":"2014-09-17T01:22:43Z","pushed_at":"2014-09-16T14:21:05Z","git_url":"git://github.com/hazelcast/hazelcast.git","ssh_url":"git@github.com:hazelcast/hazelcast.git","clone_url":"https://github.com/hazelcast/hazelcast.git","svn_url":"https://github.com/hazelcast/hazelcast","homepage":"www.hazelcast.com","size":113636,"stargazers_count":881,"watchers_count":881,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":381,"mirror_url":null,"open_issues_count":271,"forks":381,"open_issues":271,"watchers":881,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/hazelcast/hazelcast/pulls/3578"},"html":{"href":"https://github.com/hazelcast/hazelcast/pull/3578"},"issue":{"href":"https://api.github.com/repos/hazelcast/hazelcast/issues/3578"},"comments":{"href":"https://api.github.com/repos/hazelcast/hazelcast/issues/3578/comments"},"review_comments":{"href":"https://api.github.com/repos/hazelcast/hazelcast/pulls/3578/comments"},"review_comment":{"href":"https://api.github.com/repos/hazelcast/hazelcast/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/hazelcast/hazelcast/pulls/3578/commits"},"statuses":{"href":"https://api.github.com/repos/hazelcast/hazelcast/statuses/2ed0640835190da231b65feb6f96b16836248ed3"}}}}