More logging
This commit is contained in:
parent
a20ab9184e
commit
a682b018b2
@ -24,12 +24,17 @@ import io.netty.channel.ChannelPipeline;
|
|||||||
import io.netty.channel.ChannelPipelineFactory;
|
import io.netty.channel.ChannelPipelineFactory;
|
||||||
import io.netty.channel.Channels;
|
import io.netty.channel.Channels;
|
||||||
import io.netty.channel.socket.nio.NioClientSocketChannelFactory;
|
import io.netty.channel.socket.nio.NioClientSocketChannelFactory;
|
||||||
|
import io.netty.logging.InternalLogger;
|
||||||
|
import io.netty.logging.InternalLoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Keeps sending random data to the specified address.
|
* Keeps sending random data to the specified address.
|
||||||
*/
|
*/
|
||||||
public class DiscardClient {
|
public class DiscardClient {
|
||||||
|
|
||||||
|
private static final InternalLogger logger =
|
||||||
|
InternalLoggerFactory.getInstance(DiscardClient.class);
|
||||||
|
|
||||||
private final String host;
|
private final String host;
|
||||||
private final int port;
|
private final int port;
|
||||||
private final int firstMessageSize;
|
private final int firstMessageSize;
|
||||||
@ -67,7 +72,7 @@ public class DiscardClient {
|
|||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
// Print usage if no argument is specified.
|
// Print usage if no argument is specified.
|
||||||
if (args.length < 2 || args.length > 3) {
|
if (args.length < 2 || args.length > 3) {
|
||||||
System.err.println(
|
logger.error(
|
||||||
"Usage: " + DiscardClient.class.getSimpleName() +
|
"Usage: " + DiscardClient.class.getSimpleName() +
|
||||||
" <host> <port> [<first message size>]");
|
" <host> <port> [<first message size>]");
|
||||||
return;
|
return;
|
||||||
|
@ -24,6 +24,8 @@ import io.netty.channel.ChannelPipeline;
|
|||||||
import io.netty.channel.ChannelPipelineFactory;
|
import io.netty.channel.ChannelPipelineFactory;
|
||||||
import io.netty.channel.Channels;
|
import io.netty.channel.Channels;
|
||||||
import io.netty.channel.socket.nio.NioClientSocketChannelFactory;
|
import io.netty.channel.socket.nio.NioClientSocketChannelFactory;
|
||||||
|
import io.netty.logging.InternalLogger;
|
||||||
|
import io.netty.logging.InternalLoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends one message when a connection is open and echoes back any received
|
* Sends one message when a connection is open and echoes back any received
|
||||||
@ -33,6 +35,9 @@ import io.netty.channel.socket.nio.NioClientSocketChannelFactory;
|
|||||||
*/
|
*/
|
||||||
public class EchoClient {
|
public class EchoClient {
|
||||||
|
|
||||||
|
private static final InternalLogger logger =
|
||||||
|
InternalLoggerFactory.getInstance(EchoClient.class);
|
||||||
|
|
||||||
private final String host;
|
private final String host;
|
||||||
private final int port;
|
private final int port;
|
||||||
private final int firstMessageSize;
|
private final int firstMessageSize;
|
||||||
@ -70,7 +75,7 @@ public class EchoClient {
|
|||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
// Print usage if no argument is specified.
|
// Print usage if no argument is specified.
|
||||||
if (args.length < 2 || args.length > 3) {
|
if (args.length < 2 || args.length > 3) {
|
||||||
System.err.println(
|
logger.error(
|
||||||
"Usage: " + EchoClient.class.getSimpleName() +
|
"Usage: " + EchoClient.class.getSimpleName() +
|
||||||
" <host> <port> [<first message size>]");
|
" <host> <port> [<first message size>]");
|
||||||
return;
|
return;
|
||||||
|
@ -22,6 +22,8 @@ import io.netty.bootstrap.ClientBootstrap;
|
|||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelFuture;
|
import io.netty.channel.ChannelFuture;
|
||||||
import io.netty.channel.socket.nio.NioClientSocketChannelFactory;
|
import io.netty.channel.socket.nio.NioClientSocketChannelFactory;
|
||||||
|
import io.netty.logging.InternalLogger;
|
||||||
|
import io.netty.logging.InternalLoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a sequence of integers to a {@link FactorialServer} to calculate
|
* Sends a sequence of integers to a {@link FactorialServer} to calculate
|
||||||
@ -29,6 +31,9 @@ import io.netty.channel.socket.nio.NioClientSocketChannelFactory;
|
|||||||
*/
|
*/
|
||||||
public class FactorialClient {
|
public class FactorialClient {
|
||||||
|
|
||||||
|
private static final InternalLogger logger =
|
||||||
|
InternalLoggerFactory.getInstance(FactorialClient.class);
|
||||||
|
|
||||||
private final String host;
|
private final String host;
|
||||||
private final int port;
|
private final int port;
|
||||||
private final int count;
|
private final int count;
|
||||||
@ -60,8 +65,7 @@ public class FactorialClient {
|
|||||||
(FactorialClientHandler) channel.getPipeline().getLast();
|
(FactorialClientHandler) channel.getPipeline().getLast();
|
||||||
|
|
||||||
// Print out the answer.
|
// Print out the answer.
|
||||||
System.err.format(
|
logger.info(String.format("Factorial of %,d is: %,d", count, handler.getFactorial()));
|
||||||
"Factorial of %,d is: %,d", count, handler.getFactorial());
|
|
||||||
|
|
||||||
// Shut down all thread pools to exit.
|
// Shut down all thread pools to exit.
|
||||||
bootstrap.releaseExternalResources();
|
bootstrap.releaseExternalResources();
|
||||||
@ -70,7 +74,7 @@ public class FactorialClient {
|
|||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
// Print usage if no argument is specified.
|
// Print usage if no argument is specified.
|
||||||
if (args.length != 3) {
|
if (args.length != 3) {
|
||||||
System.err.println(
|
logger.error(
|
||||||
"Usage: " + FactorialClient.class.getSimpleName() +
|
"Usage: " + FactorialClient.class.getSimpleName() +
|
||||||
" <host> <port> <count>");
|
" <host> <port> <count>");
|
||||||
return;
|
return;
|
||||||
|
@ -54,6 +54,8 @@ import io.netty.handler.codec.http.HttpResponse;
|
|||||||
import io.netty.handler.codec.http.HttpResponseStatus;
|
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||||
import io.netty.handler.ssl.SslHandler;
|
import io.netty.handler.ssl.SslHandler;
|
||||||
import io.netty.handler.stream.ChunkedFile;
|
import io.netty.handler.stream.ChunkedFile;
|
||||||
|
import io.netty.logging.InternalLogger;
|
||||||
|
import io.netty.logging.InternalLoggerFactory;
|
||||||
import io.netty.util.CharsetUtil;
|
import io.netty.util.CharsetUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -104,6 +106,9 @@ import io.netty.util.CharsetUtil;
|
|||||||
*/
|
*/
|
||||||
public class HttpStaticFileServerHandler extends SimpleChannelUpstreamHandler {
|
public class HttpStaticFileServerHandler extends SimpleChannelUpstreamHandler {
|
||||||
|
|
||||||
|
private static final InternalLogger logger =
|
||||||
|
InternalLoggerFactory.getInstance(HttpStaticFileServerHandler.class);
|
||||||
|
|
||||||
public static final String HTTP_DATE_FORMAT = "EEE, dd MMM yyyy HH:mm:ss zzz";
|
public static final String HTTP_DATE_FORMAT = "EEE, dd MMM yyyy HH:mm:ss zzz";
|
||||||
public static final String HTTP_DATE_GMT_TIMEZONE = "GMT";
|
public static final String HTTP_DATE_GMT_TIMEZONE = "GMT";
|
||||||
public static final int HTTP_CACHE_SECONDS = 60;
|
public static final int HTTP_CACHE_SECONDS = 60;
|
||||||
@ -188,7 +193,7 @@ public class HttpStaticFileServerHandler extends SimpleChannelUpstreamHandler {
|
|||||||
@Override
|
@Override
|
||||||
public void operationProgressed(
|
public void operationProgressed(
|
||||||
ChannelFuture future, long amount, long current, long total) {
|
ChannelFuture future, long amount, long current, long total) {
|
||||||
System.out.printf("%s: %d / %d (+%d)%n", path, current, total, amount);
|
logger.info(String.format("%s: %d / %d (+%d)%n", path, current, total, amount));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,8 @@ import io.netty.handler.codec.http.HttpHeaders;
|
|||||||
import io.netty.handler.codec.http.HttpMethod;
|
import io.netty.handler.codec.http.HttpMethod;
|
||||||
import io.netty.handler.codec.http.HttpRequest;
|
import io.netty.handler.codec.http.HttpRequest;
|
||||||
import io.netty.handler.codec.http.HttpVersion;
|
import io.netty.handler.codec.http.HttpVersion;
|
||||||
|
import io.netty.logging.InternalLogger;
|
||||||
|
import io.netty.logging.InternalLoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple HTTP client that prints out the content of the HTTP response to
|
* A simple HTTP client that prints out the content of the HTTP response to
|
||||||
@ -36,6 +38,9 @@ import io.netty.handler.codec.http.HttpVersion;
|
|||||||
*/
|
*/
|
||||||
public class HttpSnoopClient {
|
public class HttpSnoopClient {
|
||||||
|
|
||||||
|
private static final InternalLogger logger =
|
||||||
|
InternalLoggerFactory.getInstance(HttpSnoopClient.class);
|
||||||
|
|
||||||
private final URI uri;
|
private final URI uri;
|
||||||
|
|
||||||
public HttpSnoopClient(URI uri) {
|
public HttpSnoopClient(URI uri) {
|
||||||
@ -55,7 +60,7 @@ public class HttpSnoopClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!scheme.equalsIgnoreCase("http") && !scheme.equalsIgnoreCase("https")) {
|
if (!scheme.equalsIgnoreCase("http") && !scheme.equalsIgnoreCase("https")) {
|
||||||
System.err.println("Only HTTP(S) is supported.");
|
logger.error("Only HTTP(S) is supported.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,7 +110,7 @@ public class HttpSnoopClient {
|
|||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
if (args.length != 1) {
|
if (args.length != 1) {
|
||||||
System.err.println(
|
logger.error(
|
||||||
"Usage: " + HttpSnoopClient.class.getSimpleName() +
|
"Usage: " + HttpSnoopClient.class.getSimpleName() +
|
||||||
" <URL>");
|
" <URL>");
|
||||||
return;
|
return;
|
||||||
|
@ -21,10 +21,15 @@ import io.netty.channel.MessageEvent;
|
|||||||
import io.netty.channel.SimpleChannelUpstreamHandler;
|
import io.netty.channel.SimpleChannelUpstreamHandler;
|
||||||
import io.netty.handler.codec.http.HttpChunk;
|
import io.netty.handler.codec.http.HttpChunk;
|
||||||
import io.netty.handler.codec.http.HttpResponse;
|
import io.netty.handler.codec.http.HttpResponse;
|
||||||
|
import io.netty.logging.InternalLogger;
|
||||||
|
import io.netty.logging.InternalLoggerFactory;
|
||||||
import io.netty.util.CharsetUtil;
|
import io.netty.util.CharsetUtil;
|
||||||
|
|
||||||
public class HttpSnoopClientHandler extends SimpleChannelUpstreamHandler {
|
public class HttpSnoopClientHandler extends SimpleChannelUpstreamHandler {
|
||||||
|
|
||||||
|
private static final InternalLogger logger =
|
||||||
|
InternalLoggerFactory.getInstance(HttpSnoopClientHandler.class);
|
||||||
|
|
||||||
private boolean readingChunks;
|
private boolean readingChunks;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -32,38 +37,35 @@ public class HttpSnoopClientHandler extends SimpleChannelUpstreamHandler {
|
|||||||
if (!readingChunks) {
|
if (!readingChunks) {
|
||||||
HttpResponse response = (HttpResponse) e.getMessage();
|
HttpResponse response = (HttpResponse) e.getMessage();
|
||||||
|
|
||||||
System.out.println("STATUS: " + response.getStatus());
|
logger.info("STATUS: " + response.getStatus());
|
||||||
System.out.println("VERSION: " + response.getProtocolVersion());
|
logger.info("VERSION: " + response.getProtocolVersion());
|
||||||
System.out.println();
|
|
||||||
|
|
||||||
if (!response.getHeaderNames().isEmpty()) {
|
if (!response.getHeaderNames().isEmpty()) {
|
||||||
for (String name: response.getHeaderNames()) {
|
for (String name: response.getHeaderNames()) {
|
||||||
for (String value: response.getHeaders(name)) {
|
for (String value: response.getHeaders(name)) {
|
||||||
System.out.println("HEADER: " + name + " = " + value);
|
logger.info("HEADER: " + name + " = " + value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
System.out.println();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.isChunked()) {
|
if (response.isChunked()) {
|
||||||
readingChunks = true;
|
readingChunks = true;
|
||||||
System.out.println("CHUNKED CONTENT {");
|
logger.info("CHUNKED CONTENT {");
|
||||||
} else {
|
} else {
|
||||||
ChannelBuffer content = response.getContent();
|
ChannelBuffer content = response.getContent();
|
||||||
if (content.readable()) {
|
if (content.readable()) {
|
||||||
System.out.println("CONTENT {");
|
logger.info("CONTENT {");
|
||||||
System.out.println(content.toString(CharsetUtil.UTF_8));
|
logger.info(content.toString(CharsetUtil.UTF_8));
|
||||||
System.out.println("} END OF CONTENT");
|
logger.info("} END OF CONTENT");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
HttpChunk chunk = (HttpChunk) e.getMessage();
|
HttpChunk chunk = (HttpChunk) e.getMessage();
|
||||||
if (chunk.isLast()) {
|
if (chunk.isLast()) {
|
||||||
readingChunks = false;
|
readingChunks = false;
|
||||||
System.out.println("} END OF CHUNKED CONTENT");
|
logger.info("} END OF CHUNKED CONTENT");
|
||||||
} else {
|
} else {
|
||||||
System.out.print(chunk.getContent().toString(CharsetUtil.UTF_8));
|
logger.info(chunk.getContent().toString(CharsetUtil.UTF_8));
|
||||||
System.out.flush();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,11 +41,14 @@ import io.netty.handler.codec.http.HttpRequest;
|
|||||||
import io.netty.handler.codec.http.HttpVersion;
|
import io.netty.handler.codec.http.HttpVersion;
|
||||||
import io.netty.handler.codec.http.InterfaceHttpData;
|
import io.netty.handler.codec.http.InterfaceHttpData;
|
||||||
import io.netty.handler.codec.http.QueryStringEncoder;
|
import io.netty.handler.codec.http.QueryStringEncoder;
|
||||||
|
import io.netty.logging.InternalLogger;
|
||||||
|
import io.netty.logging.InternalLoggerFactory;
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
public class HttpUploadClient {
|
public class HttpUploadClient {
|
||||||
|
|
||||||
|
private static final InternalLogger logger =
|
||||||
|
InternalLoggerFactory.getInstance(HttpUploadClient.class);
|
||||||
|
|
||||||
private final String baseUri;
|
private final String baseUri;
|
||||||
private final String filePath;
|
private final String filePath;
|
||||||
|
|
||||||
@ -69,7 +72,7 @@ public class HttpUploadClient {
|
|||||||
try {
|
try {
|
||||||
uriSimple = new URI(postSimple);
|
uriSimple = new URI(postSimple);
|
||||||
} catch (URISyntaxException e) {
|
} catch (URISyntaxException e) {
|
||||||
System.err.println("Error: " + e.getMessage());
|
logger.error("Invalid URI syntax" + e.getCause());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String scheme = uriSimple.getScheme() == null? "http" : uriSimple.getScheme();
|
String scheme = uriSimple.getScheme() == null? "http" : uriSimple.getScheme();
|
||||||
@ -84,7 +87,7 @@ public class HttpUploadClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!scheme.equalsIgnoreCase("http") && !scheme.equalsIgnoreCase("https")) {
|
if (!scheme.equalsIgnoreCase("http") && !scheme.equalsIgnoreCase("https")) {
|
||||||
System.err.println("Only HTTP(S) is supported.");
|
logger.error("Only HTTP(S) is supported.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,12 +97,12 @@ public class HttpUploadClient {
|
|||||||
try {
|
try {
|
||||||
uriFile = new URI(postFile);
|
uriFile = new URI(postFile);
|
||||||
} catch (URISyntaxException e) {
|
} catch (URISyntaxException e) {
|
||||||
System.err.println("Error: " + e.getMessage());
|
logger.error("Error: " + e.getMessage());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
File file = new File(filePath);
|
File file = new File(filePath);
|
||||||
if (! file.canRead()) {
|
if (! file.canRead()) {
|
||||||
System.err.println("A correct path is needed");
|
logger.error("A correct path is needed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,7 +179,7 @@ public class HttpUploadClient {
|
|||||||
try {
|
try {
|
||||||
uriGet = new URI(encoder.toString());
|
uriGet = new URI(encoder.toString());
|
||||||
} catch (URISyntaxException e) {
|
} catch (URISyntaxException e) {
|
||||||
System.err.println("Error: " + e.getMessage());
|
logger.error("Error: " + e.getMessage());
|
||||||
bootstrap.releaseExternalResources();
|
bootstrap.releaseExternalResources();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -377,7 +380,7 @@ public class HttpUploadClient {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
if (args.length != 2) {
|
if (args.length != 2) {
|
||||||
System.err.println(
|
logger.error(
|
||||||
"Usage: " + HttpUploadClient.class.getSimpleName() +
|
"Usage: " + HttpUploadClient.class.getSimpleName() +
|
||||||
" baseURI filePath");
|
" baseURI filePath");
|
||||||
return;
|
return;
|
||||||
|
@ -22,10 +22,15 @@ import io.netty.channel.MessageEvent;
|
|||||||
import io.netty.channel.SimpleChannelUpstreamHandler;
|
import io.netty.channel.SimpleChannelUpstreamHandler;
|
||||||
import io.netty.handler.codec.http.HttpChunk;
|
import io.netty.handler.codec.http.HttpChunk;
|
||||||
import io.netty.handler.codec.http.HttpResponse;
|
import io.netty.handler.codec.http.HttpResponse;
|
||||||
|
import io.netty.logging.InternalLogger;
|
||||||
|
import io.netty.logging.InternalLoggerFactory;
|
||||||
import io.netty.util.CharsetUtil;
|
import io.netty.util.CharsetUtil;
|
||||||
|
|
||||||
public class HttpUploadClientHandler extends SimpleChannelUpstreamHandler {
|
public class HttpUploadClientHandler extends SimpleChannelUpstreamHandler {
|
||||||
|
|
||||||
|
private static final InternalLogger logger =
|
||||||
|
InternalLoggerFactory.getInstance(HttpUploadClientHandler.class);
|
||||||
|
|
||||||
private volatile boolean readingChunks;
|
private volatile boolean readingChunks;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -33,38 +38,35 @@ public class HttpUploadClientHandler extends SimpleChannelUpstreamHandler {
|
|||||||
if (!readingChunks) {
|
if (!readingChunks) {
|
||||||
HttpResponse response = (HttpResponse) e.getMessage();
|
HttpResponse response = (HttpResponse) e.getMessage();
|
||||||
|
|
||||||
System.out.println("STATUS: " + response.getStatus());
|
logger.info("STATUS: " + response.getStatus());
|
||||||
System.out.println("VERSION: " + response.getProtocolVersion());
|
logger.info("VERSION: " + response.getProtocolVersion());
|
||||||
System.out.println();
|
|
||||||
|
|
||||||
if (!response.getHeaderNames().isEmpty()) {
|
if (!response.getHeaderNames().isEmpty()) {
|
||||||
for (String name: response.getHeaderNames()) {
|
for (String name: response.getHeaderNames()) {
|
||||||
for (String value: response.getHeaders(name)) {
|
for (String value: response.getHeaders(name)) {
|
||||||
System.out.println("HEADER: " + name + " = " + value);
|
logger.info("HEADER: " + name + " = " + value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
System.out.println();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.getStatus().getCode() == 200 && response.isChunked()) {
|
if (response.getStatus().getCode() == 200 && response.isChunked()) {
|
||||||
readingChunks = true;
|
readingChunks = true;
|
||||||
System.out.println("CHUNKED CONTENT {");
|
logger.info("CHUNKED CONTENT {");
|
||||||
} else {
|
} else {
|
||||||
ChannelBuffer content = response.getContent();
|
ChannelBuffer content = response.getContent();
|
||||||
if (content.readable()) {
|
if (content.readable()) {
|
||||||
System.out.println("CONTENT {");
|
logger.info("CONTENT {");
|
||||||
System.out.println(content.toString(CharsetUtil.UTF_8));
|
logger.info(content.toString(CharsetUtil.UTF_8));
|
||||||
System.out.println("} END OF CONTENT");
|
logger.info("} END OF CONTENT");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
HttpChunk chunk = (HttpChunk) e.getMessage();
|
HttpChunk chunk = (HttpChunk) e.getMessage();
|
||||||
if (chunk.isLast()) {
|
if (chunk.isLast()) {
|
||||||
readingChunks = false;
|
readingChunks = false;
|
||||||
System.out.println("} END OF CHUNKED CONTENT");
|
logger.info("} END OF CHUNKED CONTENT");
|
||||||
} else {
|
} else {
|
||||||
System.out.print(chunk.getContent().toString(CharsetUtil.UTF_8));
|
logger.info(chunk.getContent().toString(CharsetUtil.UTF_8));
|
||||||
System.out.flush();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,10 +58,15 @@ import io.netty.handler.codec.http.HttpVersion;
|
|||||||
import io.netty.handler.codec.http.InterfaceHttpData;
|
import io.netty.handler.codec.http.InterfaceHttpData;
|
||||||
import io.netty.handler.codec.http.InterfaceHttpData.HttpDataType;
|
import io.netty.handler.codec.http.InterfaceHttpData.HttpDataType;
|
||||||
import io.netty.handler.codec.http.QueryStringDecoder;
|
import io.netty.handler.codec.http.QueryStringDecoder;
|
||||||
|
import io.netty.logging.InternalLogger;
|
||||||
|
import io.netty.logging.InternalLoggerFactory;
|
||||||
import io.netty.util.CharsetUtil;
|
import io.netty.util.CharsetUtil;
|
||||||
|
|
||||||
public class HttpUploadServerHandler extends SimpleChannelUpstreamHandler {
|
public class HttpUploadServerHandler extends SimpleChannelUpstreamHandler {
|
||||||
|
|
||||||
|
private static final InternalLogger logger =
|
||||||
|
InternalLoggerFactory.getInstance(HttpUploadServerHandler.class);
|
||||||
|
|
||||||
private volatile HttpRequest request;
|
private volatile HttpRequest request;
|
||||||
|
|
||||||
private volatile boolean readingChunks;
|
private volatile boolean readingChunks;
|
||||||
@ -480,8 +485,7 @@ public class HttpUploadServerHandler extends SimpleChannelUpstreamHandler {
|
|||||||
@Override
|
@Override
|
||||||
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
|
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
e.getCause().printStackTrace();
|
logger.error(responseContent.toString(), e.getCause());
|
||||||
System.err.println(responseContent.toString());
|
|
||||||
e.getChannel().close();
|
e.getChannel().close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,9 +57,14 @@ import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
|
|||||||
import io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker;
|
import io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker;
|
||||||
import io.netty.handler.codec.http.websocketx.WebSocketClientHandshakerFactory;
|
import io.netty.handler.codec.http.websocketx.WebSocketClientHandshakerFactory;
|
||||||
import io.netty.handler.codec.http.websocketx.WebSocketVersion;
|
import io.netty.handler.codec.http.websocketx.WebSocketVersion;
|
||||||
|
import io.netty.logging.InternalLogger;
|
||||||
|
import io.netty.logging.InternalLoggerFactory;
|
||||||
|
|
||||||
public class WebSocketClient {
|
public class WebSocketClient {
|
||||||
|
|
||||||
|
private static final InternalLogger logger =
|
||||||
|
InternalLoggerFactory.getInstance(WebSocketClient.class);
|
||||||
|
|
||||||
private final URI uri;
|
private final URI uri;
|
||||||
|
|
||||||
public WebSocketClient(URI uri) {
|
public WebSocketClient(URI uri) {
|
||||||
@ -101,7 +106,7 @@ public class WebSocketClient {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Connect
|
// Connect
|
||||||
System.out.println("WebSocket Client connecting");
|
logger.info("WebSocket Client connecting");
|
||||||
ChannelFuture future =
|
ChannelFuture future =
|
||||||
bootstrap.connect(
|
bootstrap.connect(
|
||||||
new InetSocketAddress(uri.getHost(), uri.getPort()));
|
new InetSocketAddress(uri.getHost(), uri.getPort()));
|
||||||
@ -111,17 +116,17 @@ public class WebSocketClient {
|
|||||||
handshaker.handshake(ch).awaitUninterruptibly().rethrowIfFailed();
|
handshaker.handshake(ch).awaitUninterruptibly().rethrowIfFailed();
|
||||||
|
|
||||||
// Send 10 messages and wait for responses
|
// Send 10 messages and wait for responses
|
||||||
System.out.println("WebSocket Client sending message");
|
logger.info("WebSocket Client sending message");
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
ch.write(new TextWebSocketFrame("Message #" + i));
|
ch.write(new TextWebSocketFrame("Message #" + i));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ping
|
// Ping
|
||||||
System.out.println("WebSocket Client sending ping");
|
logger.info("WebSocket Client sending ping");
|
||||||
ch.write(new PingWebSocketFrame(ChannelBuffers.copiedBuffer(new byte[]{1, 2, 3, 4, 5, 6})));
|
ch.write(new PingWebSocketFrame(ChannelBuffers.copiedBuffer(new byte[]{1, 2, 3, 4, 5, 6})));
|
||||||
|
|
||||||
// Close
|
// Close
|
||||||
System.out.println("WebSocket Client sending close");
|
logger.info("WebSocket Client sending close");
|
||||||
ch.write(new CloseWebSocketFrame());
|
ch.write(new CloseWebSocketFrame());
|
||||||
|
|
||||||
// WebSocketClientHandler will close the connection when the server
|
// WebSocketClientHandler will close the connection when the server
|
||||||
|
@ -49,10 +49,15 @@ import io.netty.handler.codec.http.websocketx.PongWebSocketFrame;
|
|||||||
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
|
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
|
||||||
import io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker;
|
import io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker;
|
||||||
import io.netty.handler.codec.http.websocketx.WebSocketFrame;
|
import io.netty.handler.codec.http.websocketx.WebSocketFrame;
|
||||||
|
import io.netty.logging.InternalLogger;
|
||||||
|
import io.netty.logging.InternalLoggerFactory;
|
||||||
import io.netty.util.CharsetUtil;
|
import io.netty.util.CharsetUtil;
|
||||||
|
|
||||||
public class WebSocketClientHandler extends SimpleChannelUpstreamHandler {
|
public class WebSocketClientHandler extends SimpleChannelUpstreamHandler {
|
||||||
|
|
||||||
|
private static final InternalLogger logger =
|
||||||
|
InternalLoggerFactory.getInstance(WebSocketClientHandler.class);
|
||||||
|
|
||||||
private final WebSocketClientHandshaker handshaker;
|
private final WebSocketClientHandshaker handshaker;
|
||||||
|
|
||||||
public WebSocketClientHandler(WebSocketClientHandshaker handshaker) {
|
public WebSocketClientHandler(WebSocketClientHandshaker handshaker) {
|
||||||
@ -61,7 +66,7 @@ public class WebSocketClientHandler extends SimpleChannelUpstreamHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
|
public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
|
||||||
System.out.println("WebSocket Client disconnected!");
|
logger.debug("WebSocket Client disconnected!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -69,7 +74,7 @@ public class WebSocketClientHandler extends SimpleChannelUpstreamHandler {
|
|||||||
Channel ch = ctx.getChannel();
|
Channel ch = ctx.getChannel();
|
||||||
if (!handshaker.isHandshakeComplete()) {
|
if (!handshaker.isHandshakeComplete()) {
|
||||||
handshaker.finishHandshake(ch, (HttpResponse) e.getMessage());
|
handshaker.finishHandshake(ch, (HttpResponse) e.getMessage());
|
||||||
System.out.println("WebSocket Client connected!");
|
logger.debug("WebSocket Client connected!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,11 +87,11 @@ public class WebSocketClientHandler extends SimpleChannelUpstreamHandler {
|
|||||||
WebSocketFrame frame = (WebSocketFrame) e.getMessage();
|
WebSocketFrame frame = (WebSocketFrame) e.getMessage();
|
||||||
if (frame instanceof TextWebSocketFrame) {
|
if (frame instanceof TextWebSocketFrame) {
|
||||||
TextWebSocketFrame textFrame = (TextWebSocketFrame) frame;
|
TextWebSocketFrame textFrame = (TextWebSocketFrame) frame;
|
||||||
System.out.println("WebSocket Client received message: " + textFrame.getText());
|
logger.info("WebSocket Client received message: " + textFrame.getText());
|
||||||
} else if (frame instanceof PongWebSocketFrame) {
|
} else if (frame instanceof PongWebSocketFrame) {
|
||||||
System.out.println("WebSocket Client received pong");
|
logger.info("WebSocket Client received pong");
|
||||||
} else if (frame instanceof CloseWebSocketFrame) {
|
} else if (frame instanceof CloseWebSocketFrame) {
|
||||||
System.out.println("WebSocket Client received closing");
|
logger.info("WebSocket Client received closing");
|
||||||
ch.close();
|
ch.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,8 @@ import java.util.concurrent.Executors;
|
|||||||
|
|
||||||
import io.netty.bootstrap.ServerBootstrap;
|
import io.netty.bootstrap.ServerBootstrap;
|
||||||
import io.netty.channel.socket.nio.NioServerSocketChannelFactory;
|
import io.netty.channel.socket.nio.NioServerSocketChannelFactory;
|
||||||
|
import io.netty.logging.InternalLogger;
|
||||||
|
import io.netty.logging.InternalLoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A HTTP server which serves Web Socket requests at:
|
* A HTTP server which serves Web Socket requests at:
|
||||||
@ -42,6 +44,9 @@ import io.netty.channel.socket.nio.NioServerSocketChannelFactory;
|
|||||||
*/
|
*/
|
||||||
public class WebSocketServer {
|
public class WebSocketServer {
|
||||||
|
|
||||||
|
private static final InternalLogger logger =
|
||||||
|
InternalLoggerFactory.getInstance(WebSocketServer.class);
|
||||||
|
|
||||||
private final int port;
|
private final int port;
|
||||||
|
|
||||||
public WebSocketServer(int port) {
|
public WebSocketServer(int port) {
|
||||||
@ -58,8 +63,8 @@ public class WebSocketServer {
|
|||||||
// Bind and start to accept incoming connections.
|
// Bind and start to accept incoming connections.
|
||||||
bootstrap.bind(new InetSocketAddress(port));
|
bootstrap.bind(new InetSocketAddress(port));
|
||||||
|
|
||||||
System.out.println("Web socket server started at port " + port + '.');
|
logger.info("Web socket server started at port " + port + '.');
|
||||||
System.out.println("Open your browser and navigate to http://localhost:" + port + '/');
|
logger.info("Open your browser and navigate to http://localhost:" + port + '/');
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
@ -20,6 +20,8 @@ import java.util.concurrent.Executors;
|
|||||||
|
|
||||||
import io.netty.bootstrap.ServerBootstrap;
|
import io.netty.bootstrap.ServerBootstrap;
|
||||||
import io.netty.channel.socket.nio.NioServerSocketChannelFactory;
|
import io.netty.channel.socket.nio.NioServerSocketChannelFactory;
|
||||||
|
import io.netty.logging.InternalLogger;
|
||||||
|
import io.netty.logging.InternalLoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A HTTP server which serves Web Socket requests at:
|
* A HTTP server which serves Web Socket requests at:
|
||||||
@ -41,6 +43,9 @@ import io.netty.channel.socket.nio.NioServerSocketChannelFactory;
|
|||||||
*/
|
*/
|
||||||
public class WebSocketSslServer {
|
public class WebSocketSslServer {
|
||||||
|
|
||||||
|
private static final InternalLogger logger =
|
||||||
|
InternalLoggerFactory.getInstance(WebSocketSslServer.class);
|
||||||
|
|
||||||
private final int port;
|
private final int port;
|
||||||
|
|
||||||
public WebSocketSslServer(int port) {
|
public WebSocketSslServer(int port) {
|
||||||
@ -57,8 +62,8 @@ public class WebSocketSslServer {
|
|||||||
// Bind and start to accept incoming connections.
|
// Bind and start to accept incoming connections.
|
||||||
bootstrap.bind(new InetSocketAddress(port));
|
bootstrap.bind(new InetSocketAddress(port));
|
||||||
|
|
||||||
System.out.println("Web socket server started at port " + port + '.');
|
logger.info("Web socket server started at port " + port + '.');
|
||||||
System.out.println("Open your browser and navigate to https://localhost:" + port + '/');
|
logger.info("Open your browser and navigate to https://localhost:" + port + '/');
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
@ -71,13 +76,13 @@ public class WebSocketSslServer {
|
|||||||
|
|
||||||
String keyStoreFilePath = System.getProperty("keystore.file.path");
|
String keyStoreFilePath = System.getProperty("keystore.file.path");
|
||||||
if (keyStoreFilePath == null || keyStoreFilePath.isEmpty()) {
|
if (keyStoreFilePath == null || keyStoreFilePath.isEmpty()) {
|
||||||
System.out.println("ERROR: System property keystore.file.path not set. Exiting now!");
|
logger.error("ERROR: System property keystore.file.path not set. Exiting now!");
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
String keyStoreFilePassword = System.getProperty("keystore.file.password");
|
String keyStoreFilePassword = System.getProperty("keystore.file.password");
|
||||||
if (keyStoreFilePassword == null || keyStoreFilePassword.isEmpty()) {
|
if (keyStoreFilePassword == null || keyStoreFilePassword.isEmpty()) {
|
||||||
System.out.println("ERROR: System property keystore.file.password not set. Exiting now!");
|
logger.error("ERROR: System property keystore.file.password not set. Exiting now!");
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,9 +31,14 @@ import io.netty.handler.codec.string.StringEncoder;
|
|||||||
import io.netty.handler.execution.OrderedMemoryAwareThreadPoolExecutor;
|
import io.netty.handler.execution.OrderedMemoryAwareThreadPoolExecutor;
|
||||||
import io.netty.handler.logging.LoggingHandler;
|
import io.netty.handler.logging.LoggingHandler;
|
||||||
import io.netty.logging.InternalLogLevel;
|
import io.netty.logging.InternalLogLevel;
|
||||||
|
import io.netty.logging.InternalLogger;
|
||||||
|
import io.netty.logging.InternalLoggerFactory;
|
||||||
|
|
||||||
public class LocalExampleMultithreaded {
|
public class LocalExampleMultithreaded {
|
||||||
|
|
||||||
|
private static final InternalLogger logger =
|
||||||
|
InternalLoggerFactory.getInstance(LocalExampleMultithreaded.class);
|
||||||
|
|
||||||
private final String port;
|
private final String port;
|
||||||
|
|
||||||
public LocalExampleMultithreaded(String port) {
|
public LocalExampleMultithreaded(String port) {
|
||||||
@ -69,12 +74,11 @@ public class LocalExampleMultithreaded {
|
|||||||
// Read commands from array
|
// Read commands from array
|
||||||
String[] commands = { "First", "Second", "Third", "quit" };
|
String[] commands = { "First", "Second", "Third", "quit" };
|
||||||
for (int j = 0; j < 5 ; j++) {
|
for (int j = 0; j < 5 ; j++) {
|
||||||
System.err.println("Start " + j);
|
logger.info("Start " + j);
|
||||||
ChannelFuture channelFuture = cb.connect(socketAddress);
|
ChannelFuture channelFuture = cb.connect(socketAddress);
|
||||||
channelFuture.awaitUninterruptibly();
|
channelFuture.awaitUninterruptibly();
|
||||||
if (! channelFuture.isSuccess()) {
|
if (! channelFuture.isSuccess()) {
|
||||||
System.err.println("CANNOT CONNECT");
|
logger.error("CANNOT CONNECT", channelFuture.getCause());
|
||||||
channelFuture.getCause().printStackTrace();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ChannelFuture lastWriteFuture = null;
|
ChannelFuture lastWriteFuture = null;
|
||||||
@ -90,7 +94,7 @@ public class LocalExampleMultithreaded {
|
|||||||
channelFuture.getChannel().close();
|
channelFuture.getChannel().close();
|
||||||
// Wait until the connection is closed or the connection attempt fails.
|
// Wait until the connection is closed or the connection attempt fails.
|
||||||
channelFuture.getChannel().getCloseFuture().awaitUninterruptibly();
|
channelFuture.getChannel().getCloseFuture().awaitUninterruptibly();
|
||||||
System.err.println("End " + j);
|
logger.info("End " + j);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Release all resources
|
// Release all resources
|
||||||
|
@ -28,9 +28,14 @@ import io.netty.channel.MessageEvent;
|
|||||||
import io.netty.handler.codec.string.StringDecoder;
|
import io.netty.handler.codec.string.StringDecoder;
|
||||||
import io.netty.handler.codec.string.StringEncoder;
|
import io.netty.handler.codec.string.StringEncoder;
|
||||||
import io.netty.handler.execution.ExecutionHandler;
|
import io.netty.handler.execution.ExecutionHandler;
|
||||||
|
import io.netty.logging.InternalLogger;
|
||||||
|
import io.netty.logging.InternalLoggerFactory;
|
||||||
|
|
||||||
public class LocalServerPipelineFactory implements ChannelPipelineFactory {
|
public class LocalServerPipelineFactory implements ChannelPipelineFactory {
|
||||||
|
|
||||||
|
private static final InternalLogger logger =
|
||||||
|
InternalLoggerFactory.getInstance(LocalServerPipelineFactory.class);
|
||||||
|
|
||||||
private final ExecutionHandler executionHandler;
|
private final ExecutionHandler executionHandler;
|
||||||
|
|
||||||
public LocalServerPipelineFactory(Executor eventExecutor) {
|
public LocalServerPipelineFactory(Executor eventExecutor) {
|
||||||
@ -71,7 +76,7 @@ public class LocalServerPipelineFactory implements ChannelPipelineFactory {
|
|||||||
Channels.close(e.getChannel());
|
Channels.close(e.getChannel());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
System.err.println("SERVER:" + msg);
|
logger.error("SERVER:" + msg);
|
||||||
// Write back
|
// Write back
|
||||||
Channels.write(e.getChannel(), msg);
|
Channels.write(e.getChannel(), msg);
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,8 @@ import io.netty.bootstrap.ClientBootstrap;
|
|||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelFuture;
|
import io.netty.channel.ChannelFuture;
|
||||||
import io.netty.channel.socket.nio.NioClientSocketChannelFactory;
|
import io.netty.channel.socket.nio.NioClientSocketChannelFactory;
|
||||||
|
import io.netty.logging.InternalLogger;
|
||||||
|
import io.netty.logging.InternalLoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a list of continent/city pairs to a {@link LocalTimeServer} to
|
* Sends a list of continent/city pairs to a {@link LocalTimeServer} to
|
||||||
@ -33,6 +35,9 @@ import io.netty.channel.socket.nio.NioClientSocketChannelFactory;
|
|||||||
*/
|
*/
|
||||||
public class LocalTimeClient {
|
public class LocalTimeClient {
|
||||||
|
|
||||||
|
private static final InternalLogger logger =
|
||||||
|
InternalLoggerFactory.getInstance(LocalTimeClient.class);
|
||||||
|
|
||||||
private final String host;
|
private final String host;
|
||||||
private final int port;
|
private final int port;
|
||||||
private final Collection<String> cities;
|
private final Collection<String> cities;
|
||||||
@ -99,10 +104,10 @@ public class LocalTimeClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void printUsage() {
|
private static void printUsage() {
|
||||||
System.err.println(
|
logger.error(
|
||||||
"Usage: " + LocalTimeClient.class.getSimpleName() +
|
"Usage: " + LocalTimeClient.class.getSimpleName() +
|
||||||
" <host> <port> <continent/city_name> ...");
|
" <host> <port> <continent/city_name> ...");
|
||||||
System.err.println(
|
logger.error(
|
||||||
"Example: " + LocalTimeClient.class.getSimpleName() +
|
"Example: " + LocalTimeClient.class.getSimpleName() +
|
||||||
" localhost 8080 America/New_York Asia/Seoul");
|
" localhost 8080 America/New_York Asia/Seoul");
|
||||||
}
|
}
|
||||||
@ -111,7 +116,7 @@ public class LocalTimeClient {
|
|||||||
List<String> cities = new ArrayList<String>();
|
List<String> cities = new ArrayList<String>();
|
||||||
for (int i = offset; i < args.length; i ++) {
|
for (int i = offset; i < args.length; i ++) {
|
||||||
if (!args[i].matches("^[_A-Za-z]+/[_A-Za-z]+$")) {
|
if (!args[i].matches("^[_A-Za-z]+/[_A-Za-z]+$")) {
|
||||||
System.err.println("Syntax error: '" + args[i] + "'");
|
logger.error("Syntax error: '" + args[i] + "'");
|
||||||
printUsage();
|
printUsage();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,8 @@ import io.netty.example.echo.EchoClient;
|
|||||||
import io.netty.handler.codec.serialization.ClassResolvers;
|
import io.netty.handler.codec.serialization.ClassResolvers;
|
||||||
import io.netty.handler.codec.serialization.ObjectDecoder;
|
import io.netty.handler.codec.serialization.ObjectDecoder;
|
||||||
import io.netty.handler.codec.serialization.ObjectEncoder;
|
import io.netty.handler.codec.serialization.ObjectEncoder;
|
||||||
|
import io.netty.logging.InternalLogger;
|
||||||
|
import io.netty.logging.InternalLoggerFactory;
|
||||||
|
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
@ -33,6 +35,9 @@ import java.util.concurrent.Executors;
|
|||||||
*/
|
*/
|
||||||
public class ObjectEchoClient {
|
public class ObjectEchoClient {
|
||||||
|
|
||||||
|
private static final InternalLogger logger =
|
||||||
|
InternalLoggerFactory.getInstance(ObjectEchoClient.class);
|
||||||
|
|
||||||
private final String host;
|
private final String host;
|
||||||
private final int port;
|
private final int port;
|
||||||
private final int firstMessageSize;
|
private final int firstMessageSize;
|
||||||
@ -68,7 +73,7 @@ public class ObjectEchoClient {
|
|||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
// Print usage if no argument is specified.
|
// Print usage if no argument is specified.
|
||||||
if (args.length < 2 || args.length > 3) {
|
if (args.length < 2 || args.length > 3) {
|
||||||
System.err.println(
|
logger.error(
|
||||||
"Usage: " + ObjectEchoClient.class.getSimpleName() +
|
"Usage: " + ObjectEchoClient.class.getSimpleName() +
|
||||||
" <host> <port> [<first message size>]");
|
" <host> <port> [<first message size>]");
|
||||||
return;
|
return;
|
||||||
|
@ -23,9 +23,14 @@ import io.netty.bootstrap.ServerBootstrap;
|
|||||||
import io.netty.channel.socket.ClientSocketChannelFactory;
|
import io.netty.channel.socket.ClientSocketChannelFactory;
|
||||||
import io.netty.channel.socket.nio.NioClientSocketChannelFactory;
|
import io.netty.channel.socket.nio.NioClientSocketChannelFactory;
|
||||||
import io.netty.channel.socket.nio.NioServerSocketChannelFactory;
|
import io.netty.channel.socket.nio.NioServerSocketChannelFactory;
|
||||||
|
import io.netty.logging.InternalLogger;
|
||||||
|
import io.netty.logging.InternalLoggerFactory;
|
||||||
|
|
||||||
public class HexDumpProxy {
|
public class HexDumpProxy {
|
||||||
|
|
||||||
|
private static final InternalLogger logger =
|
||||||
|
InternalLoggerFactory.getInstance(HexDumpProxy.class);
|
||||||
|
|
||||||
private final int localPort;
|
private final int localPort;
|
||||||
private final String remoteHost;
|
private final String remoteHost;
|
||||||
private final int remotePort;
|
private final int remotePort;
|
||||||
@ -37,7 +42,7 @@ public class HexDumpProxy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
System.err.println(
|
logger.info(
|
||||||
"Proxying *:" + localPort + " to " +
|
"Proxying *:" + localPort + " to " +
|
||||||
remoteHost + ':' + remotePort + " ...");
|
remoteHost + ':' + remotePort + " ...");
|
||||||
|
|
||||||
@ -60,7 +65,7 @@ public class HexDumpProxy {
|
|||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
// Validate command line options.
|
// Validate command line options.
|
||||||
if (args.length != 3) {
|
if (args.length != 3) {
|
||||||
System.err.println(
|
logger.error(
|
||||||
"Usage: " + HexDumpProxy.class.getSimpleName() +
|
"Usage: " + HexDumpProxy.class.getSimpleName() +
|
||||||
" <local port> <remote host> <remote port>");
|
" <local port> <remote host> <remote port>");
|
||||||
return;
|
return;
|
||||||
|
@ -28,6 +28,8 @@ import io.netty.channel.socket.DatagramChannelFactory;
|
|||||||
import io.netty.channel.socket.nio.NioDatagramChannelFactory;
|
import io.netty.channel.socket.nio.NioDatagramChannelFactory;
|
||||||
import io.netty.handler.codec.string.StringDecoder;
|
import io.netty.handler.codec.string.StringDecoder;
|
||||||
import io.netty.handler.codec.string.StringEncoder;
|
import io.netty.handler.codec.string.StringEncoder;
|
||||||
|
import io.netty.logging.InternalLogger;
|
||||||
|
import io.netty.logging.InternalLoggerFactory;
|
||||||
import io.netty.util.CharsetUtil;
|
import io.netty.util.CharsetUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -38,6 +40,9 @@ import io.netty.util.CharsetUtil;
|
|||||||
*/
|
*/
|
||||||
public class QuoteOfTheMomentClient {
|
public class QuoteOfTheMomentClient {
|
||||||
|
|
||||||
|
private static final InternalLogger logger =
|
||||||
|
InternalLoggerFactory.getInstance(QuoteOfTheMomentClient.class);
|
||||||
|
|
||||||
private final int port;
|
private final int port;
|
||||||
|
|
||||||
public QuoteOfTheMomentClient(int port) {
|
public QuoteOfTheMomentClient(int port) {
|
||||||
@ -86,7 +91,7 @@ public class QuoteOfTheMomentClient {
|
|||||||
// response is received. If the channel is not closed within 5 seconds,
|
// response is received. If the channel is not closed within 5 seconds,
|
||||||
// print an error message and quit.
|
// print an error message and quit.
|
||||||
if (!c.getCloseFuture().awaitUninterruptibly(5000)) {
|
if (!c.getCloseFuture().awaitUninterruptibly(5000)) {
|
||||||
System.err.println("QOTM request timed out.");
|
logger.error("QOTM request timed out.");
|
||||||
c.close().awaitUninterruptibly();
|
c.close().awaitUninterruptibly();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,15 +19,20 @@ import io.netty.channel.ChannelHandlerContext;
|
|||||||
import io.netty.channel.ExceptionEvent;
|
import io.netty.channel.ExceptionEvent;
|
||||||
import io.netty.channel.MessageEvent;
|
import io.netty.channel.MessageEvent;
|
||||||
import io.netty.channel.SimpleChannelUpstreamHandler;
|
import io.netty.channel.SimpleChannelUpstreamHandler;
|
||||||
|
import io.netty.logging.InternalLogger;
|
||||||
|
import io.netty.logging.InternalLoggerFactory;
|
||||||
|
|
||||||
public class QuoteOfTheMomentClientHandler extends SimpleChannelUpstreamHandler {
|
public class QuoteOfTheMomentClientHandler extends SimpleChannelUpstreamHandler {
|
||||||
|
|
||||||
|
private static final InternalLogger logger =
|
||||||
|
InternalLoggerFactory.getInstance(QuoteOfTheMomentClientHandler.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
|
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
String msg = (String) e.getMessage();
|
String msg = (String) e.getMessage();
|
||||||
if (msg.startsWith("QOTM: ")) {
|
if (msg.startsWith("QOTM: ")) {
|
||||||
System.out.println("Quote of the Moment: " + msg.substring(6));
|
logger.info("Quote of the Moment: " + msg.substring(6));
|
||||||
e.getChannel().close();
|
e.getChannel().close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -35,7 +40,7 @@ public class QuoteOfTheMomentClientHandler extends SimpleChannelUpstreamHandler
|
|||||||
@Override
|
@Override
|
||||||
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
|
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
e.getCause().printStackTrace();
|
logger.error("Exception caught", e.getCause());
|
||||||
e.getChannel().close();
|
e.getChannel().close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,8 @@ import io.netty.handler.codec.redis.RedisDecoder;
|
|||||||
import io.netty.handler.codec.redis.RedisEncoder;
|
import io.netty.handler.codec.redis.RedisEncoder;
|
||||||
import io.netty.handler.codec.redis.Reply;
|
import io.netty.handler.codec.redis.Reply;
|
||||||
import io.netty.handler.queue.BlockingReadHandler;
|
import io.netty.handler.queue.BlockingReadHandler;
|
||||||
|
import io.netty.logging.InternalLogger;
|
||||||
|
import io.netty.logging.InternalLoggerFactory;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
@ -36,6 +38,10 @@ import java.util.concurrent.ExecutorService;
|
|||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
public final class RedisClient {
|
public final class RedisClient {
|
||||||
|
|
||||||
|
private static final InternalLogger logger =
|
||||||
|
InternalLoggerFactory.getInstance(RedisClient.class);
|
||||||
|
|
||||||
private static final byte[] VALUE = "value".getBytes();
|
private static final byte[] VALUE = "value".getBytes();
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
@ -56,9 +62,9 @@ public final class RedisClient {
|
|||||||
Channel channel = redis.getChannel();
|
Channel channel = redis.getChannel();
|
||||||
|
|
||||||
channel.write(new Command("set", "1", "value"));
|
channel.write(new Command("set", "1", "value"));
|
||||||
System.out.print(blockingReadHandler.read());
|
logger.info(blockingReadHandler.read().toString());
|
||||||
channel.write(new Command("get", "1"));
|
channel.write(new Command("get", "1"));
|
||||||
System.out.print(blockingReadHandler.read());
|
logger.info(blockingReadHandler.read().toString());
|
||||||
|
|
||||||
int CALLS = 1000000;
|
int CALLS = 1000000;
|
||||||
int PIPELINE = 50;
|
int PIPELINE = 50;
|
||||||
@ -85,7 +91,7 @@ public final class RedisClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
long end = System.currentTimeMillis();
|
long end = System.currentTimeMillis();
|
||||||
System.out.println(CALLS * 1000 / (end - start) + " calls per second");
|
logger.info(CALLS * 1000 / (end - start) + " calls per second");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void pipelinedIndividualRequests(BlockingReadHandler<Reply> blockingReadHandler, Channel channel, long CALLS, int PIPELINE) throws IOException, InterruptedException {
|
private static void pipelinedIndividualRequests(BlockingReadHandler<Reply> blockingReadHandler, Channel channel, long CALLS, int PIPELINE) throws IOException, InterruptedException {
|
||||||
@ -101,7 +107,7 @@ public final class RedisClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
long end = System.currentTimeMillis();
|
long end = System.currentTimeMillis();
|
||||||
System.out.println(CALLS * 1000 / (end - start) + " calls per second");
|
logger.info(CALLS * 1000 / (end - start) + " calls per second");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void requestResponse(BlockingReadHandler<Reply> blockingReadHandler, Channel channel, int CALLS) throws IOException, InterruptedException {
|
private static void requestResponse(BlockingReadHandler<Reply> blockingReadHandler, Channel channel, int CALLS) throws IOException, InterruptedException {
|
||||||
@ -112,7 +118,7 @@ public final class RedisClient {
|
|||||||
blockingReadHandler.read();
|
blockingReadHandler.read();
|
||||||
}
|
}
|
||||||
long end = System.currentTimeMillis();
|
long end = System.currentTimeMillis();
|
||||||
System.out.println(CALLS * 1000 / (end - start) + " calls per second");
|
logger.info(CALLS * 1000 / (end - start) + " calls per second");
|
||||||
}
|
}
|
||||||
|
|
||||||
private RedisClient() {
|
private RedisClient() {
|
||||||
|
@ -23,6 +23,8 @@ import io.netty.channel.Channels;
|
|||||||
import io.netty.channel.sctp.SctpClientSocketChannelFactory;
|
import io.netty.channel.sctp.SctpClientSocketChannelFactory;
|
||||||
import io.netty.handler.execution.ExecutionHandler;
|
import io.netty.handler.execution.ExecutionHandler;
|
||||||
import io.netty.handler.execution.OrderedMemoryAwareThreadPoolExecutor;
|
import io.netty.handler.execution.OrderedMemoryAwareThreadPoolExecutor;
|
||||||
|
import io.netty.logging.InternalLogger;
|
||||||
|
import io.netty.logging.InternalLoggerFactory;
|
||||||
|
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
@ -32,6 +34,9 @@ import java.util.concurrent.Executors;
|
|||||||
*/
|
*/
|
||||||
public class SctpClient {
|
public class SctpClient {
|
||||||
|
|
||||||
|
private static final InternalLogger logger =
|
||||||
|
InternalLoggerFactory.getInstance(SctpClient.class);
|
||||||
|
|
||||||
private final String host;
|
private final String host;
|
||||||
private final int port;
|
private final int port;
|
||||||
|
|
||||||
@ -77,7 +82,7 @@ public class SctpClient {
|
|||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
// Print usage if no argument is specified.
|
// Print usage if no argument is specified.
|
||||||
if (args.length != 2) {
|
if (args.length != 2) {
|
||||||
System.err.println(
|
logger.error(
|
||||||
"Usage: " + SctpClient.class.getSimpleName() +
|
"Usage: " + SctpClient.class.getSimpleName() +
|
||||||
" <host> <port>");
|
" <host> <port>");
|
||||||
return;
|
return;
|
||||||
|
@ -26,12 +26,17 @@ import io.netty.channel.Channel;
|
|||||||
import io.netty.channel.ChannelFuture;
|
import io.netty.channel.ChannelFuture;
|
||||||
import io.netty.channel.socket.nio.NioClientSocketChannelFactory;
|
import io.netty.channel.socket.nio.NioClientSocketChannelFactory;
|
||||||
import io.netty.example.telnet.TelnetClient;
|
import io.netty.example.telnet.TelnetClient;
|
||||||
|
import io.netty.logging.InternalLogger;
|
||||||
|
import io.netty.logging.InternalLoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple SSL chat client modified from {@link TelnetClient}.
|
* Simple SSL chat client modified from {@link TelnetClient}.
|
||||||
*/
|
*/
|
||||||
public class SecureChatClient {
|
public class SecureChatClient {
|
||||||
|
|
||||||
|
private static final InternalLogger logger =
|
||||||
|
InternalLoggerFactory.getInstance(SecureChatClient.class);
|
||||||
|
|
||||||
private final String host;
|
private final String host;
|
||||||
private final int port;
|
private final int port;
|
||||||
|
|
||||||
@ -96,7 +101,7 @@ public class SecureChatClient {
|
|||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
// Print usage if no argument is specified.
|
// Print usage if no argument is specified.
|
||||||
if (args.length != 2) {
|
if (args.length != 2) {
|
||||||
System.err.println(
|
logger.error(
|
||||||
"Usage: " + SecureChatClient.class.getSimpleName() +
|
"Usage: " + SecureChatClient.class.getSimpleName() +
|
||||||
" <host> <port>");
|
" <host> <port>");
|
||||||
return;
|
return;
|
||||||
|
@ -15,9 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.example.securechat;
|
package io.netty.example.securechat;
|
||||||
|
|
||||||
import java.util.logging.Level;
|
import io.netty.channel.Channel;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import io.netty.channel.ChannelEvent;
|
import io.netty.channel.ChannelEvent;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.ChannelStateEvent;
|
import io.netty.channel.ChannelStateEvent;
|
||||||
@ -25,14 +23,16 @@ import io.netty.channel.ExceptionEvent;
|
|||||||
import io.netty.channel.MessageEvent;
|
import io.netty.channel.MessageEvent;
|
||||||
import io.netty.channel.SimpleChannelUpstreamHandler;
|
import io.netty.channel.SimpleChannelUpstreamHandler;
|
||||||
import io.netty.handler.ssl.SslHandler;
|
import io.netty.handler.ssl.SslHandler;
|
||||||
|
import io.netty.logging.InternalLogger;
|
||||||
|
import io.netty.logging.InternalLoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles a client-side channel.
|
* Handles a client-side channel.
|
||||||
*/
|
*/
|
||||||
public class SecureChatClientHandler extends SimpleChannelUpstreamHandler {
|
public class SecureChatClientHandler extends SimpleChannelUpstreamHandler {
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(
|
private static final InternalLogger logger =
|
||||||
SecureChatClientHandler.class.getName());
|
InternalLoggerFactory.getInstance(SecureChatClientHandler.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleUpstream(
|
public void handleUpstream(
|
||||||
@ -57,14 +57,13 @@ public class SecureChatClientHandler extends SimpleChannelUpstreamHandler {
|
|||||||
@Override
|
@Override
|
||||||
public void messageReceived(
|
public void messageReceived(
|
||||||
ChannelHandlerContext ctx, MessageEvent e) {
|
ChannelHandlerContext ctx, MessageEvent e) {
|
||||||
System.err.println(e.getMessage());
|
logger.error((String) e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exceptionCaught(
|
public void exceptionCaught(
|
||||||
ChannelHandlerContext ctx, ExceptionEvent e) {
|
ChannelHandlerContext ctx, ExceptionEvent e) {
|
||||||
logger.log(
|
logger.warn(
|
||||||
Level.WARNING,
|
|
||||||
"Unexpected exception from downstream.",
|
"Unexpected exception from downstream.",
|
||||||
e.getCause());
|
e.getCause());
|
||||||
e.getChannel().close();
|
e.getChannel().close();
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.example.securechat;
|
package io.netty.example.securechat;
|
||||||
|
|
||||||
|
import io.netty.logging.InternalLogger;
|
||||||
|
import io.netty.logging.InternalLoggerFactory;
|
||||||
import java.security.InvalidAlgorithmParameterException;
|
import java.security.InvalidAlgorithmParameterException;
|
||||||
import java.security.KeyStore;
|
import java.security.KeyStore;
|
||||||
import java.security.KeyStoreException;
|
import java.security.KeyStoreException;
|
||||||
@ -32,6 +34,9 @@ import javax.net.ssl.X509TrustManager;
|
|||||||
*/
|
*/
|
||||||
public class SecureChatTrustManagerFactory extends TrustManagerFactorySpi {
|
public class SecureChatTrustManagerFactory extends TrustManagerFactorySpi {
|
||||||
|
|
||||||
|
private static final InternalLogger logger =
|
||||||
|
InternalLoggerFactory.getInstance(SecureChatTrustManagerFactory.class);
|
||||||
|
|
||||||
private static final TrustManager DUMMY_TRUST_MANAGER = new X509TrustManager() {
|
private static final TrustManager DUMMY_TRUST_MANAGER = new X509TrustManager() {
|
||||||
@Override
|
@Override
|
||||||
public X509Certificate[] getAcceptedIssuers() {
|
public X509Certificate[] getAcceptedIssuers() {
|
||||||
@ -45,7 +50,7 @@ public class SecureChatTrustManagerFactory extends TrustManagerFactorySpi {
|
|||||||
// You should do something in the real world.
|
// You should do something in the real world.
|
||||||
// You will reach here only if you enabled client certificate auth,
|
// You will reach here only if you enabled client certificate auth,
|
||||||
// as described in SecureChatSslContextFactory.
|
// as described in SecureChatSslContextFactory.
|
||||||
System.err.println(
|
logger.error(
|
||||||
"UNKNOWN CLIENT CERTIFICATE: " + chain[0].getSubjectDN());
|
"UNKNOWN CLIENT CERTIFICATE: " + chain[0].getSubjectDN());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,7 +59,7 @@ public class SecureChatTrustManagerFactory extends TrustManagerFactorySpi {
|
|||||||
X509Certificate[] chain, String authType) throws CertificateException {
|
X509Certificate[] chain, String authType) throws CertificateException {
|
||||||
// Always trust - it is an example.
|
// Always trust - it is an example.
|
||||||
// You should do something in the real world.
|
// You should do something in the real world.
|
||||||
System.err.println(
|
logger.error(
|
||||||
"UNKNOWN SERVER CERTIFICATE: " + chain[0].getSubjectDN());
|
"UNKNOWN SERVER CERTIFICATE: " + chain[0].getSubjectDN());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -25,12 +25,17 @@ import io.netty.bootstrap.ClientBootstrap;
|
|||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelFuture;
|
import io.netty.channel.ChannelFuture;
|
||||||
import io.netty.channel.socket.nio.NioClientSocketChannelFactory;
|
import io.netty.channel.socket.nio.NioClientSocketChannelFactory;
|
||||||
|
import io.netty.logging.InternalLogger;
|
||||||
|
import io.netty.logging.InternalLoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simplistic telnet client.
|
* Simplistic telnet client.
|
||||||
*/
|
*/
|
||||||
public class TelnetClient {
|
public class TelnetClient {
|
||||||
|
|
||||||
|
private static final InternalLogger logger =
|
||||||
|
InternalLoggerFactory.getInstance(TelnetClient.class);
|
||||||
|
|
||||||
private final String host;
|
private final String host;
|
||||||
private final int port;
|
private final int port;
|
||||||
|
|
||||||
@ -95,7 +100,7 @@ public class TelnetClient {
|
|||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
// Print usage if no argument is specified.
|
// Print usage if no argument is specified.
|
||||||
if (args.length != 2) {
|
if (args.length != 2) {
|
||||||
System.err.println(
|
logger.error(
|
||||||
"Usage: " + TelnetClient.class.getSimpleName() +
|
"Usage: " + TelnetClient.class.getSimpleName() +
|
||||||
" <host> <port>");
|
" <host> <port>");
|
||||||
return;
|
return;
|
||||||
|
@ -15,23 +15,23 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.example.telnet;
|
package io.netty.example.telnet;
|
||||||
|
|
||||||
import java.util.logging.Level;
|
import io.netty.channel.Channel;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import io.netty.channel.ChannelEvent;
|
import io.netty.channel.ChannelEvent;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.ChannelStateEvent;
|
import io.netty.channel.ChannelStateEvent;
|
||||||
import io.netty.channel.ExceptionEvent;
|
import io.netty.channel.ExceptionEvent;
|
||||||
import io.netty.channel.MessageEvent;
|
import io.netty.channel.MessageEvent;
|
||||||
import io.netty.channel.SimpleChannelUpstreamHandler;
|
import io.netty.channel.SimpleChannelUpstreamHandler;
|
||||||
|
import io.netty.logging.InternalLogger;
|
||||||
|
import io.netty.logging.InternalLoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles a client-side channel.
|
* Handles a client-side channel.
|
||||||
*/
|
*/
|
||||||
public class TelnetClientHandler extends SimpleChannelUpstreamHandler {
|
public class TelnetClientHandler extends SimpleChannelUpstreamHandler {
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(
|
private static final InternalLogger logger =
|
||||||
TelnetClientHandler.class.getName());
|
InternalLoggerFactory.getInstance(TelnetClientHandler.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleUpstream(
|
public void handleUpstream(
|
||||||
@ -46,14 +46,13 @@ public class TelnetClientHandler extends SimpleChannelUpstreamHandler {
|
|||||||
public void messageReceived(
|
public void messageReceived(
|
||||||
ChannelHandlerContext ctx, MessageEvent e) {
|
ChannelHandlerContext ctx, MessageEvent e) {
|
||||||
// Print out the line received from the server.
|
// Print out the line received from the server.
|
||||||
System.err.println(e.getMessage());
|
logger.info((String) e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exceptionCaught(
|
public void exceptionCaught(
|
||||||
ChannelHandlerContext ctx, ExceptionEvent e) {
|
ChannelHandlerContext ctx, ExceptionEvent e) {
|
||||||
logger.log(
|
logger.warn(
|
||||||
Level.WARNING,
|
|
||||||
"Unexpected exception from downstream.",
|
"Unexpected exception from downstream.",
|
||||||
e.getCause());
|
e.getCause());
|
||||||
e.getChannel().close();
|
e.getChannel().close();
|
||||||
|
@ -25,6 +25,8 @@ import io.netty.channel.ChannelPipelineFactory;
|
|||||||
import io.netty.channel.Channels;
|
import io.netty.channel.Channels;
|
||||||
import io.netty.channel.socket.nio.NioClientSocketChannelFactory;
|
import io.netty.channel.socket.nio.NioClientSocketChannelFactory;
|
||||||
import io.netty.handler.timeout.ReadTimeoutHandler;
|
import io.netty.handler.timeout.ReadTimeoutHandler;
|
||||||
|
import io.netty.logging.InternalLogger;
|
||||||
|
import io.netty.logging.InternalLoggerFactory;
|
||||||
import io.netty.util.HashedWheelTimer;
|
import io.netty.util.HashedWheelTimer;
|
||||||
import io.netty.util.Timer;
|
import io.netty.util.Timer;
|
||||||
|
|
||||||
@ -36,6 +38,9 @@ import io.netty.util.Timer;
|
|||||||
*/
|
*/
|
||||||
public class UptimeClient {
|
public class UptimeClient {
|
||||||
|
|
||||||
|
private static final InternalLogger logger =
|
||||||
|
InternalLoggerFactory.getInstance(UptimeClient.class);
|
||||||
|
|
||||||
// Sleep 5 seconds before a reconnection attempt.
|
// Sleep 5 seconds before a reconnection attempt.
|
||||||
static final int RECONNECT_DELAY = 5;
|
static final int RECONNECT_DELAY = 5;
|
||||||
|
|
||||||
@ -84,7 +89,7 @@ public class UptimeClient {
|
|||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
// Print usage if no argument is specified.
|
// Print usage if no argument is specified.
|
||||||
if (args.length != 2) {
|
if (args.length != 2) {
|
||||||
System.err.println(
|
logger.error(
|
||||||
"Usage: " + UptimeClient.class.getSimpleName() +
|
"Usage: " + UptimeClient.class.getSimpleName() +
|
||||||
" <host> <port>");
|
" <host> <port>");
|
||||||
return;
|
return;
|
||||||
|
@ -28,8 +28,6 @@ import java.util.concurrent.TimeUnit;
|
|||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import io.netty.bootstrap.ClientBootstrap;
|
import io.netty.bootstrap.ClientBootstrap;
|
||||||
import io.netty.bootstrap.ServerBootstrap;
|
import io.netty.bootstrap.ServerBootstrap;
|
||||||
@ -51,6 +49,8 @@ import io.netty.channel.socket.ServerSocketChannelFactory;
|
|||||||
import io.netty.channel.socket.SocketChannel;
|
import io.netty.channel.socket.SocketChannel;
|
||||||
import io.netty.channel.socket.nio.NioClientSocketChannelFactory;
|
import io.netty.channel.socket.nio.NioClientSocketChannelFactory;
|
||||||
import io.netty.channel.socket.nio.NioServerSocketChannelFactory;
|
import io.netty.channel.socket.nio.NioServerSocketChannelFactory;
|
||||||
|
import io.netty.logging.InternalLogger;
|
||||||
|
import io.netty.logging.InternalLoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests HTTP tunnel soaking
|
* Tests HTTP tunnel soaking
|
||||||
@ -59,8 +59,8 @@ public class HttpTunnelSoakTester {
|
|||||||
|
|
||||||
private static final int SERVER_PORT = 20100;
|
private static final int SERVER_PORT = 20100;
|
||||||
|
|
||||||
static final Logger LOG = Logger.getLogger(HttpTunnelSoakTester.class
|
private static final InternalLogger logger =
|
||||||
.getName());
|
InternalLoggerFactory.getInstance(HttpTunnelSoakTester.class);
|
||||||
|
|
||||||
private static final long BYTES_TO_SEND = 1024 * 1024 * 1024;
|
private static final long BYTES_TO_SEND = 1024 * 1024 * 1024;
|
||||||
|
|
||||||
@ -127,15 +127,14 @@ public class HttpTunnelSoakTester {
|
|||||||
clientBootstrap.setOption(
|
clientBootstrap.setOption(
|
||||||
HttpTunnelClientChannelConfig.PROXY_ADDRESS_OPTION,
|
HttpTunnelClientChannelConfig.PROXY_ADDRESS_OPTION,
|
||||||
proxyAddress);
|
proxyAddress);
|
||||||
System.out.println("Using " + proxyAddress +
|
logger.info("Using " + proxyAddress +
|
||||||
" as a proxy for this test run");
|
" as a proxy for this test run");
|
||||||
} else {
|
} else {
|
||||||
System.err.println("Failed to resolve proxy address " +
|
logger.error("Failed to resolve proxy address " +
|
||||||
proxyAddress);
|
proxyAddress);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
System.out
|
logger.info("No proxy specified, will connect to server directly");
|
||||||
.println("No proxy specified, will connect to server directly");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,16 +196,16 @@ public class HttpTunnelSoakTester {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void run() throws InterruptedException {
|
public void run() throws InterruptedException {
|
||||||
LOG.info("binding server channel");
|
logger.info("binding server channel");
|
||||||
Channel serverChannel =
|
Channel serverChannel =
|
||||||
serverBootstrap.bind(new InetSocketAddress(SERVER_PORT));
|
serverBootstrap.bind(new InetSocketAddress(SERVER_PORT));
|
||||||
channels.add(serverChannel);
|
channels.add(serverChannel);
|
||||||
LOG.log(Level.INFO, "server channel bound to {0}",
|
logger.info(String.format("server channel bound to {0}",
|
||||||
serverChannel.getLocalAddress());
|
serverChannel.getLocalAddress()));
|
||||||
|
|
||||||
SocketChannel clientChannel = createClientChannel();
|
SocketChannel clientChannel = createClientChannel();
|
||||||
if (clientChannel == null) {
|
if (clientChannel == null) {
|
||||||
LOG.severe("no client channel - bailing out");
|
logger.error("no client channel - bailing out");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,37 +215,37 @@ public class HttpTunnelSoakTester {
|
|||||||
executor.execute(c2sDataSender);
|
executor.execute(c2sDataSender);
|
||||||
|
|
||||||
if (!c2sDataSender.waitForFinish(5, TimeUnit.MINUTES)) {
|
if (!c2sDataSender.waitForFinish(5, TimeUnit.MINUTES)) {
|
||||||
LOG.severe("Data send from client to server failed");
|
logger.error("Data send from client to server failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!s2cDataSender.waitForFinish(5, TimeUnit.MINUTES)) {
|
if (!s2cDataSender.waitForFinish(5, TimeUnit.MINUTES)) {
|
||||||
LOG.severe("Data send from server to client failed");
|
logger.error("Data send from server to client failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG.log(Level.INFO, "Waiting for verification to complete");
|
logger.info("Waiting for verification to complete");
|
||||||
if (!c2sVerifier.waitForCompletion(30L, TimeUnit.SECONDS)) {
|
if (!c2sVerifier.waitForCompletion(30L, TimeUnit.SECONDS)) {
|
||||||
LOG.warning("Timed out waiting for verification of client-to-server stream");
|
logger.warn("Timed out waiting for verification of client-to-server stream");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!s2cVerifier.waitForCompletion(30L, TimeUnit.SECONDS)) {
|
if (!s2cVerifier.waitForCompletion(30L, TimeUnit.SECONDS)) {
|
||||||
LOG.warning("Timed out waiting for verification of server-to-client stream");
|
logger.warn("Timed out waiting for verification of server-to-client stream");
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG.info("closing client channel");
|
logger.info("closing client channel");
|
||||||
closeChannel(clientChannel);
|
closeChannel(clientChannel);
|
||||||
LOG.info("server channel status: " +
|
logger.info("server channel status: " +
|
||||||
(serverChannel.isOpen()? "open" : "closed"));
|
(serverChannel.isOpen()? "open" : "closed"));
|
||||||
LOG.info("closing server channel");
|
logger.info("closing server channel");
|
||||||
closeChannel(serverChannel);
|
closeChannel(serverChannel);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void closeChannel(Channel channel) {
|
private void closeChannel(Channel channel) {
|
||||||
try {
|
try {
|
||||||
if (!channel.close().await(5L, TimeUnit.SECONDS)) {
|
if (!channel.close().await(5L, TimeUnit.SECONDS)) {
|
||||||
LOG.warning("Failed to close connection within reasonable amount of time");
|
logger.warn("Failed to close connection within reasonable amount of time");
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
LOG.severe("Interrupted while closing connection");
|
logger.error("Interrupted while closing connection");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -258,16 +257,16 @@ public class HttpTunnelSoakTester {
|
|||||||
clientBootstrap.connect(serverAddress);
|
clientBootstrap.connect(serverAddress);
|
||||||
try {
|
try {
|
||||||
if (!clientChannelFuture.await(1000, TimeUnit.MILLISECONDS)) {
|
if (!clientChannelFuture.await(1000, TimeUnit.MILLISECONDS)) {
|
||||||
LOG.severe("did not connect within acceptable time period");
|
logger.error("did not connect within acceptable time period");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
LOG.severe("Interrupted while waiting for client connect to be established");
|
logger.error("Interrupted while waiting for client connect to be established");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!clientChannelFuture.isSuccess()) {
|
if (!clientChannelFuture.isSuccess()) {
|
||||||
LOG.log(Level.SEVERE, "did not connect successfully",
|
logger.error("did not connect successfully",
|
||||||
clientChannelFuture.getCause());
|
clientChannelFuture.getCause());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -331,9 +330,9 @@ public class HttpTunnelSoakTester {
|
|||||||
while (bytesToVerify.readable()) {
|
while (bytesToVerify.readable()) {
|
||||||
byte readByte = bytesToVerify.readByte();
|
byte readByte = bytesToVerify.readByte();
|
||||||
if (readByte != expectedNext) {
|
if (readByte != expectedNext) {
|
||||||
LOG.log(Level.SEVERE,
|
logger.error(String.format(
|
||||||
"{0}: received a byte out of sequence. Expected {1}, got {2}",
|
"{0}: received a byte out of sequence. Expected {1}, got {2}",
|
||||||
new Object[] { name, expectedNext, readByte });
|
new Object[] { name, expectedNext, readByte }));
|
||||||
System.exit(-1);
|
System.exit(-1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -416,20 +415,20 @@ public class HttpTunnelSoakTester {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (!running.compareAndSet(false, true)) {
|
if (!running.compareAndSet(false, true)) {
|
||||||
LOG.log(Level.WARNING,
|
logger.warn(String.format(
|
||||||
"{0}: Attempt made to run duplicate sender!", name);
|
"{0}: Attempt made to run duplicate sender!", name));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (finishLatch.getCount() == 0) {
|
if (finishLatch.getCount() == 0) {
|
||||||
LOG.log(Level.SEVERE,
|
logger.error(String.format(
|
||||||
"{0}: Attempt made to run after completion!", name);
|
"{0}: Attempt made to run after completion!", name));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (firstRun) {
|
if (firstRun) {
|
||||||
firstRun = false;
|
firstRun = false;
|
||||||
runStartTime = System.currentTimeMillis();
|
runStartTime = System.currentTimeMillis();
|
||||||
LOG.log(Level.INFO, "{0}: sending data", name);
|
logger.info(String.format("{0}: sending data", name));
|
||||||
}
|
}
|
||||||
|
|
||||||
while (totalBytesSent < BYTES_TO_SEND) {
|
while (totalBytesSent < BYTES_TO_SEND) {
|
||||||
@ -447,22 +446,22 @@ public class HttpTunnelSoakTester {
|
|||||||
|
|
||||||
numWrites ++;
|
numWrites ++;
|
||||||
if (numWrites % 100 == 0) {
|
if (numWrites % 100 == 0) {
|
||||||
LOG.log(Level.INFO,
|
logger.info(String.format(
|
||||||
"{0}: {1} writes dispatched, totalling {2} bytes",
|
"{0}: {1} writes dispatched, totalling {2} bytes",
|
||||||
new Object[] { name, numWrites, totalBytesSent });
|
new Object[] { name, numWrites, totalBytesSent }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG.log(Level.INFO, "{0}: completed send cycle", name);
|
logger.info(String.format("{0}: completed send cycle", name));
|
||||||
|
|
||||||
long runEndTime = System.currentTimeMillis();
|
long runEndTime = System.currentTimeMillis();
|
||||||
long totalTime = runEndTime - runStartTime;
|
long totalTime = runEndTime - runStartTime;
|
||||||
long totalKB = totalBytesSent / 1024;
|
long totalKB = totalBytesSent / 1024;
|
||||||
double rate = totalKB / (totalTime / 1000.0);
|
double rate = totalKB / (totalTime / 1000.0);
|
||||||
LOG.log(Level.INFO, "{0}: Sent {1} bytes", new Object[] { name,
|
logger.info(String.format("{0}: Sent {1} bytes", new Object[] { name,
|
||||||
totalBytesSent });
|
totalBytesSent }));
|
||||||
LOG.log(Level.INFO, "{0}: Average throughput: {1} KB/s",
|
logger.info(String.format("{0}: Average throughput: {1} KB/s",
|
||||||
new Object[] { name, rate });
|
new Object[] { name, rate }));
|
||||||
|
|
||||||
finishLatch.countDown();
|
finishLatch.countDown();
|
||||||
running.set(false);
|
running.set(false);
|
||||||
|
@ -35,6 +35,8 @@ import io.netty.channel.sctp.SctpServerSocketChannelFactory;
|
|||||||
import io.netty.channel.sctp.codec.SctpFrameDecoder;
|
import io.netty.channel.sctp.codec.SctpFrameDecoder;
|
||||||
import io.netty.channel.sctp.codec.SctpFrameEncoder;
|
import io.netty.channel.sctp.codec.SctpFrameEncoder;
|
||||||
import io.netty.channel.sctp.handler.SimpleSctpChannelHandler;
|
import io.netty.channel.sctp.handler.SimpleSctpChannelHandler;
|
||||||
|
import io.netty.logging.InternalLogger;
|
||||||
|
import io.netty.logging.InternalLoggerFactory;
|
||||||
import io.netty.testsuite.util.SctpTestUtil;
|
import io.netty.testsuite.util.SctpTestUtil;
|
||||||
import io.netty.util.internal.ExecutorUtil;
|
import io.netty.util.internal.ExecutorUtil;
|
||||||
|
|
||||||
@ -53,6 +55,10 @@ import org.junit.BeforeClass;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class SctpMultiHomingEchoTest {
|
public class SctpMultiHomingEchoTest {
|
||||||
|
|
||||||
|
private static final InternalLogger logger =
|
||||||
|
InternalLoggerFactory.getInstance(SctpMultiHomingEchoTest.class);
|
||||||
|
|
||||||
private static final Random random = new Random();
|
private static final Random random = new Random();
|
||||||
static final byte[] data = new byte[4096];//could not test ultra jumbo frames
|
static final byte[] data = new byte[4096];//could not test ultra jumbo frames
|
||||||
|
|
||||||
@ -228,7 +234,7 @@ public class SctpMultiHomingEchoTest {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sctpNotificationReceived(ChannelHandlerContext ctx, SctpNotificationEvent event) {
|
public void sctpNotificationReceived(ChannelHandlerContext ctx, SctpNotificationEvent event) {
|
||||||
System.out.println("SCTP notification event received :" + event);
|
logger.info("SCTP notification event received :" + event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -432,11 +432,10 @@ final class NioProviderMetadata {
|
|||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
for (Entry<Object, Object> e: System.getProperties().entrySet()) {
|
for (Entry<Object, Object> e: System.getProperties().entrySet()) {
|
||||||
System.out.println(e.getKey() + ": " + e.getValue());
|
logger.debug(e.getKey() + ": " + e.getValue());
|
||||||
}
|
}
|
||||||
System.out.println();
|
logger.debug("Hard-coded Constraint Level: " + CONSTRAINT_LEVEL);
|
||||||
System.out.println("Hard-coded Constraint Level: " + CONSTRAINT_LEVEL);
|
logger.debug(
|
||||||
System.out.println(
|
|
||||||
"Auto-detected Constraint Level: " +
|
"Auto-detected Constraint Level: " +
|
||||||
new ConstraintLevelAutodetector().autodetect());
|
new ConstraintLevelAutodetector().autodetect());
|
||||||
}
|
}
|
||||||
|
@ -31,8 +31,14 @@ import io.netty.channel.SimpleChannelUpstreamHandler;
|
|||||||
import io.netty.channel.local.DefaultLocalClientChannelFactory;
|
import io.netty.channel.local.DefaultLocalClientChannelFactory;
|
||||||
import io.netty.channel.local.DefaultLocalServerChannelFactory;
|
import io.netty.channel.local.DefaultLocalServerChannelFactory;
|
||||||
import io.netty.channel.local.LocalAddress;
|
import io.netty.channel.local.LocalAddress;
|
||||||
|
import io.netty.logging.InternalLogger;
|
||||||
|
import io.netty.logging.InternalLoggerFactory;
|
||||||
|
|
||||||
public class LocalAddressTest {
|
public class LocalAddressTest {
|
||||||
|
|
||||||
|
private static final InternalLogger logger =
|
||||||
|
InternalLoggerFactory.getInstance(LocalAddressTest.class);
|
||||||
|
|
||||||
private static String LOCAL_ADDR_ID = "test.id";
|
private static String LOCAL_ADDR_ID = "test.id";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -157,7 +163,7 @@ public class LocalAddressTest {
|
|||||||
ChannelEvent e)
|
ChannelEvent e)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
|
||||||
System.err.println(String.format("Received upstream event '%s'", e));
|
logger.info(String.format("Received upstream event '%s'", e));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user