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

ISPN-2010 Cache lookup of known instances in REST servlet #1092

Closed
wants to merge 2 commits into from
Closed
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
20 changes: 17 additions & 3 deletions server/rest/src/main/scala/org/infinispan/rest/Server.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import org.infinispan.manager._
import org.codehaus.jackson.map.ObjectMapper
import org.infinispan.{CacheException, Cache}
import org.infinispan.commons.hash.MurmurHash3
import org.infinispan.util.concurrent.ConcurrentMapFactory
import javax.ws.rs._

/**
* Integration server linking REST requests with Infinispan calls.
Expand Down Expand Up @@ -228,13 +230,25 @@ class Server(@Context request: Request, @HeaderParam("performAsync") useAsync: B
*/
object ManagerInstance {
var instance: EmbeddedCacheManager = null
private val knownCaches : java.util.Map[String, Cache[String, Any]] = ConcurrentMapFactory.makeConcurrentMap(4, 0.9f, 16)

def getCache(name: String): Cache[String, Any] = {
if (name != BasicCacheContainer.DEFAULT_CACHE_NAME && !instance.getCacheNames.contains(name))
val isKnownCache = knownCaches.containsKey(name);
if (name != BasicCacheContainer.DEFAULT_CACHE_NAME && !isKnownCache && !instance.getCacheNames.contains(name))
throw new CacheNotFoundException("Cache with name '" + name + "' not found amongst the configured caches")

if (name == BasicCacheContainer.DEFAULT_CACHE_NAME) instance.getCache[String, Any]
else instance.getCache(name)
if (isKnownCache) {
knownCaches.get(name)
} else {
val rv =
if (name == BasicCacheContainer.DEFAULT_CACHE_NAME)
instance.getCache[String, Any]()
else
instance.getCache[String, Any](name)

knownCaches.put(name, rv)
rv
}
}

def getEntry(cacheName: String, key: String): Any = getCache(cacheName).get(key)
Expand Down