当前位置: 首页>>代码示例>>Java>>正文


Java Attribute.get方法代码示例

本文整理汇总了Java中io.netty.util.Attribute.get方法的典型用法代码示例。如果您正苦于以下问题:Java Attribute.get方法的具体用法?Java Attribute.get怎么用?Java Attribute.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.netty.util.Attribute的用法示例。


在下文中一共展示了Attribute.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getConsoleUser

import io.netty.util.Attribute; //导入方法依赖的package包/类
private ConsoleUser getConsoleUser(Channel channel) {
	Attribute<String> attr = channel.attr(USERNAME_KEY);
	if (attr == null) {
		return null;
	}
	String username = attr.get();
	if (username == null) {
		return null;
	}
	return users.get(username);
}
 
开发者ID:HankXV,项目名称:Limitart,代码行数:12,代码来源:ConsoleServer.java

示例2: pubcomp

import io.netty.util.Attribute; //导入方法依赖的package包/类
private void pubcomp(MqttMessage mqttPubAckMessage, Channel ch){
    int messageId = ((MqttMessageIdVariableHeader)mqttPubAckMessage.variableHeader()).messageId();
    Attribute<ChannelInfo> attr = ch.attr(DovakinConstants.CHANNEL_INFO_ATTRIBUTE_KEY);
    ChannelInfo channelInfo = attr.get();
    MqttSession session = MqttSessionCache.get(channelInfo.getIdentifier().value());
    if (session == null) return;
    QoSMessagePack messagePack = session.getMessageList().get(messageId);
    if (messagePack == null) return;

    session.removeMessageTask(messageId);
}
 
开发者ID:Dovakin-IO,项目名称:DovakinMQ,代码行数:12,代码来源:MqttProcessor.java

示例3: debugResponse

import io.netty.util.Attribute; //导入方法依赖的package包/类
/**
 * Process response debug
 *
 * @param response Response Object
 * @param m_ctx    Netty Context
 * @return Return indicator shows if the response requires handling for debugging. If true, the caller needs to stop handling response
 */
public boolean debugResponse(FullHttpResponse response, ChannelHandlerContext m_ctx) {
	boolean consume = false;
	if (debugEnabled()) {
		Attribute<CacheResultVerifier> debugResult = m_ctx.attr(DEBUG_RESULT);
		if (debugResult.get() != null) {
			try {
				CacheVerifiedResult result = debugResult.get().fetchResult(response);
				m_cacheManager.getStats().addCacheVerifiedResult(result);
			} catch (Exception e) {
				LOGGER.error(e.getMessage());
			} finally {
				consume = true;
			}
		}
	}
	return consume;
}
 
开发者ID:eBay,项目名称:ServiceCOLDCache,代码行数:25,代码来源:DebugManager.java

示例4: handle

import io.netty.util.Attribute; //导入方法依赖的package包/类
@Override
public void handle(ChannelHandlerContext ctx, List<Packet> out) throws Exception {
    Attribute<InetSocketAddress> attr = ctx.attr(PipelineUtil.ADDRESS_ATTRIBUTE);
    PocketServer instance = PocketServer.getInstance();
    InetSocketAddress address = attr.get();
    Optional<PocketPlayer> optional = instance.getPlayer(address);
    if (!optional.isPresent()) {
        instance.getLogger().debug("No player found for {}.", address);
        return;
    }
    PocketPlayer player = optional.get();
    if (player.getEntityId() != entityId) {
        instance.getLogger().debug("{} possibly spoofing block packets.", player);
        return;
    }
    //player.getWorld().setBlock(x, y, z, Material.AIR); //TODO: Debug why this doesn't set the correct positions
    PacketPlayOutUpdateBlock packet = new PacketPlayOutUpdateBlock(new PacketPlayOutUpdateBlock.BlockRecord(x, z, y, (byte) 0, (byte) 0));
    instance.broadcast(packet);
}
 
开发者ID:PocketServer,项目名称:PocketServer,代码行数:20,代码来源:PacketPlayOutRemoveBlock.java

示例5: 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);
    }
}
 
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:24,代码来源:Handler.java

示例6: encode

import io.netty.util.Attribute; //导入方法依赖的package包/类
@Override
protected void encode(ChannelHandlerContext ctx, Serializable msg, ByteBuf out) throws Exception {
    Attribute<ObjectOutputStream> oosAttr = ctx.attr(OOS);
    ObjectOutputStream oos = oosAttr.get();
    if (oos == null) {
        oos = newObjectOutputStream(new ByteBufOutputStream(out));
        ObjectOutputStream newOos = oosAttr.setIfAbsent(oos);
        if (newOos != null) {
            oos = newOos;
        }
    }

    synchronized (oos) {
        if (resetInterval != 0) {
            // Resetting will prevent OOM on the receiving side.
            writtenObjects ++;
            if (writtenObjects % resetInterval == 0) {
                oos.reset();
            }
        }

        oos.writeObject(msg);
        oos.flush();
    }
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:26,代码来源:CompatibleObjectEncoder.java

示例7: messageReceived

import io.netty.util.Attribute; //导入方法依赖的package包/类
@Override
protected void messageReceived(ChannelHandlerContext ctx, Packet packet) throws Exception {
    Attribute<InetSocketAddress> addressAttribute = ctx.attr(PipelineUtils.ADDRESS_ATTRIBUTE);
    InetSocketAddress address = addressAttribute.get();
    try {
        List<Packet> out = Lists.newLinkedList();
        packet.record(this);
        packet.handle(ctx, out);
        packet.close();
        for (Packet outbound : out) {
            ctx.write(outbound).addListener(new PacketChannelListener(address, packet));
        }
        ctx.flush();
    } finally {
        addressAttribute.remove();
    }
}
 
开发者ID:PocketServer,项目名称:PocketServer-Ref,代码行数:18,代码来源:PocketServerHandler.java

示例8: end

import io.netty.util.Attribute; //导入方法依赖的package包/类
@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();
      ctx = null;
      committed = true;
      return;
    }
    if (!committed) {
      DefaultHttpResponse rsp = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, status);
      headers.set(HttpHeaderNames.CONTENT_LENGTH, 0);
      // dump headers
      rsp.headers().set(headers);
      if (keepAlive) {
        ctx.write(rsp, ctx.voidPromise());
      } else {
        ctx.write(rsp).addListener(CLOSE);
      }
      committed = true;
    }
    ctx = null;
  }
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:27,代码来源:NettyResponse.java

示例9: testBlockingRead

import io.netty.util.Attribute; //导入方法依赖的package包/类
@Test
public void testBlockingRead() throws Exception{
	Channel channel = client.connect("192.168.13.64", 8888);
	ByteBuffer buffer = ByteBuffer.allocate(10);
	buffer.putShort((short)8);
	buffer.putLong(3l);
	buffer.flip();
	boolean wrote = false;
	while (!wrote) {
		while (channel.isWritable()) {
			channel.writeAndFlush(buffer.array());
			wrote = true;
			break;
		}
	}
	Attribute<BlockingRead> value = channel.attr(BlockingRead.CHANNEL_BLOCKING_READ_KEY);
	if (value.get() == null) {
		throw new NullPointerException();
	}
	Object result = value.get().read();
	System.out.println(result);
	System.in.read();
}
 
开发者ID:leo27lijiang,项目名称:remote-netty,代码行数:24,代码来源:IOClientBlockTest.java

示例10: exceptionCaught

import io.netty.util.Attribute; //导入方法依赖的package包/类
@Override
public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) {
  try {
    if (ConnectionResetByPeer.test(cause)) {
      log.trace("execution of: " + ctx.channel().attr(PATH).get() + " resulted in error", cause);
    } else {
      Attribute<NettyWebSocket> ws = ctx.channel().attr(NettyWebSocket.KEY);
      if (ws != null && ws.get() != null) {
        ws.get().handle(cause);
      } else {
        log.debug("execution of: " + ctx.channel().attr(PATH).get() + " resulted in error",
            cause);
      }
    }
  } finally {
    ctx.close();
  }

}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:20,代码来源:NettyHandler.java

示例11: getOrCreateQueryStringDecoder

import io.netty.util.Attribute; //导入方法依赖的package包/类
private QueryStringDecoder getOrCreateQueryStringDecoder(HttpServerRequest<?> request) {
    if (null == request) {
        throw new NullPointerException("Request can not be null.");
    }
    String uri = request.getUri();
    if (null == uri) {
        return null;
    }

    Attribute<QueryStringDecoder> queryDecoderAttr = channel.attr(queryDecoderKey);

    QueryStringDecoder _queryStringDecoder = queryDecoderAttr.get();

    if (null == _queryStringDecoder) {
        _queryStringDecoder = new QueryStringDecoder(uri);
        queryDecoderAttr.setIfAbsent(_queryStringDecoder);
    }
    return _queryStringDecoder;
}
 
开发者ID:Netflix,项目名称:karyon,代码行数:20,代码来源:HttpKeyEvaluationContext.java

示例12: channelInactive

import io.netty.util.Attribute; //导入方法依赖的package包/类
/**
 * 连接被关闭
 * @param ctx
 * @throws Exception
 */
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {

    AttributeKey<Session> attrKeySession = AttributeKey.valueOf("Session");
    Attribute<Session> attrSession = ctx.attr(attrKeySession);
    Session session = attrSession.get();

    logger.warn("client diconnect!");
    super.channelInactive(ctx);
}
 
开发者ID:ninelook,项目名称:wecard-server,代码行数:16,代码来源:NettyServerHandler.java

示例13: activeChannel

import io.netty.util.Attribute; //导入方法依赖的package包/类
/**
 * 保存已激活的 Channel
 *
 * @param channel 已激活的 Channel
 */
public void activeChannel(Channel channel) {
    Attribute<Integer> key = channel.attr(AttributeKey.valueOf("ID"));
    int id = key.get();

    CHANNEL_ARRAY.set(id, channel);
    SENDING_MESSAGE_QUEUE.get(id).clear();
}
 
开发者ID:bitkylin,项目名称:ClusterDeviceControlPlatform,代码行数:13,代码来源:TcpRepository.java

示例14: pubrec

import io.netty.util.Attribute; //导入方法依赖的package包/类
private void pubrec(MqttMessage mqttPubAckMessage, Channel ch){
    int messageId = ((MqttMessageIdVariableHeader)mqttPubAckMessage.variableHeader()).messageId();
    Attribute<ChannelInfo> attr = ch.attr(DovakinConstants.CHANNEL_INFO_ATTRIBUTE_KEY);
    ChannelInfo channelInfo = attr.get();
    MqttSession session = MqttSessionCache.get(channelInfo.getIdentifier().value());
    if (session == null) return;
    QoSMessagePack messagePack = session.getMessageList().get(messageId);
    if (messagePack == null) return;

    messagePack.setState(QoSMessagePack.STATE.PUBREC);
    session.removeMessageTask(messageId);
    MessageExecutor.put(messagePack);
}
 
开发者ID:Dovakin-IO,项目名称:DovakinMQ,代码行数:14,代码来源:MqttProcessor.java

示例15: puback

import io.netty.util.Attribute; //导入方法依赖的package包/类
private void puback(MqttPubAckMessage mqttPubAckMessage, Channel ch){
    int messageId = mqttPubAckMessage.variableHeader().messageId();
    Attribute<ChannelInfo> attr = ch.attr(DovakinConstants.CHANNEL_INFO_ATTRIBUTE_KEY);
    ChannelInfo channelInfo = attr.get();
    MqttSession session = MqttSessionCache.get(channelInfo.getIdentifier().value());
    if (session == null) return;
    QoSMessagePack messagePack = session.getMessageList().get(messageId);
    if (messagePack == null) return;
    if (messagePack.getLevel() == mqttPubAckMessage.fixedHeader().qosLevel()){
        session.removeMessageTask(messageId);
    }
}
 
开发者ID:Dovakin-IO,项目名称:DovakinMQ,代码行数:13,代码来源:MqttProcessor.java


注:本文中的io.netty.util.Attribute.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。