
pl.bristleback.server.bristle.engine.netty.WebsocketFrameHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of websocket-engine-netty Show documentation
Show all versions of websocket-engine-netty Show documentation
High level, Spring integrated WebSocket Framework
The newest version!
/*
* Bristleback Websocket Framework - Copyright (c) 2010-2013 http://bristleback.pl
* ---------------------------------------------------------------------------
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation; either version 3 of the License, or (at your
* option) any later version.
* This library is distributed in the hope that it will be useful,
* but without any warranty; without even the implied warranty of merchantability
* or fitness for a particular purpose.
* You should have received a copy of the GNU Lesser General Public License along
* with this program; if not, see .
* ---------------------------------------------------------------------------
*/
package pl.bristleback.server.bristle.engine.netty;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.handler.codec.http.websocketx.BinaryWebSocketFrame;
import org.jboss.netty.handler.codec.http.websocketx.CloseWebSocketFrame;
import org.jboss.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import org.jboss.netty.handler.codec.http.websocketx.WebSocketFrame;
import org.springframework.stereotype.Component;
import pl.bristleback.server.bristle.api.FrontController;
import pl.bristleback.server.bristle.api.WebsocketConnector;
import pl.bristleback.server.bristle.engine.OperationCode;
import javax.inject.Inject;
import javax.inject.Named;
/**
* //@todo class description
*
* Created on: 2011-07-19 13:15:02
*
* @author Wojciech Niemiec
* @author Andrea Nanni
*/
@Component
public class WebsocketFrameHandler {
@Inject
@Named("defaultFrontController")
private FrontController frontController;
@SuppressWarnings("rawtypes")
public void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame frame) {
WebsocketConnector connector = (WebsocketConnector) ctx.getAttachment();
int operationCode = 0;
if (frame instanceof TextWebSocketFrame) {
operationCode = OperationCode.TEXT_FRAME_CODE.getCode();
} else if (frame instanceof BinaryWebSocketFrame) {
operationCode = OperationCode.BINARY_FRAME_CODE.getCode();
} else if (frame instanceof CloseWebSocketFrame) {
operationCode = OperationCode.CLOSE_FRAME_CODE.getCode();
}
frontController.processCommand(connector, operationCode, getData(frame));
}
private Object getData(WebSocketFrame frame) {
if (frame instanceof TextWebSocketFrame) {
return ((TextWebSocketFrame) frame).getText();
} else {
return frame.getBinaryData();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy