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

finagle-protobuf #91

Closed
wants to merge 56 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
a844e92
added load test, refactored
Apr 11, 2012
4a7e0eb
moved method lookup tests to scala
Apr 11, 2012
d8d8ba0
Merge branch 'master' of git://github.com/twitter/finagle
Apr 17, 2012
5502ea4
added finagle-protobuf pom
Apr 18, 2012
397a250
added release() for the stub
Apr 20, 2012
e619a53
sbt eclipse support
May 1, 2012
7e4780d
eclipsify finagle-serversets
May 2, 2012
443040f
temporary workaround for ChannelClosedExceptions raise when servers s…
May 7, 2012
b218582
move snapshot
May 7, 2012
be6b50d
add scm pointer to finagle-protobuf pom
May 11, 2012
afda314
[maven-release-plugin] prepare release finagle-protobuf-3.0.2
May 11, 2012
562b63b
[maven-release-plugin] prepare for next development iteration
May 11, 2012
46ef82f
release 3.0.2
May 11, 2012
48a9b19
merged
May 11, 2012
4f7e2eb
preconditions check
May 16, 2012
563b64e
handle runtime exceptions and return empty messages
May 22, 2012
ff85203
[maven-release-plugin] prepare release finagle-protobuf-3.0.4-TENDRIL
May 23, 2012
85a3b4e
[maven-release-plugin] prepare for next development iteration
May 23, 2012
47d1437
using a promise for async computations
May 30, 2012
572cbcc
Merge branch 'master' of https://fisheye.tendrilinc.com/git/finagle
May 30, 2012
997b0a4
fixed def to val
May 31, 2012
69e9136
release 3.0.5-TENDRIL
May 31, 2012
9b40464
add .gitignore
May 31, 2012
40dfc44
bump finagle-protobuf to next snapshot version
mkochco Jun 1, 2012
0963750
added loggin
Jun 27, 2012
8ccd3d4
added loggin
Jun 27, 2012
02477fb
3.0.7 snapshot
Jun 27, 2012
07a3375
3.0.7
Jun 27, 2012
0498fd5
3.0.8 SNAPSHOT
Jun 27, 2012
9da0f7d
use toString()
Jun 27, 2012
17482dd
corrected version
Jun 27, 2012
a333a23
typo fix
Jun 27, 2012
43182e7
3.0.9 added service exception handler
Jun 28, 2012
2413d6a
client side exception deserializer
Jun 28, 2012
adebac7
client side exception deserializer
Jun 28, 2012
74504e8
snapshot
Jun 29, 2012
1085cd1
scala to java array fix
Jun 29, 2012
21f10fd
Added Git ignores
cgleissner Jul 2, 2012
9c47fe6
refactored
Jul 2, 2012
908cc00
Merge branch 'master' of https://fisheye.tendrilinc.com/git/finagle
Jul 2, 2012
39f05db
use dynamic message to create a prototype
Jul 17, 2012
13bf461
release finagle-protobuf 3.1.2-TENDRIL
Jul 18, 2012
55bb502
bump development to next snapshot
Jul 18, 2012
2ff98a6
fixed tests
Dec 11, 2012
9c9755c
typo
Dec 11, 2012
a0b37f7
code format
Dec 11, 2012
f2c291c
Merge remote-tracking branch 'github/master'
mkochco Jul 15, 2013
d863d4e
Merge in upstream changes for finagle 6.5.1
mkochco Jul 18, 2013
0824eba
PS-35 Upgrade to latest finagle (6.5.1)
mkochco Jul 19, 2013
154533d
split protobuf class to make scala happy; added test for service to s…
Aug 16, 2013
488e7e0
added server spec to verify on which thread pool SPF side requests ar…
george-vacariuc Aug 26, 2013
d7a3fa5
added comments
george-vacariuc Aug 26, 2013
80fd22c
removed unused spec
Sep 11, 2013
64f5cb3
added logging statements back
Sep 11, 2013
4297889
callbacks can be dispatched in a separate thread
Oct 1, 2013
76fa8d6
updated version 6.5.3-TENDRIL
Oct 1, 2013
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions finagle-protobuf/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.classpath
.project
.settings
38 changes: 38 additions & 0 deletions finagle-protobuf/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.twitter</groupId>
<artifactId>finagle-protobuf</artifactId>
<packaging>jar</packaging>
<version>6.5.3-TENDRIL</version>
<distributionManagement>
<repository>
<id>artifactory-release</id>
<name>Artifactory Releases</name>
<url>http://build:8081/nexus/content/repositories/platform-services</url>
</repository>
<snapshotRepository>
<id>artifactory-snapshot</id>
<name>Artifactory Snapshots</name>
<url>http://build:8081/nexus/content/repositories/platform-services-snapshot</url>
</snapshotRepository>
</distributionManagement>
<scm>
<connection>scm:git:https://fisheye.tendrilinc.com/git/finagle.git</connection>
<developerConnection>scm:git:https://fisheye.tendrilinc.com/git/finagle.git</developerConnection>
</scm>
<build>
<directory>target/scala-2.9.2</directory>
</build>
<dependencies>
<dependency>
<groupId>com.twitter</groupId>
<artifactId>finagle-core</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>2.4.1</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.twitter.finagle.protobuf.rpc

/**
* Inspects a response message and if it contains an exception code it throws the correspondent exception. See also ServiceExceptionHandler.
*/
trait ExceptionResponseHandler[T] {

def canHandle(message: T): Boolean

def handle(message: T): RuntimeException

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package com.twitter.finagle.protobuf.rpc

import com.google.protobuf.RpcCallback
import com.google.protobuf.RpcController
import com.twitter.finagle.TimeoutException
import com.twitter.finagle.ChannelClosedException

class RpcControllerWithOnFailureCallback extends RpcController {

private var cancelRequested = false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
package com.twitter.finagle.protobuf.rpc

import com.google.protobuf.Message
import com.google.protobuf.RpcChannel
import com.google.protobuf.Service
import com.twitter.finagle.builder.ClientBuilder
import com.twitter.finagle.builder.ServerBuilder
import com.google.protobuf.RpcController
import com.twitter.util.Duration
import java.util.concurrent.ExecutorService

trait RpcFactory {

def createServer(sb: ServerBuilder[(String, Message), (String, Message), Any, Any, Any], port: Int, service: Service, executorService: ExecutorService): RpcServer
def createServer(sb: ServerBuilder[(String, Message), (String, Message), Any, Any, Any], port: Int, service: Service, handler: ServiceExceptionHandler[Message], executorService: ExecutorService): RpcServer

def createStub[T <: Service](cb: ClientBuilder[(String, Message), (String, Message), Any, Any, Any], service: { def newStub(c: RpcChannel): T }, executorService: ExecutorService): T
def createStub[T <: Service](cb: ClientBuilder[(String, Message), (String, Message), Any, Any, Any], service: {def newStub(c: RpcChannel): T}, handler: ExceptionResponseHandler[Message], executorService: ExecutorService): T

def createController(): RpcController

def release(stub: { def getChannel(): RpcChannel })
def release(stub: {def getChannel(): RpcChannel})

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.twitter.finagle.protobuf.rpc

import com.twitter.util.Duration

trait RpcServer {

def close(d: Duration): Unit;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.twitter.finagle.protobuf.rpc

import com.google.protobuf.Message

/**
* If the invocation of a service causes a RuntimeException this handler serializes it into a response message
* that can be deserialized by an ExceptioResponseHandler.
*/
trait ServiceExceptionHandler[T] {

def canHandle(e: RuntimeException): Boolean

def handle(e: RuntimeException, m: Message): T

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,35 @@ package com.twitter.finagle.protobuf.rpc

import java.util.List

import com.google.common.base.Function
import com.google.common.collect.Lists
import com.google.protobuf.Descriptors.MethodDescriptor
import com.google.protobuf.Service
import com.google.protobuf.Message

import scala.collection.JavaConversions._
import scala.collection.mutable._

import org.slf4j.LoggerFactory

object Util {

def extractMethodNames(s: Service) : List[String] = {
return Lists.transform(s.getDescriptorForType().getMethods(),
new Function[MethodDescriptor, String]() {
private val log = LoggerFactory.getLogger(getClass)

def extractMethodNames(s: Service): List[String] = {
return Lists.transform(s.getDescriptorForType().getMethods(),
new Function[MethodDescriptor, String]() {

@Override
def apply(d: MethodDescriptor) : String = {
return d.getName()
}
})
}
@Override
def apply(d: MethodDescriptor): String = {
return d.getName()
}
})
}

def log(reqOrResp: String, method: String, m: Message) {
if (log.isDebugEnabled()) {
log.debug("#log# {} {}: {}", Array[AnyRef](reqOrResp, method, m.toString()))
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
package com.twitter.finagle.protobuf.rpc.channel

import org.jboss.netty.buffer.ChannelBuffer
import org.jboss.netty.buffer.ChannelBufferInputStream
import org.jboss.netty.channel.Channel
import org.jboss.netty.channel.ChannelHandlerContext
import org.jboss.netty.handler.codec.frame.FrameDecoder

import com.google.protobuf.Message
import com.google.protobuf.Service


class ClientSideDecoder(val repo: MethodLookup, val service: Service) extends FrameDecoder with ProtobufDecoder {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package com.twitter.finagle.protobuf.rpc.channel

/**
* Lookup repository that maps method names to 4 bytes.
*
* */
*
**/
trait MethodLookup {

def encode(methodName: String ) : Int
def encode(methodName: String): Int

def lookup(code: Int) : String
def lookup(code: Int): String

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
package com.twitter.finagle.protobuf.rpc.channel

import org.jboss.netty.channel.ChannelPipelineFactory
import org.jboss.netty.channel.Channels
import com.google.protobuf.Message
import com.google.protobuf.Service
import com.twitter.conversions.storage.intToStorageUnitableWholeNumber
import com.twitter.finagle.Codec
import com.twitter.finagle.CodecFactory

class ProtoBufCodec(val service: Service) extends CodecFactory[(String, Message), (String, Message)] {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package com.twitter.finagle.protobuf.rpc.channel

import org.jboss.netty.buffer.ChannelBuffer
import org.jboss.netty.buffer.ChannelBufferInputStream
import org.jboss.netty.channel.Channel
import org.jboss.netty.channel.ChannelHandlerContext

import com.google.protobuf.Message
/**
*
* Knows how to decode a ("doSomething()", ProtobufMessage) binary message.
Expand All @@ -9,9 +14,9 @@ package com.twitter.finagle.protobuf.rpc.channel
* ==============
*
* Offset: 0 4 8
* +-------------+----------------+------------------+
* | method code | message length | protobuf message |
* +-------------+----------------+------------------+
* +-------------+----------------+------------------+
* | method code | message length | protobuf message |
* +-------------+----------------+------------------+
*
*/

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package com.twitter.finagle.protobuf.rpc.channel

import org.jboss.netty.handler.codec.oneone.OneToOneEncoder
import org.jboss.netty.channel.ChannelHandlerContext
import org.jboss.netty.channel.Channel
import org.jboss.netty.buffer.ChannelBuffers

import com.google.protobuf.Message

/**
* Knows how to encode a ("doSomething()", ProtobufMessage) tuple.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
package com.twitter.finagle.protobuf.rpc.channel

import org.jboss.netty.buffer.ChannelBuffer
import org.jboss.netty.channel.Channel
import org.jboss.netty.channel.ChannelHandlerContext
import org.jboss.netty.handler.codec.frame.FrameDecoder

import com.google.protobuf.Message
import com.google.protobuf.Service

class ServerSideDecoder(val repo: MethodLookup, val service: Service) extends FrameDecoder with ProtobufDecoder {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,40 @@
package com.twitter.finagle.protobuf.rpc.channel

import com.twitter.finagle.protobuf.rpc.Util
import com.google.protobuf.Service
import scala.collection.JavaConversions._
import scala.collection.mutable._
import com.google.common.base.Joiner

/**
* Maps method names to short codes. This particular implementation uses the trivial String.hashCode.
*/
class SimpleMethodLookup(val methods: java.util.List[String]) extends MethodLookup {

val codeToNameMulti = new HashMap[Int, Set[String]] with MultiMap[Int, String]
methods.toList foreach { it => codeToNameMulti.getOrElseUpdate(createEncoding(it), Set.empty[String]) += it }
methods.toList foreach {
it => codeToNameMulti.getOrElseUpdate(createEncoding(it), Set.empty[String]) += it
}

// do we have collisions?
codeToNameMulti foreach { it =>
if (it._2.size > 1) {
val sb = new StringBuilder("Collision on ")
it._2 foreach { it => sb.append(it).append(", ") }
throw new IllegalArgumentException(sb.toString())
}
codeToNameMulti foreach {
it =>
if (it._2.size > 1) {
val sb = new StringBuilder("Collision on ")
it._2 foreach {
it => sb.append(it).append(", ")
}
throw new IllegalArgumentException(sb.toString())
}
}

val codeToName = new HashMap[Int, String]
codeToNameMulti foreach { it => codeToName(it._1) = it._2.iterator.next() }
val nameToCode = codeToName map { _.swap }
codeToNameMulti foreach {
it => codeToName(it._1) = it._2.iterator.next()
}
val nameToCode = codeToName map {
_.swap
}

def encode(methodName: String): Int = nameToCode.getOrElse(methodName, throw new NoSuchMethodException("Method: " + methodName))

Expand All @@ -34,6 +47,8 @@ class SimpleMethodLookup(val methods: java.util.List[String]) extends MethodLook
}

object SimpleMethodLookup {
def apply(s: Service): SimpleMethodLookup = { new SimpleMethodLookup(Util.extractMethodNames(s)) }
def apply(s: Service): SimpleMethodLookup = {
new SimpleMethodLookup(Util.extractMethodNames(s))
}
}

Loading