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
6d18f8a1
Commit
6d18f8a1
authored
Aug 15, 2017
by
GregDThomas
Committed by
daryl herzmann
Aug 14, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure that Hazelcast backed Cache objects have the correct settings (#847)
parent
c399e891
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
37 deletions
+54
-37
Cache.java
src/java/org/jivesoftware/util/cache/Cache.java
+8
-2
plugin.xml
src/plugins/hazelcast/plugin.xml
+11
-11
ClusteredCacheFactory.java
...are/openfire/plugin/util/cache/ClusteredCacheFactory.java
+35
-24
No files found.
src/java/org/jivesoftware/util/cache/Cache.java
View file @
6d18f8a1
...
...
@@ -72,6 +72,9 @@ public interface Cache<K,V> extends java.util.Map<K,V> {
* than the max size, the least frequently used items will be removed. If
* the max cache size is set to -1, there is no size limit.
*
*<p><strong>Note:</strong> If using the Hazelcast clustering plugin, this will not take
* effect until the next time the cache is created</p>
*
* @param maxSize the maximum size of the cache in bytes.
*/
void
setMaxCacheSize
(
int
maxSize
);
...
...
@@ -79,7 +82,7 @@ public interface Cache<K,V> extends java.util.Map<K,V> {
/**
* Returns the maximum number of milliseconds that any object can live
* in cache. Once the specified number of milliseconds passes, the object
* will be automatically exp
ri
ed from cache. If the max lifetime is set
* will be automatically exp
ir
ed from cache. If the max lifetime is set
* to -1, then objects never expire.
*
* @return the maximum number of milliseconds before objects are expired.
...
...
@@ -89,9 +92,12 @@ public interface Cache<K,V> extends java.util.Map<K,V> {
/**
* Sets the maximum number of milliseconds that any object can live
* in cache. Once the specified number of milliseconds passes, the object
* will be automatically exp
ri
ed from cache. If the max lifetime is set
* will be automatically exp
ir
ed from cache. If the max lifetime is set
* to -1, then objects never expire.
*
*<p><strong>Note:</strong> If using the Hazelcast clustering plugin, this will not take
* effect until the next time the cache is created</p>
*
* @param maxLifetime the maximum number of milliseconds before objects are expired.
*/
void
setMaxLifetime
(
long
maxLifetime
);
...
...
src/plugins/hazelcast/plugin.xml
View file @
6d18f8a1
<?xml version="1.0" encoding="UTF-8"?>
<plugin>
<class>
org.jivesoftware.openfire.plugin.HazelcastPlugin
</class>
<name>
Hazelcast plugin
</name>
<description>
Adds clustering support
</description>
<author>
Tom Evans
</author>
<version>
2.2.
1
</version>
<date>
11/04/2016
</date>
<minServerVersion>
4.0.0
</minServerVersion>
</plugin>
<?xml version="1.0" encoding="UTF-8"?>
<plugin>
<class>
org.jivesoftware.openfire.plugin.HazelcastPlugin
</class>
<name>
Hazelcast plugin
</name>
<description>
Adds clustering support
</description>
<author>
Tom Evans
</author>
<version>
2.2.
2
</version>
<date>
08/03/2017
</date>
<minServerVersion>
4.0.0
</minServerVersion>
</plugin>
src/plugins/hazelcast/src/java/org/jivesoftware/openfire/plugin/util/cache/ClusteredCacheFactory.java
View file @
6d18f8a1
...
...
@@ -16,24 +16,14 @@
package
org
.
jivesoftware
.
openfire
.
plugin
.
util
.
cache
;
import
java.io.Serializable
;
import
java.text.MessageFormat
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.Iterator
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.concurrent.Callable
;
import
java.util.concurrent.Future
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeoutException
;
import
java.util.concurrent.locks.Condition
;
import
java.util.concurrent.locks.Lock
;
import
com.hazelcast.config.ClasspathXmlConfig
;
import
com.hazelcast.config.Config
;
import
com.hazelcast.config.MapConfig
;
import
com.hazelcast.config.MaxSizeConfig
;
import
com.hazelcast.core.Cluster
;
import
com.hazelcast.core.Hazelcast
;
import
com.hazelcast.core.HazelcastInstance
;
import
com.hazelcast.core.Member
;
import
org.jivesoftware.openfire.JMXManager
;
import
org.jivesoftware.openfire.XMPPServer
;
import
org.jivesoftware.openfire.cluster.ClusterNodeInfo
;
...
...
@@ -44,6 +34,7 @@ import org.jivesoftware.openfire.plugin.util.cluster.HazelcastClusterNodeInfo;
import
org.jivesoftware.util.JiveGlobals
;
import
org.jivesoftware.util.StringUtils
;
import
org.jivesoftware.util.cache.Cache
;
import
org.jivesoftware.util.cache.CacheFactory
;
import
org.jivesoftware.util.cache.CacheFactoryStrategy
;
import
org.jivesoftware.util.cache.CacheWrapper
;
import
org.jivesoftware.util.cache.ClusterTask
;
...
...
@@ -52,12 +43,23 @@ import org.jivesoftware.util.cache.ExternalizableUtilStrategy;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
com.hazelcast.config.ClasspathXmlConfig
;
import
com.hazelcast.config.Config
;
import
com.hazelcast.core.Cluster
;
import
com.hazelcast.core.Hazelcast
;
import
com.hazelcast.core.HazelcastInstance
;
import
com.hazelcast.core.Member
;
import
java.io.Serializable
;
import
java.text.MessageFormat
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.Iterator
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.concurrent.Callable
;
import
java.util.concurrent.Future
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeoutException
;
import
java.util.concurrent.locks.Condition
;
import
java.util.concurrent.locks.Lock
;
/**
* CacheFactory implementation to use when using Hazelcast in cluster mode.
...
...
@@ -211,6 +213,15 @@ public class ClusteredCacheFactory implements CacheFactoryStrategy {
if
(
state
==
State
.
stopped
)
{
throw
new
IllegalStateException
(
"Cannot create clustered cache when not in a cluster"
);
}
// Determine the time to live. Note that in Hazelcast 0 means "forever", not -1
final
long
openfireLifetimeInMilliseconds
=
CacheFactory
.
getMaxCacheLifetime
(
name
);
final
int
hazelcastLifetimeInSeconds
=
openfireLifetimeInMilliseconds
<
0
?
0
:
(
int
)
(
openfireLifetimeInMilliseconds
/
1000
);
// Determine the max cache size. Note that in Hazelcast the max cache size must be positive
final
long
openfireMaxCacheSize
=
CacheFactory
.
getMaxCacheSize
(
name
);
final
int
hazelcastMaxCacheSize
=
openfireMaxCacheSize
<
0
?
Integer
.
MAX_VALUE
:
(
int
)
openfireMaxCacheSize
;
final
MapConfig
mapConfig
=
hazelcast
.
getConfig
().
getMapConfig
(
name
);
mapConfig
.
setTimeToLiveSeconds
(
hazelcastLifetimeInSeconds
);
mapConfig
.
setMaxSizeConfig
(
new
MaxSizeConfig
(
hazelcastMaxCacheSize
,
MaxSizeConfig
.
MaxSizePolicy
.
USED_HEAP_SIZE
));
return
new
ClusteredCache
(
name
,
hazelcast
.
getMap
(
name
));
}
...
...
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