org.jboss.netty.channel.SimpleChannelUpstreamHandler Java Examples

The following examples show how to use org.jboss.netty.channel.SimpleChannelUpstreamHandler. 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: RaopRtspPipelineFactory.java    From Android-Airplay-Server with MIT License 5 votes vote down vote up
@Override
public ChannelPipeline getPipeline() throws Exception {
	final ChannelPipeline pipeline = Channels.pipeline();

	final AirPlayServer airPlayServer = AirPlayServer.getIstance();
	
	pipeline.addLast("executionHandler", airPlayServer.getChannelExecutionHandler());
	pipeline.addLast("closeOnShutdownHandler", new SimpleChannelUpstreamHandler() {
		@Override
		public void channelOpen(final ChannelHandlerContext ctx, final ChannelStateEvent e) throws Exception {
			airPlayServer.getChannelGroup().add(e.getChannel());
			super.channelOpen(ctx, e);
		}
	});
	pipeline.addLast("exceptionLogger", new ExceptionLoggingHandler());
	pipeline.addLast("decoder", new RtspRequestDecoder());
	pipeline.addLast("encoder", new RtspResponseEncoder());
	pipeline.addLast("logger", new RtspLoggingHandler());
	pipeline.addLast("errorResponse", new RtspErrorResponseHandler());
	pipeline.addLast("challengeResponse", new RaopRtspChallengeResponseHandler(NetworkUtils.getInstance().getHardwareAddress()));
	pipeline.addLast("header", new RaopRtspHeaderHandler());
	pipeline.addLast("options", new RaopRtspOptionsHandler());
	pipeline.addLast("audio", new RaopAudioHandler(airPlayServer.getExecutorService()));
	pipeline.addLast("unsupportedResponse", new RtspUnsupportedResponseHandler());

	return pipeline;
}
 
Example #2
Source File: RtpServer.java    From feeyo-hlsserver with Apache License 2.0 4 votes vote down vote up
public void startup(int port) {

		this.dataBootstrap = new ConnectionlessBootstrap(factory);
		dataBootstrap.setOption("receiveBufferSizePredictor", new FixedReceiveBufferSizePredictor(2048));
		dataBootstrap.setOption("receiveBufferSizePredictorFactory", new FixedReceiveBufferSizePredictorFactory(2048));

		this.dataBootstrap.getPipeline().addLast("handler", new SimpleChannelUpstreamHandler() {
			@Override
			public void messageReceived(ChannelHandlerContext ctx, final MessageEvent e) throws Exception {

				ChannelBuffer buffer = (ChannelBuffer) e.getMessage();

				if (buffer.readableBytes() < 12) {
					throw new IllegalArgumentException("A RTP packet must be at least 12 octets long");
				}

				byte b = buffer.readByte();
				byte version = (byte) (b & 0xc0);
				boolean padding = (b & 0x20) > 0; // mask 0010 0000
				boolean extension = (b & 0x10) > 0; // mask 0001 0000
				int contributingSourcesCount = b & 0x0f; // mask 0000 1111

				// Marker, Payload Type
				b = buffer.readByte();
				boolean marker = (b & 0x80) > 0; // mask 0000 0001
				int payloadType = (b & 0x7f); // mask 0111 1111

				int sequenceNumber = buffer.readUnsignedShort();
				long timestamp = buffer.readUnsignedInt();
				long ssrc = buffer.readUnsignedInt();

				// Read CCRC's
				if (contributingSourcesCount > 0) {
					for (int i = 0; i < contributingSourcesCount; i++) {
						long contributingSource = buffer.readUnsignedInt();
					}
				}

				// Read extension headers & data
				if (extension) {
					short extensionHeaderData = buffer.readShort();
					byte[] extensionData = new byte[buffer.readUnsignedShort() * 4];
					buffer.readBytes(extensionData);
				}

				if (!padding) {
					// No padding used, assume remaining data is the packet
					byte[] remainingBytes = new byte[buffer.readableBytes()];
					buffer.readBytes(remainingBytes);

					// remainingBytes == data
				} else {
					// Padding bit was set, so last byte contains the number of
					// padding octets that should be discarded.
					short lastByte = buffer.getUnsignedByte(buffer.readerIndex() + buffer.readableBytes() - 1);
					byte[] dataBytes = new byte[buffer.readableBytes() - lastByte];
					buffer.readBytes(dataBytes);

					// dataBytes == data

					// Discard rest of buffer.
					buffer.skipBytes(buffer.readableBytes());
				}

				// 应答
				ChannelBuffer replyBuffer = ChannelBuffers.copiedBuffer(REPLY_BYTES);
				e.getChannel().write(replyBuffer, e.getRemoteAddress());

			}
		});
		this.dataChannel = (DatagramChannel) this.dataBootstrap.bind(new InetSocketAddress(port));

	}
 
Example #3
Source File: SimpleUdpServer.java    From hadoop with Apache License 2.0 4 votes vote down vote up
public SimpleUdpServer(int port, SimpleChannelUpstreamHandler program,
    int workerCount) {
  this.port = port;
  this.rpcProgram = program;
  this.workerCount = workerCount;
}
 
Example #4
Source File: SimpleUdpServer.java    From big-c with Apache License 2.0 4 votes vote down vote up
public SimpleUdpServer(int port, SimpleChannelUpstreamHandler program,
    int workerCount) {
  this.port = port;
  this.rpcProgram = program;
  this.workerCount = workerCount;
}
 
Example #5
Source File: NettyClientPipelineFactory.java    From migration-tool with Apache License 2.0 4 votes vote down vote up
public NettyClientPipelineFactory(SimpleChannelUpstreamHandler handler){
	this.handler = handler;
}