@Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { ChannelFuture f = null; if (null != policyFile) { f = e.getChannel().write(policyFile); } else { f = e.getChannel().write(this.getPolicyFileContents()); } f.addListener(ChannelFutureListener.CLOSE); }
@Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { // Lookup the session from the local address. DatagramChannel datagramChannel = (DatagramChannel) e.getChannel(); Session session = NettyUDPClient.CLIENTS.get(datagramChannel .getLocalAddress()); if (null != session) { Event event = (Event) e.getMessage(); // Pass the event on to the session session.onEvent(event); } }
@Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) { try { NettyDataPack dataPack = (NettyDataPack) e.getMessage(); List<ByteBuffer> req = dataPack.getDatas(); List<ByteBuffer> res = responder.respond(req, connectionMetadata); // response will be null for oneway messages. if(res != null) { dataPack.setDatas(res); e.getChannel().write(dataPack); } } catch (IOException ex) { LOG.warn("unexpected error"); } }
@Override public void sendResponse(StoreStats performanceStats, boolean isFromLocalZone, long startTimeInMs) { // Create the Response object HttpResponse response = new DefaultHttpResponse(HTTP_1_1, NO_CONTENT); // Set the right headers response.setHeader(CONTENT_LENGTH, "0"); // Write the response to the Netty Channel if(logger.isDebugEnabled()) { String keyStr = RestUtils.getKeyHexString(key); debugLog("DELETE", this.storeName, keyStr, startTimeInMs, System.currentTimeMillis(), 0); } this.messageEvent.getChannel().write(response); if(performanceStats != null && isFromLocalZone) { recordStats(performanceStats, startTimeInMs, Tracked.DELETE); } } }
protected boolean doEncode(ChannelHandlerContext ctx, MessageEvent e) throws Exception { Object originalMessage = e.getMessage(); Object encodedMessage = encode(ctx, e.getChannel(), originalMessage); if (originalMessage == encodedMessage) { return false; } if (encodedMessage != null) { write(ctx, e.getFuture(), encodedMessage, e.getRemoteAddress()); } return true; }
MotanErrorMsgConstant.SERVICE_REJECT)); response.setProcessTime(System.currentTimeMillis() - processStartTime); e.getChannel().write(response);
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(), originalMessage); if (originalMessage == decodedMessage) { ctx.sendUpstream(evt); } else if (decodedMessage != null) { fireMessageReceived(ctx, decodedMessage, e.getRemoteAddress()); } }
numVectorClockEntries); this.messageEvent.getChannel().write(response);
"Unsupported namespace. Only /" + STORE_OPS_NAMESPACE + "/ is supported."); messageEvent.getChannel().write(response);
(DatagramChannel) e.getChannel());
@Override public void messageReceived( ChannelHandlerContext ctx, MessageEvent e) throws Exception { Object m = e.getMessage(); if (!(m instanceof ChannelBuffer)) { ctx.sendUpstream(e); return; } 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, e.getChannel(), input, e.getRemoteAddress()); } finally { updateCumulation(ctx, input); } } else { input = appendToCumulation(input); try { callDecode(ctx, e.getChannel(), input, e.getRemoteAddress()); } finally { updateCumulation(ctx, input); } } }
this.messageEvent.getChannel().write(response);
@Override public void sendResponse(StoreStats performanceStats, boolean isFromLocalZone, long startTimeInMs) throws Exception { String base64Key = RestUtils.encodeVoldemortKey(key.get()); String contentLocationKey = "/" + this.storeName + "/" + base64Key; List<VectorClock> vectorClocks = new ArrayList<VectorClock>(); for(Version versionedValue: versionedValues) { VectorClock vectorClock = (VectorClock) versionedValue; vectorClocks.add(vectorClock); numVectorClockEntries += vectorClock.getVersionMap().size(); } String eTags = RestUtils.getSerializedVectorClocks(vectorClocks); byte[] responseContent = eTags.getBytes(); ChannelBuffer responseContentBuffer = ChannelBuffers.dynamicBuffer(responseContent.length); responseContentBuffer.writeBytes(responseContent); // Create the Response object HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK); // Set the right headers response.setHeader(CONTENT_TYPE, "binary"); response.setHeader(CONTENT_TRANSFER_ENCODING, "binary"); response.setHeader(CONTENT_LOCATION, contentLocationKey); // Copy the data into the payload response.setContent(responseContentBuffer); response.setHeader(CONTENT_LENGTH, response.getContent().readableBytes()); // Write the response to the Netty Channel this.messageEvent.getChannel().write(response); }
telnetCommand.execute(msgevent.getChannel(), command);
/** * Writes all error responses to the client. * * TODO REST-Server 1. collect error stats * * @param messageEvent - for retrieving the channel details * @param status - error code * @param message - error message */ public static void writeErrorResponse(MessageEvent messageEvent, HttpResponseStatus status, String message) { // Create the Response object HttpResponse response = new DefaultHttpResponse(HTTP_1_1, status); response.setHeader(CONTENT_TYPE, "text/plain; charset=UTF-8"); response.setContent(ChannelBuffers.copiedBuffer("Failure: " + status.toString() + ". " + message + "\r\n", CharsetUtil.UTF_8)); response.setHeader(CONTENT_LENGTH, response.getContent().readableBytes()); // Write the response to the Netty Channel messageEvent.getChannel().write(response); } }
OioSocketChannel channel = (OioSocketChannel) event.getChannel(); ChannelFuture future = event.getFuture(); Object message = event.getMessage();
DefaultLocalChannel channel = (DefaultLocalChannel) event.getChannel(); boolean offered = channel.writeBuffer.offer(event); assert offered;
public void messageReceived(final ChannelHandlerContext ctx, final MessageEvent e) throws Exception { final Event event = (Event) e.getMessage(); final ChannelBuffer buffer = (ChannelBuffer) event.getSource(); final Channel channel = e.getChannel(); int type = event.getType(); if (Events.LOG_IN == type) { LOG.debug("Login attempt from {}", channel.getRemoteAddress()); Player player = lookupPlayer(buffer, channel); handleLogin(player, channel, buffer); } else if (Events.RECONNECT == type) { LOG.debug("Reconnect attempt from {}", channel.getRemoteAddress()); String reconnectKey = NettyUtils.readString(buffer); PlayerSession playerSession = lookupSession(reconnectKey); handleReconnect(playerSession, channel, buffer); } else { LOG.error("Invalid event {} sent from remote address {}. " + "Going to close channel {}", new Object[] { event.getType(), channel.getRemoteAddress(), channel.getId() }); closeChannelWithLoginFailure(channel); } }
NioSocketChannel channel = (NioSocketChannel) event.getChannel(); boolean offered = channel.writeBufferQueue.offer(event); assert offered;
NioSocketChannel channel = (NioSocketChannel) event.getChannel(); boolean offered = channel.writeBufferQueue.offer(event); assert offered;