Example usage for io.netty.util Attribute get

List of usage examples for io.netty.util Attribute get

Introduction

In this page you can find the example usage for io.netty.util Attribute get.

Prototype

T get();

Source Link

Document

Returns the current value, which may be null

Usage

From source file:org.jooby.internal.netty.NettyResponse.java

License:Apache License

private void send(final ByteBuf buffer) throws Exception {
    DefaultFullHttpResponse rsp = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, status, buffer);

    if (!headers.contains(HttpHeaderNames.CONTENT_LENGTH)) {
        headers.remove(HttpHeaderNames.TRANSFER_ENCODING).set(HttpHeaderNames.CONTENT_LENGTH,
                buffer.readableBytes());
    }//w w w  .ja va 2s  .com

    if (keepAlive) {
        headers.set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE);
    }

    // dump headers
    rsp.headers().set(headers);

    Attribute<Boolean> async = ctx.channel().attr(NettyRequest.ASYNC);
    boolean isAsync = async != null && async.get() == Boolean.TRUE;
    if (isAsync) {
        // we need flush, from async
        keepAlive(ctx.writeAndFlush(rsp));
    } else {
        keepAlive(ctx.write(rsp));
    }

    committed = true;
}

From source file:org.jooby.internal.netty.NettyResponse.java

License:Apache License

@Override
public void end() {
    if (ctx != null) {
        Attribute<NettyWebSocket> ws = ctx.channel().attr(NettyWebSocket.KEY);
        if (ws != null && ws.get() != null) {
            status = HttpResponseStatus.SWITCHING_PROTOCOLS;
            ws.get().hankshake();//w  w  w . j  a v a  2 s. c  o  m
            ctx = null;
            committed = true;
            return;
        }
        if (!committed) {
            DefaultHttpResponse rsp = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, status);
            // dump headers
            rsp.headers().set(headers);
            keepAlive(ctx.write(rsp));
        }
        committed = true;
        ctx = null;
    }
}

From source file:org.jupiter.registry.ConfigClient.java

License:Apache License

private static boolean attachPublishEventOnChannel(RegisterMeta meta, Channel channel) {
    Attribute<ConcurrentSet<RegisterMeta>> attr = channel.attr(C_PUBLISH_KEY);
    ConcurrentSet<RegisterMeta> registerMetaSet = attr.get();
    if (registerMetaSet == null) {
        ConcurrentSet<RegisterMeta> newRegisterMetaSet = new ConcurrentSet<>();
        registerMetaSet = attr.setIfAbsent(newRegisterMetaSet);
        if (registerMetaSet == null) {
            registerMetaSet = newRegisterMetaSet;
        }/*from  ww w  . j ava2s.  c  o  m*/
    }

    return registerMetaSet.add(meta);
}

From source file:org.jupiter.registry.ConfigClient.java

License:Apache License

private static boolean attachSubscribeEventOnChannel(ServiceMeta serviceMeta, Channel channel) {
    Attribute<ConcurrentSet<ServiceMeta>> attr = channel.attr(C_SUBSCRIBE_KEY);
    ConcurrentSet<ServiceMeta> serviceMetaSet = attr.get();
    if (serviceMetaSet == null) {
        ConcurrentSet<ServiceMeta> newServiceMetaSet = new ConcurrentSet<>();
        serviceMetaSet = attr.setIfAbsent(newServiceMetaSet);
        if (serviceMetaSet == null) {
            serviceMetaSet = newServiceMetaSet;
        }//from  w  ww  .jav a  2s. c  om
    }

    return serviceMetaSet.add(serviceMeta);
}

From source file:org.jupiter.registry.ConfigServer.java

License:Apache License

private static boolean attachPublishEventOnChannel(RegisterMeta meta, Channel channel) {
    Attribute<ConcurrentSet<RegisterMeta>> attr = channel.attr(S_PUBLISH_KEY);
    ConcurrentSet<RegisterMeta> registerMetaSet = attr.get();
    if (registerMetaSet == null) {
        ConcurrentSet<RegisterMeta> newRegisterMetaSet = new ConcurrentSet<>();
        registerMetaSet = attr.setIfAbsent(newRegisterMetaSet);
        if (registerMetaSet == null) {
            registerMetaSet = newRegisterMetaSet;
        }/*from   w w w . j  av  a  2  s . c o  m*/
    }

    return registerMetaSet.add(meta);
}

From source file:org.jupiter.registry.ConfigServer.java

License:Apache License

private static boolean attachPublishCancelEventOnChannel(RegisterMeta meta, Channel channel) {
    Attribute<ConcurrentSet<RegisterMeta>> attr = channel.attr(S_PUBLISH_KEY);
    ConcurrentSet<RegisterMeta> registerMetaSet = attr.get();
    if (registerMetaSet == null) {
        ConcurrentSet<RegisterMeta> newRegisterMetaSet = new ConcurrentSet<>();
        registerMetaSet = attr.setIfAbsent(newRegisterMetaSet);
        if (registerMetaSet == null) {
            registerMetaSet = newRegisterMetaSet;
        }/*from  w  w w .j  ava 2  s. co m*/
    }

    return registerMetaSet.remove(meta);
}

From source file:org.jupiter.registry.ConfigServer.java

License:Apache License

private static boolean attachSubscribeEventOnChannel(ServiceMeta serviceMeta, Channel channel) {
    Attribute<ConcurrentSet<ServiceMeta>> attr = channel.attr(S_SUBSCRIBE_KEY);
    ConcurrentSet<ServiceMeta> serviceMetaSet = attr.get();
    if (serviceMetaSet == null) {
        ConcurrentSet<ServiceMeta> newServiceMetaSet = new ConcurrentSet<>();
        serviceMetaSet = attr.setIfAbsent(newServiceMetaSet);
        if (serviceMetaSet == null) {
            serviceMetaSet = newServiceMetaSet;
        }//from   w ww  .  j  a  v  a2 s.  c om
    }

    return serviceMetaSet.add(serviceMeta);
}

From source file:org.jupiter.registry.DefaultRegistry.java

License:Apache License

private static boolean attachSubscribeEventOnChannel(RegisterMeta.ServiceMeta serviceMeta, Channel channel) {
    Attribute<ConcurrentSet<RegisterMeta.ServiceMeta>> attr = channel.attr(C_SUBSCRIBE_KEY);
    ConcurrentSet<RegisterMeta.ServiceMeta> serviceMetaSet = attr.get();
    if (serviceMetaSet == null) {
        ConcurrentSet<RegisterMeta.ServiceMeta> newServiceMetaSet = new ConcurrentSet<>();
        serviceMetaSet = attr.setIfAbsent(newServiceMetaSet);
        if (serviceMetaSet == null) {
            serviceMetaSet = newServiceMetaSet;
        }//from   w  ww .j  ava  2s. c o m
    }

    return serviceMetaSet.add(serviceMeta);
}

From source file:org.jupiter.registry.DefaultRegistryServer.java

License:Apache License

private static boolean attachSubscribeEventOnChannel(RegisterMeta.ServiceMeta serviceMeta, Channel channel) {
    Attribute<ConcurrentSet<RegisterMeta.ServiceMeta>> attr = channel.attr(S_SUBSCRIBE_KEY);
    ConcurrentSet<RegisterMeta.ServiceMeta> serviceMetaSet = attr.get();
    if (serviceMetaSet == null) {
        ConcurrentSet<RegisterMeta.ServiceMeta> newServiceMetaSet = new ConcurrentSet<>();
        serviceMetaSet = attr.setIfAbsent(newServiceMetaSet);
        if (serviceMetaSet == null) {
            serviceMetaSet = newServiceMetaSet;
        }/*from w  w w .  j a  v  a 2s  . c o  m*/
    }

    return serviceMetaSet.add(serviceMeta);
}

From source file:org.jupiter.transport.netty.channel.NettyChannel.java

License:Apache License

/**
 * Returns the {@link NettyChannel} for given {@link Channel}, this method never return null.
 *///w w w .  ja v  a  2  s. c o  m
public static NettyChannel attachChannel(Channel channel) {
    Attribute<NettyChannel> attr = channel.attr(NETTY_CHANNEL_KEY);
    NettyChannel nChannel = attr.get();
    if (nChannel == null) {
        NettyChannel newNChannel = new NettyChannel(channel);
        nChannel = attr.setIfAbsent(newNChannel);
        if (nChannel == null) {
            nChannel = newNChannel;
        }
    }
    return nChannel;
}