Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
Openfire
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Openfire
Commits
02093e1c
Commit
02093e1c
authored
Dec 01, 2017
by
Guus der Kinderen
Committed by
daryl herzmann
Dec 01, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
OF-1445: Apply cache config changes at runtime. (#948)
parent
33d18367
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
94 additions
and
7 deletions
+94
-7
CacheFactory.java
src/java/org/jivesoftware/util/cache/CacheFactory.java
+94
-7
No files found.
src/java/org/jivesoftware/util/cache/CacheFactory.java
View file @
02093e1c
...
...
@@ -33,9 +33,7 @@ import org.jivesoftware.openfire.cluster.ClusterNodeInfo;
import
org.jivesoftware.openfire.container.Plugin
;
import
org.jivesoftware.openfire.container.PluginClassLoader
;
import
org.jivesoftware.openfire.container.PluginManager
;
import
org.jivesoftware.util.InitializationException
;
import
org.jivesoftware.util.JiveConstants
;
import
org.jivesoftware.util.JiveGlobals
;
import
org.jivesoftware.util.*
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -203,6 +201,52 @@ public class CacheFactory {
cacheProps
.
put
(
"cache.pepServiceManager.maxLifetime"
,
JiveConstants
.
MINUTE
*
30
);
cacheProps
.
put
(
"cache.publishedItems.size"
,
1024
l
*
1024
*
10
);
cacheProps
.
put
(
"cache.publishedItems.maxLifetime"
,
JiveConstants
.
MINUTE
*
15
);
PropertyEventDispatcher
.
addListener
(
new
PropertyEventListener
()
{
@Override
public
void
propertySet
(
String
property
,
Map
<
String
,
Object
>
params
)
{
final
Cache
cache
=
getCacheByProperty
(
property
);
if
(
cache
==
null
)
{
return
;
}
if
(
property
.
endsWith
(
".size"
)
)
{
final
Long
size
=
getMaxCacheSize
(
cache
.
getName
()
);
cache
.
setMaxCacheSize
(
size
<
Integer
.
MAX_VALUE
?
size
.
intValue
()
:
Integer
.
MAX_VALUE
);
}
if
(
property
.
endsWith
(
".maxLifeTime"
)
)
{
final
Long
lifetime
=
getMaxCacheLifetime
(
cache
.
getName
()
);
cache
.
setMaxLifetime
(
lifetime
);
}
// Note that changes to 'min' and 'type' cannot be applied runtime - a restart is required for those.
}
@Override
public
void
propertyDeleted
(
String
property
,
Map
<
String
,
Object
>
params
)
{
propertySet
(
property
,
params
);
}
@Override
public
void
xmlPropertySet
(
String
property
,
Map
<
String
,
Object
>
params
)
{
propertySet
(
property
,
params
);
}
@Override
public
void
xmlPropertyDeleted
(
String
property
,
Map
<
String
,
Object
>
params
)
{
propertySet
(
property
,
params
);
}
}
);
}
private
CacheFactory
()
{
...
...
@@ -227,7 +271,10 @@ public class CacheFactory {
*/
public
static
void
setMaxSizeProperty
(
String
cacheName
,
long
size
)
{
cacheName
=
cacheName
.
replaceAll
(
" "
,
""
);
JiveGlobals
.
setProperty
(
"cache."
+
cacheName
+
".size"
,
Long
.
toString
(
size
));
if
(
!
Long
.
toString
(
size
).
equals
(
JiveGlobals
.
getProperty
(
"cache."
+
cacheName
+
".size"
)
)
)
{
JiveGlobals
.
setProperty
(
"cache."
+
cacheName
+
".size"
,
Long
.
toString
(
size
)
);
}
}
public
static
boolean
hasMaxSizeFromProperty
(
String
cacheName
)
{
...
...
@@ -253,7 +300,10 @@ public class CacheFactory {
*/
public
static
void
setMaxLifetimeProperty
(
String
cacheName
,
long
lifetime
)
{
cacheName
=
cacheName
.
replaceAll
(
" "
,
""
);
JiveGlobals
.
setProperty
((
"cache."
+
cacheName
+
".maxLifetime"
),
Long
.
toString
(
lifetime
));
if
(
!
Long
.
toString
(
lifetime
).
equals
(
JiveGlobals
.
getProperty
(
"cache."
+
cacheName
+
".maxLifetime"
)
))
{
JiveGlobals
.
setProperty
(
(
"cache."
+
cacheName
+
".maxLifetime"
),
Long
.
toString
(
lifetime
)
);
}
}
public
static
boolean
hasMaxLifetimeFromProperty
(
String
cacheName
)
{
...
...
@@ -262,7 +312,10 @@ public class CacheFactory {
public
static
void
setCacheTypeProperty
(
String
cacheName
,
String
type
)
{
cacheName
=
cacheName
.
replaceAll
(
" "
,
""
);
JiveGlobals
.
setProperty
(
"cache."
+
cacheName
+
".type"
,
type
);
if
(
!
type
.
equals
(
JiveGlobals
.
getProperty
(
"cache."
+
cacheName
+
".type"
)
))
{
JiveGlobals
.
setProperty
(
"cache."
+
cacheName
+
".type"
,
type
);
}
}
public
static
String
getCacheTypeProperty
(
String
cacheName
)
{
...
...
@@ -272,13 +325,47 @@ public class CacheFactory {
public
static
void
setMinCacheSize
(
String
cacheName
,
long
size
)
{
cacheName
=
cacheName
.
replaceAll
(
" "
,
""
);
JiveGlobals
.
setProperty
(
"cache."
+
cacheName
+
".min"
,
Long
.
toString
(
size
));
if
(
!
Long
.
toString
(
size
).
equals
(
JiveGlobals
.
getProperty
(
"cache."
+
cacheName
+
".min"
)
))
{
JiveGlobals
.
setProperty
(
"cache."
+
cacheName
+
".min"
,
Long
.
toString
(
size
)
);
}
}
public
static
long
getMinCacheSize
(
String
cacheName
)
{
return
getCacheProperty
(
cacheName
,
".min"
,
0
);
}
private
static
Cache
getCacheByProperty
(
String
property
)
{
if
(
!
property
.
startsWith
(
"cache."
)
)
{
return
null
;
}
// Extract the cache name identifier from the property name.
final
String
name
=
property
.
substring
(
"cache."
.
length
(),
property
.
lastIndexOf
(
"."
)
);
// See if property is using the short name variant.
for
(
final
Map
.
Entry
<
String
,
String
>
entry
:
cacheNames
.
entrySet
()
)
{
if
(
name
.
equals
(
entry
.
getValue
()
)
)
{
return
caches
.
get
(
entry
.
getKey
()
);
}
}
// If not a short name, then try for a normalized name.
for
(
final
Map
.
Entry
<
String
,
Cache
>
entry
:
caches
.
entrySet
()
)
{
if
(
entry
.
getKey
().
replaceAll
(
" "
,
""
).
equals
(
name
)
)
{
return
entry
.
getValue
();
}
}
return
null
;
}
private
static
long
getCacheProperty
(
String
cacheName
,
String
suffix
,
long
defaultValue
)
{
// First check if user is overwriting default value using a system property for the cache name
String
propName
=
"cache."
+
cacheName
.
replaceAll
(
" "
,
""
)
+
suffix
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment