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


Java Attribute類代碼示例

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


Attribute類屬於io.netty.util包,在下文中一共展示了Attribute類的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: testIssueDebugRequest_fromDebugFilter

import io.netty.util.Attribute; //導入依賴的package包/類
@Test
@SuppressWarnings("unchecked")
public void testIssueDebugRequest_fromDebugFilter() {
	Mockito.when(m_appConfiguration.getBoolean("debugManager.debugEnabled")).thenReturn(true);
	FullHttpRequest request = Mockito.mock(FullHttpRequest.class);
	FullHttpResponse cacheResponse = Mockito.mock(FullHttpResponse.class);
	ChannelHandlerContext ctx = Mockito.mock(ChannelHandlerContext.class);
	Mockito.when(request.copy()).thenReturn(request);
	Mockito.when(m_cacheManager.get("test_req")).thenReturn(cacheResponse);
	Mockito.when(m_policyManager.generateCacheKey(request)).thenReturn("test_req");

	Attribute<CacheResultVerifier> debugging = Mockito.mock(Attribute.class);
	Mockito.when(ctx.attr(DebugManager.DEBUG_RESULT)).thenReturn(debugging);
	debugManager.issueDebugRequest(request, ctx, true);
	CacheResultVerifier verifier = new CacheResultVerifier("test_req", request, cacheResponse);
	Mockito.verify(debugging, Mockito.times(1)).set(Mockito.refEq(verifier));
}
 
開發者ID:eBay,項目名稱:ServiceCOLDCache,代碼行數:18,代碼來源:DebugManagerTest.java

示例5: testIssueDebugRequest_sslFromDebugFilter

import io.netty.util.Attribute; //導入依賴的package包/類
@Test
@SuppressWarnings("unchecked")
public void testIssueDebugRequest_sslFromDebugFilter() {
	Mockito.when(m_appConfiguration.getBoolean("debugManager.debugEnabled")).thenReturn(true);
	FullHttpRequest request = Mockito.mock(FullHttpRequest.class);
	FullHttpResponse cacheResponse = Mockito.mock(FullHttpResponse.class);
	ChannelHandlerContext ctx = Mockito.mock(ChannelHandlerContext.class);
	Mockito.when(ctx.handler()).thenReturn(clientToProxyConnection);
	Mockito.when(request.copy()).thenReturn(request);
	String key = "https://serverHostAndPort=www.ebay.com:443";
	Mockito.when(m_cacheManager.get(key)).thenReturn(cacheResponse);
	Mockito.when(m_policyManager.generateCacheKey(request)).thenReturn(key);

	Attribute<CacheResultVerifier> debugging = Mockito.mock(Attribute.class);
	Mockito.when(ctx.attr(DebugManager.DEBUG_RESULT)).thenReturn(debugging);
	debugManager.issueDebugRequest(request, ctx, true);
	Assert.assertTrue((Boolean) readField(clientToProxyConnection, "mitming"));
	CacheResultVerifier verifier = new CacheResultVerifier(key, request, cacheResponse);
	Mockito.verify(debugging, Mockito.times(1)).set(Mockito.refEq(verifier));
}
 
開發者ID:eBay,項目名稱:ServiceCOLDCache,代碼行數:21,代碼來源:DebugManagerTest.java

示例6: testDebugResponse_consume

import io.netty.util.Attribute; //導入依賴的package包/類
@Test
@SuppressWarnings("unchecked")
public void testDebugResponse_consume() {
	Mockito.when(m_appConfiguration.getBoolean("debugManager.debugEnabled")).thenReturn(true);
	FullHttpResponse actualResponse = Mockito.mock(FullHttpResponse.class);

	ChannelHandlerContext ctx = Mockito.mock(ChannelHandlerContext.class);
	Attribute<CacheResultVerifier> debugging = Mockito.mock(Attribute.class);
	Mockito.when(ctx.attr(DebugManager.DEBUG_RESULT)).thenReturn(debugging);
	CacheResultVerifier verifier = Mockito.mock(CacheResultVerifier.class);
	CacheVerifiedResult result = new CacheVerifiedResult();
	result.key = "test_req";
	Mockito.when(verifier.fetchResult(actualResponse)).thenReturn(result);
	Mockito.when(debugging.get()).thenReturn(verifier);

	CacheStats cacheStats = Mockito.mock(CacheStats.class);
	Mockito.when(m_cacheManager.getStats()).thenReturn(cacheStats);
	debugManager.debugResponse(actualResponse, ctx);
	Mockito.verify(cacheStats, Mockito.times(1)).addCacheVerifiedResult(verifier.fetchResult(actualResponse));
}
 
開發者ID:eBay,項目名稱:ServiceCOLDCache,代碼行數:21,代碼來源:DebugManagerTest.java

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

示例8: 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);
    Optional<PocketPlayer> optional = PocketServer.getInstance().getPlayer(attr.get());
    if (!optional.isPresent()) {
        PocketServer.getInstance().getLogger().debug("No player found for address {}", attr.get());
    }
    PocketPlayer player = optional.get();
    if (player.getEntityId() != entityId) {
        PocketServer.getInstance().getLogger().debug("Possible spoof for player from address {}", attr.get());
    }
    PocketServer.getInstance().getLogger().debug(MoreObjects.toStringHelper(this)
            .add("x", x)
            .add("y", y)
            .add("z", z)
            .add("pitch", pitch)
            .add("yaw", yaw)
            .add("bodyYaw", bodyYaw)
            .add("mode", mode)
            .add("onGround", onGround)
            .toString()
    );
    PocketServer.getInstance().broadcast(this, p -> p != player); //TODO: Update player location
}
 
開發者ID:PocketServer,項目名稱:PocketServer,代碼行數:25,代碼來源:PacketPlayOutMovePlayer.java

示例9: beforeMethod

import io.netty.util.Attribute; //導入依賴的package包/類
@Before
public void beforeMethod() {
    stateMock = mock(HttpProcessingState.class);
    ctxMock = mock(ChannelHandlerContext.class);
    channelMock = mock(Channel.class);
    stateAttrMock = mock(Attribute.class);
    endpointMock = mock(Endpoint.class);
    maxRequestSizeInBytes = 10;
    httpContentMock = mock(HttpContent.class);
    byteBufMock = mock(ByteBuf.class);
    requestInfo = mock(RequestInfo.class);

    handler = new RequestInfoSetterHandler(maxRequestSizeInBytes);

    doReturn(channelMock).when(ctxMock).channel();
    doReturn(stateAttrMock).when(channelMock).attr(ChannelAttributes.HTTP_PROCESSING_STATE_ATTRIBUTE_KEY);
    doReturn(stateMock).when(stateAttrMock).get();
    doReturn(endpointMock).when(stateMock).getEndpointForExecution();
    doReturn(byteBufMock).when(httpContentMock).content();
    doReturn(null).when(endpointMock).maxRequestSizeInBytesOverride();
    doReturn(requestInfo).when(stateMock).getRequestInfo();
}
 
開發者ID:Nike-Inc,項目名稱:riposte,代碼行數:23,代碼來源:RequestInfoSetterHandlerTest.java

示例10: beforeMethod

import io.netty.util.Attribute; //導入依賴的package包/類
@Before
public void beforeMethod() {
    handlerSpy = spy(new DTraceEndHandler());
    channelMock = mock(Channel.class);
    ctxMock = mock(ChannelHandlerContext.class);
    stateAttributeMock = mock(Attribute.class);
    state = new HttpProcessingState();
    doReturn(channelMock).when(ctxMock).channel();
    doReturn(stateAttributeMock).when(channelMock).attr(ChannelAttributes.HTTP_PROCESSING_STATE_ATTRIBUTE_KEY);
    doReturn(state).when(stateAttributeMock).get();
    resetTracingAndMdc();

    responseInfoMock = mock(ResponseInfo.class);
    doReturn(true).when(responseInfoMock).isResponseSendingLastChunkSent();
    state.setResponseInfo(responseInfoMock);

    lastChunkChannelFutureMock = mock(ChannelFuture.class);
    state.setResponseWriterFinalChunkChannelFuture(lastChunkChannelFutureMock);

    doAnswer(invocation -> {
        currentSpanWhenCompleteCurrentSpanWasCalled = Tracer.getInstance().getCurrentSpan();
        invocation.callRealMethod();
        currentSpanAfterCompleteCurrentSpanWasCalled = Tracer.getInstance().getCurrentSpan();
        return null;
    }).when(handlerSpy).completeCurrentSpan();
}
 
開發者ID:Nike-Inc,項目名稱:riposte,代碼行數:27,代碼來源:DTraceEndHandlerTest.java

示例11: beforeMethod

import io.netty.util.Attribute; //導入依賴的package包/類
@Before
public void beforeMethod() {
    channelMock = mock(Channel.class);
    ctxMock = mock(ChannelHandlerContext.class);
    stateAttributeMock = mock(Attribute.class);
    state = new HttpProcessingState();

    doReturn(channelMock).when(ctxMock).channel();
    doReturn(stateAttributeMock).when(channelMock).attr(ChannelAttributes.HTTP_PROCESSING_STATE_ATTRIBUTE_KEY);
    doReturn(state).when(stateAttributeMock).get();

    firstChunkMsgMock = mock(HttpRequest.class);
    lastChunkMsgMock = mock(LastHttpContent.class);

    filter1Mock = mock(RequestAndResponseFilter.class);
    filter2Mock = mock(RequestAndResponseFilter.class);
    filtersList = Arrays.asList(filter1Mock, filter2Mock);

    handlerSpy = spy(new RequestFilterHandler(filtersList));

    requestInfoMock = mock(RequestInfo.class);

    state.setRequestInfo(requestInfoMock);
}
 
開發者ID:Nike-Inc,項目名稱:riposte,代碼行數:25,代碼來源:RequestFilterHandlerTest.java

示例12: beforeMethod

import io.netty.util.Attribute; //導入依賴的package包/類
@Before
public void beforeMethod() {
    stateMock = mock(HttpProcessingState.class);
    ctxMock = mock(ChannelHandlerContext.class);
    channelMock = mock(Channel.class);
    stateAttrMock = mock(Attribute.class);
    metricsListenerMock = mock(MetricsListener.class);
    msgMock = mock(HttpRequest.class);
    responseSenderMock = mock(ResponseSender.class);
    responseInfo = ResponseInfo.newBuilder(UUID.randomUUID().toString()).build();
    endpointExecutedMock = mock(Endpoint.class);
    customSerializerMock = mock(ObjectMapper.class);

    doReturn(channelMock).when(ctxMock).channel();
    doReturn(stateAttrMock).when(channelMock).attr(ChannelAttributes.HTTP_PROCESSING_STATE_ATTRIBUTE_KEY);
    doReturn(stateMock).when(stateAttrMock).get();
    doReturn(responseInfo).when(stateMock).getResponseInfo();
    doReturn(endpointExecutedMock).when(stateMock).getEndpointForExecution();
    doReturn(customSerializerMock).when(endpointExecutedMock).customResponseContentSerializer(any(RequestInfo.class));

    handlerSpy = spy(new ResponseSenderHandler(responseSenderMock));
}
 
開發者ID:Nike-Inc,項目名稱:riposte,代碼行數:23,代碼來源:ResponseSenderHandlerTest.java

示例13: beforeMethod

import io.netty.util.Attribute; //導入依賴的package包/類
@Before
public void beforeMethod() {
    stateMock = mock(HttpProcessingState.class);
    ctxMock = mock(ChannelHandlerContext.class);
    channelMock = mock(Channel.class);
    stateAttrMock = mock(Attribute.class);
    requestInfoMock = mock(RequestInfo.class);
    endpointMock = mock(StandardEndpoint.class);
    matcherMock = mock(Matcher.class);
    endpoints = new ArrayList<>(Collections.singleton(endpointMock));
    httpHeaders = new DefaultHttpHeaders();
    maxRequestSizeInBytes = 10;
    msg = mock(HttpRequest.class);

    doReturn(channelMock).when(ctxMock).channel();
    doReturn(stateAttrMock).when(channelMock).attr(ChannelAttributes.HTTP_PROCESSING_STATE_ATTRIBUTE_KEY);
    doReturn(stateMock).when(stateAttrMock).get();
    doReturn(endpointMock).when(stateMock).getEndpointForExecution();
    doReturn(matcherMock).when(endpointMock).requestMatcher();
    doReturn(Optional.of(defaultPath)).when(matcherMock).matchesPath(any(RequestInfo.class));
    doReturn(true).when(matcherMock).matchesMethod(any(RequestInfo.class));
    doReturn(requestInfoMock).when(stateMock).getRequestInfo();
    doReturn(httpHeaders).when(msg).headers();

    handlerSpy = spy(new RoutingHandler(endpoints, maxRequestSizeInBytes));
}
 
開發者ID:Nike-Inc,項目名稱:riposte,代碼行數:27,代碼來源:RoutingHandlerTest.java

示例14: beforeMethod

import io.netty.util.Attribute; //導入依賴的package包/類
@Before
public void beforeMethod() {
    stateMock = mock(HttpProcessingState.class);
    ctxMock = mock(ChannelHandlerContext.class);
    channelMock = mock(Channel.class);
    pipelineMock = mock(ChannelPipeline.class);
    stateAttrMock = mock(Attribute.class);
    proxyRouterProcessingStateAttrMock = mock(Attribute.class);
    metricsListenerMock = mock(MetricsListener.class);
    msgMockFirstChunkOnly = mock(HttpRequest.class);
    msgMockFullRequest = mock(FullHttpRequest.class);
    msgMockLastChunkOnly = mock(LastHttpContent.class);
    idleChannelTimeoutHandlerMock = mock(IdleChannelTimeoutHandler.class);

    doReturn(channelMock).when(ctxMock).channel();
    doReturn(pipelineMock).when(ctxMock).pipeline();
    doReturn(idleChannelTimeoutHandlerMock).when(pipelineMock).get(IDLE_CHANNEL_TIMEOUT_HANDLER_NAME);
    doReturn(stateAttrMock).when(channelMock).attr(ChannelAttributes.HTTP_PROCESSING_STATE_ATTRIBUTE_KEY);
    doReturn(stateMock).when(stateAttrMock).get();
    doReturn(proxyRouterProcessingStateAttrMock).when(channelMock).attr(ChannelAttributes.PROXY_ROUTER_PROCESSING_STATE_ATTRIBUTE_KEY);

    handler = new RequestStateCleanerHandler(metricsListenerMock, incompleteHttpCallTimeoutMillis);
}
 
開發者ID:Nike-Inc,項目名稱:riposte,代碼行數:24,代碼來源:RequestStateCleanerHandlerTest.java

示例15: beforeMethod

import io.netty.util.Attribute; //導入依賴的package包/類
@Before
public void beforeMethod() {
    requestValidatorMock = mock(RequestValidator.class);
    stateMock = mock(HttpProcessingState.class);
    ctxMock = mock(ChannelHandlerContext.class);
    channelMock = mock(Channel.class);
    stateAttrMock = mock(Attribute.class);
    endpointMock = mock(Endpoint.class);
    requestInfoMock = mock(RequestInfo.class);

    doReturn(channelMock).when(ctxMock).channel();
    doReturn(stateAttrMock).when(channelMock).attr(ChannelAttributes.HTTP_PROCESSING_STATE_ATTRIBUTE_KEY);
    doReturn(stateMock).when(stateAttrMock).get();
    doReturn(endpointMock).when(stateMock).getEndpointForExecution();
    doReturn(requestInfoMock).when(stateMock).getRequestInfo();
    doReturn(true).when(endpointMock).isValidateRequestContent(any());
    doReturn(content).when(requestInfoMock).getContent();

    doReturn(true).when(requestInfoMock).isCompleteRequestWithAllChunks();
    doReturn(true).when(requestInfoMock).isContentDeserializerSetup();
    doReturn(content.length()).when(requestInfoMock).getRawContentLengthInBytes();

    handler = new RequestContentValidationHandler(requestValidatorMock);
}
 
開發者ID:Nike-Inc,項目名稱:riposte,代碼行數:25,代碼來源:RequestContentValidationHandlerTest.java


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