[infinispan-commits] Infinispan SVN: r1940 - branches/4.1.x/server/hotrod/src/main/scala/org/infinispan/server/hotrod.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Wed Jun 30 16:11:25 EDT 2010


Author: galder.zamarreno at jboss.com
Date: 2010-06-30 16:11:25 -0400 (Wed, 30 Jun 2010)
New Revision: 1940

Modified:
   branches/4.1.x/server/hotrod/src/main/scala/org/infinispan/server/hotrod/HotRodDecoder.scala
   branches/4.1.x/server/hotrod/src/main/scala/org/infinispan/server/hotrod/HotRodEncoder.scala
   branches/4.1.x/server/hotrod/src/main/scala/org/infinispan/server/hotrod/HotRodServer.scala
Log:
Tidy up cache retrieval in Hot Rod.

Modified: branches/4.1.x/server/hotrod/src/main/scala/org/infinispan/server/hotrod/HotRodDecoder.scala
===================================================================
--- branches/4.1.x/server/hotrod/src/main/scala/org/infinispan/server/hotrod/HotRodDecoder.scala	2010-06-30 17:17:43 UTC (rev 1939)
+++ branches/4.1.x/server/hotrod/src/main/scala/org/infinispan/server/hotrod/HotRodDecoder.scala	2010-06-30 20:11:25 UTC (rev 1940)
@@ -19,7 +19,7 @@
  */
 class HotRodDecoder(cacheManager: EmbeddedCacheManager) extends AbstractProtocolDecoder[ByteArrayKey, CacheValue] {
    import HotRodDecoder._
-   import HotRodServer.TopologyCacheName
+   import HotRodServer._
    
    type SuitableHeader = HotRodHeader
    type SuitableParameters = RequestParameters
@@ -75,8 +75,7 @@
       if (!cacheName.isEmpty && !cacheManager.getCacheNames.contains(cacheName))
          throw new CacheNotFoundException("Cache with name '" + cacheName + "' not found amongst the configured caches")
 
-      if (cacheName.isEmpty) cacheManager.getCache[ByteArrayKey, CacheValue]
-      else cacheManager.getCache(cacheName)
+      getCacheInstance(cacheName, cacheManager)
    }
 
    override def readKey(h: HotRodHeader, b: ChannelBuffer): ByteArrayKey =

Modified: branches/4.1.x/server/hotrod/src/main/scala/org/infinispan/server/hotrod/HotRodEncoder.scala
===================================================================
--- branches/4.1.x/server/hotrod/src/main/scala/org/infinispan/server/hotrod/HotRodEncoder.scala	2010-06-30 17:17:43 UTC (rev 1939)
+++ branches/4.1.x/server/hotrod/src/main/scala/org/infinispan/server/hotrod/HotRodEncoder.scala	2010-06-30 20:11:25 UTC (rev 1940)
@@ -5,7 +5,7 @@
 import org.infinispan.server.core.transport.ChannelBuffers._
 import collection.mutable.ListBuffer
 import org.infinispan.manager.EmbeddedCacheManager
-import org.infinispan.{CacheException, Cache}
+import org.infinispan.Cache
 import org.infinispan.server.core.{CacheValue, Logging}
 import org.infinispan.util.ByteArrayKey
 
@@ -64,7 +64,7 @@
             case 2 | 3 => {
                val currentTopologyView = topologyCache.get("view")
                if (r.topologyId != currentTopologyView.topologyId) {
-                  val cache = getCache(r.cacheName)
+                  val cache = getCacheInstance(r.cacheName, cacheManager)
                   val config = cache.getConfiguration
                   if (r.clientIntel == 2 || !config.getCacheMode.isDistributed) {
                      TopologyAwareResponse(TopologyView(currentTopologyView.topologyId, currentTopologyView.members))
@@ -137,7 +137,7 @@
       buffer.writeUnsignedInt(h.view.members.size)
       var hashIdUpdateRequired = false
       // If we reached here, we know for sure that this is a cache configured with distribution
-      val consistentHash = getCache(r.cacheName).getAdvancedCache.getDistributionManager.getConsistentHash
+      val consistentHash = getCacheInstance(r.cacheName, cacheManager).getAdvancedCache.getDistributionManager.getConsistentHash
       val updateMembers = new ListBuffer[TopologyAddress]
       h.view.members.foreach{address =>
          buffer.writeString(address.host)
@@ -163,19 +163,6 @@
       }
    }
 
-   private def getCache(cacheName: String): Cache[ByteArrayKey, CacheValue] = {
-      if (isTraceEnabled) trace("Cache was requested {0}", cacheName)
-      if (cacheName == TopologyCacheName)
-         throw new CacheException("Remote requests are not allowed to topology cache. Do no send remote requests to cache "
-               + TopologyCacheName)
-
-      if (!cacheName.isEmpty && !cacheManager.getCacheNames.contains(cacheName))
-         throw new CacheNotFoundException("Cache with name '" + cacheName + "' not found amongst the configured caches")
-
-      if (cacheName.isEmpty) cacheManager.getCache[ByteArrayKey, CacheValue]
-      else cacheManager.getCache(cacheName)
-   }
-
 }
 
 object HotRodEncoder extends Logging {

Modified: branches/4.1.x/server/hotrod/src/main/scala/org/infinispan/server/hotrod/HotRodServer.scala
===================================================================
--- branches/4.1.x/server/hotrod/src/main/scala/org/infinispan/server/hotrod/HotRodServer.scala	2010-06-30 17:17:43 UTC (rev 1939)
+++ branches/4.1.x/server/hotrod/src/main/scala/org/infinispan/server/hotrod/HotRodServer.scala	2010-06-30 20:11:25 UTC (rev 1940)
@@ -1,7 +1,6 @@
 package org.infinispan.server.hotrod
 
 import org.infinispan.server.core.transport.{Decoder, Encoder}
-import org.infinispan.server.core.{Logging, AbstractProtocolServer}
 import org.infinispan.config.Configuration
 import org.infinispan.config.Configuration.CacheMode
 import org.infinispan.notifications.Listener
@@ -9,11 +8,12 @@
 import org.infinispan.notifications.cachemanagerlistener.event.ViewChangedEvent
 import scala.collection.JavaConversions._
 import java.util.concurrent.TimeUnit._
-import org.infinispan.util.Util
 import org.infinispan.{CacheException, Cache}
 import org.infinispan.remoting.transport.Address
 import org.infinispan.manager.EmbeddedCacheManager
-import java.util.{Properties, Random};
+import java.util.{Properties, Random}
+import org.infinispan.server.core.{CacheValue, Logging, AbstractProtocolServer}
+import org.infinispan.util.{ByteArrayKey, Util};
 import org.infinispan.server.core.Main._
 
 /**
@@ -199,5 +199,10 @@
 
 object HotRodServer {
    val TopologyCacheName = "___hotRodTopologyCache"
+
+   def getCacheInstance(cacheName: String, cacheManager: EmbeddedCacheManager): Cache[ByteArrayKey, CacheValue] = {
+      if (cacheName.isEmpty) cacheManager.getCache[ByteArrayKey, CacheValue]
+      else cacheManager.getCache(cacheName)
+   }   
 }
 



More information about the infinispan-commits mailing list