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
Chunyan Song
committed
Apr 5, 2013
1 parent
3243e1d
commit ccc831f
Showing
9 changed files
with
104 additions
and
70 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import java.net.InetSocketAddress | ||
import com.twitter.util.Future | ||
import java.util.concurrent.atomic.AtomicInteger | ||
import com.twitter.mydemo.renamed.{User, UserService} | ||
import com.twitter.finagle.thrift.{ThriftServerFramedCodec, ThriftClientFramedCodec, ThriftClientRequest} | ||
import com.twitter.finagle.builder.{ServerBuilder, ClientBuilder} | ||
import org.apache.thrift.protocol.TBinaryProtocol | ||
|
||
|
||
object DemoServer { | ||
private val userIdCounter: AtomicInteger = new AtomicInteger(0) | ||
|
||
// need to provide an implementation for the finagle service | ||
class MyUserImpl extends UserService.FutureIface { | ||
def createUser(name: String): Future[User] = { | ||
val id = userIdCounter.incrementAndGet() | ||
Future.value(User(id, name)) | ||
} | ||
} | ||
|
||
def buildServer() = { | ||
val protocol = new TBinaryProtocol.Factory() | ||
val serverService = new UserService.FinagledService(new MyUserImpl, protocol) | ||
ServerBuilder() | ||
.codec(ThriftServerFramedCodec()) | ||
.name("binary_service") | ||
.bindTo(new InetSocketAddress(0)) | ||
.build(serverService) | ||
} | ||
} |
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
41 changes: 41 additions & 0 deletions
41
scrooge-maven-plugin/demo/src/main/scala/com/twitter/example/Demo.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,41 @@ | ||
package com.twitter.example | ||
import com.twitter.mydemo.renamed.{User, UserService} | ||
import com.twitter.finagle.thrift.{ThriftServerFramedCodec, ThriftClientFramedCodec, ThriftClientRequest} | ||
import com.twitter.finagle.builder.{ServerBuilder, ClientBuilder} | ||
import org.apache.thrift.protocol.TBinaryProtocol | ||
import java.net.{SocketAddress, InetSocketAddress} | ||
import com.twitter.util.Future | ||
import java.util.concurrent.atomic.AtomicInteger | ||
|
||
object DemoClient { | ||
def buildClient(address: SocketAddress) = { | ||
val clientService = ClientBuilder() | ||
.hosts(Seq(address)) | ||
.codec(ThriftClientFramedCodec()) | ||
.hostConnectionLimit(1) | ||
.build() | ||
new UserService.FinagledClient(clientService) | ||
} | ||
} | ||
|
||
object DemoServer { | ||
private val userIdCounter: AtomicInteger = new AtomicInteger(0) | ||
|
||
// need to provide an implementation for the finagle service | ||
class MyUserImpl extends UserService.FutureIface { | ||
def createUser(name: String): Future[User] = { | ||
val id = userIdCounter.incrementAndGet() | ||
Future.value(User(id, name)) | ||
} | ||
} | ||
|
||
def buildServer() = { | ||
val protocol = new TBinaryProtocol.Factory() | ||
val serverService = new UserService.FinagledService(new MyUserImpl, protocol) | ||
ServerBuilder() | ||
.codec(ThriftServerFramedCodec()) | ||
.name("binary_service") | ||
.bindTo(new InetSocketAddress(0)) | ||
.build(serverService) | ||
} | ||
} |
10 changes: 0 additions & 10 deletions
10
scrooge-maven-plugin/demo/src/main/scala/com/twitter/example/Foo.scala
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 @@ | ||
namespace java com.twitter.demo | ||
|
||
struct User { | ||
1: i64 id | ||
2: string name | ||
} | ||
|
||
service UserService { | ||
User createUser(1: string name) | ||
} | ||
|
This file was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
scrooge-maven-plugin/demo/src/test/scala/com/twitter/example/DemoSpec.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,18 @@ | ||
package com.twitter.example | ||
|
||
import org.specs.SpecificationWithJUnit | ||
import com.twitter.mydemo.renamed.User | ||
|
||
class DemoSpec extends SpecificationWithJUnit { | ||
def printUser(user: User) {println("User %s, id %d".format(user.name, user.id))} | ||
|
||
"generated finagle service" should { | ||
"server and client" in { | ||
val server = DemoServer.buildServer() | ||
val client = DemoClient.buildClient(server.localAddress) | ||
client.createUser("Tyrion")().name mustEqual("Tyrion") | ||
client.createUser("Jon")().name mustEqual("Jon") | ||
} | ||
} | ||
} | ||
|
21 changes: 0 additions & 21 deletions
21
scrooge-maven-plugin/demo/src/test/scala/com/twitter/example/FooSpec.scala
This file was deleted.
Oops, something went wrong.