Skip to content

Commit

Permalink
clean up static Exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
slandelle committed Apr 28, 2015
1 parent e8e3ec0 commit fc45a6a
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 32 deletions.
16 changes: 2 additions & 14 deletions api/src/main/java/org/asynchttpclient/MaxRedirectException.java
Expand Up @@ -22,19 +22,7 @@
public class MaxRedirectException extends Exception { public class MaxRedirectException extends Exception {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;


public MaxRedirectException() {
super();
}

public MaxRedirectException(String msg) { public MaxRedirectException(String msg) {
super(msg); super(msg, null, true, false);
}

public MaxRedirectException(Throwable cause) {
super(cause);
}

public MaxRedirectException(String message, Throwable cause) {
super(message, cause);
} }
} }
Expand Up @@ -13,7 +13,7 @@
package org.asynchttpclient.util; package org.asynchttpclient.util;


import static java.nio.charset.StandardCharsets.ISO_8859_1; import static java.nio.charset.StandardCharsets.ISO_8859_1;
import static org.asynchttpclient.util.MiscUtils.isNonEmpty; import static org.asynchttpclient.util.MiscUtils.*;


import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
Expand All @@ -32,12 +32,8 @@
*/ */
public class AsyncHttpProviderUtils { public class AsyncHttpProviderUtils {


public static final IOException REMOTELY_CLOSED_EXCEPTION = new IOException("Remotely closed"); public static final IOException REMOTELY_CLOSED_EXCEPTION = buildStaticIOException("Remotely closed");
public static final IOException CHANNEL_CLOSED_EXCEPTION = new IOException("Channel closed"); public static final IOException CHANNEL_CLOSED_EXCEPTION = buildStaticIOException("Channel closed");
static {
REMOTELY_CLOSED_EXCEPTION.setStackTrace(new StackTraceElement[0]);
CHANNEL_CLOSED_EXCEPTION.setStackTrace(new StackTraceElement[0]);
}


private final static byte[] NO_BYTES = new byte[0]; private final static byte[] NO_BYTES = new byte[0];


Expand Down
2 changes: 1 addition & 1 deletion api/src/main/java/org/asynchttpclient/util/MiscUtils.java
Expand Up @@ -59,7 +59,7 @@ public static void closeSilently(Closeable closeable) {
} }
} }


public static IOException buildStaticException(String message) { public static IOException buildStaticIOException(String message) {
IOException ioe = new IOException(message); IOException ioe = new IOException(message);
ioe.setStackTrace(new StackTraceElement[] {}); ioe.setStackTrace(new StackTraceElement[] {});
return ioe; return ioe;
Expand Down
Expand Up @@ -16,7 +16,7 @@
import static org.asynchttpclient.providers.netty.commons.util.HttpUtils.WEBSOCKET; import static org.asynchttpclient.providers.netty.commons.util.HttpUtils.WEBSOCKET;
import static org.asynchttpclient.providers.netty.commons.util.HttpUtils.isSecure; import static org.asynchttpclient.providers.netty.commons.util.HttpUtils.isSecure;
import static org.asynchttpclient.providers.netty.commons.util.HttpUtils.isWebSocket; import static org.asynchttpclient.providers.netty.commons.util.HttpUtils.isWebSocket;
import static org.asynchttpclient.util.MiscUtils.buildStaticException; import static org.asynchttpclient.util.MiscUtils.buildStaticIOException;
import static org.jboss.netty.channel.Channels.pipeline; import static org.jboss.netty.channel.Channels.pipeline;
import static org.jboss.netty.handler.ssl.SslHandler.getDefaultBufferPool; import static org.jboss.netty.handler.ssl.SslHandler.getDefaultBufferPool;


Expand Down Expand Up @@ -122,9 +122,9 @@ public ChannelManager(AsyncHttpClientConfig config, NettyAsyncHttpProviderConfig
} }
this.channelPool = channelPool; this.channelPool = channelPool;


tooManyConnections = buildStaticException(String.format("Too many connections %s", config.getMaxConnections())); tooManyConnections = buildStaticIOException(String.format("Too many connections %s", config.getMaxConnections()));
tooManyConnectionsPerHost = buildStaticException(String.format("Too many connections per host %s", config.getMaxConnectionsPerHost())); tooManyConnectionsPerHost = buildStaticIOException(String.format("Too many connections per host %s", config.getMaxConnectionsPerHost()));
poolAlreadyClosed = buildStaticException("Pool is already closed"); poolAlreadyClosed = buildStaticIOException("Pool is already closed");
maxTotalConnectionsEnabled = config.getMaxConnections() > 0; maxTotalConnectionsEnabled = config.getMaxConnections() > 0;
maxConnectionsPerHostEnabled = config.getMaxConnectionsPerHost() > 0; maxConnectionsPerHostEnabled = config.getMaxConnectionsPerHost() > 0;


Expand Down
Expand Up @@ -87,7 +87,6 @@ public Protocol(ChannelManager channelManager, AsyncHttpClientConfig config, Net
hasResponseFilters = !config.getResponseFilters().isEmpty(); hasResponseFilters = !config.getResponseFilters().isEmpty();
hasIOExceptionFilters = !config.getIOExceptionFilters().isEmpty(); hasIOExceptionFilters = !config.getIOExceptionFilters().isEmpty();
maxRedirectException = new MaxRedirectException("Maximum redirect reached: " + config.getMaxRedirects()); maxRedirectException = new MaxRedirectException("Maximum redirect reached: " + config.getMaxRedirects());
maxRedirectException.setStackTrace(new StackTraceElement[0]);
} }


public abstract void handle(Channel channel, NettyResponseFuture<?> future, Object message) throws Exception; public abstract void handle(Channel channel, NettyResponseFuture<?> future, Object message) throws Exception;
Expand Down
Expand Up @@ -16,7 +16,7 @@
import static org.asynchttpclient.providers.netty.commons.util.HttpUtils.WEBSOCKET; import static org.asynchttpclient.providers.netty.commons.util.HttpUtils.WEBSOCKET;
import static org.asynchttpclient.providers.netty.commons.util.HttpUtils.isSecure; import static org.asynchttpclient.providers.netty.commons.util.HttpUtils.isSecure;
import static org.asynchttpclient.providers.netty.commons.util.HttpUtils.isWebSocket; import static org.asynchttpclient.providers.netty.commons.util.HttpUtils.isWebSocket;
import static org.asynchttpclient.util.MiscUtils.buildStaticException; import static org.asynchttpclient.util.MiscUtils.buildStaticIOException;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelInitializer;
Expand Down Expand Up @@ -116,9 +116,9 @@ public ChannelManager(AsyncHttpClientConfig config, NettyAsyncHttpProviderConfig
} }
this.channelPool = channelPool; this.channelPool = channelPool;


tooManyConnections = buildStaticException(String.format("Too many connections %s", config.getMaxConnections())); tooManyConnections = buildStaticIOException(String.format("Too many connections %s", config.getMaxConnections()));
tooManyConnectionsPerHost = buildStaticException(String.format("Too many connections per host %s", config.getMaxConnectionsPerHost())); tooManyConnectionsPerHost = buildStaticIOException(String.format("Too many connections per host %s", config.getMaxConnectionsPerHost()));
poolAlreadyClosed = buildStaticException("Pool is already closed"); poolAlreadyClosed = buildStaticIOException("Pool is already closed");
maxTotalConnectionsEnabled = config.getMaxConnections() > 0; maxTotalConnectionsEnabled = config.getMaxConnections() > 0;
maxConnectionsPerHostEnabled = config.getMaxConnectionsPerHost() > 0; maxConnectionsPerHostEnabled = config.getMaxConnectionsPerHost() > 0;


Expand Down
Expand Up @@ -87,7 +87,6 @@ public Protocol(ChannelManager channelManager, AsyncHttpClientConfig config, Net
hasResponseFilters = !config.getResponseFilters().isEmpty(); hasResponseFilters = !config.getResponseFilters().isEmpty();
hasIOExceptionFilters = !config.getIOExceptionFilters().isEmpty(); hasIOExceptionFilters = !config.getIOExceptionFilters().isEmpty();
maxRedirectException = new MaxRedirectException("Maximum redirect reached: " + config.getMaxRedirects()); maxRedirectException = new MaxRedirectException("Maximum redirect reached: " + config.getMaxRedirects());
maxRedirectException.setStackTrace(new StackTraceElement[0]);
} }


public abstract void handle(Channel channel, NettyResponseFuture<?> future, Object message) throws Exception; public abstract void handle(Channel channel, NettyResponseFuture<?> future, Object message) throws Exception;
Expand Down

0 comments on commit fc45a6a

Please sign in to comment.