本文整理匯總了Java中io.netty.util.Attribute.set方法的典型用法代碼示例。如果您正苦於以下問題:Java Attribute.set方法的具體用法?Java Attribute.set怎麽用?Java Attribute.set使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類io.netty.util.Attribute
的用法示例。
在下文中一共展示了Attribute.set方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: channelRead0
import io.netty.util.Attribute; //導入方法依賴的package包/類
@Override
protected void channelRead0(final ChannelHandlerContext channelHandlerContext, final ResponseMessage response) throws Exception {
// We are only interested in AUTHENTICATE responses here. Everything else can
// get passed down the pipeline
if (response.getStatus().getCode() == ResponseStatusCode.AUTHENTICATE) {
final Attribute<SaslClient> saslClient = channelHandlerContext.attr(saslClientKey);
final Attribute<Subject> subject = channelHandlerContext.attr(subjectKey);
RequestMessage.Builder messageBuilder = RequestMessage.build(Tokens.OPS_AUTHENTICATION);
// First time through we don't have a sasl client
if (saslClient.get() == null) {
subject.set(login());
saslClient.set(saslClient(getHostName(channelHandlerContext)));
messageBuilder.addArg(Tokens.ARGS_SASL_MECHANISM, getMechanism());
messageBuilder.addArg(Tokens.ARGS_SASL, saslClient.get().hasInitialResponse() ?
evaluateChallenge(subject, saslClient, NULL_CHALLENGE) : null);
} else {
messageBuilder.addArg(Tokens.ARGS_SASL, evaluateChallenge(subject, saslClient, (byte[])response.getResult().getData()));
}
channelHandlerContext.writeAndFlush(messageBuilder.create());
} else {
channelHandlerContext.fireChannelRead(response);
}
}
示例2: clientToProxyRequest
import io.netty.util.Attribute; //導入方法依賴的package包/類
@Override
public HttpResponse clientToProxyRequest(HttpObject httpObject) {
if (httpObject instanceof HttpRequest) {
HttpRequest httpRequest = (HttpRequest) httpObject;
if (ProxyUtils.isCONNECT(httpRequest)) {
Attribute<String> hostname = ctx.attr(AttributeKey.<String>valueOf(HttpsAwareFiltersAdapter.HOST_ATTRIBUTE_NAME));
String hostAndPort = httpRequest.getUri();
// CONNECT requests contain the port, even when using the default port. a sensible default is to remove the
// default port, since in most cases it is not explicitly specified and its presence (in a HAR file, for example)
// would be unexpected.
String hostNoDefaultPort = BrowserMobHttpUtil.removeMatchingPort(hostAndPort, 443);
hostname.set(hostNoDefaultPort);
}
}
return null;
}
示例3: bind
import io.netty.util.Attribute; //導入方法依賴的package包/類
public static boolean bind(Channel channel, NettyClient nettyClient){
Attribute<NettyClient> attribute = channel.attr(KEY_CLIENT);
if(attribute != null){
return false;
}
synchronized (channel) {
attribute = channel.attr(KEY_CLIENT);
if(attribute == null){
return false;
}
attribute.set(nettyClient);
}
return true;
}
示例4: initChannel
import io.netty.util.Attribute; //導入方法依賴的package包/類
@Override
protected void initChannel(SocketChannel ch) throws Exception {
final ChannelPipeline p = ch.pipeline();
final UUID uuid = UUID.randomUUID();
LOG.debug("KaaTcpServerInitializer Initializing Channel {} connection from {}:{}",
uuid, ch.remoteAddress().getAddress().toString(), ch.remoteAddress().getPort());
Attribute<UUID> uuidAttr = ch.attr(AbstractNettyServer.UUID_KEY);
uuidAttr.set(uuid);
p.addLast("binaryDecoder", new ByteArrayDecoder());
p.addLast("kaaTcpDecoder", getDecoder());
p.addLast("binaryEncoder", new ByteArrayEncoder());
p.addLast("kaaTcpEncoder", new KaaTcpEncoder());
p.addLast("mainHandler", getMainHandler(uuid));
p.addLast("kaaTcpExceptionHandler", new KaaTcpExceptionHandler());
}
示例5: initChannel
import io.netty.util.Attribute; //導入方法依賴的package包/類
@Override
protected void initChannel(SocketChannel ch) throws Exception {
final ChannelPipeline p = ch.pipeline();
final UUID uuid = UUID.randomUUID();
LOG.info("DefaultServerInitializer Initializing Channel {} connection from {}:{}", uuid,
ch.remoteAddress().getAddress().toString(), ch.remoteAddress().getPort());
Attribute<UUID> uuidAttr = ch.attr(AbstractNettyServer.UUID_KEY);
uuidAttr.set(uuid);
p.addLast("httpDecoder", new HttpRequestDecoder());
p.addLast("httpAggregator", new HttpObjectAggregator(getClientMaxBodySize()));
p.addLast("httpDecoderAux", getRequestDecoder());
p.addLast("httpEncoder", new HttpResponseEncoder());
p.addLast("httpEncoderAux", new ResponseEncoder());
p.addLast("handler", getMainHandler(uuid));
p.addLast("httpExceptionHandler", new DefaultExceptionHandler());
}
示例6: setActive
import io.netty.util.Attribute; //導入方法依賴的package包/類
/**
* Marks a {@link Channel} as active.
*
* @param channel
* the Channel to mark active
* @throws IllegalArgumentException
* if the Channel was not added to this manager
*/
public void setActive(final Channel channel) {
synchronized (channels) {
if (!channels.contains(channel)) {
throw new IllegalArgumentException("channel " + channel + " was not added to this manager");
}
final ModuleID remoteID = getRemoteID(channel);
final boolean informListeners = (remoteID != null && getActiveChannels(remoteID).isEmpty());
final Attribute<Boolean> activeAttribute = channel.attr(ACTIVE_KEY);
LOGGER.debug("setting active attribute on {}", channel);
activeAttribute.set(true);
if (informListeners) {
delegatingConnectionListener.connectionEstablished(remoteID);
}
}
}
示例7: bindKey
import io.netty.util.Attribute; //導入方法依賴的package包/類
@Override
public void bindKey(Channel ctx, String key) {
Attribute<String> attr = ctx.attr(attributeKey);
if(attr!=null){
attr.set(key);
//put delivery
deliveryClient.putKey(getModelName(),getUniqueKey(ctx),key);
}
}
示例8: issueDebugRequest
import io.netty.util.Attribute; //導入方法依賴的package包/類
/**
* Issue a debug request when debugging is enabled.
*
* @param httpObject Http request of client
* @param m_ctx Netty context
* @param fromDebugFilter Indicator shows if the request require to be forwarded
* @return An indicator showing if debug manager consumes the request. If true, the caller needs to stop handling request.
*/
public void issueDebugRequest(FullHttpRequest httpObject, final ChannelHandlerContext m_ctx, boolean fromDebugFilter) {
if (debugEnabled()) {
final FullHttpRequest request = httpObject.copy();
if (fromDebugFilter) {
try {
if (ssl(request)) {
Field field = ClientToProxyConnection.class.getDeclaredField("mitming");
field.setAccessible(true);
field.set(m_ctx.handler(), true);
}
} catch (Exception e) {
LOGGER.error(e.getMessage());
}
String key = m_policyManager.generateCacheKey(request);
FullHttpResponse cacheResponse = m_policyManager.getCacheManager().get(key);
CacheResultVerifier verifier = new CacheResultVerifier(key, request, cacheResponse);
Attribute<CacheResultVerifier> debugging = m_ctx.attr(DEBUG_RESULT);
debugging.set(verifier);
} else {
executor.execute(new Runnable() {
@Override
public void run() {
forwardDebugRequest(request);
}
});
}
}
}
示例9: getOrCreateProxyRouterProcessingState
import io.netty.util.Attribute; //導入方法依賴的package包/類
protected ProxyRouterProcessingState getOrCreateProxyRouterProcessingState(ChannelHandlerContext ctx) {
Attribute<ProxyRouterProcessingState> proxyRouterStateAttribute =
ChannelAttributes.getProxyRouterProcessingStateForChannel(ctx);
ProxyRouterProcessingState proxyRouterState = proxyRouterStateAttribute.get();
if (proxyRouterState == null) {
proxyRouterState = new ProxyRouterProcessingState();
proxyRouterStateAttribute.set(proxyRouterState);
}
return proxyRouterState;
}
示例10: channelActive
import io.netty.util.Attribute; //導入方法依賴的package包/類
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
Attribute<MessageMetrics> attr = ctx.attr(ATTR_KEY_METRICS);
attr.set(new MessageMetrics());
super.channelActive(ctx);
}
示例11: channelActive
import io.netty.util.Attribute; //導入方法依賴的package包/類
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
Attribute<BytesMetrics> attr = ctx.attr(ATTR_KEY_METRICS);
attr.set(new BytesMetrics());
super.channelActive(ctx);
}
示例12: handlerRemoved
import io.netty.util.Attribute; //導入方法依賴的package包/類
@Override
public void handlerRemoved(ChannelHandlerContext ctx) {
Attribute<ByteBuf> bytebufAttr = ctx.channel().attr(BUFFER_IN);
ByteBuf buffer = bytebufAttr.get();
Util.safeRelease(buffer);
bytebufAttr.set(null);
}
示例13: HttpsOriginalHostCaptureFilter
import io.netty.util.Attribute; //導入方法依賴的package包/類
public HttpsOriginalHostCaptureFilter(HttpRequest originalRequest, ChannelHandlerContext ctx) {
super(originalRequest, ctx);
// if this is an HTTP CONNECT, set the isHttps attribute on the ChannelHandlerConect and capture the hostname from the original request.
// capturing the original host (and the remapped/modified host in clientToProxyRequest() below) guarantees that we will
// have the "true" host, rather than relying on the Host header in subsequent requests (which may be absent or spoofed by malicious clients).
if (ProxyUtils.isCONNECT(originalRequest)) {
Attribute<String> originalHostAttr = ctx.attr(AttributeKey.<String>valueOf(HttpsAwareFiltersAdapter.ORIGINAL_HOST_ATTRIBUTE_NAME));
String hostAndPort = originalRequest.getUri();
originalHostAttr.set(hostAndPort);
Attribute<Boolean> isHttpsAttr = ctx.attr(AttributeKey.<Boolean>valueOf(HttpsAwareFiltersAdapter.IS_HTTPS_ATTRIBUTE_NAME));
isHttpsAttr.set(true);
}
}
示例14: attachSession
import io.netty.util.Attribute; //導入方法依賴的package包/類
private Session attachSession(ChannelHandlerContext ctx){
Session sess = new NettySession(ctx);
Attribute<String> attr = ctx.channel().attr(sessionKey);
attr.set(sess.id());
sessionMap.put(sess.id(), sess);
return sess;
}
示例15: ensurePlay
import io.netty.util.Attribute; //導入方法依賴的package包/類
private static void ensurePlay(Channel channel) {
Attribute<EnumConnectionState> attr = channel.attr(NetworkManager.attrKeyConnectionState);
EnumConnectionState enumConnectionState = attr.get();
if (enumConnectionState == null) {
Core.logSevere("Changing ConnectionState from null to PLAY: " + channel);
attr.set(EnumConnectionState.PLAY);
}
}