當前位置: 首頁>>代碼示例>>Java>>正文


Java Attribute.setIfAbsent方法代碼示例

本文整理匯總了Java中io.netty.util.Attribute.setIfAbsent方法的典型用法代碼示例。如果您正苦於以下問題:Java Attribute.setIfAbsent方法的具體用法?Java Attribute.setIfAbsent怎麽用?Java Attribute.setIfAbsent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.netty.util.Attribute的用法示例。


在下文中一共展示了Attribute.setIfAbsent方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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

示例2: testGetSetString

import io.netty.util.Attribute; //導入方法依賴的package包/類
@Test
public void testGetSetString() {
    AttributeKey<String> key = AttributeKey.valueOf("Nothing");
    Attribute<String> one = map.attr(key);

    assertSame(one, map.attr(key));

    one.setIfAbsent("Whoohoo");
    assertSame("Whoohoo", one.get());

    one.setIfAbsent("What");
    assertNotSame("What", one.get());

    one.remove();
    assertNull(one.get());
}
 
開發者ID:line,項目名稱:armeria,代碼行數:17,代碼來源:DefaultAttributeMapTest.java

示例3: testGetSetInt

import io.netty.util.Attribute; //導入方法依賴的package包/類
@Test
public void testGetSetInt() {
    AttributeKey<Integer> key = AttributeKey.valueOf("Nada");
    Attribute<Integer> one = map.attr(key);

    assertSame(one, map.attr(key));

    one.setIfAbsent(3653);
    assertEquals(Integer.valueOf(3653), one.get());

    one.setIfAbsent(1);
    assertNotSame(1, one.get());

    one.remove();
    assertNull(one.get());
}
 
開發者ID:line,項目名稱:armeria,代碼行數:17,代碼來源:DefaultAttributeMapTest.java

示例4: 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

示例5: channelActive

import io.netty.util.Attribute; //導入方法依賴的package包/類
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
    Attribute<RequestRecorder> attr = ctx.channel().attr(DovakinConstants.RECORDER_ATTRIBUTE_KEY);
    RequestRecorder var1 = attr.get();
    if(var1 == null){
        RequestRecorder var2 = new RequestRecorder();
        var1 = attr.setIfAbsent(var2);
    }

    ctx.fireChannelActive();
}
 
開發者ID:Dovakin-IO,項目名稱:DovakinMQ,代碼行數:12,代碼來源:MqttHandler.java

示例6: getWriter

import io.netty.util.Attribute; //導入方法依賴的package包/類
private static HighPerformanceChannelWriter getWriter(Channel channel) {
	Attribute<HighPerformanceChannelWriter> attr = channel.attr(ChannelAttrKeys.highPerformanceWriter);
	HighPerformanceChannelWriter writer = attr.get();
	if (null == writer) {
		HighPerformanceChannelWriter old = attr.setIfAbsent(writer = new HighPerformanceChannelWriter(channel));
		if (null != old) {
			writer = old;
		}
	}
	return writer;
}
 
開發者ID:spccold,項目名稱:sailfish,代碼行數:12,代碼來源:HighPerformanceChannelWriter.java

示例7: channelRead

import io.netty.util.Attribute; //導入方法依賴的package包/類
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    Attribute<AtomicInteger> attr = ctx.attr(REQUEST_COUNT);
    if (attr.get() == null) {
        attr.setIfAbsent(new AtomicInteger());
    }
    attr.get().incrementAndGet();
    ctx.fireChannelRead(msg);
}
 
開發者ID:pulsarIO,項目名稱:jetstream,代碼行數:10,代碼來源:KeepAliveHandler.java

示例8: getPingEnabled

import io.netty.util.Attribute; //導入方法依賴的package包/類
public static boolean getPingEnabled(Channel ch) {
    final Attribute<Boolean> attr = ch.attr(SEND_PINGS);
    attr.setIfAbsent(false);
    return attr.get();
}
 
開發者ID:SecureSmartHome,項目名稱:SecureSmartHome,代碼行數:6,代碼來源:TimeoutHandler.java

示例9: handle

import io.netty.util.Attribute; //導入方法依賴的package包/類
@Override
public void handle(NetworkContext context, MessagePlayInChatMessage message) {
    final NetworkSession session = context.getSession();
    final LanternPlayer player = session.getPlayer();
    player.resetIdleTimeoutCounter();
    final String message0 = message.getMessage();

    // Check for a valid click action callback
    final Matcher matcher = LanternClickActionCallbacks.COMMAND_PATTERN.matcher(message0);
    if (matcher.matches()) {
        final UUID uniqueId = UUID.fromString(matcher.group(1));
        final Optional<Consumer<CommandSource>> callback = LanternClickActionCallbacks.get().getCallbackForUUID(uniqueId);
        if (callback.isPresent()) {
            callback.get().accept(player);
        } else {
            player.sendMessage(error(t("The callback you provided was not valid. Keep in mind that callbacks will expire "
                    + "after 10 minutes, so you might want to consider clicking faster next time!")));
        }
        return;
    }

    String message1 = StringUtils.normalizeSpace(message0);
    if (!isAllowedString(message0)) {
        session.disconnect(t("multiplayer.disconnect.illegal_characters"));
        return;
    }
    if (message1.startsWith("/")) {
        Lantern.getSyncExecutorService().submit(() -> Sponge.getCommandManager().process(player, message1.substring(1)));
    } else {
        final Text nameText = player.get(Keys.DISPLAY_NAME).get();
        final Text rawMessageText = Text.of(message0);
        final GlobalConfig.Chat.Urls urls = Lantern.getGame().getGlobalConfig().getChat().getUrls();
        final Text messageText;
        if (urls.isEnabled() && player.hasPermission(Permissions.Chat.FORMAT_URLS)) {
            messageText = newTextWithLinks(message0, urls.getTemplate(), false);
        } else {
            messageText = rawMessageText;
        }
        final MessageChannel channel = player.getMessageChannel();

        final CauseStack causeStack = CauseStack.current();
        try (CauseStack.Frame frame = causeStack.pushCauseFrame()) {
            frame.addContext(EventContextKeys.PLAYER, player);
            final MessageChannelEvent.Chat event = SpongeEventFactory.createMessageChannelEventChat(causeStack.getCurrentCause(),
                    channel, Optional.of(channel), new MessageEvent.MessageFormatter(nameText, messageText), rawMessageText, false);
            if (!Sponge.getEventManager().post(event) && !event.isMessageCancelled()) {
                event.getChannel().ifPresent(c -> c.send(player, event.getMessage(), ChatTypes.CHAT));
            }
        }
    }
    final Attribute<ChatData> attr = context.getChannel().attr(CHAT_DATA);
    ChatData chatData = attr.get();
    if (chatData == null) {
        chatData = new ChatData();
        final ChatData chatData1 = attr.setIfAbsent(chatData);
        if (chatData1 != null) {
            chatData = chatData1;
        }
    }
    //noinspection SynchronizationOnLocalVariableOrMethodParameter
    synchronized (chatData) {
        final long currentTime = LanternGame.currentTimeTicks();
        if (chatData.lastChatTime != -1L) {
            chatData.chatThrottle = (int) Math.max(0, chatData.chatThrottle - (currentTime - chatData.lastChatTime));
        }
        chatData.lastChatTime = currentTime;
        chatData.chatThrottle += 20;
        if (chatData.chatThrottle > Lantern.getGame().getGlobalConfig().getChatSpamThreshold()) {
            session.disconnect(t("disconnect.spam"));
        }
    }
}
 
開發者ID:LanternPowered,項目名稱:LanternServer,代碼行數:73,代碼來源:HandlerPlayInChatMessage.java


注:本文中的io.netty.util.Attribute.setIfAbsent方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。