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