org.jboss.netty.channel.MessageEvent Java Examples
The following examples show how to use
org.jboss.netty.channel.MessageEvent.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HlsStreamsHandler.java From feeyo-hlsserver with Apache License 2.0 | 6 votes |
@Override public void execute(ChannelHandlerContext ctx, MessageEvent e) throws Exception { VelocityBuilder velocityBuilder = new VelocityBuilder(); Map<String,Object> model = new HashMap<String, Object>(); model.put("streams", HlsLiveStreamMagr.INSTANCE().getAllLiveStream()); String htmlText = velocityBuilder.generate("streams.vm", "UTF8", model); HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK); response.headers().add(HttpHeaders.Names.CONTENT_LENGTH, htmlText.length()); response.headers().set(HttpHeaders.Names.CONTENT_TYPE, "text/html; charset=UTF-8"); ChannelBuffer buffer = ChannelBuffers.copiedBuffer(htmlText, Charset.defaultCharset());// CharsetUtil.UTF_8); response.setContent(buffer); ChannelFuture channelFuture = ctx.getChannel().write(response); if (channelFuture.isSuccess()) { channelFuture.getChannel().close(); } }
Example #2
Source File: NettyRpcServerHandler.java From voyage with Apache License 2.0 | 6 votes |
@Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { Object msg = e.getMessage(); if (!(msg instanceof RpcRequest)) { logger.error("not RpcRequest received!"); return; } RpcRequest request = (RpcRequest) msg; ctx.setAttachment(request); RpcResponse response = new RpcResponse(request.getRequestID()); try { Object result = handle(request); response.setResult(result); } catch (Throwable t) { logger.error("handle rpc request fail! request:"+request, t); response.setException(t); } e.getChannel().write(response); }
Example #3
Source File: MongoProxyServerHandler.java From usergrid with Apache License 2.0 | 6 votes |
@Override public void messageReceived( ChannelHandlerContext ctx, MessageEvent e ) { Message message = null; if ( e.getMessage() instanceof Message ) { message = ( Message ) e.getMessage(); } OpReply reply = OpReply.errorReply( "not implemented" ); if ( message != null ) { logger.info( message.getClass().getName() ); reply.setResponseTo( message.getRequestID() ); } e.getChannel().write( reply ); }
Example #4
Source File: HttpServerHandler.java From glowroot with Apache License 2.0 | 6 votes |
@Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { if (!readingChunks) { request = (HttpRequest) e.getMessage(); String uri = request.getUri(); if (uri.equals("/exception")) { throw new Exception("Test"); } if (request.isChunked()) { readingChunks = true; } else { writeResponse(e); } } else { HttpChunk chunk = (HttpChunk) e.getMessage(); if (chunk.isLast()) { readingChunks = false; writeResponse(e); } } }
Example #5
Source File: MongoProxyInboundHandler.java From usergrid with Apache License 2.0 | 6 votes |
@Override public void messageReceived( ChannelHandlerContext ctx, final MessageEvent e ) throws Exception { ChannelBuffer msg = ( ChannelBuffer ) e.getMessage(); Message mongo_message = MongoMessageDecoder.decode( msg ); if ( mongo_message != null ) { System.out.println( ">>> " + mongo_message.toString() ); } synchronized ( trafficLock ) { outboundChannel.write( msg ); // If outboundChannel is saturated, do not read until notified in // OutboundHandler.channelInterestChanged(). if ( !outboundChannel.isWritable() ) { e.getChannel().setReadable( false ); } } }
Example #6
Source File: SyslogUDPSource.java From mt-flume with Apache License 2.0 | 6 votes |
@Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent mEvent) { try { syslogUtils.setEventSize(maxsize); Event e = syslogUtils.extractEvent((ChannelBuffer)mEvent.getMessage()); if (e == null) { return; } getChannelProcessor().processEvent(e); counterGroup.incrementAndGet("events.success"); } catch (ChannelException ex) { counterGroup.incrementAndGet("events.dropped"); logger.error("Error writting to channel", ex); return; } }
Example #7
Source File: HttpRequestFrameworkHandler.java From zuul-netty with Apache License 2.0 | 6 votes |
@Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { if (e.getMessage() instanceof HttpRequest) { HttpRequest request = (HttpRequest) e.getMessage(); InterruptsImpl callback = new InterruptsImpl(request, e.getChannel()); LOG.debug("handler: {} is calling request-handler: {}", tag, requestHandler.getClass().getSimpleName()); requestHandler.requestReceived(new HttpRequestFrameworkAdapter(request)); if (callback.isInterrupted()) { //plugin requested that execution is interrupted i.e. not passed down the pipeline return; } } else if (e.getMessage() instanceof HttpChunk) { LOG.debug("encountered a chunk, not passed to handler"); } super.messageReceived(ctx, e); }
Example #8
Source File: RaopRtspChallengeResponseHandler.java From Android-Airplay-Server with MIT License | 6 votes |
@Override public void writeRequested(final ChannelHandlerContext ctx, final MessageEvent evt) throws Exception { final HttpResponse resp = (HttpResponse)evt.getMessage(); synchronized(this) { if (m_challenge != null) { try { /* Get appropriate response to challenge and * add to the response base-64 encoded. XXX */ final String sig = Base64.encodePadded(getSignature()); resp.setHeader(HeaderSignature, sig); } finally { /* Forget last challenge */ m_challenge = null; m_localAddress = null; } } } super.writeRequested(ctx, evt); }
Example #9
Source File: HttpElasticsearchClient.java From elasticsearch-helper with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { HttpInvocationContext<Request, Response> httpInvocationContext = contextMap.get(ctx.getChannel()); if (httpInvocationContext == null) { throw new IllegalStateException("no context for channel?"); } try { if (e.getMessage() instanceof HttpResponse) { HttpResponse httpResponse = (HttpResponse) e.getMessage(); HttpAction<Request, Response> action = httpInvocationContext.getHttpAction(); ActionListener<Response> listener = httpInvocationContext.getListener(); httpInvocationContext.httpResponse = httpResponse; if (httpResponse.getContent().readable() && listener != null && action != null) { listener.onResponse(action.createResponse(httpInvocationContext)); } } } finally { ctx.getChannel().close(); contextMap.remove(ctx.getChannel()); } }
Example #10
Source File: RpcProgram.java From big-c with Apache License 2.0 | 6 votes |
@Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { RpcInfo info = (RpcInfo) e.getMessage(); RpcCall call = (RpcCall) info.header(); SocketAddress remoteAddress = info.remoteAddress(); if (LOG.isTraceEnabled()) { LOG.trace(program + " procedure #" + call.getProcedure()); } if (this.progNumber != call.getProgram()) { LOG.warn("Invalid RPC call program " + call.getProgram()); sendAcceptedReply(call, remoteAddress, AcceptState.PROG_UNAVAIL, ctx); return; } int ver = call.getVersion(); if (ver < lowProgVersion || ver > highProgVersion) { LOG.warn("Invalid RPC call version " + ver); sendAcceptedReply(call, remoteAddress, AcceptState.PROG_MISMATCH, ctx); return; } handleInternal(ctx, info); }
Example #11
Source File: SyslogTcpSource.java From mt-flume with Apache License 2.0 | 6 votes |
@Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent mEvent) { ChannelBuffer buff = (ChannelBuffer) mEvent.getMessage(); while (buff.readable()) { Event e = syslogUtils.extractEvent(buff); if (e == null) { logger.debug("Parsed partial event, event will be generated when " + "rest of the event is received."); continue; } try { getChannelProcessor().processEvent(e); counterGroup.incrementAndGet("events.success"); } catch (ChannelException ex) { counterGroup.incrementAndGet("events.dropped"); logger.error("Error writting to channel, event dropped", ex); } } }
Example #12
Source File: MyServerHandler.java From whiteboard with Apache License 2.0 | 6 votes |
@Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { Channel channel = e.getChannel(); SerializablePath newPath = (SerializablePath) e.getMessage(); Commons.myUUID = newPath.getMyUUID(); recordMyUUID(Commons.myUUID, channel); System.out.println("������յ���Ϣ,�豸��ʾ��--" + Commons.myUUID); if ("send_uuid".equals(newPath.getOPType())) return; if ("clear".equals(newPath.getOPType())) { if (MetadataRepositories.getInstance().getBufferShapes().size() != 0) { System.out.println("������������ͼ������"); MetadataRepositories.getInstance().getBufferShapes().clear(); } return; } MetadataRepositories.getInstance().getBufferShapes().add(newPath); // // ��DZ��͑���д����ͼ������ sendNewShapeToClient(newPath); }
Example #13
Source File: TSOClientRaw.java From phoenix-omid with Apache License 2.0 | 6 votes |
@Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) { LOG.info("Message received", e); if (e.getMessage() instanceof Response) { Response resp = (Response) e.getMessage(); try { SettableFuture<Response> future = responseQueue.take(); future.set(resp); } catch (InterruptedException ie) { Thread.currentThread().interrupt(); LOG.warn("Interrupted in handler", ie); } } else { LOG.warn("Received unknown message", e.getMessage()); } }
Example #14
Source File: ChannelEncoder.java From android-netty with Apache License 2.0 | 6 votes |
@Override public void writeRequested(ChannelHandlerContext ctx, MessageEvent event) throws Exception { PowerManager.WakeLock wakeLock = WakeLockWrapper.getWakeLockInstance(mContext, ChannelEncoder.class.getSimpleName()); wakeLock.acquire(); try { String jsonString = event.getMessage().toString(); LogByCodeLab.i(String.format("WRITE [%s]", jsonString)); ChannelBuffer cb = new BigEndianHeapChannelBuffer(24); cb.writeBytes(new byte[24]); Channels.write(ctx, event.getFuture(), cb); } finally { wakeLock.release(); } }
Example #15
Source File: NettyHandler.java From dubbo3 with Apache License 2.0 | 5 votes |
@Override public void writeRequested(ChannelHandlerContext ctx, MessageEvent e) throws Exception { super.writeRequested(ctx, e); NettyChannel channel = NettyChannel.getOrAddChannel(ctx.getChannel(), url, handler); try { handler.sent(channel, e.getMessage()); } finally { NettyChannel.removeChannelIfDisconnected(ctx.getChannel()); } }
Example #16
Source File: NettyHandler.java From anima with GNU General Public License v3.0 | 5 votes |
@Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { NettyChannel channel = NettyChannel.getOrAddChannel(conf,ctx.getChannel(), handler); try { handler.received(channel, e.getMessage()); } finally { NettyChannel.removeChannelIfDisconnected(ctx.getChannel()); } }
Example #17
Source File: ClientIOHandler.java From nfs-client-java with Apache License 2.0 | 5 votes |
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { byte[] rpcResponse = (byte[]) e.getMessage(); // remove marking Xdr x = RecordMarkingUtil.removeRecordMarking(rpcResponse); // remove the request from timeout manager map int xid = x.getXid(); _connection.notifySender(Integer.valueOf(xid), x); }
Example #18
Source File: RaopRtpTimingHandler.java From Android-Airplay-Server with MIT License | 5 votes |
@Override public void messageReceived(final ChannelHandlerContext ctx, final MessageEvent evt) throws Exception { if (evt.getMessage() instanceof RaopRtpPacket.Sync){ syncReceived((RaopRtpPacket.Sync)evt.getMessage()); } else if (evt.getMessage() instanceof RaopRtpPacket.TimingResponse){ timingResponseReceived((RaopRtpPacket.TimingResponse)evt.getMessage()); } super.messageReceived(ctx, evt); }
Example #19
Source File: MongoChannelHandler.java From usergrid with Apache License 2.0 | 5 votes |
public OpReply handleMessage( ChannelHandlerContext ctx, MessageEvent e, Message message ) { logger.debug( "message type: {}", message.getClass().getCanonicalName() ); if ( message instanceof OpCrud ) { return ( ( OpCrud ) message ).doOp( this, ctx, e ); } OpReply reply = new OpReply( message ); return reply; }
Example #20
Source File: NettyServerHandler.java From migration-tool with Apache License 2.0 | 5 votes |
public void messageReceived(final ChannelHandlerContext ctx, MessageEvent e) throws Exception { Object message = e.getMessage(); if (!(message instanceof String)) { log.error("receive message error,only support String"); throw new Exception("receive message error,only support String"); } handleRequest(ctx, message); }
Example #21
Source File: HttpKeepAliveHandler.java From zuul-netty with Apache License 2.0 | 5 votes |
@Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { if (e.getMessage() instanceof HttpRequest && isKeepAliveSupported) { ctx.setAttachment(e.getMessage()); } super.messageReceived(ctx, e); }
Example #22
Source File: RegistrationClient.java From hadoop with Apache License 2.0 | 5 votes |
@Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) { ChannelBuffer buf = (ChannelBuffer) e.getMessage(); // Read reply if (!validMessageLength(buf.readableBytes())) { e.getChannel().close(); return; } // handling fragment header for TCP, 4 bytes. byte[] fragmentHeader = Arrays.copyOfRange(buf.array(), 0, 4); int fragmentSize = XDR.fragmentSize(fragmentHeader); boolean isLast = XDR.isLastFragment(fragmentHeader); assert (fragmentSize == 28 && isLast == true); XDR xdr = new XDR(); xdr.writeFixedOpaque(Arrays.copyOfRange(buf.array(), 4, buf.readableBytes())); RpcReply reply = RpcReply.read(xdr); if (reply.getState() == RpcReply.ReplyState.MSG_ACCEPTED) { RpcAcceptedReply acceptedReply = (RpcAcceptedReply) reply; handle(acceptedReply, xdr); } else { RpcDeniedReply deniedReply = (RpcDeniedReply) reply; handle(deniedReply); } e.getChannel().close(); // shutdown now that request is complete }
Example #23
Source File: OFControllerChannelHandler.java From FlowSpaceFirewall with Apache License 2.0 | 5 votes |
@Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { if (e.getMessage() instanceof List) { @SuppressWarnings("unchecked") List<OFMessage> msglist = (List<OFMessage>)e.getMessage(); for (OFMessage ofm : msglist) { try { // Do the actual packet processing state.processOFMessage(this, ofm); } catch (Exception ex) { // We are the last handler in the stream, so run the // exception through the channel again by passing in // ctx.getChannel(). Channels.fireExceptionCaught(ctx.getChannel(), ex); } } // Flush all thread local queues etc. generated by this train // of messages. } else { Channels.fireExceptionCaught(ctx.getChannel(), new AssertionError("Message received from Channel is not a list")); } }
Example #24
Source File: OpQuery.java From usergrid with Apache License 2.0 | 5 votes |
private OpReply handleUnauthorizedCommand( MessageEvent e ) { // { "assertion" : "unauthorized db:admin lock type:-1 client:127.0.0.1" // , "assertionCode" : 10057 , "errmsg" : "db assertion failure" , "ok" // : 0.0} OpReply reply = new OpReply( this ); reply.addDocument( map( entry( "assertion", "unauthorized db:" + getDatabaseName() + " lock type:-1 client:" + ( ( InetSocketAddress ) e .getRemoteAddress() ).getAddress().getHostAddress() ), entry( "assertionCode", 10057 ), entry( "errmsg", "db assertion failure" ), entry( "ok", 0.0 ) ) ); return reply; }
Example #25
Source File: RpcUtil.java From big-c with Apache License 2.0 | 5 votes |
@Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { RpcResponse r = (RpcResponse) e.getMessage(); byte[] fragmentHeader = XDR.recordMark(r.data().readableBytes(), true); ChannelBuffer header = ChannelBuffers.wrappedBuffer(fragmentHeader); ChannelBuffer d = ChannelBuffers.wrappedBuffer(header, r.data()); e.getChannel().write(d); }
Example #26
Source File: BasicChannelUpstreamHandler.java From james-project with Apache License 2.0 | 5 votes |
/** * Call the {@link LineHandler} */ @SuppressWarnings({ "unchecked", "rawtypes" }) @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { try (Closeable closeable = mdcContextFactory.from(protocol, ctx)) { ProtocolSession pSession = (ProtocolSession) ctx.getAttachment(); LinkedList<LineHandler> lineHandlers = chain.getHandlers(LineHandler.class); LinkedList<ProtocolHandlerResultHandler> resultHandlers = chain.getHandlers(ProtocolHandlerResultHandler.class); if (lineHandlers.size() > 0) { ChannelBuffer buf = (ChannelBuffer) e.getMessage(); LineHandler lHandler = (LineHandler) lineHandlers.getLast(); long start = System.currentTimeMillis(); Response response = lHandler.onLine(pSession, buf.toByteBuffer()); long executionTime = System.currentTimeMillis() - start; for (ProtocolHandlerResultHandler resultHandler : resultHandlers) { response = resultHandler.onResponse(pSession, response, executionTime, lHandler); } if (response != null) { // TODO: This kind of sucks but I was able to come up with something more elegant here ((ProtocolSessionImpl) pSession).getProtocolTransport().writeResponse(response, pSession); } } super.messageReceived(ctx, e); } }
Example #27
Source File: TSOClient.java From phoenix-omid with Apache License 2.0 | 5 votes |
@Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) { if (e.getMessage() instanceof TSOProto.Response) { fsm.sendEvent(new ResponseEvent((TSOProto.Response) e.getMessage())); } else { LOG.warn("Received unknown message", e.getMessage()); } }
Example #28
Source File: AbstractNioChannel.java From android-netty with Apache License 2.0 | 5 votes |
private int getMessageSize(MessageEvent e) { Object m = e.getMessage(); if (m instanceof ChannelBuffer) { return ((ChannelBuffer) m).readableBytes(); } return 0; }
Example #29
Source File: TSOChannelHandler.java From phoenix-omid with Apache License 2.0 | 5 votes |
/** * Handle received messages */ @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) { Object msg = e.getMessage(); if (msg instanceof TSOProto.Request) { TSOProto.Request request = (TSOProto.Request) msg; if (request.hasHandshakeRequest()) { checkHandshake(ctx, request.getHandshakeRequest()); return; } if (!handshakeCompleted(ctx)) { LOG.error("Handshake not completed. Closing channel {}", ctx.getChannel()); ctx.getChannel().close(); } if (request.hasTimestampRequest()) { requestProcessor.timestampRequest(ctx.getChannel(), MonitoringContextFactory.getInstance(config,metrics)); } else if (request.hasCommitRequest()) { TSOProto.CommitRequest cr = request.getCommitRequest(); requestProcessor.commitRequest(cr.getStartTimestamp(), cr.getCellIdList(), cr.getTableIdList(), cr.getIsRetry(), ctx.getChannel(), MonitoringContextFactory.getInstance(config,metrics)); } else if (request.hasFenceRequest()) { TSOProto.FenceRequest fr = request.getFenceRequest(); requestProcessor.fenceRequest(fr.getTableId(), ctx.getChannel(), MonitoringContextFactory.getInstance(config,metrics)); } else { LOG.error("Invalid request {}. Closing channel {}", request, ctx.getChannel()); ctx.getChannel().close(); } } else { LOG.error("Unknown message type", msg); } }
Example #30
Source File: NettyHandler.java From dubbo-2.6.5 with Apache License 2.0 | 5 votes |
@Override public void writeRequested(ChannelHandlerContext ctx, MessageEvent e) throws Exception { super.writeRequested(ctx, e); NettyChannel channel = NettyChannel.getOrAddChannel(ctx.getChannel(), url, handler); try { handler.sent(channel, e.getMessage()); } finally { NettyChannel.removeChannelIfDisconnected(ctx.getChannel()); } }