當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。