-
Notifications
You must be signed in to change notification settings - Fork 0
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
fddcbbc
commit a5ccef8
Showing
127 changed files
with
4,895 additions
and
13 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
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
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
6 changes: 6 additions & 0 deletions
6
EchoServer/src/main/java/com/plort/polarlights/raincloud/Server.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,6 @@ | ||
package com.plort.polarlights.raincloud; | ||
|
||
public interface Server { | ||
|
||
void start() throws Exception; | ||
} |
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
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,9 @@ | ||
target | ||
bin | ||
.settings | ||
.project | ||
.classpath | ||
.idea | ||
.DS_Store | ||
*.iml | ||
/.idea |
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 @@ | ||
This Repository contains the source-code for all chapters of the book [Netty in Action](http://manning.com/maurer) | ||
by Norman Maurer and Marvin Allen Wolfthal. | ||
|
||
Latest version: https://github.com/normanmaurer/netty-in-action/tree/2.0-SNAPSHOT | ||
|
||
Enjoy! Feedback and PR's welcome! | ||
|
||
|
||
Prerequisites | ||
|
||
JDK 1.7.0u71 or better | ||
|
||
Maven 3.3.9 or better | ||
|
||
|
||
If you want to build everything at once, from the top directory run | ||
|
||
mvn install | ||
|
||
|
||
If you want to build only single projects then from the top directory first run | ||
|
||
mvn install -pl utils | ||
|
||
|
||
This will make the utils jar available to all the projects. |
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 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>nia</groupId> | ||
<artifactId>nia-samples-parent</artifactId> | ||
<version>2.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>chapter1</artifactId> | ||
<version>2.0-SNAPSHOT</version> | ||
|
||
<packaging>jar</packaging> | ||
<name>Chapter 1. Netty—asynchronous and event-driven</name> | ||
<description> | ||
Build an Echo Server and Client | ||
</description> | ||
</project> |
40 changes: 40 additions & 0 deletions
40
相关资料/netty-in-action-2.0-SNAPSHOT/chapter1/src/main/java/nia/chapter1/BlockingIoExample.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,40 @@ | ||
package nia.chapter1; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.io.PrintWriter; | ||
import java.net.ServerSocket; | ||
import java.net.Socket; | ||
|
||
/** | ||
* Created by kerr. | ||
* | ||
* Listing 1.1 Blocking I/O example | ||
*/ | ||
public class BlockingIoExample { | ||
|
||
/** | ||
* Listing 1.1 Blocking I/O example | ||
* */ | ||
public void serve(int portNumber) throws IOException { | ||
ServerSocket serverSocket = new ServerSocket(portNumber); | ||
Socket clientSocket = serverSocket.accept(); | ||
BufferedReader in = new BufferedReader( | ||
new InputStreamReader(clientSocket.getInputStream())); | ||
PrintWriter out = | ||
new PrintWriter(clientSocket.getOutputStream(), true); | ||
String request, response; | ||
while ((request = in.readLine()) != null) { | ||
if ("Done".equals(request)) { | ||
break; | ||
} | ||
response = processRequest(request); | ||
out.println(response); | ||
} | ||
} | ||
|
||
private String processRequest(String request){ | ||
return "Processed"; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
相关资料/netty-in-action-2.0-SNAPSHOT/chapter1/src/main/java/nia/chapter1/ConnectExample.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 nia.chapter1; | ||
|
||
import io.netty.buffer.ByteBuf; | ||
import io.netty.buffer.Unpooled; | ||
import io.netty.channel.Channel; | ||
import io.netty.channel.ChannelFuture; | ||
import io.netty.channel.ChannelFutureListener; | ||
import io.netty.channel.socket.nio.NioSocketChannel; | ||
|
||
import java.net.InetSocketAddress; | ||
import java.nio.charset.Charset; | ||
|
||
/** | ||
* Created by kerr. | ||
* | ||
* Listing 1.3 Asynchronous connect | ||
* | ||
* Listing 1.4 Callback in action | ||
*/ | ||
public class ConnectExample { | ||
private static final Channel CHANNEL_FROM_SOMEWHERE = new NioSocketChannel(); | ||
|
||
/** | ||
* Listing 1.3 Asynchronous connect | ||
* | ||
* Listing 1.4 Callback in action | ||
* */ | ||
public static void connect() { | ||
Channel channel = CHANNEL_FROM_SOMEWHERE; //reference form somewhere | ||
// Does not block | ||
ChannelFuture future = channel.connect( | ||
new InetSocketAddress("192.168.0.1", 25)); | ||
future.addListener(new ChannelFutureListener() { | ||
@Override | ||
public void operationComplete(ChannelFuture future) { | ||
if (future.isSuccess()) { | ||
ByteBuf buffer = Unpooled.copiedBuffer( | ||
"Hello", Charset.defaultCharset()); | ||
ChannelFuture wf = future.channel() | ||
.writeAndFlush(buffer); | ||
// ... | ||
} else { | ||
Throwable cause = future.cause(); | ||
cause.printStackTrace(); | ||
} | ||
} | ||
}); | ||
|
||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
相关资料/netty-in-action-2.0-SNAPSHOT/chapter1/src/main/java/nia/chapter1/ConnectHandler.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,18 @@ | ||
package nia.chapter1; | ||
|
||
import io.netty.channel.ChannelHandlerContext; | ||
import io.netty.channel.ChannelInboundHandlerAdapter; | ||
|
||
/** | ||
* Created by kerr. | ||
* | ||
* Listing 1.2 ChannelHandler triggered by a callback | ||
*/ | ||
public class ConnectHandler extends ChannelInboundHandlerAdapter { | ||
@Override | ||
public void channelActive(ChannelHandlerContext ctx) | ||
throws Exception { | ||
System.out.println( | ||
"Client " + ctx.channel().remoteAddress() + " connected"); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
相关资料/netty-in-action-2.0-SNAPSHOT/chapter1/src/main/java/nia/chapter1/package-info.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,12 @@ | ||
/** | ||
* kerr. | ||
* | ||
* Listing 1.1 Blocking I/O example {@link nia.chapter1.BlockingIoExample#serve(int)} | ||
* | ||
* Listing 1.2 ChannelHandler triggered by a callback {@link nia.chapter1.ConnectHandler} | ||
* | ||
* Listing 1.3 Asynchronous connect {@link nia.chapter1.ConnectExample#connect()} | ||
* | ||
* Listing 1.4 Callback in action {@link nia.chapter1.ConnectExample#connect()} | ||
*/ | ||
package nia.chapter1; |
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 @@ | ||
<?xml version="1.0" encoding="ISO-8859-15"?> | ||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>nia</groupId> | ||
<artifactId>nia-samples-parent</artifactId> | ||
<version>2.0-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
|
||
<artifactId>chapter10</artifactId> | ||
<name>Chapter 10: The codec framework</name> | ||
<description>An overview of decoders, encoders and codecs</description> | ||
</project> |
23 changes: 23 additions & 0 deletions
23
...netty-in-action-2.0-SNAPSHOT/chapter10/src/main/java/nia/chapter10/ByteToCharDecoder.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,23 @@ | ||
package nia.chapter10; | ||
|
||
import io.netty.buffer.ByteBuf; | ||
import io.netty.channel.ChannelHandlerContext; | ||
import io.netty.handler.codec.ByteToMessageDecoder; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Listing 10.8 Class ByteToCharDecoder | ||
* | ||
* @author <a href="mailto:norman.maurer@gmail.com">Norman Maurer</a> | ||
*/ | ||
public class ByteToCharDecoder extends ByteToMessageDecoder { | ||
@Override | ||
public void decode(ChannelHandlerContext ctx, ByteBuf in, | ||
List<Object> out) throws Exception { | ||
if (in.readableBytes() >= 2) { | ||
out.add(in.readChar()); | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.