本文整理汇总了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);
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
}
示例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();
}
}
示例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();
}
}
示例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;
}
}
示例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();
}
示例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();
}
}
示例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;
}
示例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);
}
示例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();
}
示例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);
}
示例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);
}
}