Skip to content
This repository has been archived by the owner on May 6, 2020. It is now read-only.

Some examples #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Binary file not shown.
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=
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=
19 changes: 15 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>se.cgbystrom.netty</groupId>
<artifactId>netty-tools</artifactId>
<version>1.2.0</version>
<version>1.2.1</version>
<description>
A small collection of tools useful when working with JBoss Netty.
</description>
Expand All @@ -23,13 +23,13 @@
<dependency>
<groupId>org.jboss.netty</groupId>
<artifactId>netty</artifactId>
<version>3.2.0.BETA1</version>
<version>3.2.3.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.thrift</groupId>
<artifactId>thrift</artifactId>
<version>2009-08-26</version>
<version>0.4.0</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand All @@ -44,6 +44,17 @@
<version>3.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>[5.12.1,6.0.0)</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.1</version>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -73,7 +84,7 @@
<repositories>
<repository>
<id>repository.jboss.org</id>
<url>http://repository.jboss.org/maven2</url>
<url>http://repository.jboss.org/nexus/content/groups/public/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
Expand Down
46 changes: 46 additions & 0 deletions src/examples/java/random/pkg/client/SimpleHttpClient.java
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 src/examples/java/random/pkg/client/SimpleSocketClient.java
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);
}
}
60 changes: 60 additions & 0 deletions src/examples/java/random/pkg/server/NtMultiServer.java
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();
}
}
Loading