forked from cgbystrom/netty-tools
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
1 parent
ace673e
commit aeebb3d
Showing
10 changed files
with
1,863 additions
and
1 deletion.
There are no files selected for viewing
Binary file not shown.
10 changes: 10 additions & 0 deletions
10
embedded-repo/org/apache/thrift/thrift/0.4.0/thrift-0.4.0.jar.lastUpdated
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,10 @@ | ||
#NOTE: This is an internal implementation file, its format can be changed without prior notice. | ||
#Wed Jan 12 12:04:21 IST 2011 | ||
file\:///home/arvindj/oss/netty-tools-a/embedded-repo/.lastUpdated=1294814059871 | ||
http\://repository.jboss.org/maven2/.lastUpdated=1294814059867 | ||
http\://download.java.net/maven/2/.lastUpdated=1294814060528 | ||
http\://repo1.maven.org/maven2/.error= | ||
http\://repository.jboss.org/maven2/.error= | ||
http\://repo1.maven.org/maven2/.lastUpdated=1294814061111 | ||
file\:///home/arvindj/oss/netty-tools-a/embedded-repo/.error= | ||
http\://download.java.net/maven/2/.error= |
10 changes: 10 additions & 0 deletions
10
embedded-repo/org/apache/thrift/thrift/0.4.0/thrift-0.4.0.pom.lastUpdated
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,10 @@ | ||
#NOTE: This is an internal implementation file, its format can be changed without prior notice. | ||
#Wed Jan 12 12:04:18 IST 2011 | ||
file\:///home/arvindj/oss/netty-tools-a/embedded-repo/.lastUpdated=1294814057186 | ||
http\://repository.jboss.org/maven2/.lastUpdated=1294814057181 | ||
http\://download.java.net/maven/2/.lastUpdated=1294814058172 | ||
http\://repo1.maven.org/maven2/.error= | ||
http\://repository.jboss.org/maven2/.error= | ||
http\://repo1.maven.org/maven2/.lastUpdated=1294814058918 | ||
file\:///home/arvindj/oss/netty-tools-a/embedded-repo/.error= | ||
http\://download.java.net/maven/2/.error= |
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,46 @@ | ||
package random.pkg.client; | ||
import static org.testng.Assert.assertEquals; | ||
|
||
import org.apache.thrift.TException; | ||
import org.apache.thrift.protocol.TBinaryProtocol; | ||
import org.apache.thrift.protocol.TProtocol; | ||
import org.apache.thrift.transport.THttpClient; | ||
import org.apache.thrift.transport.TTransport; | ||
import org.apache.thrift.transport.TTransportException; | ||
import org.testng.annotations.AfterTest; | ||
import org.testng.annotations.BeforeTest; | ||
import org.testng.annotations.Test; | ||
|
||
import random.pkg.service.MathServ; | ||
|
||
public class SimpleHttpClient { | ||
TTransport transport; | ||
MathServ.Client client; | ||
|
||
@BeforeTest | ||
private void setup() { | ||
try { | ||
transport = new THttpClient("http://localhost:9981"); | ||
TProtocol protocol = new TBinaryProtocol(transport); | ||
client = new MathServ.Client(protocol); | ||
transport.open(); | ||
} catch (TTransportException e) { | ||
e.printStackTrace(); | ||
} catch (TException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
@AfterTest | ||
void tearDown() | ||
{ | ||
transport.close(); | ||
} | ||
|
||
@Test | ||
public void a() throws TException { | ||
long x = 2239, y =21; | ||
long a = client.add(x ,y); | ||
assertEquals(a, x+y); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/examples/java/random/pkg/client/SimpleSocketClient.java
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 random.pkg.client; | ||
import static org.testng.Assert.assertEquals; | ||
|
||
import org.apache.thrift.TException; | ||
import org.apache.thrift.protocol.TBinaryProtocol; | ||
import org.apache.thrift.protocol.TProtocol; | ||
import org.apache.thrift.transport.TSocket; | ||
import org.apache.thrift.transport.TTransport; | ||
import org.apache.thrift.transport.TTransportException; | ||
import org.testng.annotations.AfterTest; | ||
import org.testng.annotations.BeforeTest; | ||
import org.testng.annotations.Test; | ||
import org.testng.log4testng.Logger; | ||
|
||
import random.pkg.service.MathServ; | ||
|
||
public class SimpleSocketClient { | ||
TTransport transport; | ||
MathServ.Client client; | ||
private static final Logger LOGGER = Logger.getLogger(SimpleSocketClient.class); | ||
|
||
|
||
@BeforeTest | ||
private void setup() { | ||
try { | ||
transport = new TSocket("localhost", 7911); | ||
TProtocol protocol = new TBinaryProtocol(transport); | ||
client = new MathServ.Client(protocol); | ||
transport.open(); | ||
} catch (TTransportException e) { | ||
e.printStackTrace(); | ||
} catch (TException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
@AfterTest | ||
void tearDown() | ||
{ | ||
transport.close(); | ||
} | ||
|
||
@Test | ||
public void a() throws TException { | ||
long x = 2239, y =21; | ||
long a = client.add(x ,y); | ||
LOGGER.fatal(a); | ||
assertEquals(a, x+y); | ||
} | ||
} |
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 random.pkg.server; | ||
import java.net.InetSocketAddress; | ||
import java.util.concurrent.Executors; | ||
|
||
import org.jboss.netty.bootstrap.ServerBootstrap; | ||
import org.jboss.netty.channel.ChannelPipelineFactory; | ||
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; | ||
|
||
import random.pkg.service.MathServ; | ||
import random.pkg.service.MathServImpl; | ||
import se.cgbystrom.netty.thrift.ThriftPipelineFactory; | ||
import se.cgbystrom.netty.thrift.ThriftServerHandler; | ||
import se.cgbystrom.netty.thrift.http.ThriftHttpServerPipelineFactory; | ||
|
||
|
||
public class NtMultiServer { | ||
ThriftServerHandler x = null; | ||
|
||
private synchronized ThriftServerHandler getTHandler() | ||
{ | ||
if( x == null) | ||
{ | ||
x = new ThriftServerHandler(new MathServ.Processor( new MathServImpl())); | ||
} | ||
return x; | ||
} | ||
|
||
private void framedSocketServer() { | ||
ChannelPipelineFactory factory = new ThriftPipelineFactory(getTHandler()); | ||
ServerBootstrap bootstrap = new ServerBootstrap( | ||
new NioServerSocketChannelFactory( | ||
Executors.newCachedThreadPool(), | ||
Executors.newCachedThreadPool(), | ||
1)); | ||
|
||
bootstrap.setPipelineFactory(factory); | ||
|
||
bootstrap.bind(new InetSocketAddress(7912)); | ||
} | ||
|
||
private void httpServer() { | ||
ChannelPipelineFactory factory = new ThriftHttpServerPipelineFactory(getTHandler()); | ||
ServerBootstrap bootstrap = new ServerBootstrap( | ||
new NioServerSocketChannelFactory( | ||
Executors.newCachedThreadPool(), | ||
Executors.newCachedThreadPool(), | ||
1)); | ||
|
||
bootstrap.setPipelineFactory(factory); | ||
|
||
bootstrap.bind(new InetSocketAddress(9981)); | ||
} | ||
|
||
public static void main(String args[]) { | ||
NtMultiServer srv = new NtMultiServer(); | ||
|
||
srv.framedSocketServer(); | ||
srv.httpServer(); | ||
} | ||
} |
Oops, something went wrong.