Fix various inspection warnings

This commit is contained in:
Trustin Lee 2013-01-10 15:23:58 +09:00
parent 3c9d912355
commit eb337ff5a7
47 changed files with 293 additions and 331 deletions

View File

@ -42,7 +42,7 @@ public interface CompositeByteBuf extends ByteBuf, Iterable<ByteBuf> {
* the {@link ByteBuf} to add * the {@link ByteBuf} to add
* @return self * @return self
* this instance * this instance
* @thows {@link IndexOutOfBoundsException} * @throws {@link IndexOutOfBoundsException}
* if the index is invalid * if the index is invalid
*/ */
CompositeByteBuf addComponent(int cIndex, ByteBuf buffer); CompositeByteBuf addComponent(int cIndex, ByteBuf buffer);
@ -72,7 +72,7 @@ public interface CompositeByteBuf extends ByteBuf, Iterable<ByteBuf> {
* the {@link ByteBuf}s to add * the {@link ByteBuf}s to add
* @return self * @return self
* this instance * this instance
* @thows {@link IndexOutOfBoundsException} * @throws {@link IndexOutOfBoundsException}
* if the index is invalid * if the index is invalid
* *
*/ */
@ -87,7 +87,7 @@ public interface CompositeByteBuf extends ByteBuf, Iterable<ByteBuf> {
* the {@link ByteBuf}s to add * the {@link ByteBuf}s to add
* @return self * @return self
* this instance * this instance
* @thows {@link IndexOutOfBoundsException} * @throws {@link IndexOutOfBoundsException}
* if the index is invalid * if the index is invalid
*/ */
CompositeByteBuf addComponents(int cIndex, Iterable<ByteBuf> buffers); CompositeByteBuf addComponents(int cIndex, Iterable<ByteBuf> buffers);
@ -99,7 +99,7 @@ public interface CompositeByteBuf extends ByteBuf, Iterable<ByteBuf> {
* the index on from which the {@link ByteBuf} will be remove * the index on from which the {@link ByteBuf} will be remove
* @return self * @return self
* this instance * this instance
* @thows {@link IndexOutOfBoundsException} * @throws {@link IndexOutOfBoundsException}
* if the index is invalid * if the index is invalid
*/ */
CompositeByteBuf removeComponent(int cIndex); CompositeByteBuf removeComponent(int cIndex);
@ -113,7 +113,7 @@ public interface CompositeByteBuf extends ByteBuf, Iterable<ByteBuf> {
* the number of components to remove * the number of components to remove
* @return self * @return self
* this instance * this instance
* @thows {@link IndexOutOfBoundsException} * @throws {@link IndexOutOfBoundsException}
* if the index is invalid * if the index is invalid
*/ */
CompositeByteBuf removeComponents(int cIndex, int numComponents); CompositeByteBuf removeComponents(int cIndex, int numComponents);
@ -135,7 +135,7 @@ public interface CompositeByteBuf extends ByteBuf, Iterable<ByteBuf> {
* the index for which the {@link ByteBuf} should be returned * the index for which the {@link ByteBuf} should be returned
* @return buf * @return buf
* the {@link ByteBuf} on the specified index * the {@link ByteBuf} on the specified index
* @thows {@link IndexOutOfBoundsException} * @throws {@link IndexOutOfBoundsException}
* if the index is invalid * if the index is invalid
*/ */
ByteBuf component(int cIndex); ByteBuf component(int cIndex);
@ -147,7 +147,7 @@ public interface CompositeByteBuf extends ByteBuf, Iterable<ByteBuf> {
* the offset for which the {@link ByteBuf} should be returned * the offset for which the {@link ByteBuf} should be returned
* @return buf * @return buf
* the {@link ByteBuf} on the specified index * the {@link ByteBuf} on the specified index
* @thows {@link IndexOutOfBoundsException} * @throws {@link IndexOutOfBoundsException}
* if the offset is invalid * if the offset is invalid
*/ */
ByteBuf componentAtOffset(int offset); ByteBuf componentAtOffset(int offset);
@ -175,7 +175,7 @@ public interface CompositeByteBuf extends ByteBuf, Iterable<ByteBuf> {
* the number of components to compose * the number of components to compose
* @return self * @return self
* this instance * this instance
* @thows {@link IndexOutOfBoundsException} * @throws {@link IndexOutOfBoundsException}
* if the offset is invalid * if the offset is invalid
*/ */
CompositeByteBuf consolidate(int cIndex, int numComponents); CompositeByteBuf consolidate(int cIndex, int numComponents);

View File

@ -131,7 +131,7 @@ final class DefaultMessageBuf<T> extends ArrayDeque<T> implements MessageBuf<T>
} }
@Override @Override
public <T1 extends Object> T1[] toArray(T1[] a) { public <T1> T1[] toArray(T1[] a) {
ensureValid(); ensureValid();
return super.toArray(a); return super.toArray(a);
} }

View File

@ -16,7 +16,6 @@
package io.netty.handler.codec.http.websocketx; package io.netty.handler.codec.http.websocketx;
import io.netty.buffer.MessageBuf; import io.netty.buffer.MessageBuf;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundMessageHandlerAdapter; import io.netty.channel.ChannelInboundMessageHandlerAdapter;

View File

@ -27,12 +27,6 @@ public final class SocksAuthResponse extends SocksResponse {
private static final SubnegotiationVersion SUBNEGOTIATION_VERSION = SubnegotiationVersion.AUTH_PASSWORD; private static final SubnegotiationVersion SUBNEGOTIATION_VERSION = SubnegotiationVersion.AUTH_PASSWORD;
private final AuthStatus authStatus; private final AuthStatus authStatus;
/**
*
* @param authStatus
* @throws NullPointerException
*/
public SocksAuthResponse(AuthStatus authStatus) { public SocksAuthResponse(AuthStatus authStatus) {
super(SocksResponseType.AUTH); super(SocksResponseType.AUTH);
if (authStatus == null) { if (authStatus == null) {

View File

@ -216,7 +216,7 @@ public abstract class SocksMessage {
private final byte b; private final byte b;
private SubnegotiationVersion(byte b) { SubnegotiationVersion(byte b) {
this.b = b; this.b = b;
} }
@ -245,9 +245,6 @@ public abstract class SocksMessage {
/** /**
* Encode socks message into its byte representation and write it into byteBuf * Encode socks message into its byte representation and write it into byteBuf
*
* @param byteBuf
* @see ByteBuf
*/ */
public abstract void encodeAsByteBuf(ByteBuf byteBuf); public abstract void encodeAsByteBuf(ByteBuf byteBuf);
} }

View File

@ -47,7 +47,8 @@ public final class MonitorRegistries implements Iterable<MonitorRegistry> {
private static final int SUCCESSFUL_INITIALIZATION = 2; private static final int SUCCESSFUL_INITIALIZATION = 2;
private static final int NOP_FALLBACK_INITIALIZATION = 3; private static final int NOP_FALLBACK_INITIALIZATION = 3;
private static int INITIALIZATION_STATE = UNINITIALIZED; @SuppressWarnings("RedundantFieldInitialization")
private static int initState = UNINITIALIZED;
private static MonitorRegistry selectedRegistry; private static MonitorRegistry selectedRegistry;
/** /**
@ -107,11 +108,11 @@ public final class MonitorRegistries implements Iterable<MonitorRegistry> {
*/ */
public MonitorRegistry unique() { public MonitorRegistry unique() {
//Implementation based on SLF4J's //Implementation based on SLF4J's
if (INITIALIZATION_STATE == UNINITIALIZED) { if (initState == UNINITIALIZED) {
INITIALIZATION_STATE = ONGOING_INITIALIZATION; initState = ONGOING_INITIALIZATION;
performInitialization(); performInitialization();
} }
switch (INITIALIZATION_STATE) { switch (initState) {
case SUCCESSFUL_INITIALIZATION: case SUCCESSFUL_INITIALIZATION:
return selectedRegistry; return selectedRegistry;
case NOP_FALLBACK_INITIALIZATION: case NOP_FALLBACK_INITIALIZATION:
@ -125,14 +126,14 @@ public final class MonitorRegistries implements Iterable<MonitorRegistry> {
final Iterator<MonitorRegistry> registries = iterator(); final Iterator<MonitorRegistry> registries = iterator();
if (registries.hasNext()) { if (registries.hasNext()) {
selectedRegistry = registries.next(); selectedRegistry = registries.next();
INITIALIZATION_STATE = SUCCESSFUL_INITIALIZATION; initState = SUCCESSFUL_INITIALIZATION;
} }
if (selectedRegistry != null && registries.hasNext()) { if (selectedRegistry != null && registries.hasNext()) {
logger.warn(String.format("Multiple metrics implementations found. " + logger.warn(String.format("Multiple metrics implementations found. " +
"Selected %s, ignoring other implementations", selectedRegistry.getClass().getName())); "Selected %s, ignoring other implementations", selectedRegistry.getClass().getName()));
} }
if (selectedRegistry == null) { if (selectedRegistry == null) {
INITIALIZATION_STATE = NOP_FALLBACK_INITIALIZATION; initState = NOP_FALLBACK_INITIALIZATION;
logger.debug("No metrics implementation found on the classpath."); logger.debug("No metrics implementation found on the classpath.");
} }
} }

View File

@ -16,6 +16,7 @@
package io.netty.util.internal; package io.netty.util.internal;
import sun.misc.Cleaner; import sun.misc.Cleaner;
import sun.misc.Unsafe;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
@ -119,7 +120,7 @@ public final class DetectionUtil {
} }
/** /**
* Return {@code true} if {@link sun.misc.Unsafe} was found on the classpath and can be used. * Return {@code true} if {@link Unsafe} was found on the classpath and can be used.
*/ */
public static boolean hasUnsafe() { public static boolean hasUnsafe() {
return HAS_UNSAFE; return HAS_UNSAFE;

View File

@ -1,44 +1,58 @@
/*
* Copyright 2013 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.monitor; package io.netty.monitor;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import io.netty.monitor.support.SampleMonitorRegistryFactory; import io.netty.monitor.support.SampleMonitorRegistryFactory;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.*;
public class MonitorRegistriesTest { public class MonitorRegistriesTest {
@Test @Test
public final void instanceShouldNotReturnNull() { public final void instanceShouldNotReturnNull() {
assertNotNull("instance() should NEVER return null", assertNotNull("instance() should NEVER return null",
MonitorRegistries.instance()); MonitorRegistries.instance());
} }
@Test @Test
public final void instanceShouldAlwaysReturnTheSameInstance() { public final void instanceShouldAlwaysReturnTheSameInstance() {
final MonitorRegistries firstInstance = MonitorRegistries.instance(); final MonitorRegistries firstInstance = MonitorRegistries.instance();
final MonitorRegistries secondInstance = MonitorRegistries.instance(); final MonitorRegistries secondInstance = MonitorRegistries.instance();
assertSame("instance() should always return the same instance", assertSame("instance() should always return the same instance",
firstInstance, secondInstance); firstInstance, secondInstance);
} }
@Test @Test
public final void forProviderShouldReturnMonitorRegistryMatchingTheSuppliedProvider() { public final void forProviderShouldReturnMonitorRegistryMatchingTheSuppliedProvider() {
final MonitorRegistries objectUnderTest = MonitorRegistries.instance(); final MonitorRegistries objectUnderTest = MonitorRegistries.instance();
final MonitorRegistry registry = objectUnderTest final MonitorRegistry registry = MonitorRegistries.forProvider(SampleMonitorRegistryFactory.PROVIDER);
.forProvider(SampleMonitorRegistryFactory.PROVIDER);
assertSame("forProvider(" + SampleMonitorRegistryFactory.PROVIDER assertSame("forProvider(" + SampleMonitorRegistryFactory.PROVIDER
+ ") should return a MonitorRegistry by the supplied provider", + ") should return a MonitorRegistry by the supplied provider",
SampleMonitorRegistryFactory.SampleMonitorRegistry.class, SampleMonitorRegistryFactory.SampleMonitorRegistry.class,
registry.getClass()); registry.getClass());
} }
@Test @Test
public final void uniqueShouldThrowIllegalStateExceptionIfMoreThanOneProviderIsRegistered() { public final void uniqueShouldThrowIllegalStateExceptionIfMoreThanOneProviderIsRegistered() {
final MonitorRegistries objectUnderTest = MonitorRegistries.instance(); final MonitorRegistries objectUnderTest = MonitorRegistries.instance();
objectUnderTest.unique(); objectUnderTest.unique();
} }
} }

View File

@ -15,17 +15,17 @@
*/ */
package io.netty.util; package io.netty.util;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import static org.junit.Assert.*; import static org.junit.Assert.*;
public class NetUtilTest { public class NetUtilTest {
private final static Map<String, byte[]> validIpV4Hosts = new HashMap<String, byte[]>() { private final static Map<String, byte[]> validIpV4Hosts = new HashMap<String, byte[]>() {
private static final long serialVersionUID = 2629792739366724032L;
{ {
put("192.168.1.0", new byte[]{ put("192.168.1.0", new byte[]{
(byte) 0xc0, (byte) 0xa8, 0x01, 0x00} (byte) 0xc0, (byte) 0xa8, 0x01, 0x00}
@ -46,6 +46,7 @@ public class NetUtilTest {
} }
}; };
private final static Map<String, byte[]> invalidIpV4Hosts = new HashMap<String, byte[]>() { private final static Map<String, byte[]> invalidIpV4Hosts = new HashMap<String, byte[]>() {
private static final long serialVersionUID = 1299215199895717282L;
{ {
put("1.256.3.4", null); put("1.256.3.4", null);
put("256.0.0.1", null); put("256.0.0.1", null);
@ -53,6 +54,7 @@ public class NetUtilTest {
} }
}; };
private final static Map<String, byte[]> validIpV6Hosts = new HashMap<String, byte[]>() { private final static Map<String, byte[]> validIpV6Hosts = new HashMap<String, byte[]>() {
private static final long serialVersionUID = 3999763170377573184L;
{ {
put("::ffff:5.6.7.8", new byte[]{ put("::ffff:5.6.7.8", new byte[]{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@ -164,6 +166,7 @@ public class NetUtilTest {
} }
}; };
private final static Map<String, byte[]> invalidIpV6Hosts = new HashMap<String, byte[]>() { private final static Map<String, byte[]> invalidIpV6Hosts = new HashMap<String, byte[]>() {
private static final long serialVersionUID = -5870810805409009696L;
{ {
// Test method with garbage. // Test method with garbage.
put("Obvious Garbage", null); put("Obvious Garbage", null);
@ -278,17 +281,17 @@ public class NetUtilTest {
@Test @Test
public void testCreateByteArrayFromIpAddressString() { public void testCreateByteArrayFromIpAddressString() {
for (String host : validIpV4Hosts.keySet()) { for (Entry<String, byte[]> stringEntry : validIpV4Hosts.entrySet()) {
assertTrue(Arrays.equals(validIpV4Hosts.get(host), NetUtil.createByteArrayFromIpAddressString(host))); assertArrayEquals(stringEntry.getValue(), NetUtil.createByteArrayFromIpAddressString(stringEntry.getKey()));
} }
for (String host : invalidIpV4Hosts.keySet()) { for (Entry<String, byte[]> stringEntry : invalidIpV4Hosts.entrySet()) {
assertTrue(Arrays.equals(invalidIpV4Hosts.get(host), NetUtil.createByteArrayFromIpAddressString(host))); assertArrayEquals(stringEntry.getValue(), NetUtil.createByteArrayFromIpAddressString(stringEntry.getKey()));
} }
for (String host : validIpV6Hosts.keySet()) { for (Entry<String, byte[]> stringEntry : validIpV6Hosts.entrySet()) {
assertTrue(Arrays.equals(validIpV6Hosts.get(host), NetUtil.createByteArrayFromIpAddressString(host))); assertArrayEquals(stringEntry.getValue(), NetUtil.createByteArrayFromIpAddressString(stringEntry.getKey()));
} }
for (String host : invalidIpV6Hosts.keySet()) { for (Entry<String, byte[]> stringEntry : invalidIpV6Hosts.entrySet()) {
assertTrue(Arrays.equals(invalidIpV6Hosts.get(host), NetUtil.createByteArrayFromIpAddressString(host))); assertArrayEquals(stringEntry.getValue(), NetUtil.createByteArrayFromIpAddressString(stringEntry.getKey()));
} }
} }
} }

View File

@ -26,13 +26,17 @@ import io.netty.channel.socket.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.util.CharsetUtil; import io.netty.util.CharsetUtil;
import javax.swing.JApplet; import javax.swing.*;
/** /**
* {@link JApplet} which starts up a Server that receive data and discard it. * {@link JApplet} which starts up a Server that receive data and discard it.
*/ */
public class AppletDiscardServer extends JApplet { public class AppletDiscardServer extends JApplet {
private static final long serialVersionUID = -7824894101960583175L;
private ServerBootstrap bootstrap; private ServerBootstrap bootstrap;
@Override @Override
public void init() { public void init() {
try { try {

View File

@ -21,10 +21,10 @@ import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundMessageHandlerAdapter; import io.netty.channel.ChannelInboundMessageHandlerAdapter;
import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption; import io.netty.channel.ChannelOption;
import io.netty.channel.DefaultFileRegion;
import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioEventLoopGroup; import io.netty.channel.socket.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.channel.DefaultFileRegion;
import io.netty.handler.codec.LineBasedFrameDecoder; import io.netty.handler.codec.LineBasedFrameDecoder;
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;
@ -95,14 +95,14 @@ public class FileServer {
File file = new File(msg); File file = new File(msg);
if (file.exists()) { if (file.exists()) {
if (!file.isFile()) { if (!file.isFile()) {
ctx.write("Not a file: " + file + "\n"); ctx.write("Not a file: " + file + '\n');
return; return;
} }
ctx.write(file + " " + file.length() + "\n"); ctx.write(file + " " + file.length() + '\n');
ctx.sendFile(new DefaultFileRegion(new FileInputStream(file).getChannel(), 0, file.length())); ctx.sendFile(new DefaultFileRegion(new FileInputStream(file).getChannel(), 0, file.length()));
ctx.write("\n"); ctx.write("\n");
} else { } else {
ctx.write("File not found: " + file + "\n"); ctx.write("File not found: " + file + '\n');
} }
} }

View File

@ -15,14 +15,12 @@
*/ */
package io.netty.example.udt.echo.message; package io.netty.example.udt.echo.message;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.MessageBuf; import io.netty.buffer.MessageBuf;
import io.netty.channel.ChannelHandler.Sharable; import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundMessageHandlerAdapter; import io.netty.channel.ChannelInboundMessageHandlerAdapter;
import io.netty.transport.udt.UdtMessage; import io.netty.transport.udt.UdtMessage;
import io.netty.transport.udt.nio.NioUdtProvider; import io.netty.transport.udt.nio.NioUdtProvider;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -52,7 +50,6 @@ public class MsgEchoServerHandler extends
@Override @Override
protected void messageReceived(final ChannelHandlerContext ctx, protected void messageReceived(final ChannelHandlerContext ctx,
final UdtMessage message) throws Exception { final UdtMessage message) throws Exception {
final ByteBuf byteBuf = message.data();
final MessageBuf<Object> out = ctx.nextOutboundMessageBuffer(); final MessageBuf<Object> out = ctx.nextOutboundMessageBuffer();
out.add(message); out.add(message);
ctx.flush(); ctx.flush();

View File

@ -24,13 +24,12 @@ import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler; import io.netty.handler.logging.LoggingHandler;
import io.netty.transport.udt.UdtChannel; import io.netty.transport.udt.UdtChannel;
import io.netty.transport.udt.nio.NioUdtProvider; import io.netty.transport.udt.nio.NioUdtProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.concurrent.ThreadFactory; import java.util.concurrent.ThreadFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* UDT Message Flow Peer * UDT Message Flow Peer
* <p> * <p>
@ -46,8 +45,7 @@ public abstract class MsgEchoPeerBase {
protected final InetSocketAddress self; protected final InetSocketAddress self;
protected final InetSocketAddress peer; protected final InetSocketAddress peer;
public MsgEchoPeerBase(final InetSocketAddress self, protected MsgEchoPeerBase(final InetSocketAddress self, final InetSocketAddress peer, final int messageSize) {
final InetSocketAddress peer, final int messageSize) {
this.messageSize = messageSize; this.messageSize = messageSize;
this.self = self; this.self = self;
this.peer = peer; this.peer = peer;

View File

@ -16,15 +16,6 @@
package io.netty.example.udt.util; package io.netty.example.udt.util;
import java.io.PrintStream;
import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Map.Entry;
import java.util.SortedMap;
import java.util.TimeZone;
import java.util.concurrent.TimeUnit;
import com.yammer.metrics.Metrics; import com.yammer.metrics.Metrics;
import com.yammer.metrics.core.Clock; import com.yammer.metrics.core.Clock;
import com.yammer.metrics.core.Counter; import com.yammer.metrics.core.Counter;
@ -40,6 +31,15 @@ import com.yammer.metrics.core.Timer;
import com.yammer.metrics.reporting.AbstractPollingReporter; import com.yammer.metrics.reporting.AbstractPollingReporter;
import com.yammer.metrics.stats.Snapshot; import com.yammer.metrics.stats.Snapshot;
import java.io.PrintStream;
import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Map.Entry;
import java.util.SortedMap;
import java.util.TimeZone;
import java.util.concurrent.TimeUnit;
/** /**
* A simple reporters which prints out application metrics to a * A simple reporters which prints out application metrics to a
* {@link PrintStream} periodically. * {@link PrintStream} periodically.
@ -123,7 +123,7 @@ public class UtilConsoleReporter extends AbstractPollingReporter implements
final String dateTime = format.format(new Date(clock.time())); final String dateTime = format.format(new Date(clock.time()));
out.print(dateTime); out.print(dateTime);
out.print(' '); out.print(' ');
for (int i = 0; i < (CONSOLE_WIDTH - dateTime.length() - 1); i++) { for (int i = 0; i < CONSOLE_WIDTH - dateTime.length() - 1; i++) {
out.print('='); out.print('=');
} }
out.println(); out.println();
@ -227,7 +227,7 @@ public class UtilConsoleReporter extends AbstractPollingReporter implements
snapshot.get999thPercentile(), durationUnit); snapshot.get999thPercentile(), durationUnit);
} }
private String abbrev(final TimeUnit unit) { private static String abbrev(final TimeUnit unit) {
switch (unit) { switch (unit) {
case NANOSECONDS: case NANOSECONDS:
return "ns"; return "ns";

View File

@ -35,6 +35,5 @@ public class UtilThreadFactory implements ThreadFactory {
@Override @Override
public Thread newThread(final Runnable runnable) { public Thread newThread(final Runnable runnable) {
return new Thread(runnable, name + "-" + counter.getAndIncrement()); return new Thread(runnable, name + "-" + counter.getAndIncrement());
}; }
} }

View File

@ -33,7 +33,7 @@ public final class IdleStateEvent {
* Create a new instance * Create a new instance
* *
* @param state the detailed idle state. * @param state the detailed idle state.
* @param count the count how often this kind of {@IdleStateEvent} was fired before * @param count the count how often this kind of {@link IdleStateEvent} was fired before
* @param durationMillis the duration which caused the {@link IdleStateEvent} to get fired in milliseconds * @param durationMillis the duration which caused the {@link IdleStateEvent} to get fired in milliseconds
*/ */
public IdleStateEvent(IdleState state, int count, long durationMillis) { public IdleStateEvent(IdleState state, int count, long durationMillis) {
@ -61,7 +61,7 @@ public final class IdleStateEvent {
} }
/** /**
* Return the count how often this kind of {@IdleStateEvent} was fired before. * Return the count how often this kind of {@link IdleStateEvent} was fired before.
*/ */
public int count() { public int count() {
return count; return count;

View File

@ -86,7 +86,7 @@ public class TrafficCounter {
/** /**
* Delay between two captures * Delay between two captures
*/ */
AtomicLong checkInterval = new AtomicLong( final AtomicLong checkInterval = new AtomicLong(
AbstractTrafficShapingHandler.DEFAULT_CHECK_INTERVAL); AbstractTrafficShapingHandler.DEFAULT_CHECK_INTERVAL);
// default 1 s // default 1 s
@ -117,7 +117,7 @@ public class TrafficCounter {
/** /**
* Is Monitor active * Is Monitor active
*/ */
AtomicBoolean monitorActive = new AtomicBoolean(); final AtomicBoolean monitorActive = new AtomicBoolean();
/** /**
* Class to implement monitoring at fix delay * Class to implement monitoring at fix delay

View File

@ -69,7 +69,6 @@
<properties> <properties>
<jboss.marshalling.version>1.3.14.GA</jboss.marshalling.version> <jboss.marshalling.version>1.3.14.GA</jboss.marshalling.version>
<yammer.metrics.version>2.1.4</yammer.metrics.version>
</properties> </properties>
<modules> <modules>
@ -113,6 +112,12 @@
<version>2.1.7</version> <version>2.1.7</version>
</dependency> </dependency>
<dependency>
<groupId>com.barchart.udt</groupId>
<artifactId>barchart-udt-bundle</artifactId>
<version>2.2.0</version>
</dependency>
<dependency> <dependency>
<groupId>javax.servlet</groupId> <groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId> <artifactId>servlet-api</artifactId>
@ -174,7 +179,7 @@
<dependency> <dependency>
<groupId>com.yammer.metrics</groupId> <groupId>com.yammer.metrics</groupId>
<artifactId>metrics-core</artifactId> <artifactId>metrics-core</artifactId>
<version>${yammer.metrics.version}</version> <version>2.2.0</version>
</dependency> </dependency>
<!-- Test dependencies for jboss marshalling encoder/decoder --> <!-- Test dependencies for jboss marshalling encoder/decoder -->

View File

@ -15,87 +15,77 @@
~ under the License. ~ under the License.
--> -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <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/maven-v4_0_0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
<groupId>io.netty</groupId> <groupId>io.netty</groupId>
<artifactId>netty-parent</artifactId> <artifactId>netty-parent</artifactId>
<version>4.0.0.Beta1-SNAPSHOT</version> <version>4.0.0.Beta1-SNAPSHOT</version>
</parent> </parent>
<artifactId>netty-transport-udt</artifactId> <artifactId>netty-transport-udt</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>Netty/Transport/UDT</name> <name>Netty/Transport/UDT</name>
<dependencies> <dependencies>
<!-- MAIN --> <!-- MAIN -->
<dependency> <dependency>
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>
<artifactId>netty-buffer</artifactId> <artifactId>netty-buffer</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>
<artifactId>netty-transport</artifactId> <artifactId>netty-transport</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.barchart.udt</groupId> <groupId>com.barchart.udt</groupId>
<artifactId>barchart-udt-bundle</artifactId> <artifactId>barchart-udt-bundle</artifactId>
<version>2.2.0</version> </dependency>
</dependency>
<!-- TEST --> <!-- TEST -->
<!-- see https://github.com/netty/netty/issues/874 --> <!-- see https://github.com/netty/netty/issues/874 -->
<dependency> <dependency>
<groupId>com.yammer.metrics</groupId> <groupId>com.yammer.metrics</groupId>
<artifactId>metrics-core</artifactId> <artifactId>metrics-core</artifactId>
<version>2.2.0</version> <scope>test</scope>
<scope>test</scope> </dependency>
</dependency>
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId> <artifactId>slf4j-api</artifactId>
<version>1.7.2</version> <version>1.7.2</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.9</version>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>com.google.caliper</groupId> <groupId>com.google.caliper</groupId>
<artifactId>caliper</artifactId> <artifactId>caliper</artifactId>
<version>0.5-rc1</version> <scope>test</scope>
<scope>test</scope> </dependency>
</dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<configuration> <configuration>
<forkMode>always</forkMode> <forkMode>always</forkMode>
</configuration> </configuration>
</plugin> </plugin>
</plugins>
</build>
</plugins>
</build>
</project> </project>

View File

@ -15,16 +15,16 @@
*/ */
package io.netty.transport.udt; package io.netty.transport.udt;
import static io.netty.channel.ChannelOption.*; import com.barchart.udt.OptionUDT;
import com.barchart.udt.SocketUDT;
import com.barchart.udt.nio.ChannelUDT;
import io.netty.channel.ChannelOption; import io.netty.channel.ChannelOption;
import io.netty.channel.DefaultChannelConfig; import io.netty.channel.DefaultChannelConfig;
import java.io.IOException; import java.io.IOException;
import java.util.Map; import java.util.Map;
import com.barchart.udt.OptionUDT; import static io.netty.channel.ChannelOption.*;
import com.barchart.udt.SocketUDT;
import com.barchart.udt.nio.ChannelUDT;
/** /**
* The default {@link UdtChannelConfig} implementation. * The default {@link UdtChannelConfig} implementation.
@ -38,8 +38,8 @@ public class DefaultUdtChannelConfig extends DefaultChannelConfig implements
private volatile int protocolReceiveBuferSize = 10 * M; private volatile int protocolReceiveBuferSize = 10 * M;
private volatile int protocolSendBuferSize = 10 * M; private volatile int protocolSendBuferSize = 10 * M;
private volatile int systemReceiveBufferSize = 1 * M; private volatile int systemReceiveBufferSize = M;
private volatile int systemSendBuferSize = 1 * M; private volatile int systemSendBuferSize = M;
private volatile int allocatorReceiveBufferSize = 128 * K; private volatile int allocatorReceiveBufferSize = 128 * K;
private volatile int allocatorSendBufferSize = 128 * K; private volatile int allocatorSendBufferSize = 128 * K;
@ -149,8 +149,8 @@ public class DefaultUdtChannelConfig extends DefaultChannelConfig implements
} }
@Override @Override
public UdtChannelConfig setProtocolReceiveBufferSize(final int allocator) { public UdtChannelConfig setProtocolReceiveBufferSize(final int protocolReceiveBuferSize) {
this.protocolReceiveBuferSize = allocator; this.protocolReceiveBuferSize = protocolReceiveBuferSize;
return this; return this;
} }

View File

@ -15,23 +15,13 @@
*/ */
package io.netty.transport.udt.nio; package io.netty.transport.udt.nio;
import io.netty.logging.InternalLogger;
import io.netty.logging.InternalLoggerFactory;
import io.netty.transport.udt.UdtChannel;
import com.barchart.udt.TypeUDT; import com.barchart.udt.TypeUDT;
/** /**
* Byte Channel Rendezvous for UDT Streams. * Byte Channel Rendezvous for UDT Streams.
*/ */
public class NioUdtByteRendezvousChannel extends NioUdtByteConnectorChannel public class NioUdtByteRendezvousChannel extends NioUdtByteConnectorChannel {
implements UdtChannel {
private static final InternalLogger logger = InternalLoggerFactory
.getInstance(NioUdtByteRendezvousChannel.class);
public NioUdtByteRendezvousChannel() { public NioUdtByteRendezvousChannel() {
super(NioUdtProvider.newRendezvousChannelUDT(TypeUDT.STREAM)); super(NioUdtProvider.newRendezvousChannelUDT(TypeUDT.STREAM));
} }
} }

View File

@ -15,12 +15,8 @@
*/ */
package io.netty.transport.udt.nio; package io.netty.transport.udt.nio;
import io.netty.logging.InternalLogger;
import io.netty.logging.InternalLoggerFactory;
import io.netty.transport.udt.UdtChannel;
import io.netty.transport.udt.UdtMessage;
import com.barchart.udt.TypeUDT; import com.barchart.udt.TypeUDT;
import io.netty.transport.udt.UdtMessage;
/** /**
* Message Rendezvous for UDT Datagrams. * Message Rendezvous for UDT Datagrams.
@ -28,10 +24,7 @@ import com.barchart.udt.TypeUDT;
* Note: send/receive must use {@link UdtMessage} in the pipeline * Note: send/receive must use {@link UdtMessage} in the pipeline
*/ */
public class NioUdtMessageRendezvousChannel extends public class NioUdtMessageRendezvousChannel extends
NioUdtMessageConnectorChannel implements UdtChannel { NioUdtMessageConnectorChannel {
private static final InternalLogger logger = InternalLoggerFactory
.getInstance(NioUdtMessageConnectorChannel.class);
public NioUdtMessageRendezvousChannel() { public NioUdtMessageRendezvousChannel() {
super(NioUdtProvider.newRendezvousChannelUDT(TypeUDT.DATAGRAM)); super(NioUdtProvider.newRendezvousChannelUDT(TypeUDT.DATAGRAM));

View File

@ -16,7 +16,10 @@
package io.netty.transport.udt.bench.xfer; package io.netty.transport.udt.bench.xfer;
import static io.netty.transport.udt.util.UnitHelp.*; import com.barchart.udt.SocketUDT;
import com.barchart.udt.StatusUDT;
import com.barchart.udt.TypeUDT;
import com.google.caliper.Param;
import io.netty.transport.udt.bench.BenchXfer; import io.netty.transport.udt.bench.BenchXfer;
import io.netty.transport.udt.util.CaliperRunner; import io.netty.transport.udt.util.CaliperRunner;
import io.netty.transport.udt.util.TrafficControl; import io.netty.transport.udt.util.TrafficControl;
@ -29,10 +32,7 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import com.barchart.udt.SocketUDT; import static io.netty.transport.udt.util.UnitHelp.*;
import com.barchart.udt.StatusUDT;
import com.barchart.udt.TypeUDT;
import com.google.caliper.Param;
/** /**
* perform two way native UDT socket send/recv * perform two way native UDT socket send/recv
@ -210,7 +210,7 @@ public class UdtNative extends BenchXfer {
if (count != message) { if (count != message) {
throw new Exception("count"); throw new Exception("count");
} }
if (this.sequence++ != buffer.getLong(0)) { if (sequence ++ != buffer.getLong(0)) {
throw new Exception("sequence"); throw new Exception("sequence");
} }
} }
@ -241,7 +241,7 @@ public class UdtNative extends BenchXfer {
if (count != message) { if (count != message) {
throw new Exception("count"); throw new Exception("count");
} }
if (this.sequence++ != buffer.getLong(0)) { if (sequence ++ != buffer.getLong(0)) {
throw new Exception("sequence"); throw new Exception("sequence");
} }
} }

View File

@ -16,6 +16,9 @@
package io.netty.transport.udt.bench.xfer; package io.netty.transport.udt.bench.xfer;
import com.yammer.metrics.Metrics;
import com.yammer.metrics.core.Counter;
import com.yammer.metrics.core.Meter;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandler;
@ -26,18 +29,13 @@ import io.netty.transport.udt.util.CustomReporter;
import io.netty.transport.udt.util.EchoMessageHandler; import io.netty.transport.udt.util.EchoMessageHandler;
import io.netty.transport.udt.util.TrafficControl; import io.netty.transport.udt.util.TrafficControl;
import io.netty.transport.udt.util.UnitHelp; import io.netty.transport.udt.util.UnitHelp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.yammer.metrics.Metrics;
import com.yammer.metrics.core.Counter;
import com.yammer.metrics.core.Meter;
/** /**
* perform two way netty send/recv * perform two way netty send/recv
*/ */
@ -118,12 +116,12 @@ public final class UdtNetty {
isOn.set(false); isOn.set(false);
Thread.sleep(1 * 1000); Thread.sleep(1000);
peerFuture1.channel().close().sync(); peerFuture1.channel().close().sync();
peerFuture2.channel().close().sync(); peerFuture2.channel().close().sync();
Thread.sleep(1 * 1000); Thread.sleep(1000);
peerBoot1.shutdown(); peerBoot1.shutdown();
peerBoot2.shutdown(); peerBoot2.shutdown();

View File

@ -16,12 +16,12 @@
package io.netty.transport.udt.nio; package io.netty.transport.udt.nio;
import static org.junit.Assert.*;
import io.netty.buffer.BufType; import io.netty.buffer.BufType;
import org.junit.Test; import org.junit.Test;
public class TestNioUdtByteAcceptorChannel extends TestAny { import static org.junit.Assert.*;
public class NioUdtByteAcceptorChannelTest extends TestAny {
/** /**
* verify channel meta data * verify channel meta data
@ -33,5 +33,4 @@ public class TestNioUdtByteAcceptorChannel extends TestAny {
.bufferType()); .bufferType());
} }
} }

View File

@ -16,12 +16,12 @@
package io.netty.transport.udt.nio; package io.netty.transport.udt.nio;
import static org.junit.Assert.*;
import io.netty.buffer.BufType; import io.netty.buffer.BufType;
import org.junit.Test; import org.junit.Test;
public class TestNioUdtByteConnectorChannel extends TestAny { import static org.junit.Assert.*;
public class NioUdtByteConnectorChannelTest extends TestAny {
/** /**
* verify channel meta data * verify channel meta data

View File

@ -16,23 +16,22 @@
package io.netty.transport.udt.nio; package io.netty.transport.udt.nio;
import static org.junit.Assert.*; import com.yammer.metrics.Metrics;
import com.yammer.metrics.core.Meter;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.buffer.BufType; import io.netty.buffer.BufType;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.transport.udt.util.BootHelp; import io.netty.transport.udt.util.BootHelp;
import io.netty.transport.udt.util.EchoByteHandler; import io.netty.transport.udt.util.EchoByteHandler;
import io.netty.transport.udt.util.UnitHelp; import io.netty.transport.udt.util.UnitHelp;
import org.junit.Test;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.junit.Test; import static org.junit.Assert.*;
import com.yammer.metrics.Metrics; public class NioUdtByteRendezvousChannelTest extends TestAny {
import com.yammer.metrics.core.Meter;
public class TestNioUdtByteRendezvousChannel extends TestAny {
/** /**
* verify channel meta data * verify channel meta data
@ -55,11 +54,11 @@ public class TestNioUdtByteRendezvousChannel extends TestAny {
final int transferLimit = messageSize * 16; final int transferLimit = messageSize * 16;
final Meter rate1 = Metrics.newMeter( final Meter rate1 = Metrics.newMeter(
TestNioUdtMessageRendezvousChannel.class, "send rate", "bytes", NioUdtMessageRendezvousChannelTest.class, "send rate", "bytes",
TimeUnit.SECONDS); TimeUnit.SECONDS);
final Meter rate2 = Metrics.newMeter( final Meter rate2 = Metrics.newMeter(
TestNioUdtMessageRendezvousChannel.class, "send rate", "bytes", NioUdtMessageRendezvousChannelTest.class, "send rate", "bytes",
TimeUnit.SECONDS); TimeUnit.SECONDS);
final InetSocketAddress addr1 = UnitHelp.localSocketAddress(); final InetSocketAddress addr1 = UnitHelp.localSocketAddress();

View File

@ -16,12 +16,12 @@
package io.netty.transport.udt.nio; package io.netty.transport.udt.nio;
import static org.junit.Assert.*;
import io.netty.buffer.BufType; import io.netty.buffer.BufType;
import org.junit.Test; import org.junit.Test;
public class TestNioUdtMessageAcceptorChannel extends TestAny { import static org.junit.Assert.*;
public class NioUdtMessageAcceptorChannelTest extends TestAny {
/** /**
* verify channel meta data * verify channel meta data

View File

@ -16,12 +16,12 @@
package io.netty.transport.udt.nio; package io.netty.transport.udt.nio;
import static org.junit.Assert.*;
import io.netty.buffer.BufType; import io.netty.buffer.BufType;
import org.junit.Test; import org.junit.Test;
public class TestNioUdtMessageConnectorChannel extends TestAny { import static org.junit.Assert.*;
public class NioUdtMessageConnectorChannelTest extends TestAny {
/** /**
* verify channel meta data * verify channel meta data

View File

@ -16,23 +16,22 @@
package io.netty.transport.udt.nio; package io.netty.transport.udt.nio;
import static org.junit.Assert.*; import com.yammer.metrics.Metrics;
import com.yammer.metrics.core.Meter;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.buffer.BufType; import io.netty.buffer.BufType;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.transport.udt.util.BootHelp; import io.netty.transport.udt.util.BootHelp;
import io.netty.transport.udt.util.EchoMessageHandler; import io.netty.transport.udt.util.EchoMessageHandler;
import io.netty.transport.udt.util.UnitHelp; import io.netty.transport.udt.util.UnitHelp;
import org.junit.Test;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.junit.Test; import static org.junit.Assert.*;
import com.yammer.metrics.Metrics; public class NioUdtMessageRendezvousChannelTest extends TestAny {
import com.yammer.metrics.core.Meter;
public class TestNioUdtMessageRendezvousChannel extends TestAny {
/** /**
* verify channel meta data * verify channel meta data
@ -55,11 +54,11 @@ public class TestNioUdtMessageRendezvousChannel extends TestAny {
final int transferLimit = messageSize * 16; final int transferLimit = messageSize * 16;
final Meter rate1 = Metrics.newMeter( final Meter rate1 = Metrics.newMeter(
TestNioUdtMessageRendezvousChannel.class, "send rate", "bytes", NioUdtMessageRendezvousChannelTest.class, "send rate", "bytes",
TimeUnit.SECONDS); TimeUnit.SECONDS);
final Meter rate2 = Metrics.newMeter( final Meter rate2 = Metrics.newMeter(
TestNioUdtMessageRendezvousChannel.class, "send rate", "bytes", NioUdtMessageRendezvousChannelTest.class, "send rate", "bytes",
TimeUnit.SECONDS); TimeUnit.SECONDS);
final InetSocketAddress addr1 = UnitHelp.localSocketAddress(); final InetSocketAddress addr1 = UnitHelp.localSocketAddress();

View File

@ -16,11 +16,11 @@
package io.netty.transport.udt.nio; package io.netty.transport.udt.nio;
import static org.junit.Assert.*;
import org.junit.Test; import org.junit.Test;
public class TestNioUdtProvider extends TestAny { import static org.junit.Assert.*;
public class NioUdtProviderTest extends TestAny {
/** /**
* verify factory * verify factory

View File

@ -27,7 +27,7 @@ import java.util.concurrent.ThreadFactory;
/** /**
* Bootstrap utilities. * Bootstrap utilities.
*/ */
public class BootHelp { public final class BootHelp {
/** /**
* bootstrap for byte rendezvous peer * bootstrap for byte rendezvous peer
@ -70,4 +70,5 @@ public class BootHelp {
} }
private BootHelp() { }
} }

View File

@ -16,13 +16,6 @@
package io.netty.transport.udt.util; package io.netty.transport.udt.util;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.caliper.Measurement; import com.google.caliper.Measurement;
import com.google.caliper.MeasurementSet; import com.google.caliper.MeasurementSet;
import com.google.caliper.Run; import com.google.caliper.Run;
@ -33,6 +26,10 @@ import com.yammer.metrics.core.Meter;
import com.yammer.metrics.core.MetricsRegistry; import com.yammer.metrics.core.MetricsRegistry;
import com.yammer.metrics.core.Timer; import com.yammer.metrics.core.Timer;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
/** /**
* Caliper measure with Metrics provider. * Caliper measure with Metrics provider.
* <p> * <p>
@ -40,9 +37,6 @@ import com.yammer.metrics.core.Timer;
*/ */
public class CaliperMeasure { public class CaliperMeasure {
private final static Logger log = LoggerFactory
.getLogger(CaliperMeasure.class);
/** /**
* Gauge any double value * Gauge any double value
*/ */
@ -55,8 +49,8 @@ public class CaliperMeasure {
return size; return size;
} }
public void value(final double number) { public void value(final double size) {
this.size = number; this.size = size;
} }
} }
@ -134,7 +128,7 @@ public class CaliperMeasure {
/** /**
* Workaround: zero breaks gwt web app. * Workaround: zero breaks gwt web app.
*/ */
private double filter(final double value) { private static double filter(final double value) {
if (value <= 0.0) { if (value <= 0.0) {
return 1.0; return 1.0;
} else { } else {
@ -179,8 +173,8 @@ public class CaliperMeasure {
return variables; return variables;
} }
private MeasurementSet measurementSet(final Map<Long, Measurement> map) { private static MeasurementSet measurementSet(final Map<Long, Measurement> map) {
final Measurement[] array = map.values().toArray(new Measurement[0]); final Measurement[] array = map.values().toArray(new Measurement[map.size()]);
final MeasurementSet set = new MeasurementSet(array); final MeasurementSet set = new MeasurementSet(array);
return set; return set;
} }

View File

@ -17,6 +17,20 @@
package io.netty.transport.udt.util; package io.netty.transport.udt.util;
import com.google.caliper.ConfiguredBenchmark;
import com.google.caliper.Environment;
import com.google.caliper.EnvironmentGetter;
import com.google.caliper.Json;
import com.google.caliper.Result;
import com.google.caliper.Run;
import com.google.caliper.Runner;
import com.google.caliper.Scenario;
import com.google.caliper.ScenarioResult;
import com.google.caliper.SimpleBenchmark;
import com.yammer.metrics.core.TimerContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -31,21 +45,6 @@ import java.util.Set;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.TreeSet; import java.util.TreeSet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.caliper.ConfiguredBenchmark;
import com.google.caliper.Environment;
import com.google.caliper.EnvironmentGetter;
import com.google.caliper.Json;
import com.google.caliper.Result;
import com.google.caliper.Run;
import com.google.caliper.Runner;
import com.google.caliper.Scenario;
import com.google.caliper.ScenarioResult;
import com.google.caliper.SimpleBenchmark;
import com.yammer.metrics.core.TimerContext;
/** /**
* Custom caliper runner for {@link CaliperBench}. * Custom caliper runner for {@link CaliperBench}.
*/ */
@ -69,9 +68,8 @@ public final class CaliperRunner {
*/ */
public static void execute(final Class<? extends CaliperBench> klaz) public static void execute(final Class<? extends CaliperBench> klaz)
throws Exception { throws Exception {
Run run; execute("WARMUP", klaz);
run = execute("WARMUP", klaz); Run run = execute("REPORT", klaz);
run = execute("REPORT", klaz);
publish(newResult(run)); publish(newResult(run));
} }
@ -226,7 +224,7 @@ public final class CaliperRunner {
final Run run = newRun("test-main"); final Run run = newRun("test-main");
for (int param = 0; param < 5; param++) { for (int param = 0; param < 5; param++) {
final CaliperMeasure measure = new CaliperMeasure(); final CaliperMeasure measure = new CaliperMeasure();
measure.variables().put("param", "" + param); measure.variables().put("param", String.valueOf(param));
for (int step = 0; step < 5; step++) { for (int step = 0; step < 5; step++) {
measure.rate().mark(50 + step); measure.rate().mark(50 + step);
final TimerContext time = measure.time().time(); final TimerContext time = measure.time().time();

View File

@ -16,15 +16,6 @@
package io.netty.transport.udt.util; package io.netty.transport.udt.util;
import java.io.PrintStream;
import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Map.Entry;
import java.util.SortedMap;
import java.util.TimeZone;
import java.util.concurrent.TimeUnit;
import com.yammer.metrics.Metrics; import com.yammer.metrics.Metrics;
import com.yammer.metrics.core.Clock; import com.yammer.metrics.core.Clock;
import com.yammer.metrics.core.Counter; import com.yammer.metrics.core.Counter;
@ -40,6 +31,15 @@ import com.yammer.metrics.core.Timer;
import com.yammer.metrics.reporting.AbstractPollingReporter; import com.yammer.metrics.reporting.AbstractPollingReporter;
import com.yammer.metrics.stats.Snapshot; import com.yammer.metrics.stats.Snapshot;
import java.io.PrintStream;
import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Map.Entry;
import java.util.SortedMap;
import java.util.TimeZone;
import java.util.concurrent.TimeUnit;
/** /**
* A simple reporters which prints out application metrics to a * A simple reporters which prints out application metrics to a
* {@link PrintStream} periodically. * {@link PrintStream} periodically.
@ -123,7 +123,7 @@ public class CustomReporter extends AbstractPollingReporter implements
final String dateTime = format.format(new Date(clock.time())); final String dateTime = format.format(new Date(clock.time()));
out.print(dateTime); out.print(dateTime);
out.print(' '); out.print(' ');
for (int i = 0; i < (CONSOLE_WIDTH - dateTime.length() - 1); i++) { for (int i = 0; i < CONSOLE_WIDTH - dateTime.length() - 1; i++) {
out.print('='); out.print('=');
} }
out.println(); out.println();
@ -227,7 +227,7 @@ public class CustomReporter extends AbstractPollingReporter implements
snapshot.get999thPercentile(), durationUnit); snapshot.get999thPercentile(), durationUnit);
} }
private String abbrev(final TimeUnit unit) { private static String abbrev(final TimeUnit unit) {
switch (unit) { switch (unit) {
case NANOSECONDS: case NANOSECONDS:
return "ns"; return "ns";

View File

@ -16,6 +16,7 @@
package io.netty.transport.udt.util; package io.netty.transport.udt.util;
import com.yammer.metrics.core.Meter;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.MessageBuf; import io.netty.buffer.MessageBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
@ -23,12 +24,9 @@ import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundMessageHandlerAdapter; import io.netty.channel.ChannelInboundMessageHandlerAdapter;
import io.netty.transport.udt.UdtMessage; import io.netty.transport.udt.UdtMessage;
import io.netty.transport.udt.nio.NioUdtProvider; import io.netty.transport.udt.nio.NioUdtProvider;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.yammer.metrics.core.Meter;
/** /**
* Handler implementation for the echo peer. It initiates the ping-pong traffic * Handler implementation for the echo peer. It initiates the ping-pong traffic
* between the echo peers by sending the first message to the other peer on * between the echo peers by sending the first message to the other peer on
@ -59,7 +57,7 @@ public class EchoMessageHandler extends
byteBuf.writeByte((byte) i); byteBuf.writeByte((byte) i);
} }
this.message = new UdtMessage(byteBuf); message = new UdtMessage(byteBuf);
} }

View File

@ -16,6 +16,11 @@
package io.netty.transport.udt.util; package io.netty.transport.udt.util;
import com.barchart.udt.SocketUDT;
import com.barchart.udt.StatusUDT;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File; import java.io.File;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
@ -25,12 +30,7 @@ import java.util.HashSet;
import java.util.Random; import java.util.Random;
import java.util.Set; import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.regex.Pattern;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.barchart.udt.SocketUDT;
import com.barchart.udt.StatusUDT;
/** /**
* Unit test helper. * Unit test helper.
@ -38,6 +38,7 @@ import com.barchart.udt.StatusUDT;
public final class UnitHelp { public final class UnitHelp {
private static final Logger log = LoggerFactory.getLogger(UnitHelp.class); private static final Logger log = LoggerFactory.getLogger(UnitHelp.class);
private static final Pattern SPACES = Pattern.compile("\\s+");
/** /**
* Zero out buffer. * Zero out buffer.
@ -80,7 +81,7 @@ public final class UnitHelp {
* Invoke external process and wait for completion. * Invoke external process and wait for completion.
*/ */
public static void process(final String command) throws Exception { public static void process(final String command) throws Exception {
final ProcessBuilder builder = new ProcessBuilder(command.split("\\s+")); final ProcessBuilder builder = new ProcessBuilder(SPACES.split(command));
final Process process = builder.start(); final Process process = builder.start();
process.waitFor(); process.waitFor();
} }
@ -215,11 +216,11 @@ public final class UnitHelp {
} }
public static String randomString() { public static String randomString() {
return "" + System.currentTimeMillis(); return String.valueOf(System.currentTimeMillis());
} }
public static String randomSuffix(final String name) { public static String randomSuffix(final String name) {
return name + "-" + System.currentTimeMillis(); return name + '-' + System.currentTimeMillis();
} }
/** /**

View File

@ -34,7 +34,7 @@ public class UtilThreadFactory implements ThreadFactory {
@Override @Override
public Thread newThread(final Runnable runnable) { public Thread newThread(final Runnable runnable) {
return new Thread(runnable, name + "-" + counter.getAndIncrement()); return new Thread(runnable, name + '-' + counter.getAndIncrement());
} }
} }

View File

@ -16,7 +16,6 @@
package io.netty.channel; package io.netty.channel;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufHolder;
import io.netty.buffer.Freeable; import io.netty.buffer.Freeable;
import io.netty.buffer.MessageBuf; import io.netty.buffer.MessageBuf;

View File

@ -46,23 +46,19 @@ public final class ChannelPromiseAggregator implements ChannelFutureListener {
} }
@Override @Override
public void operationComplete(ChannelFuture future) public synchronized void operationComplete(ChannelFuture future) throws Exception {
throws Exception { if (pendingPromises == null) {
aggregatePromise.setSuccess();
synchronized (this) { } else {
if (pendingPromises == null) { pendingPromises.remove(future);
aggregatePromise.setSuccess(); if (!future.isSuccess()) {
aggregatePromise.setFailure(future.cause());
for (ChannelPromise pendingFuture : pendingPromises) {
pendingFuture.setFailure(future.cause());
}
} else { } else {
pendingPromises.remove(future); if (pendingPromises.isEmpty()) {
if (!future.isSuccess()) { aggregatePromise.setSuccess();
aggregatePromise.setFailure(future.cause());
for (ChannelPromise pendingFuture: pendingPromises) {
pendingFuture.setFailure(future.cause());
}
} else {
if (pendingPromises.isEmpty()) {
aggregatePromise.setSuccess();
}
} }
} }
} }

View File

@ -15,13 +15,13 @@
*/ */
package io.netty.channel; package io.netty.channel;
import io.netty.logging.InternalLogger;
import io.netty.logging.InternalLoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.nio.channels.FileChannel; import java.nio.channels.FileChannel;
import java.nio.channels.WritableByteChannel; import java.nio.channels.WritableByteChannel;
import io.netty.logging.InternalLogger;
import io.netty.logging.InternalLoggerFactory;
/** /**
* Default {@link FileRegion} implementation which transfer data from a {@link FileChannel}. * Default {@link FileRegion} implementation which transfer data from a {@link FileChannel}.
*/ */
@ -71,7 +71,7 @@ public class DefaultFileRegion implements FileRegion {
if (count < 0 || position < 0) { if (count < 0 || position < 0) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"position out of range: " + position + "position out of range: " + position +
" (expected: 0 - " + (this.count - 1) + ")"); " (expected: 0 - " + (this.count - 1) + ')');
} }
if (count == 0) { if (count == 0) {
return 0L; return 0L;

View File

@ -242,7 +242,6 @@ public abstract class SingleThreadEventExecutor extends AbstractExecutorService
/** /**
* Poll all tasks from the task queue and run them via {@link Runnable#run()} method. * Poll all tasks from the task queue and run them via {@link Runnable#run()} method.
* @return
*/ */
protected boolean runAllTasks() { protected boolean runAllTasks() {
boolean ran = false; boolean ran = false;

View File

@ -26,7 +26,7 @@ import java.util.concurrent.ThreadFactory;
* *
*/ */
public abstract class SingleThreadEventLoop extends SingleThreadEventExecutor implements EventLoop { public abstract class SingleThreadEventLoop extends SingleThreadEventExecutor implements EventLoop {
protected CounterMonitor channelCounter = MonitorRegistries.instance() protected final CounterMonitor channelCounter = MonitorRegistries.instance()
.unique().newCounterMonitor(new MonitorName(getClass(), "total-channels-registered")); .unique().newCounterMonitor(new MonitorName(getClass(), "total-channels-registered"));
/** /**

View File

@ -65,7 +65,7 @@ public class AioSocketChannel extends AbstractAioChannel implements SocketChanne
} }
} }
private DefaultAioSocketChannelConfig config; private final DefaultAioSocketChannelConfig config;
private volatile boolean inputShutdown; private volatile boolean inputShutdown;
private volatile boolean outputShutdown; private volatile boolean outputShutdown;

View File

@ -194,8 +194,8 @@ public abstract class AbstractNioChannel extends AbstractChannel {
if (connectTimeoutException == null) { if (connectTimeoutException == null) {
connectTimeoutException = new ConnectException("connection timed out"); connectTimeoutException = new ConnectException("connection timed out");
} }
ChannelPromise connectFuture = AbstractNioChannel.this.connectPromise; ChannelPromise connectPromise = AbstractNioChannel.this.connectPromise;
if (connectFuture != null && connectFuture.tryFailure(connectTimeoutException)) { if (connectPromise != null && connectPromise.tryFailure(connectTimeoutException)) {
close(voidFuture()); close(voidFuture());
} }
} }

View File

@ -25,7 +25,6 @@ import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
@ -62,7 +61,6 @@ public class SingleThreadEventLoopTest {
@Test @Test
public void shutdownAfterStart() throws Exception { public void shutdownAfterStart() throws Exception {
final AtomicBoolean interrupted = new AtomicBoolean();
final CountDownLatch latch = new CountDownLatch(1); final CountDownLatch latch = new CountDownLatch(1);
loop.execute(new Runnable() { loop.execute(new Runnable() {
@Override @Override

View File

@ -18,8 +18,6 @@ package io.netty.channel.socket.nio;
import io.netty.channel.AbstractEventLoopTest; import io.netty.channel.AbstractEventLoopTest;
import io.netty.channel.EventLoopGroup; import io.netty.channel.EventLoopGroup;
import io.netty.channel.socket.ServerSocketChannel; import io.netty.channel.socket.ServerSocketChannel;
import io.netty.channel.socket.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
public class NioEventLoopTest extends AbstractEventLoopTest { public class NioEventLoopTest extends AbstractEventLoopTest {