当前位置: 首页>>代码示例>>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;未经允许,请勿转载。