[infinispan-commits] Infinispan SVN: r1937 - 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 02:32:33 EDT 2010


Author: mircea.markus
Date: 2010-06-30 02:32:33 -0400 (Wed, 30 Jun 2010)
New Revision: 1937

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/Response.scala
Log:
- if cache name is empty the default cache should be used, as per hotrod protocol spec

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 06:27:54 UTC (rev 1936)
+++ branches/4.1.x/server/hotrod/src/main/scala/org/infinispan/server/hotrod/HotRodEncoder.scala	2010-06-30 06:32:33 UTC (rev 1937)
@@ -1,12 +1,13 @@
 package org.infinispan.server.hotrod
 
-import org.infinispan.server.core.Logging
 import org.infinispan.server.core.transport.{ChannelBuffer, ChannelHandlerContext, Channel, Encoder}
 import OperationStatus._
 import org.infinispan.server.core.transport.ChannelBuffers._
-import org.infinispan.Cache
 import collection.mutable.ListBuffer
 import org.infinispan.manager.EmbeddedCacheManager
+import org.infinispan.{CacheException, Cache}
+import org.infinispan.server.core.{CacheValue, Logging}
+import org.infinispan.util.ByteArrayKey
 
 /**
  * // TODO: Document this
@@ -63,7 +64,7 @@
             case 2 | 3 => {
                val currentTopologyView = topologyCache.get("view")
                if (r.topologyId != currentTopologyView.topologyId) {
-                  val cache = cacheManager.getCache(r.cacheName)
+                  val cache = getCache(r.cacheName)
                   val config = cache.getConfiguration
                   if (r.clientIntel == 2 || !config.getCacheMode.isDistributed) {
                      TopologyAwareResponse(TopologyView(currentTopologyView.topologyId, currentTopologyView.members))
@@ -136,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 = cacheManager.getCache(r.cacheName).getAdvancedCache.getDistributionManager.getConsistentHash
+      val consistentHash = getCache(r.cacheName).getAdvancedCache.getDistributionManager.getConsistentHash
       val updateMembers = new ListBuffer[TopologyAddress]
       h.view.members.foreach{address =>
          buffer.writeString(address.host)
@@ -162,6 +163,19 @@
       }
    }
 
+   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/Response.scala
===================================================================
--- branches/4.1.x/server/hotrod/src/main/scala/org/infinispan/server/hotrod/Response.scala	2010-06-30 06:27:54 UTC (rev 1936)
+++ branches/4.1.x/server/hotrod/src/main/scala/org/infinispan/server/hotrod/Response.scala	2010-06-30 06:32:33 UTC (rev 1937)
@@ -16,6 +16,7 @@
          .append("messageId=").append(messageId)
          .append(", operation=").append(operation)
          .append(", status=").append(status)
+         .append(", cacheName=").append(cacheName)
          .append("}").toString
    }
 }



More information about the infinispan-commits mailing list