Example usage for io.netty.util.internal StringUtil simpleClassName

List of usage examples for io.netty.util.internal StringUtil simpleClassName

Introduction

In this page you can find the example usage for io.netty.util.internal StringUtil simpleClassName.

Prototype

public static String simpleClassName(Class<?> clazz) 

Source Link

Document

Generates a simplified name from a Class .

Usage

From source file:code.google.nfs.rpc.netty.serialize.NettyProtocolDecoder.java

License:Apache License

/**
 * Called once data should be decoded from the given {@link ByteBuf}. This method will call
 * {@link #decode(ChannelHandlerContext, ByteBuf, List)} as long as decoding should take place.
 *
 * @param ctx           the {@link ChannelHandlerContext} which this {@link ByteToMessageDecoder} belongs to
 * @param in            the {@link ByteBuf} from which to read data
 * @param out           the {@link List} to which decoded messages should be added
 *///from w  w  w  . j  a v  a2 s.co  m
protected void callDecode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) {
    try {
        while (in.isReadable()) {
            int outSize = out.size();
            int oldInputLength = in.readableBytes();
            decode(ctx, in, out);

            // Check if this handler was removed before try to continue the loop.
            // If it was removed it is not safe to continue to operate on the buffer
            //
            // See https://github.com/netty/netty/issues/1664
            if (ctx.isRemoved()) {
                break;
            }

            if (outSize == out.size()) {
                if (oldInputLength == in.readableBytes()) {
                    break;
                } else {
                    continue;
                }
            }

            if (oldInputLength == in.readableBytes()) {
                throw new DecoderException(StringUtil.simpleClassName(getClass())
                        + ".decode() did not read anything but decoded a message.");
            }

            if (isSingleDecode()) {
                break;
            }
        }
    } catch (DecoderException e) {
        throw e;
    } catch (Throwable cause) {
        throw new DecoderException(cause);
    }
}

From source file:com.caricah.iotracah.server.netty.channelgroup.IotChannelGroup.java

License:Apache License

@Override
public String toString() {
    return StringUtil.simpleClassName(this) + "(name: " + name() + ", size: " + size() + ')';
}

From source file:com.couchbase.client.core.logging.AbstractCouchbaseLogger.java

License:Apache License

@Override
public String toString() {
    return StringUtil.simpleClassName(this) + '(' + name() + ')';
}

From source file:com.google.devtools.build.lib.remote.blobstore.http.HttpDownloadHandler.java

License:Open Source License

@Override
protected void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Exception {
    if (!msg.decoderResult().isSuccess()) {
        failAndClose(new IOException("Failed to parse the HTTP response."), ctx);
        return;/*from w w  w  .  ja v  a2  s.  c o m*/
    }
    if (!(msg instanceof HttpResponse) && !(msg instanceof HttpContent)) {
        failAndClose(
                new IllegalArgumentException("Unsupported message type: " + StringUtil.simpleClassName(msg)),
                ctx);
        return;
    }
    checkState(userPromise != null, "response before request");

    if (msg instanceof HttpResponse) {
        response = (HttpResponse) msg;
        if (!response.protocolVersion().equals(HttpVersion.HTTP_1_1)) {
            HttpException error = new HttpException(response,
                    "HTTP version 1.1 is required, was: " + response.protocolVersion(), null);
            failAndClose(error, ctx);
            return;
        }
        if (!HttpUtil.isContentLengthSet(response) && !HttpUtil.isTransferEncodingChunked(response)) {
            HttpException error = new HttpException(response,
                    "Missing 'Content-Length' or 'Transfer-Encoding: chunked' header", null);
            failAndClose(error, ctx);
            return;
        }
        downloadSucceeded = response.status().equals(HttpResponseStatus.OK);
        if (!downloadSucceeded) {
            out = new ByteArrayOutputStream();
        }
        keepAlive = HttpUtil.isKeepAlive((HttpResponse) msg);
    }

    if (msg instanceof HttpContent) {
        checkState(response != null, "content before headers");

        ByteBuf content = ((HttpContent) msg).content();
        content.readBytes(out, content.readableBytes());
        if (msg instanceof LastHttpContent) {
            if (downloadSucceeded) {
                succeedAndReset(ctx);
            } else {
                String errorMsg = response.status() + "\n";
                errorMsg += new String(((ByteArrayOutputStream) out).toByteArray(),
                        HttpUtil.getCharset(response));
                out.close();
                HttpException error = new HttpException(response, errorMsg, null);
                failAndReset(error, ctx);
            }
        }
    }
}

From source file:com.google.devtools.build.lib.remote.blobstore.http.HttpDownloadHandler.java

License:Open Source License

@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
    checkState(userPromise == null, "handler can't be shared between pipelines.");
    userPromise = promise;/*w  ww. j av  a 2s . co  m*/
    if (!(msg instanceof DownloadCommand)) {
        failAndResetUserPromise(
                new IllegalArgumentException("Unsupported message type: " + StringUtil.simpleClassName(msg)));
        return;
    }
    out = ((DownloadCommand) msg).out();
    HttpRequest request = buildRequest((DownloadCommand) msg);
    addCredentialHeaders(request, ((DownloadCommand) msg).uri());
    ctx.writeAndFlush(request).addListener((f) -> {
        if (!f.isSuccess()) {
            failAndClose(f.cause(), ctx);
        }
    });
}

From source file:com.google.devtools.build.lib.remote.blobstore.http.HttpUploadHandler.java

License:Open Source License

@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
    checkState(userPromise == null, "handler can't be shared between pipelines.");
    userPromise = promise;/*from   w w w.j  a va2s .c  o m*/
    if (!(msg instanceof UploadCommand)) {
        failAndResetUserPromise(
                new IllegalArgumentException("Unsupported message type: " + StringUtil.simpleClassName(msg)));
        return;
    }
    HttpRequest request = buildRequest((UploadCommand) msg);
    addCredentialHeaders(request, ((UploadCommand) msg).uri());
    HttpChunkedInput body = buildBody((UploadCommand) msg);
    ctx.writeAndFlush(request).addListener((f) -> {
        if (f.isSuccess()) {
            return;
        }
        failAndClose(f.cause(), ctx);
    });
    ctx.writeAndFlush(body).addListener((f) -> {
        if (f.isSuccess()) {
            return;
        }
        failAndClose(f.cause(), ctx);
    });
}

From source file:com.leekli.demo.utils.ReflectiveChannelFactory.java

License:Apache License

@Override
public String toString() {
    return StringUtil.simpleClassName(clazz) + ".class";
}

From source file:com.test.AbstractBootstrap.java

License:Apache License

@Override
public String toString() {
    StringBuilder buf = new StringBuilder().append(StringUtil.simpleClassName(this)).append('(');
    if (group != null) {
        buf.append("group: ").append(StringUtil.simpleClassName(group)).append(", ");
    }/*from   w ww .  ja  v  a 2 s  . co  m*/
    if (channelFactory != null) {
        buf.append("channelFactory: ").append(channelFactory).append(", ");
    }
    if (localAddress != null) {
        buf.append("localAddress: ").append(localAddress).append(", ");
    }
    synchronized (options) {
        if (!options.isEmpty()) {
            buf.append("options: ").append(options).append(", ");
        }
    }
    synchronized (attrs) {
        if (!attrs.isEmpty()) {
            buf.append("attrs: ").append(attrs).append(", ");
        }
    }
    if (handler != null) {
        buf.append("handler: ").append(handler).append(", ");
    }
    if (buf.charAt(buf.length() - 1) == '(') {
        buf.append(')');
    } else {
        buf.setCharAt(buf.length() - 2, ')');
        buf.setLength(buf.length() - 1);
    }
    return buf.toString();
}

From source file:com.twitter.http2.DefaultHttpDataFrame.java

License:Apache License

@Override
public String toString() {
    StringBuilder buf = new StringBuilder();
    buf.append(StringUtil.simpleClassName(this));
    buf.append("(last: ");
    buf.append(isLast());/*from  ww  w  . ja  v a  2s.  c o m*/
    buf.append(')');
    buf.append(StringUtil.NEWLINE);
    buf.append("--> Stream-ID = ");
    buf.append(getStreamId());
    buf.append(StringUtil.NEWLINE);
    buf.append("--> Size = ");
    if (refCnt() == 0) {
        buf.append("(freed)");
    } else {
        buf.append(content().readableBytes());
    }
    return buf.toString();
}

From source file:com.twitter.http2.DefaultHttpGoAwayFrame.java

License:Apache License

@Override
public String toString() {
    StringBuilder buf = new StringBuilder();
    buf.append(StringUtil.simpleClassName(this));
    buf.append(StringUtil.NEWLINE);//from  w  w w.ja  va 2s.  c  o  m
    buf.append("--> Last-Stream-ID = ");
    buf.append(getLastStreamId());
    buf.append(StringUtil.NEWLINE);
    buf.append("--> Error Code: ");
    buf.append(getErrorCode().toString());
    return buf.toString();
}