@Override
public void handleUpstream(
ChannelHandlerContext ctx, ChannelEvent evt) throws Exception {
if (!(evt instanceof MessageEvent)) {
ctx.sendUpstream(evt);
return;
}
MessageEvent e = (MessageEvent) evt;
Object originalMessage = e.getMessage();
Object decodedMessage = decode(ctx, e.getChannel(), e.getRemoteAddress(), originalMessage);
if (originalMessage == decodedMessage) {
ctx.sendUpstream(evt);
} else if (decodedMessage != null) {
fireMessageReceived(ctx, decodedMessage, e.getRemoteAddress());
}
}
java类org.jboss.netty.channel.ChannelEvent的实例源码
BaseProtocolDecoder.java 文件源码
项目:traccar-mongodb
阅读 24
收藏 0
点赞 0
评论 0
FrameDecoder.java 文件源码
项目:andy
阅读 32
收藏 0
点赞 0
评论 0
public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e, Object m, FrameHandler frameHandler) throws Exception {
ChannelBuffer input = (ChannelBuffer) m;
if (!input.readable()) {
return;
}
if (cumulation == null) {
try {
// the cumulation buffer is not created yet so just pass the input to callDecode(...) method
callDecode(ctx, null, input, frameHandler);
} finally {
updateCumulation(ctx, input);
}
} else {
input = appendToCumulation(input);
try {
callDecode(ctx, null, input, frameHandler);
} finally {
updateCumulation(ctx, input);
}
}
}
IsdnServerPipelineSink.java 文件源码
项目:netty-isdn-transport
阅读 28
收藏 0
点赞 0
评论 0
private void handleServerChannel(ChannelEvent e) {
IsdnServerChannel channel = (IsdnServerChannel) e.getChannel();
ChannelFuture future = e.getFuture();
if (e instanceof ChannelStateEvent) {
ChannelStateEvent stateEvent = (ChannelStateEvent) e;
ChannelState state = stateEvent.getState();
Object value = stateEvent.getValue();
switch (state) {
case OPEN:
if (Boolean.FALSE.equals(value)) {
close(channel, future);
}
break;
case BOUND:
if (value != null) {
bind(channel, future, (IsdnSocketAddress) value);
} else {
logger.warn("eventSunk() :: UNHANDLED (BOUND value=null) --> {}", e);
close(channel, future);
}
break;
default:
logger.warn("eventSunk() :: UNHANDLED --> {}", e);
}
}
}
IsdnConnectionHandler.java 文件源码
项目:netty-isdn-transport
阅读 30
收藏 0
点赞 0
评论 0
@Transition (on = WRITE_REQUESTED, in = NCCI_ACTIVE)
public void ncciDataB3Req(IsdnChannel channel, ChannelBuffer message, ChannelHandlerContext ctx, ChannelEvent channelEvent) throws CapiException {
if (message == ChannelBuffers.EMPTY_BUFFER) {
// send flush() signal downstream
LOGGER.warn("ncciDataB3Req() :: empty buffer");
handleEvent(WRITE_REQUESTED, ctx, channelEvent);
return;
}
if (LOGGER.isTraceEnabled()) {
try {
LOGGER.trace("ncciDataB3Req() :: data = {}", message.duplicate().toString(US_ASCII_CHARSET));
} catch (Throwable t) {
LOGGER.trace("ncciDataB3Req()");
}
}
CapiMessage dataReq = createDataB3Req(channel, message);
// channel.write(dataReq);
write(ctx, channelEvent.getFuture(), dataReq);
}
ConnectionPerIpLimitHandlerTest.java 文件源码
项目:whois
阅读 28
收藏 0
点赞 0
评论 0
@Test
public void multiple_connected_same_ip() throws Exception {
final InetSocketAddress remoteAddress = new InetSocketAddress("10.0.0.0", 43);
when(channel.getRemoteAddress()).thenReturn(remoteAddress);
final ChannelEvent openEvent = new UpstreamChannelStateEvent(channel, ChannelState.OPEN, Boolean.TRUE);
subject.handleUpstream(ctx, openEvent);
subject.handleUpstream(ctx, openEvent);
subject.handleUpstream(ctx, openEvent);
verify(ctx, times(2)).sendUpstream(openEvent);
verify(channel, times(1)).write(argThat(new ArgumentMatcher<Object>() {
@Override
public boolean matches(Object argument) {
return QueryMessages.connectionsExceeded(MAX_CONNECTIONS_PER_IP).equals(argument);
}
}));
verify(channelFuture, times(1)).addListener(ChannelFutureListener.CLOSE);
verify(whoisLog).logQueryResult(anyString(), eq(0), eq(0), eq(QueryCompletionInfo.REJECTED), eq(0L), (InetAddress) Mockito.anyObject(), Mockito.anyInt(), eq(""));
verify(ctx, times(2)).sendUpstream(openEvent);
}
ConnectionPerIpLimitHandlerTest.java 文件源码
项目:whois
阅读 28
收藏 0
点赞 0
评论 0
@Test
public void multiple_connected_limit_disabled() throws Exception {
subject.setMaxConnectionsPerIp(0);
final InetSocketAddress remoteAddress = new InetSocketAddress("10.0.0.0", 43);
when(channel.getRemoteAddress()).thenReturn(remoteAddress);
final ChannelEvent openEvent = new UpstreamChannelStateEvent(channel, ChannelState.OPEN, Boolean.TRUE);
subject.handleUpstream(ctx, openEvent);
subject.handleUpstream(ctx, openEvent);
subject.handleUpstream(ctx, openEvent);
final ChannelEvent closeEvent = new UpstreamChannelStateEvent(channel, ChannelState.OPEN, Boolean.FALSE);
subject.handleUpstream(ctx, closeEvent);
subject.handleUpstream(ctx, closeEvent);
subject.handleUpstream(ctx, closeEvent);
verify(ctx, times(3)).sendUpstream(openEvent);
verify(ctx, times(3)).sendUpstream(closeEvent);
verify(channel, never()).close();
verify(channel, never()).write(anyObject());
verify(channelFuture, never()).addListener(ChannelFutureListener.CLOSE);
}
ConnectionPerIpLimitHandlerTest.java 文件源码
项目:whois
阅读 32
收藏 0
点赞 0
评论 0
@Test
public void multiple_connected_unlimited_allowed() throws Exception {
final InetSocketAddress remoteAddress = new InetSocketAddress("10.0.0.0", 43);
when(ipResourceConfiguration.isUnlimitedConnections(any(IpInterval.class))).thenReturn(true);
when(channel.getRemoteAddress()).thenReturn(remoteAddress);
final ChannelEvent event = new UpstreamChannelStateEvent(channel, ChannelState.OPEN, Boolean.TRUE);
subject.handleUpstream(ctx, event);
subject.handleUpstream(ctx, event);
subject.handleUpstream(ctx, event);
verify(ctx, times(3)).sendUpstream(event);
verify(channel, never()).close();
verify(channel, never()).write(anyObject());
verify(channelFuture, never()).addListener(ChannelFutureListener.CLOSE);
}
ConnectionPerIpLimitHandlerTest.java 文件源码
项目:whois
阅读 33
收藏 0
点赞 0
评论 0
@Test
public void multiple_connected_proxy_allowed() throws Exception {
final InetSocketAddress remoteAddress = new InetSocketAddress("10.0.0.0", 43);
when(ipResourceConfiguration.isProxy(any(IpInterval.class))).thenReturn(true);
when(channel.getRemoteAddress()).thenReturn(remoteAddress);
final ChannelEvent event = new UpstreamChannelStateEvent(channel, ChannelState.OPEN, Boolean.TRUE);
subject.handleUpstream(ctx, event);
subject.handleUpstream(ctx, event);
subject.handleUpstream(ctx, event);
verify(ctx, times(3)).sendUpstream(event);
verify(channel, never()).close();
verify(channel, never()).write(anyObject());
verify(channelFuture, never()).addListener(ChannelFutureListener.CLOSE);
}
ConnectionPerIpLimitHandlerTest.java 文件源码
项目:whois
阅读 34
收藏 0
点赞 0
评论 0
@Test
public void multiple_connected_different_ip() throws Exception {
final InetSocketAddress remoteAddress = new InetSocketAddress("10.0.0.0", 43);
final InetSocketAddress remoteAddress2 = new InetSocketAddress("10.0.0.1", 43);
when(channel.getRemoteAddress()).thenReturn(remoteAddress).thenReturn(remoteAddress).thenReturn(remoteAddress2);
final ChannelEvent event = new UpstreamChannelStateEvent(channel, ChannelState.OPEN, Boolean.TRUE);
subject.handleUpstream(ctx, event);
subject.handleUpstream(ctx, event);
final ChannelEvent event2 = new UpstreamChannelStateEvent(channel, ChannelState.OPEN, Boolean.TRUE);
subject.handleUpstream(ctx, event2);
verify(ctx, times(2)).sendUpstream(event);
verify(ctx, times(1)).sendUpstream(event2);
verify(channel, never()).close();
verify(channel, never()).write(anyObject());
verify(channelFuture, never()).addListener(ChannelFutureListener.CLOSE);
}
ConnectionPerIpLimitHandlerTest.java 文件源码
项目:whois
阅读 39
收藏 0
点赞 0
评论 0
@Test
public void multiple_connected_same_ip_and_closed() throws Exception {
final InetSocketAddress remoteAddress = new InetSocketAddress("10.0.0.0", 43);
when(channel.getRemoteAddress()).thenReturn(remoteAddress);
final ChannelEvent openEvent = new UpstreamChannelStateEvent(channel, ChannelState.OPEN, Boolean.TRUE);
subject.handleUpstream(ctx, openEvent);
subject.handleUpstream(ctx, openEvent);
final ChannelEvent closeEvent = new UpstreamChannelStateEvent(channel, ChannelState.OPEN, Boolean.FALSE);
subject.handleUpstream(ctx, closeEvent);
subject.handleUpstream(ctx, closeEvent);
subject.handleUpstream(ctx, openEvent);
subject.handleUpstream(ctx, openEvent);
verify(ctx, times(4)).sendUpstream(openEvent);
verify(ctx, times(2)).sendUpstream(closeEvent);
verify(channel, never()).close();
verify(channel, never()).write(anyObject());
verify(channelFuture, never()).addListener(ChannelFutureListener.CLOSE);
}
ByteCounter.java 文件源码
项目:giraph-gora
阅读 33
收藏 0
点赞 0
评论 0
@Override
public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e)
throws Exception {
if (e instanceof MessageEvent &&
((MessageEvent) e).getMessage() instanceof ChannelBuffer) {
ChannelBuffer b = (ChannelBuffer) ((MessageEvent) e).getMessage();
int receivedBytes = b.readableBytes();
bytesReceived.addAndGet(receivedBytes);
receivedBytesHist.update(receivedBytes);
receivedRequests.incrementAndGet();
receivedRequestsMeter.mark();
if (LOG.isDebugEnabled()) {
LOG.debug("handleUpstream: " + ctx.getName() + " buffer size = " +
receivedBytes + ", total bytes = " + bytesReceived.get());
}
}
super.handleUpstream(ctx, e);
}
ByteCounter.java 文件源码
项目:giraph-gora
阅读 29
收藏 0
点赞 0
评论 0
@Override
public void handleDownstream(ChannelHandlerContext ctx, ChannelEvent e)
throws Exception {
if (e instanceof MessageEvent &&
((MessageEvent) e).getMessage() instanceof ChannelBuffer) {
ChannelBuffer b = (ChannelBuffer) ((MessageEvent) e).getMessage();
int sentBytes = b.readableBytes();
bytesSent.addAndGet(sentBytes);
sentBytesHist.update(sentBytes);
sentRequests.incrementAndGet();
sentRequestsMeter.mark();
if (LOG.isDebugEnabled()) {
LOG.debug("handleDownstream: " + ctx.getName() + " buffer size = " +
sentBytes + ", total bytes = " + bytesSent.get());
}
}
super.handleDownstream(ctx, e);
}
PNPClientFrameDecoder.java 文件源码
项目:proactive-component-monitoring
阅读 35
收藏 0
点赞 0
评论 0
public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent event) throws Exception {
if (event instanceof MessageEvent) {
MessageEvent msgEvent = (MessageEvent) event;
Object msg = msgEvent.getMessage();
if (msg instanceof ChannelBuffer) {
callDecode(ctx, (ChannelBuffer) msg, msgEvent.getRemoteAddress());
return;
}
} else if (event instanceof ChannelStateEvent) {
ChannelStateEvent stateEvent = (ChannelStateEvent) event;
if (stateEvent.getState() == ChannelState.CONNECTED) {
if (stateEvent.getValue() != null) {
lengthBytesToRead = lengthFieldLength;
lengthBuffer = getBuffer(ctx.getChannel().getConfig().getBufferFactory(),
lengthBytesToRead);
}
}
}
ctx.sendUpstream(event);
}
PNPServerFrameDecoder.java 文件源码
项目:proactive-component-monitoring
阅读 25
收藏 0
点赞 0
评论 0
public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent event) throws Exception {
if (event instanceof MessageEvent) {
MessageEvent msgEvent = (MessageEvent) event;
Object msg = msgEvent.getMessage();
if (msg instanceof ChannelBuffer) {
callDecode(ctx, (ChannelBuffer) msg, msgEvent.getRemoteAddress());
return;
}
} else if (event instanceof ChannelStateEvent) {
ChannelStateEvent stateEvent = (ChannelStateEvent) event;
if (stateEvent.getState() == ChannelState.CONNECTED) {
if (stateEvent.getValue() != null) {
lengthBytesToRead = lengthFieldLength;
lengthBuffer = getBuffer(ctx.getChannel().getConfig().getBufferFactory(),
lengthBytesToRead);
}
}
}
ctx.sendUpstream(event);
}
ByteCounter.java 文件源码
项目:giraph-research
阅读 37
收藏 0
点赞 0
评论 0
@Override
public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e)
throws Exception {
if (e instanceof MessageEvent &&
((MessageEvent) e).getMessage() instanceof ChannelBuffer) {
ChannelBuffer b = (ChannelBuffer) ((MessageEvent) e).getMessage();
int receivedBytes = b.readableBytes();
bytesReceived.addAndGet(receivedBytes);
receivedBytesHist.update(receivedBytes);
receivedRequests.incrementAndGet();
receivedRequestsMeter.mark();
if (LOG.isDebugEnabled()) {
LOG.debug("handleUpstream: " + ctx.getName() + " buffer size = " +
receivedBytes + ", total bytes = " + bytesReceived.get());
}
}
super.handleUpstream(ctx, e);
}
ByteCounter.java 文件源码
项目:giraph-research
阅读 30
收藏 0
点赞 0
评论 0
@Override
public void handleDownstream(ChannelHandlerContext ctx, ChannelEvent e)
throws Exception {
if (e instanceof MessageEvent &&
((MessageEvent) e).getMessage() instanceof ChannelBuffer) {
ChannelBuffer b = (ChannelBuffer) ((MessageEvent) e).getMessage();
int sentBytes = b.readableBytes();
bytesSent.addAndGet(sentBytes);
sentBytesHist.update(sentBytes);
sentRequests.incrementAndGet();
sentRequestsMeter.mark();
if (LOG.isDebugEnabled()) {
LOG.debug("handleDownstream: " + ctx.getName() + " buffer size = " +
sentBytes + ", total bytes = " + bytesSent.get());
}
}
super.handleDownstream(ctx, e);
}
ByteCounter.java 文件源码
项目:giraph-research
阅读 28
收藏 0
点赞 0
评论 0
@Override
public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e)
throws Exception {
if (e instanceof MessageEvent &&
((MessageEvent) e).getMessage() instanceof ChannelBuffer) {
ChannelBuffer b = (ChannelBuffer) ((MessageEvent) e).getMessage();
int receivedBytes = b.readableBytes();
bytesReceived.addAndGet(receivedBytes);
receivedBytesHist.update(receivedBytes);
receivedRequests.incrementAndGet();
receivedRequestsMeter.mark();
if (LOG.isDebugEnabled()) {
LOG.debug("handleUpstream: " + ctx.getName() + " buffer size = " +
receivedBytes + ", total bytes = " + bytesReceived.get());
}
}
super.handleUpstream(ctx, e);
}
ByteCounter.java 文件源码
项目:giraph-research
阅读 34
收藏 0
点赞 0
评论 0
@Override
public void handleDownstream(ChannelHandlerContext ctx, ChannelEvent e)
throws Exception {
if (e instanceof MessageEvent &&
((MessageEvent) e).getMessage() instanceof ChannelBuffer) {
ChannelBuffer b = (ChannelBuffer) ((MessageEvent) e).getMessage();
int sentBytes = b.readableBytes();
bytesSent.addAndGet(sentBytes);
sentBytesHist.update(sentBytes);
sentRequests.incrementAndGet();
sentRequestsMeter.mark();
if (LOG.isDebugEnabled()) {
LOG.debug("handleDownstream: " + ctx.getName() + " buffer size = " +
sentBytes + ", total bytes = " + bytesSent.get());
}
}
super.handleDownstream(ctx, e);
}
ByteCounter.java 文件源码
项目:giraph-research
阅读 36
收藏 0
点赞 0
评论 0
@Override
public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e)
throws Exception {
if (e instanceof MessageEvent &&
((MessageEvent) e).getMessage() instanceof ChannelBuffer) {
ChannelBuffer b = (ChannelBuffer) ((MessageEvent) e).getMessage();
int receivedBytes = b.readableBytes();
bytesReceived.addAndGet(receivedBytes);
receivedBytesHist.update(receivedBytes);
receivedRequests.incrementAndGet();
receivedRequestsMeter.mark();
if (LOG.isDebugEnabled()) {
LOG.debug("handleUpstream: " + ctx.getName() + " buffer size = " +
receivedBytes + ", total bytes = " + bytesReceived.get());
}
}
super.handleUpstream(ctx, e);
}
ByteCounter.java 文件源码
项目:giraph-research
阅读 32
收藏 0
点赞 0
评论 0
@Override
public void handleDownstream(ChannelHandlerContext ctx, ChannelEvent e)
throws Exception {
if (e instanceof MessageEvent &&
((MessageEvent) e).getMessage() instanceof ChannelBuffer) {
ChannelBuffer b = (ChannelBuffer) ((MessageEvent) e).getMessage();
int sentBytes = b.readableBytes();
bytesSent.addAndGet(sentBytes);
sentBytesHist.update(sentBytes);
sentRequests.incrementAndGet();
sentRequestsMeter.mark();
if (LOG.isDebugEnabled()) {
LOG.debug("handleDownstream: " + ctx.getName() + " buffer size = " +
sentBytes + ", total bytes = " + bytesSent.get());
}
}
super.handleDownstream(ctx, e);
}
ServerHandler.java 文件源码
项目:perfload-core
阅读 42
收藏 0
点赞 0
评论 0
/**
* <p>
* {@inheritDoc}
* </p>
* <p>
* Overriden to log ChannelStateEvents if they have a state other than
* {@link ChannelState#INTEREST_OPS}, i. e. OPEN, BOUND, CONNECTED.
* </p>
*
* @param ctx
* the context object for this handler
* @param e
* the upstream event to process or intercept
*/
@Override
public void handleUpstream(final ChannelHandlerContext ctx, final ChannelEvent e) throws Exception {
if (e instanceof ChannelStateEvent) {
ChannelStateEvent stateEvent = (ChannelStateEvent) e;
if (stateEvent.getState() != ChannelState.INTEREST_OPS) {
log.info(e.toString());
if (stateEvent.getState() == ChannelState.CONNECTED && stateEvent.getValue() == null) {
// Remove channel from container when client disconnects
channelContainer.removeChannel(e.getChannel());
}
}
}
super.handleUpstream(ctx, e);
}
HttpTunnelClientChannelTest.java 文件源码
项目:httptunnel
阅读 33
收藏 0
点赞 0
评论 0
@Test
public void testBind_preResolvedAddress_ipv6() {
ChannelFuture bindFuture = Channels.bind(channel,
RESOLVED_LOCAL_ADDRESS_IPV6);
assertFalse(bindFuture.isDone());
assertEquals(1, sendSink.events.size());
assertEquals(1, pollSink.events.size());
ChannelEvent sendChannelEvent = sendSink.events.poll();
NettyTestUtils.checkIsStateEvent(sendChannelEvent, ChannelState.BOUND,
RESOLVED_LOCAL_ADDRESS_IPV6);
ChannelEvent pollChannelEvent = pollSink.events.poll();
NettyTestUtils.checkIsStateEvent(pollChannelEvent, ChannelState.BOUND,
RESOLVED_LOCAL_ADDRESS_IPV6_EPHEMERAL_PORT);
sendChannel.emulateBound(RESOLVED_LOCAL_ADDRESS_IPV6,
sendChannelEvent.getFuture());
assertFalse(bindFuture.isDone());
pollChannel.emulateBound(RESOLVED_LOCAL_ADDRESS_IPV4_SELECTED_PORT,
pollChannelEvent.getFuture());
assertTrue(bindFuture.isDone());
assertTrue(bindFuture.isSuccess());
assertEquals(channel.getLocalAddress(), RESOLVED_LOCAL_ADDRESS_IPV6);
}
ExtendedObjectDecoder.java 文件源码
项目:traccar-service
阅读 27
收藏 0
点赞 0
评论 0
@Override
public void handleUpstream(
ChannelHandlerContext ctx, ChannelEvent evt) throws Exception {
if (!(evt instanceof MessageEvent)) {
ctx.sendUpstream(evt);
return;
}
MessageEvent e = (MessageEvent) evt;
Object originalMessage = e.getMessage();
Object decodedMessage = decode(e.getChannel(), e.getRemoteAddress(), originalMessage);
onMessageEvent(e.getChannel(), e.getRemoteAddress(), originalMessage, decodedMessage);
if (originalMessage == decodedMessage) {
ctx.sendUpstream(evt);
} else {
if (decodedMessage == null) {
decodedMessage = handleEmptyMessage(e.getChannel(), e.getRemoteAddress(), originalMessage);
}
if (decodedMessage != null) {
if (decodedMessage instanceof Collection) {
for (Object o : (Collection) decodedMessage) {
saveOriginal(o, originalMessage);
Channels.fireMessageReceived(ctx, o, e.getRemoteAddress());
}
} else {
saveOriginal(decodedMessage, originalMessage);
Channels.fireMessageReceived(ctx, decodedMessage, e.getRemoteAddress());
}
}
}
}
BasePipelineFactory.java 文件源码
项目:traccar-service
阅读 31
收藏 0
点赞 0
评论 0
@Override
public void log(ChannelEvent e) {
if (e instanceof MessageEvent) {
MessageEvent event = (MessageEvent) e;
StringBuilder msg = new StringBuilder();
msg.append("[").append(String.format("%08X", e.getChannel().getId())).append(": ");
msg.append(((InetSocketAddress) e.getChannel().getLocalAddress()).getPort());
if (e instanceof DownstreamMessageEvent) {
msg.append(" > ");
} else {
msg.append(" < ");
}
if (event.getRemoteAddress() != null) {
msg.append(((InetSocketAddress) event.getRemoteAddress()).getHostString());
} else {
msg.append("null");
}
msg.append("]");
if (event.getMessage() instanceof ChannelBuffer) {
msg.append(" HEX: ");
msg.append(ChannelBuffers.hexDump((ChannelBuffer) event.getMessage()));
}
Log.debug(msg.toString());
}
}
WebSocketServiceHandler.java 文件源码
项目:HeliosStreams
阅读 35
收藏 0
点赞 0
评论 0
/**
* {@inheritDoc}
* @see org.jboss.netty.channel.ChannelDownstreamHandler#handleDownstream(org.jboss.netty.channel.ChannelHandlerContext, org.jboss.netty.channel.ChannelEvent)
*/
@Override
public void handleDownstream(ChannelHandlerContext ctx, ChannelEvent e) throws Exception {
Channel channel = e.getChannel();
if(!channel.isOpen()) return;
if(!(e instanceof MessageEvent)) {
ctx.sendDownstream(e);
return;
}
Object message = ((MessageEvent)e).getMessage();
if((message instanceof HttpResponse) || (message instanceof WebSocketFrame)) {
ctx.sendDownstream(e);
return;
}
if((message instanceof ChannelBuffer)) {
ctx.sendDownstream(new DownstreamMessageEvent(channel, Channels.future(channel), new TextWebSocketFrame((ChannelBuffer)message), channel.getRemoteAddress()));
} else if((message instanceof JsonNode)) {
String json = marshaller.writeValueAsString(message);
ctx.sendDownstream(new DownstreamMessageEvent(channel, Channels.future(channel), new TextWebSocketFrame(json), channel.getRemoteAddress()));
} else if((message instanceof ChannelBufferizable)) {
ctx.sendDownstream(new DownstreamMessageEvent(channel, Channels.future(channel), new TextWebSocketFrame(((Netty3ChannelBufferizable)message).toChannelBuffer()), channel.getRemoteAddress()));
} else if((message instanceof CharSequence)) {
ctx.sendDownstream(new DownstreamMessageEvent(channel, Channels.future(channel), new TextWebSocketFrame(marshaller.writeValueAsString(message)), channel.getRemoteAddress()));
} else if((message instanceof JSONResponse)) {
ObjectMapper mapper = (ObjectMapper)((JSONResponse)message).getChannelOption("mapper", TSDBTypeSerializer.DEFAULT.getMapper());
ctx.sendDownstream(new DownstreamMessageEvent(channel, Channels.future(channel), new TextWebSocketFrame(mapper.writeValueAsString(message)), channel.getRemoteAddress()));
} else {
ctx.sendUpstream(e);
}
}
WebSocketServiceHandler.java 文件源码
项目:HeliosStreams
阅读 35
收藏 0
点赞 0
评论 0
/**
* {@inheritDoc}
* @see org.jboss.netty.channel.ChannelUpstreamHandler#handleUpstream(org.jboss.netty.channel.ChannelHandlerContext, org.jboss.netty.channel.ChannelEvent)
*/
@Override
public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e) throws Exception {
log.warn("ChannelEvent: {}", e);
if(e instanceof MessageEvent) {
Object message = ((MessageEvent)e).getMessage();
if (message instanceof HttpRequest) {
handleRequest(ctx, (HttpRequest) message, (MessageEvent)e);
} else if (message instanceof WebSocketFrame) {
handleRequest(ctx, (WebSocketFrame) message);
}
} else {
ctx.sendUpstream(e);
}
}
MyChannelHandler.java 文件源码
项目:Netty-Resteasy-Spring
阅读 35
收藏 0
点赞 0
评论 0
@Override
public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e) throws Exception {
// Log all channel state changes.
if (e instanceof ChannelStateEvent) {
// logger.info("Channel state changed: " + e);
}
super.handleUpstream(ctx, e);
}
NaviHttpServerCodec.java 文件源码
项目:navi
阅读 29
收藏 0
点赞 0
评论 0
@Override
public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e) throws Exception {
try {
super.handleUpstream(ctx, e);
} catch (Exception ex) {
Channel channel = ctx.getChannel();
if (!channel.isOpen()) {
return;
}
ctx.sendUpstream(new UpstreamMessageEvent(channel, new NaviBadRequest(ex), channel.getRemoteAddress()));
}
}
Handler.java 文件源码
项目:cellhealth-ng
阅读 30
收藏 0
点赞 0
评论 0
@Override
public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e) throws Exception {
if (e instanceof ChannelStateEvent) {
this.warning(e.toString());
}
super.handleUpstream(ctx, e);
}
TestJDBCSocketTransport.java 文件源码
项目:teiid
阅读 26
收藏 0
点赞 0
评论 0
@BeforeClass public static void oneTimeSetup() throws Exception {
SocketConfiguration config = new SocketConfiguration();
config.setSSLConfiguration(new SSLConfiguration());
addr = new InetSocketAddress(0);
config.setBindAddress(addr.getHostName());
config.setPortNumber(0);
EmbeddedConfiguration dqpConfig = new EmbeddedConfiguration();
dqpConfig.setMaxActivePlans(2);
server = new FakeServer(false);
server.start(dqpConfig, false);
server.deployVDB("parts", UnitTestUtil.getTestDataPath() + "/PartsSupplier.vdb");
jdbcTransport = new SocketListener(addr, config, server.getClientServiceRegistry(), BufferManagerFactory.getStandaloneBufferManager()) {
@Override
protected SSLAwareChannelHandler createChannelPipelineFactory(
SSLConfiguration config, StorageManager storageManager) {
SSLAwareChannelHandler result = new SSLAwareChannelHandler(this, config, Thread.currentThread().getContextClassLoader(), storageManager) {
@Override
public void handleDownstream(ChannelHandlerContext ctx,
ChannelEvent e) throws Exception {
if (delay > 0) {
Thread.sleep(delay);
}
super.handleDownstream(ctx, e);
}
};
result.setMaxMessageSize(MAX_MESSAGE);
result.setMaxLobSize(MAX_LOB);
return result;
}
};
}