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

OF-1408 Show the cache expiry time on the caches page #896

Merged
merged 2 commits into from Oct 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/i18n/openfire_i18n_cs_CZ.properties
Expand Up @@ -1963,6 +1963,7 @@ system.cache.info=Openfire spol\u00e9h\u00e1 na svou ke\u0161, aby mohl b\u011b\
a klikn\u011bte na "Vy\u010disti vybran\u00e9".
system.cache.head.name=Jm\u00e9no ke\u0161e
system.cache.head.max=Maxim\u00e1ln\u00ed velikost
system.cache.head.lifetime=Max Lifetime
system.cache.head.current=Sou\u010dasn\u00e1 velikost
system.cache.head.percent=Procento vyu\u017eit\u00ed
system.cache.head.effectiveness=Efektivita*
Expand Down
1 change: 1 addition & 0 deletions src/i18n/openfire_i18n_de.properties
Expand Up @@ -1866,6 +1866,7 @@ system.cache.info=Openfire relies on its cache to run efficiently. Below is a su
you want to clear and click "Clear Selected" below.
system.cache.head.name=Cache Name
system.cache.head.max=Max Size
system.cache.head.lifetime=Max Lifetime
system.cache.head.current=Current Size
system.cache.head.percent=Percent Used
system.cache.head.effectiveness=Effectiveness*
Expand Down
3 changes: 3 additions & 0 deletions src/i18n/openfire_i18n_en.properties
Expand Up @@ -835,6 +835,8 @@ global.main=Main
global.continue=Continue
global.none=None
global.refresh=Refresh
global.millisecond=ms
global.milliseconds=ms
global.second=second
global.seconds=seconds
global.minute=minute
Expand Down Expand Up @@ -2929,6 +2931,7 @@ system.cache.info=The server relies on its cache to run efficiently. Below is a
you want to clear and click "Clear Selected" below.
system.cache.head.name=Cache Name
system.cache.head.max=Max Size
system.cache.head.lifetime=Max Lifetime
system.cache.head.current=Current Size
system.cache.head.percent=Percent Used
system.cache.head.effectiveness=Effectiveness*
Expand Down
1 change: 1 addition & 0 deletions src/i18n/openfire_i18n_es.properties
Expand Up @@ -2223,6 +2223,7 @@ system.cache.info=Openfire se basa en sus caches para correr eficientemente. A c
que desea limpiar y haga click en "Limpiar Seleccionados".
system.cache.head.name=Nombre del Cache
system.cache.head.max=Tama\u00f1o Max
system.cache.head.lifetime=Max Lifetime
system.cache.head.current=Tama\u00f1o Actual
system.cache.head.percent=Porcentaje Usado
system.cache.head.effectiveness=Efectividad*
Expand Down
1 change: 1 addition & 0 deletions src/i18n/openfire_i18n_fr.properties
Expand Up @@ -1572,6 +1572,7 @@ system.cache.cleared = Cache(s) vid\u00E9(s) avec succ\u00E8s.
system.cache.info = Openfire d\u00E9pend de son cache pour fonctionner efficacement. Ci-dessous se trouve un r\u00E9sum\u00E9 des \tcaches existants. Pour vider le contenu du cache, cliquez sur la case \u00E0 cot\u00E9 du cache \tque vous voulez vider et cliquez sur "Vider les caches selectionn\u00E9s" ci-dessous.
system.cache.head.name = Nom du Cache
system.cache.head.max = Taille Maximale
system.cache.head.lifetime=Max Lifetime
system.cache.head.current = Taille Actuelle
system.cache.head.percent = Pourcentage utilis\u00E9.
system.cache.head.effectiveness = Efficience*
Expand Down
1 change: 1 addition & 0 deletions src/i18n/openfire_i18n_ja_JP.properties
Expand Up @@ -1947,6 +1947,7 @@ system.cache.info=\u30b5\u30fc\u30d0\u30fc\u306f\u3001\u52b9\u679c\u7684\u306b\u
\u30af\u30ea\u30a2\u30fc\u3057\u305f\u3044\u30ad\u30e3\u30c3\u30b7\u30e5\u306e\u96a3\u308a\u306e\u30c1\u30a7\u30c3\u30af\u30dc\u30c3\u30af\u30b9\u3092\u30c1\u30a7\u30c3\u30af\u3057\u3001"\u9078\u629e\u3057\u305f\u3082\u306e\u3092\u30af\u30ea\u30a2\u30fc"\u3092\u30af\u30ea\u30c3\u30af\u3057\u3066\u304f\u3060\u3055\u3044\u3002
system.cache.head.name=\u30ad\u30e3\u30c3\u30b7\u30e5\u540d
system.cache.head.max=\u6700\u5927\u30b5\u30a4\u30ba
system.cache.head.lifetime=Max Lifetime
system.cache.head.current=\u73fe\u5728\u306e\u30b5\u30a4\u30ba
system.cache.head.percent=\u4f7f\u7528\u3055\u308c\u3066\u3044\u308b\u30d1\u30fc\u30bb\u30f3\u30c8
system.cache.head.effectiveness=\u52b9\u679c*
Expand Down
1 change: 1 addition & 0 deletions src/i18n/openfire_i18n_nl.properties
Expand Up @@ -1869,6 +1869,7 @@ system.cache.info=Openfire relies on its cache to run efficiently. Below is a su
you want to clear and click "Clear Selected" below.
system.cache.head.name=Cache Name
system.cache.head.max=Max Size
system.cache.head.lifetime=Max Lifetime
system.cache.head.current=Current Size
system.cache.head.percent=Percent Used
system.cache.head.effectiveness=Effectiveness*
Expand Down
1 change: 1 addition & 0 deletions src/i18n/openfire_i18n_pl_PL.properties
Expand Up @@ -1845,6 +1845,7 @@ system.cache.info=Openfire wykorzystuje cache w celu wydajniejszej pracy. Poni\u
i kliknij "Wyczy\u015b\u0107 zaznaczone" poni\u017cej.
system.cache.head.name=Nazwa cache
system.cache.head.max=Maksymalna wielko\u015b\u0107
system.cache.head.lifetime=Max Lifetime
system.cache.head.current=Bie\u017c\u0105ca wielko\u015b\u0107
system.cache.head.percent=Procent u\u017cycia
system.cache.head.effectiveness=Wydajno\u015b\u0107*
Expand Down
1 change: 1 addition & 0 deletions src/i18n/openfire_i18n_pt_BR.properties
Expand Up @@ -1933,6 +1933,7 @@ system.cache.info=O Openfire depende do seu cache para rodar eficientemente. Aba
que voc\u00ea quer limpar e clique em "Limpar Selecionados".
system.cache.head.name=Nome do Cache
system.cache.head.max=Tamanho M\u00e1ximo
system.cache.head.lifetime=Max Lifetime
system.cache.head.current=Tamanho Atual
system.cache.head.percent=Percentual Utilizado
system.cache.head.effectiveness=Efic\u00e1cia*
Expand Down
1 change: 1 addition & 0 deletions src/i18n/openfire_i18n_pt_PT.properties
Expand Up @@ -2539,6 +2539,7 @@ system.cache.info=O Openfire depende do seu cache para funcionar eficientemente.
que voc\u00ea quer limpar e clique em "Limpar Selecionados".
system.cache.head.name=Nome do Cache
system.cache.head.max=Tamanho M\u00e1ximo
system.cache.head.lifetime=Max Lifetime
system.cache.head.current=Tamanho Atual
system.cache.head.percent=Percentagem Utilizada
system.cache.head.effectiveness=Efic\u00e1cia*
Expand Down
1 change: 1 addition & 0 deletions src/i18n/openfire_i18n_ru_RU.properties
Expand Up @@ -1648,6 +1648,7 @@ system.cache.desc.effectiveness=* \u042D\u0444\u0444\u0435\u043A\u0442\u0438\u04
system.cache.head.current=\u0422\u0435\u043A\u0443\u0449\u0438\u0439 \u0420\u0430\u0437\u043C\u0435\u0440
system.cache.head.effectiveness=\u042D\u0444\u0444\u0435\u043A\u0442\u0438\u0432\u043D\u043E\u0441\u0442\u044C*
system.cache.head.max=\u041C\u0430\u043A\u0441.\u0440\u0430\u0437\u043C\u0435\u0440
system.cache.head.lifetime=Max Lifetime
system.cache.head.name=\u0418\u043C\u044F
system.cache.head.percent=\u0418\u0441\u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u043D\u043E \u0432 %
system.cache.info=\u0421\u0435\u0440\u0432\u0435\u0440 \u0438\u0441\u043F\u043E\u043B\u044C\u0437\u0443\u0435\u0442 \u0441\u0432\u043E\u0439 \u043A\u044D\u0448 \u0434\u043B\u044F \u044D\u0444\u0444\u0435\u043A\u0442\u0438\u0432\u043D\u043E\u0439 \u0440\u0430\u0431\u043E\u0442\u044B. \u041D\u0438\u0436\u0435 \u043F\u0440\u0438\u0432\u043E\u0434\u0438\u0442\u0441\u044F \u043A\u0440\u0430\u0442\u043A\u043E\u0435 \u043E\u043F\u0438\u0441\u0430\u043D\u0438\u0435 \u0432\u0441\u0435\u0445 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044E\u0449\u0438\u0445 \u043A\u0435\u0448\u0435\u0439.\u0427\u0442\u043E\u0431\u044B \u043E\u0447\u0438\u0441\u0442\u0438\u0442\u044C \u0441\u043E\u0434\u0435\u0440\u0436\u0438\u043C\u043E\u0435 \u043A\u044D\u0448\u0430, \u0443\u0441\u0442\u0430\u043D\u043E\u0432\u0438\u0442\u0435 \u0444\u043B\u0430\u0436\u043E\u043A \u0440\u044F\u0434\u043E\u043C \u0441 \u043A\u044D\u0448-\u043F\u0430\u043C\u044F\u0442\u044C\u044E \u043A\u043E\u0442\u043E\u0440\u0443\u044E \u0432\u044B \u0445\u043E\u0442\u0438\u0442\u0435 \u043E\u0447\u0438\u0441\u0442\u0438\u0442\u044C, \u0438 \u043D\u0430\u0436\u043C\u0438\u0442\u0435 \u043A\u043D\u043E\u043F\u043A\u0443 "\u041E\u0447\u0438\u0441\u0442\u0438\u0442\u044C" \u043D\u0438\u0436\u0435.
Expand Down
1 change: 1 addition & 0 deletions src/i18n/openfire_i18n_sk.properties
Expand Up @@ -1859,6 +1859,7 @@ system.cache.cleared=Vyrovn\u00e1vacie pam\u00e4te boli \u00faspe\u0161ne vy\u01
system.cache.info=Efekt\u00edvny beh servera z\u00e1vis\u00ed na vyrovn\u00e1vacej pam\u00e4ti. Toto je preh\u013ead existuj\u00facich vyrovn\u00e1vac\u00edch pam\u00e4t\u00ed. Ozna\u010den\u00edm za\u0161krt\u00e1vacieho po\u013ea a kliknut\u00edm na \u201eVy\u010disti\u0165 ozna\u010den\u00e9\u201c ved\u013ea vyrovn\u00e1vacej pam\u00e4te m\u00f4\u017eete vy\u010disti\u0165 jej obsah.
system.cache.head.name=N\u00e1zov vyrovn\u00e1vacej pam\u00e4te
system.cache.head.max=Maxim\u00e1lna ve\u013ekos\u0165
system.cache.head.lifetime=Max Lifetime
system.cache.head.current=Moment\u00e1lna ve\u013ekos\u0165
system.cache.head.percent=Vyu\u017eitie v percent\u00e1ch
system.cache.head.effectiveness=Efekt\u00edvnos\u0165*
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/openfire_i18n_zh_CN.properties
Expand Up @@ -2000,6 +2000,7 @@ system.cache.cleared=\u7f13\u5b58\u6e05\u9664\u6210\u529f
system.cache.info=Openfire\u670d\u52a1\u5668\u4f9d\u8d56\u5b83\u7684\u7f13\u5b58\u6765\u9ad8\u6548\u8fd0\u884c\u3002\u4e0b\u9762\u662f\u6240\u6709\u5b58\u5728\u7684\u7684\u7f13\u5b58\u7684\u6458\u8981\u3002\u4e3a\u4e86\u6e05\u9664\u7f13\u5b58\u7684\u5185\u5bb9\uff0c\u628a\u60f3\u6e05\u9664\u7f13\u5b58\u7684\u9879\u76ee\u540e\u7684\u590d\u9009\u6846\u9009\u4e2d\uff0c\u518d\u70b9\u51fb"\u6e05\u9664\u5df2\u9009\u9879\u76ee"\u952e\u3002
system.cache.head.name=\u7f13\u5b58\u540d\u79f0
system.cache.head.max=\u6700\u5927\u7a7a\u95f4
system.cache.head.lifetime=Max Lifetime
system.cache.head.current=\u5f53\u524d\u7a7a\u95f4
system.cache.head.percent=\u4f7f\u7528\u767e\u5206\u6bd4
system.cache.head.effectiveness=\u6548\u7387*
Expand Down Expand Up @@ -2420,4 +2421,4 @@ connection-type.connection-manager=\u5ba2\u6237\u7aef\u7ba1\u7406
connection-type.unspecified=\u4e0d\u6307\u5b9a
connection-mode.plain=\u7eaf\u6587\u672c\uff08\u4f7f\u7528STARTSSL\uff09
connection-mode.legacy=\u52a0\u5bc6\uff08\u4f20\u7edf\u6a21\u5f0f\uff09
connection-mode.unspecified=\u4e0d\u6307\u5b9a
connection-mode.unspecified=\u4e0d\u6307\u5b9a
50 changes: 49 additions & 1 deletion src/java/org/jivesoftware/util/StringUtils.java
Expand Up @@ -841,6 +841,54 @@ public static String dateToMillis(Date date) {
return zeroPadString(Long.toString(date.getTime()), 15);
}

/**
* Returns a textual representation for the time that has elapsed.
*
* @param delta the elapsed time in milliseconds
* @return textual representation for the time that has elapsed.
*/
public static String getFullElapsedTime(final long delta) {
if (delta < JiveConstants.SECOND) {
return String.format("%d %s", delta, delta == 1 ? LocaleUtils.getLocalizedString("global.millisecond") : LocaleUtils.getLocalizedString("global.milliseconds"));
} else if (delta < JiveConstants.MINUTE) {
final long millis = delta % JiveConstants.SECOND;
final long seconds = delta / JiveConstants.SECOND;
final String secondsString = String.format("%d %s", seconds, seconds == 1 ? LocaleUtils.getLocalizedString("global.second") : LocaleUtils.getLocalizedString("global.seconds"));
if (millis > 0) {
return secondsString + ", " + getFullElapsedTime(millis);
} else {
return secondsString;
}
} else if (delta < JiveConstants.HOUR) {
final long millis = delta % JiveConstants.MINUTE;
final long minutes = delta / JiveConstants.MINUTE;
final String minutesString = String.format("%d %s", minutes, minutes == 1 ? LocaleUtils.getLocalizedString("global.minute") : LocaleUtils.getLocalizedString("global.minutes"));
if (millis > 0) {
return minutesString + ", " + getFullElapsedTime(millis);
} else {
return minutesString;
}
} else if (delta < JiveConstants.DAY) {
final long millis = delta % JiveConstants.HOUR;
final long hours = delta / JiveConstants.HOUR;
final String daysString = String.format("%d %s", hours, hours == 1 ? LocaleUtils.getLocalizedString("global.hour") : LocaleUtils.getLocalizedString("global.hours"));
if (millis > 0) {
return daysString + ", " + getFullElapsedTime(millis);
} else {
return daysString;
}
} else {
final long millis = delta % JiveConstants.DAY;
final long days = delta / JiveConstants.DAY;
final String daysString = String.format("%d %s", days, days == 1 ? LocaleUtils.getLocalizedString("global.day") : LocaleUtils.getLocalizedString("global.days"));
if (millis > 0) {
return daysString + ", " + getFullElapsedTime(millis);
} else {
return daysString;
}
}
}

/**
* Returns a textual representation for the time that has elapsed.
*
Expand Down Expand Up @@ -1105,4 +1153,4 @@ public static byte[] getBytes(String input) {
public static String getString(byte[] input) {
return new String(input, StandardCharsets.UTF_8);
}
}
}
37 changes: 37 additions & 0 deletions src/test/java/org/jivesoftware/util/StringUtilsTest.java
@@ -1,6 +1,8 @@
package org.jivesoftware.util;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;

import org.junit.Test;
Expand Down Expand Up @@ -55,4 +57,39 @@ private void assertInvalidDomainName(String domain, String expectedCause) {
//assertEquals("Unexpected cause: " + iae.getMessage(), expectedCause, iae.getMessage());
}
}

@Test
public void testElapsedTimeInMilliseconds() throws Exception {
assertThat(StringUtils.getFullElapsedTime(0), is("0 ms"));
assertThat(StringUtils.getFullElapsedTime(1), is("1 ms"));
assertThat(StringUtils.getFullElapsedTime(250), is("250 ms"));
}

@Test
public void testElapsedTimeInSeconds() throws Exception {
assertThat(StringUtils.getFullElapsedTime(JiveConstants.SECOND), is("1 second"));
assertThat(StringUtils.getFullElapsedTime(JiveConstants.SECOND + 1), is("1 second, 1 ms"));
assertThat(StringUtils.getFullElapsedTime(JiveConstants.SECOND * 30 + 30), is("30 seconds, 30 ms"));
}

@Test
public void testElapsedTimeInMinutes() throws Exception {
assertThat(StringUtils.getFullElapsedTime(JiveConstants.MINUTE), is("1 minute"));
assertThat(StringUtils.getFullElapsedTime(JiveConstants.MINUTE + JiveConstants.SECOND + 1), is("1 minute, 1 second, 1 ms"));
assertThat(StringUtils.getFullElapsedTime(JiveConstants.MINUTE * 30 + JiveConstants.SECOND * 30), is("30 minutes, 30 seconds"));
}

@Test
public void testElapsedTimeInHours() throws Exception {
assertThat(StringUtils.getFullElapsedTime(JiveConstants.HOUR), is("1 hour"));
assertThat(StringUtils.getFullElapsedTime(JiveConstants.HOUR + JiveConstants.MINUTE + JiveConstants.SECOND + 1), is("1 hour, 1 minute, 1 second, 1 ms"));
assertThat(StringUtils.getFullElapsedTime(JiveConstants.HOUR * 10 + JiveConstants.MINUTE * 30), is("10 hours, 30 minutes"));
}

@Test
public void testElapsedTimeInDays() throws Exception {
assertThat(StringUtils.getFullElapsedTime(JiveConstants.DAY), is("1 day"));
assertThat(StringUtils.getFullElapsedTime(JiveConstants.DAY + JiveConstants.HOUR + JiveConstants.MINUTE + JiveConstants.SECOND + 1), is("1 day, 1 hour, 1 minute, 1 second, 1 ms"));
assertThat(StringUtils.getFullElapsedTime(JiveConstants.DAY * 10 + JiveConstants.HOUR * 10), is("10 days, 10 hours"));
}
}
10 changes: 9 additions & 1 deletion src/web/system-cache.jsp
Expand Up @@ -169,8 +169,9 @@
<tr>
<th width="39%" nowrap><fmt:message key="system.cache.head.name" /></th>
<th width="10%" nowrap><fmt:message key="system.cache.head.max" /></th>
<th width="10%" nowrap><fmt:message key="system.cache.head.lifetime" /></th>
<th width="10%" nowrap><fmt:message key="system.cache.head.current" /></th>
<th width="20%" nowrap><fmt:message key="system.cache.head.percent" /></th>
<th width="10%" nowrap><fmt:message key="system.cache.head.percent" /></th>
<th width="20%" nowrap><fmt:message key="system.cache.head.effectiveness" /></th>
<th width="1%" class="c5"><input type="checkbox" name="" value="" onclick="handleCBClick(this);"></th>
</tr>
Expand Down Expand Up @@ -217,6 +218,13 @@
<fmt:message key="global.unlimited" />
<% } %>
</td>
<td class="c2">
<% if (cache.getMaxLifetime() != -1) { %>
<%= StringUtils.getFullElapsedTime(cache.getMaxLifetime()) %>
<% } else { %>
<fmt:message key="global.unlimited" />
<% } %>
</td>
<td class="c3">
<%= mbFormat.format(memUsed)%> MB
</td>
Expand Down