Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/facebookarchive/nifty
Thrift on Netty
https://github.com/facebookarchive/nifty
Last synced: 3 days ago
JSON representation
Thrift on Netty
- Host: GitHub
- URL: https://github.com/facebookarchive/nifty
- Owner: facebookarchive
- License: apache-2.0
- Archived: true
- Created: 2012-05-11T18:20:14.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2018-05-16T19:04:25.000Z (about 6 years ago)
- Last Synced: 2024-06-19T19:38:12.824Z (6 days ago)
- Language: Java
- Size: 981 KB
- Stars: 897
- Watchers: 179
- Forks: 322
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- License: LICENSE.txt
Lists
- awesome-java - Nifty - Implementation of Thrift clients and servers on Netty. (Projects / Networking)
README
# Project Status: 🚨 Unmaintained 🚨
This project is archived and no longer maintained. At the time of archiving,
open issues and pull requests were closed and tagged with `2018-05-archive`.
For pre-existing users who need an open source alternative, we recommend taking
a look at [airlift/drift](https://github.com/airlift/drift).# Nifty
Nifty is an implementation of [Thrift](http://thrift.apache.org/) clients and servers on [Netty](http://netty.io/).
It is also the implementation used by [Swift](https://github.com/facebook/swift).
# Examples
To create a basic Thrift server using Nifty, use the [Thrift 0.9.0](https://dist.apache.org/repos/dist/release/thrift/0.9.0/thrift-0.9.0.tar.gz) code generator to generate Java stub code, write a Handler for your service interface, and pass it to Nifty like this:
public void startServer() {
// Create the handler
MyService.Iface serviceInterface = new MyServiceHandler();// Create the processor
TProcessor processor = new MyService.Processor<>(serviceInterface);// Build the server definition
ThriftServerDef serverDef = new ThriftServerDefBuilder().withProcessor(processor)
.build();// Create the server transport
final NettyServerTransport server = new NettyServerTransport(serverDef,
new NettyServerConfigBuilder(),
new DefaultChannelGroup(),
new HashedWheelTimer());// Create netty boss and executor thread pools
ExecutorService bossExecutor = Executors.newCachedThreadPool();
ExecutorService workerExecutor = Executors.newCachedThreadPool();// Start the server
server.start(bossExecutor, workerExecutor);// Arrange to stop the server at shutdown
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
try {
server.stop();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
});
}Or the same thing using guice:
public void startGuiceServer() {
final NiftyBootstrap bootstrap = Guice.createInjector(
Stage.PRODUCTION,
new NiftyModule() {
@Override
protected void configureNifty() {
// Create the handler
MyService.Iface serviceInterface = new MyServiceHandler();// Create the processor
TProcessor processor = new MyService.Processor<>(serviceInterface);// Build the server definition
ThriftServerDef serverDef = new ThriftServerDefBuilder().withProcessor(processor)
.build();// Bind the definition
bind().toInstance(serverDef);
}
}).getInstance(NiftyBootstrap.class);// Start the server
bootstrap.start();// Arrange to stop the server at shutdown
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
bootstrap.stop();
}
});
}