Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nick Kallen
committed
Jan 20, 2011
1 parent
1048abb
commit bf9d1f6
Showing
10 changed files
with
172 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
finagle-kestrel/src/main/scala/com/twitter/finagle/kestrel/Interpreter.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.twitter.finagle.kestrel | ||
|
||
import com.twitter.finagle.kestrel.protocol._ | ||
import org.jboss.netty.buffer.ChannelBuffer | ||
import com.twitter.conversions.time._ | ||
import java.util.concurrent.{TimeUnit, BlockingQueue} | ||
import com.twitter.util.{Future, MapMaker} | ||
|
||
class Interpreter(Queue: () => BlockingQueue[ChannelBuffer]) { | ||
private[this] val queues = MapMaker[ChannelBuffer, BlockingQueue[ChannelBuffer]] { config => | ||
config.compute { key => | ||
Queue() | ||
} | ||
} | ||
|
||
def apply(command: Command): Response = { | ||
command match { | ||
case Get(queueName, options) => | ||
val timeoutOption = options.find(_.isInstanceOf[Timeout]).asInstanceOf[Option[Timeout]] | ||
val wait = timeoutOption.map(_.duration).getOrElse(0.seconds) | ||
val item = queues(queueName).poll(wait.inMilliseconds, TimeUnit.MILLISECONDS) | ||
if (item eq null) | ||
Values(Seq.empty) | ||
else | ||
Values(Seq(Value(queueName, item))) | ||
case Set(queueName, flags, expiry, value) => | ||
queues(queueName).add(value) | ||
Stored | ||
case Delete(queueName) => | ||
queues.remove(queueName) | ||
Deleted | ||
case Flush(queueName) => | ||
queues.remove(queueName) | ||
Deleted | ||
case FlushAll() => | ||
queues.clear() | ||
Deleted | ||
case Version() => | ||
NotFound | ||
case ShutDown() => | ||
NotFound | ||
case DumpConfig() => | ||
NotFound | ||
case Stats() => | ||
NotFound | ||
case DumpStats() => | ||
NotFound | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
finagle-kestrel/src/main/scala/com/twitter/finagle/kestrel/protocol/Command.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.twitter.finagle.kestrel.protocol | ||
|
||
import org.jboss.netty.buffer.ChannelBuffer | ||
import com.twitter.util.Duration | ||
|
||
sealed abstract class Command | ||
|
||
case class Get(queueName: ChannelBuffer, options: collection.Set[GetOption]) extends Command | ||
case class Set(queueName: ChannelBuffer, flags: Int, expiry: Duration, value: ChannelBuffer) extends Command | ||
|
||
case class Delete(queueName: ChannelBuffer) extends Command | ||
case class Flush(queueName: ChannelBuffer) extends Command | ||
case class FlushAll() extends Command | ||
|
||
case class Version() extends Command | ||
case class ShutDown() extends Command | ||
case class Reload() extends Command | ||
case class DumpConfig() extends Command | ||
case class Stats() extends Command | ||
case class DumpStats() extends Command | ||
|
||
sealed abstract class GetOption | ||
|
||
case class Timeout(duration: Duration) extends GetOption | ||
case class Open() extends GetOption | ||
case class Close() extends GetOption | ||
case class Abort() extends GetOption | ||
case class Peek() extends GetOption |
14 changes: 14 additions & 0 deletions
14
finagle-kestrel/src/main/scala/com/twitter/finagle/kestrel/protocol/Response.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.twitter.finagle.kestrel.protocol | ||
|
||
import org.jboss.netty.buffer.ChannelBuffer | ||
|
||
// fixme remove case objects | ||
sealed abstract class Response | ||
case object NotFound extends Response | ||
case object Stored extends Response | ||
case object NotStored extends Response | ||
case object Deleted extends Response | ||
|
||
case class Values(values: Seq[Value]) extends Response | ||
|
||
case class Value(key: ChannelBuffer, value: ChannelBuffer) |
60 changes: 60 additions & 0 deletions
60
finagle-kestrel/src/test/scala/com/twitter/finagle/kestrel/InterpreterSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.twitter.finagle.kestrel | ||
|
||
import org.specs.Specification | ||
import com.twitter.finagle.memcached.util.ChannelBufferUtils._ | ||
import com.twitter.finagle.kestrel.protocol._ | ||
import com.twitter.conversions.time._ | ||
import org.jboss.netty.buffer.ChannelBuffers.wrappedBuffer | ||
import org.jboss.netty.buffer.ChannelBuffer | ||
import java.util.concurrent.LinkedBlockingQueue | ||
|
||
object InterpreterSpec extends Specification { | ||
"Interpreter" should { | ||
val interpreter = new Interpreter(() => new LinkedBlockingQueue[ChannelBuffer]) | ||
|
||
"set & get" in { | ||
interpreter(Set("name", 0, 0.seconds, "rawr")) | ||
interpreter(Get("name", collection.Set.empty)) mustEqual | ||
Values(Seq(Value("name", "rawr"))) | ||
} | ||
|
||
"delete" in { | ||
interpreter(Set("name", 0, 0.seconds, "rawr")) | ||
interpreter(Delete("name")) | ||
interpreter(Get("name", collection.Set.empty)) mustEqual Values(Seq.empty) | ||
} | ||
|
||
"flush" in { | ||
interpreter(Set("name", 0, 0.seconds, "rawr")) | ||
interpreter(Flush("name")) | ||
interpreter(Get("name", collection.Set.empty)) mustEqual Values(Seq.empty) | ||
} | ||
|
||
"flushAll" in { | ||
interpreter(Set("name", 0, 0.seconds, "rawr")) | ||
interpreter(FlushAll()) | ||
interpreter(Get("name", collection.Set.empty)) //mustEqual Values(Seq.empty) | ||
interpreter(Get("name", collection.Set.empty)) mustEqual Values(Seq.empty) | ||
} | ||
|
||
"version" in { | ||
|
||
} | ||
|
||
"shutDown" in { | ||
|
||
} | ||
|
||
"dumpConfig" in { | ||
|
||
} | ||
|
||
"stats" in { | ||
|
||
} | ||
|
||
"dumpStats" in { | ||
|
||
} | ||
} | ||
} |
5 changes: 2 additions & 3 deletions
5
finagle-memcached/src/main/scala/com/twitter/finagle/memcached/Interpreter.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
finagle-memcached/src/main/scala/com/twitter/finagle/memcached/util/AtomicMap.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters