-
Notifications
You must be signed in to change notification settings - Fork 244
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
Jeremy Cloud
committed
Aug 15, 2011
1 parent
6fee6f7
commit 10fba50
Showing
34 changed files
with
503 additions
and
361 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
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 |
---|---|---|
|
@@ -6,4 +6,4 @@ object Constants { | |
val {{name}}: {{type}} = {{value}} | ||
{{/constants}} | ||
} | ||
{{/hasConstants}} | ||
{{/hasConstants}} |
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 |
---|---|---|
|
@@ -24,4 +24,4 @@ object {{enum}} { | |
|
||
abstract class {{enum}}(val value: Int) extends TEnum { | ||
def getValue = value | ||
} | ||
} |
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,15 @@ | ||
// ----- finagle client | ||
|
||
import com.twitter.finagle.{Service => FinagleService} | ||
import com.twitter.finagle.thrift.ThriftClientRequest | ||
import com.twitter.scrooge.FinagleThriftClient | ||
|
||
class FinagledClient( | ||
val service: FinagleService[ThriftClientRequest, Array[Byte]], | ||
val protocolFactory: TProtocolFactory) | ||
extends FinagleThriftClient with FutureIface | ||
{ | ||
{{#functions}} | ||
{{function}} | ||
{{/function}} | ||
} |
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,7 @@ | ||
{{functionDecl}} = { | ||
encodeRequest("{{name}}", {{name}}_args({{argNames}})) flatMap { this.service } flatMap { | ||
decodeResponse(_, {{name}}_result.decoder) | ||
} flatMap { result => | ||
{{resultUnwrapper}} | ||
} | ||
} |
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,13 @@ | ||
// ----- finagle service | ||
|
||
import com.twitter.scrooge.FinagleThriftService | ||
|
||
class FinagledService( | ||
iface: FutureIface, | ||
val protocolFactory: TProtocolFactory) | ||
extends FinagleThriftService | ||
{ | ||
{{#functions}} | ||
{{function}} | ||
{{/function}} | ||
} |
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,26 @@ | ||
functionMap("{{name}}") = { (iprot: TProtocol, seqid: Int) => | ||
try { | ||
val args = {{name}}_args.decoder(iprot) | ||
iprot.readMessageEnd() | ||
(try { | ||
iface.{{name}}({{argNames}}) | ||
} catch { | ||
case e: Exception => Future.exception(e) | ||
}) flatMap { value: {{scalaType}} => | ||
reply("{{name}}", seqid, {{name}}_result({{resultNamedArg}})) | ||
} rescue { | ||
{{#exceptions}} | ||
case e: {{exceptionType}} => | ||
reply("{{name}}", seqid, {{name}}_result({{fieldName}} = Some(e))) | ||
{{/exception}} | ||
case e: Throwable => | ||
exception("{{name}}", seqid, TApplicationException.INTERNAL_ERROR, "Internal error processing {{name}}") | ||
} | ||
} catch { | ||
case e: TProtocolException => | ||
iprot.readMessageEnd() | ||
exception("{{name}}", seqid, TApplicationException.PROTOCOL_ERROR, e.getMessage) | ||
case e: Exception => | ||
Future.exception(e) | ||
} | ||
} |
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,3 @@ | ||
{{#throws}} | ||
@throws(classOf[{{scalaType}}]) | ||
{{/throws}}def {{name}}({{fieldArgs}}): {{scalaType}} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// ----- ostrich service | ||
|
||
import com.twitter.finagle.builder.{Server, ServerBuilder} | ||
import com.twitter.finagle.stats.OstrichStatsReceiver | ||
import com.twitter.finagle.thrift.ThriftServerFramedCodec | ||
import com.twitter.logging.Logger | ||
import com.twitter.ostrich.admin.Service | ||
|
||
trait ThriftServer extends Service with FutureIface { | ||
val log = Logger.get(getClass) | ||
|
||
def thriftCodec = ThriftServerFramedCodec() | ||
val thriftProtocolFactory = new TBinaryProtocol.Factory() | ||
val thriftPort: Int | ||
val serverName: String | ||
|
||
var server: Server = null | ||
|
||
def start() { | ||
val thriftImpl = new FinagledService(this, thriftProtocolFactory) | ||
val serverAddr = new InetSocketAddress(thriftPort) | ||
server = ServerBuilder().codec(thriftCodec).name(serverName).reportTo(new OstrichStatsReceiver).bindTo(serverAddr).build(thriftImpl) | ||
} | ||
|
||
def shutdown() { | ||
synchronized { | ||
if (server != null) { | ||
server.close(0.seconds) | ||
} | ||
} | ||
} | ||
} |
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 @@ | ||
_iprot.{{protocolReadMethod}}() |
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 @@ | ||
{{name}}(_iprot.readI32()) |
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,11 @@ | ||
case {{id}} => { /* {{name}} */ | ||
_field.`type` match { | ||
case TType.{{constType}} => { | ||
{{name}} = {{optionality}}{ | ||
{{valueReader}} | ||
} | ||
{{#required}}_got_{{name}} = true{{/required}} | ||
} | ||
case _ => TProtocolUtil.skip(_iprot, _field.`type`) | ||
} | ||
} |
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,11 @@ | ||
val _list = _iprot.readListBegin() | ||
val _rv = new mutable.ArrayBuffer[{{eltType}}](_list.size) | ||
var _i = 0 | ||
while (_i < _list.size) { | ||
_rv += { | ||
{{eltReader}} | ||
} | ||
_i += 1 | ||
} | ||
_iprot.readListEnd() | ||
_rv.toSeq |
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,15 @@ | ||
val _map = _iprot.readMapBegin() | ||
val _rv = new mutable.HashMap[{{keyType}}, {{valueType}}] | ||
var _i = 0 | ||
while (_i < _map.size) { | ||
val _key = { | ||
{{keyReader}} | ||
} | ||
val _value = { | ||
{{valueReader}} | ||
} | ||
_rv(_key) = _value | ||
_i += 1 | ||
} | ||
_iprot.readMapEnd() | ||
_rv |
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,11 @@ | ||
val _set = _iprot.readSetBegin() | ||
val _rv = new mutable.HashSet[{{eltType}}] | ||
var _i = 0 | ||
while (_i < _set.size) { | ||
_rv += { | ||
{{eltReader}} | ||
} | ||
_i += 1 | ||
} | ||
_iprot.readSetEnd() | ||
_rv |
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 @@ | ||
{{name}}.decoder(_iprot) |
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,21 @@ | ||
object {{name}} { | ||
trait Iface {{extends}}{ | ||
{{#syncFunctions}} | ||
{{> function}} | ||
{{/syncFunctions}} | ||
} | ||
|
||
trait FutureIface {{extends}}{ | ||
{{#asyncFunctions}} | ||
{{> function}} | ||
{{/asyncFunctions}} | ||
} | ||
|
||
{{#functionStructs}} | ||
{{> struct}} | ||
{{/functionStructs}} | ||
|
||
{{finagleClient}} | ||
{{finagleService}} | ||
{{ostrichServer}} | ||
} |
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,55 @@ | ||
object {{name}} { | ||
private val STRUCT_DESC = new TStruct("{{name}}") | ||
{{#fields}} | ||
private val {{fieldConst}} = new TField("{{name}}", TType.{{constType}}, {{id}}) | ||
{{/fields}} | ||
|
||
object decoder extends (TProtocol => {{name}}) { | ||
override def apply(_iprot: TProtocol) = { | ||
var _field: TField = null | ||
{{#fields}} | ||
var {{name}}: {{scalaType}} = {{defaultValue}} | ||
{{#required}}var _got_{{name}} = false{{/required}} | ||
{{/fields}} | ||
var _done = false | ||
_iprot.readStructBegin() | ||
while (!_done) { | ||
_field = _iprot.readFieldBegin | ||
if (_field.`type` == TType.STOP) { | ||
_done = true | ||
} else { | ||
_field.id match { | ||
{{#fields}} | ||
{{reader}} | ||
{{/fields}} | ||
case _ => TProtocolUtil.skip(_iprot, _field.`type`) | ||
} | ||
_iprot.readFieldEnd() | ||
} | ||
} | ||
_iprot.readStructEnd() | ||
{{#fields}} | ||
{{#required}} | ||
if (!_got_{{name}}) throw new TProtocolException("Required field '{{name}}' was not found in serialized data for struct {{struct}}") | ||
{{/required}} | ||
{{/fields}} | ||
{{name}}({{fieldNames}}) | ||
} | ||
} | ||
} | ||
|
||
case class {{name}}({{fieldArgs}}) extends {{parentType}} { | ||
import {{name}}._ | ||
|
||
override def write(_oprot: TProtocol) { | ||
validate() | ||
_oprot.writeStructBegin(STRUCT_DESC) | ||
{{#fields}} | ||
{{writer}} | ||
{{/fields}} | ||
_oprot.writeFieldStop() | ||
_oprot.writeStructEnd() | ||
} | ||
|
||
def validate() = true //TODO: Implement this | ||
} |
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 @@ | ||
_oprot.{{protocolWriteMethod}}(_item) |
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 @@ | ||
_oprot.writeI32(_item.value) |
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,6 @@ | ||
if ({{conditional}}) { | ||
val _item = {{name}}{{getter}} | ||
_oprot.writeFieldBegin({{fieldConst}}) | ||
{{valueWriter}} | ||
_oprot.writeFieldEnd() | ||
} |
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,5 @@ | ||
_oprot.writeListBegin(new TList(TType.{{eltType}}, _item.size)) | ||
_item.foreach { _item => | ||
{{eltWriter}} | ||
} | ||
_oprot.writeListEnd() |
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,12 @@ | ||
_oprot.writeMapBegin(new TMap(TType.{{keyType}}, TType.{{valueType}}, _item.size)) | ||
_item.foreach { case (_key, _value) => | ||
{ | ||
val _item = _key | ||
{{keyWriter}} | ||
} | ||
{ | ||
val _item = _value | ||
{{valueWriter}} | ||
} | ||
} | ||
_oprot.writeMapEnd() |
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,5 @@ | ||
_oprot.writeSetBegin(new TSet(TType.{{eltType}}, _item.size)) | ||
_item.foreach { _item => | ||
{{eltWriter}} | ||
} | ||
_oprot.writeSetEnd() |
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 @@ | ||
_item.write(_oprot) |
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
Oops, something went wrong.