-
Notifications
You must be signed in to change notification settings - Fork 4
Replicate the XWiki Cache feature from the community version #128 #157
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4e3e2d1
Replicate the XWiki Cache feature from the community version #128
ChiuchiuSorin d4446eb
Merge branch 'main' into iss128
ChiuchiuSorin 1f92c7a
Merge branch 'main' into iss128
ChiuchiuSorin 0ef59e4
Replicate the XWiki Cache feature from the community version #128
ChiuchiuSorin 9dd0df2
Replicate the XWiki Cache feature from the community version #128
ChiuchiuSorin 05c9e02
Merge branch 'main' into iss128
ChiuchiuSorin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
117 changes: 117 additions & 0 deletions
117
application-admintools-api/src/main/java/com/xwiki/admintools/health/cache/CacheInfo.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| /* | ||
| * See the NOTICE file distributed with this work for additional | ||
| * information regarding copyright ownership. | ||
| * | ||
| * This is free software; you can redistribute it and/or modify it | ||
| * under the terms of the GNU Lesser General Public License as | ||
| * published by the Free Software Foundation; either version 2.1 of | ||
| * the License, or (at your option) any later version. | ||
| * | ||
| * This software is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| * Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public | ||
| * License along with this software; if not, write to the Free | ||
| * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
| * 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
| */ | ||
| package com.xwiki.admintools.health.cache; | ||
|
|
||
| import org.xwiki.stability.Unstable; | ||
|
|
||
| /** | ||
| * Holds JMX-exposed information regarding the name, eviction limit, and size for a single cache. | ||
| * | ||
| * @version $Id$ | ||
| * @since 1.4 | ||
| */ | ||
| @Unstable | ||
| public class CacheInfo | ||
| { | ||
| private String cacheName; | ||
|
|
||
| private long evictionSize; | ||
|
|
||
| private long numberOfEntries; | ||
|
|
||
| /** | ||
| * Default constructor. | ||
| */ | ||
| public CacheInfo() | ||
| { | ||
|
|
||
| } | ||
|
|
||
| /** | ||
| * {@link #setEvictionSize}. | ||
| * | ||
| * @return the eviction size | ||
| */ | ||
| public long getEvictionSize() | ||
| { | ||
| return evictionSize; | ||
| } | ||
|
|
||
| /** | ||
| * Set the maximum eviction size for the cache. This represents the configured upper limit after which entries may | ||
| * be evicted. | ||
| * | ||
| * @param evictionSize the configured eviction size for the cache | ||
| */ | ||
| public void setEvictionSize(long evictionSize) | ||
| { | ||
| this.evictionSize = evictionSize; | ||
| } | ||
|
|
||
| /** | ||
| * {@link #setNumberOfEntries}. | ||
| * | ||
| * @return the number of entries | ||
| */ | ||
| public long getNumberOfEntries() | ||
| { | ||
| return numberOfEntries; | ||
| } | ||
|
|
||
| /** | ||
| * Set the current number of entries stored in the cache. | ||
| * | ||
| * @param numberOfEntries the current number of cache entries | ||
| */ | ||
| public void setNumberOfEntries(long numberOfEntries) | ||
| { | ||
| this.numberOfEntries = numberOfEntries; | ||
| } | ||
|
|
||
| /** | ||
| * {@link #setCacheName}. | ||
| * | ||
| * @return the cache name | ||
| */ | ||
| public String getCacheName() | ||
| { | ||
| return cacheName; | ||
| } | ||
|
|
||
| /** | ||
| * Set the name of the cache. | ||
| * | ||
| * @param cacheName name of the cache | ||
| */ | ||
| public void setCacheName(String cacheName) | ||
| { | ||
| this.cacheName = cacheName; | ||
| } | ||
|
|
||
| /** | ||
| * Get a formatted display of the cache load level, expressed as numberOfEntries/evictionSize. | ||
| * | ||
| * @return a formatted display of the cache size | ||
| */ | ||
| public String getFormattedCacheSize() | ||
| { | ||
| return String.format("%d/%d", numberOfEntries, evictionSize); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
...ntools-default/src/main/java/com/xwiki/admintools/internal/health/cache/CacheManager.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| /* | ||
| * See the NOTICE file distributed with this work for additional | ||
| * information regarding copyright ownership. | ||
| * | ||
| * This is free software; you can redistribute it and/or modify it | ||
| * under the terms of the GNU Lesser General Public License as | ||
| * published by the Free Software Foundation; either version 2.1 of | ||
| * the License, or (at your option) any later version. | ||
| * | ||
| * This software is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| * Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public | ||
| * License along with this software; if not, write to the Free | ||
| * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
| * 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
| */ | ||
| package com.xwiki.admintools.internal.health.cache; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Comparator; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import javax.inject.Inject; | ||
| import javax.inject.Singleton; | ||
| import javax.management.JMException; | ||
| import javax.management.ObjectName; | ||
|
|
||
| import org.xwiki.component.annotation.Component; | ||
|
|
||
| import com.xwiki.admintools.health.cache.CacheInfo; | ||
| import com.xwiki.admintools.internal.health.cache.data.CacheDataGenerator; | ||
|
|
||
| import groovy.jmx.GroovyMBean; | ||
|
|
||
| /** | ||
| * Manager class that handles JMX managed cache operations. | ||
| * | ||
| * @version $Id$ | ||
| * @since 1.3 | ||
| */ | ||
| @Component(roles = CacheManager.class) | ||
| @Singleton | ||
| public class CacheManager | ||
| { | ||
| @Inject | ||
| private CacheDataGenerator cacheDataGenerator; | ||
|
|
||
| /** | ||
| * Get a sorted and filtered {@code List} with the JMX managed caches. | ||
| * | ||
| * @param filter used to filter caches by name | ||
| * @param order the sort order applied to the result, based on the number of entries | ||
| * @return a sorted and filtered {@code List} with the JMX managed caches | ||
| * @throws JMException if there are any errors during {@link ObjectName} or {@link GroovyMBean} creation | ||
| * @throws IOException if there are any errors during the {@link GroovyMBean} creation | ||
| */ | ||
| public List<CacheInfo> getJMXCaches(String filter, String order) throws JMException, IOException | ||
| { | ||
| List<CacheInfo> cacheEntries = cacheDataGenerator.getCacheEntries(filter); | ||
| return getSortedAndFilteredCacheEntries(cacheEntries, order); | ||
| } | ||
|
|
||
| /** | ||
| * Get detailed statistics for a specific cache. | ||
| * | ||
| * @param name cache name to be searched for | ||
| * @return a {@link Map} with the detailed statistics | ||
| * @throws JMException if there are any errors during {@link ObjectName} or {@link GroovyMBean} creation | ||
| * @throws IOException if there are any errors during the {@link GroovyMBean} creation | ||
| */ | ||
| public Map<String, Object> getCacheDetailedView(String name) throws JMException, IOException | ||
| { | ||
| return cacheDataGenerator.getDetailedCacheEntry(name); | ||
| } | ||
|
|
||
| private List<CacheInfo> getSortedAndFilteredCacheEntries(List<CacheInfo> cacheEntries, String order) | ||
| { | ||
|
|
||
| boolean descending = order.equals("desc"); | ||
| return cacheEntries.stream().sorted( | ||
| descending ? Comparator.comparingLong(CacheInfo::getNumberOfEntries).reversed() | ||
| : Comparator.comparingLong(CacheInfo::getNumberOfEntries)).collect(Collectors.toList()); | ||
| } | ||
| } | ||
69 changes: 69 additions & 0 deletions
69
...ols-default/src/main/java/com/xwiki/admintools/internal/health/cache/GroovyMBeanUtil.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| /* | ||
| * See the NOTICE file distributed with this work for additional | ||
| * information regarding copyright ownership. | ||
| * | ||
| * This is free software; you can redistribute it and/or modify it | ||
| * under the terms of the GNU Lesser General Public License as | ||
| * published by the Free Software Foundation; either version 2.1 of | ||
| * the License, or (at your option) any later version. | ||
| * | ||
| * This software is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| * Lesser General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public | ||
| * License along with this software; if not, write to the Free | ||
| * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
| * 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
| */ | ||
| package com.xwiki.admintools.internal.health.cache; | ||
|
|
||
| import java.io.IOException; | ||
| import java.lang.management.ManagementFactory; | ||
|
|
||
| import javax.inject.Singleton; | ||
| import javax.management.JMException; | ||
| import javax.management.MBeanServer; | ||
| import javax.management.ObjectName; | ||
|
|
||
| import org.xwiki.component.annotation.Component; | ||
|
|
||
| import groovy.jmx.GroovyMBean; | ||
|
|
||
| /** | ||
| * Utility class used to access JMX MBeans. | ||
| * | ||
| * @version $Id$ | ||
| * @since 1.3 | ||
| */ | ||
| @Component(roles = GroovyMBeanUtil.class) | ||
| @Singleton | ||
| public class GroovyMBeanUtil | ||
| { | ||
| private MBeanServer mBeanServer; | ||
|
|
||
| /** | ||
| * Return {@link MBeanServer}. | ||
| * | ||
| * @return the platform MBean server | ||
| */ | ||
| public MBeanServer getMBeanServer() | ||
| { | ||
| if (mBeanServer == null) { | ||
| mBeanServer = ManagementFactory.getPlatformMBeanServer(); | ||
| } | ||
| return mBeanServer; | ||
| } | ||
|
|
||
| /** | ||
| * Create a {@link GroovyMBean} wrapper for a given {@link ObjectName}. | ||
| * | ||
| * @param objectName the JMX object name identifying the MBean | ||
| * @return a {@link GroovyMBean} instance for the given object name | ||
| */ | ||
| public GroovyMBean getGroovyMBean(ObjectName objectName) throws JMException, IOException | ||
| { | ||
| return new GroovyMBean(getMBeanServer(), objectName); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.