All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.zusmart.base.network.handler.support.DefaultRecognizeHandler Maven / Gradle / Ivy

Go to download

提供基础的工具类及方法类,Logging,Scanner,Buffer,NetWork,Future,Thread

There is a newer version: 1.0.6
Show newest version
package com.zusmart.base.network.handler.support;

import java.io.IOException;

import com.zusmart.base.buffer.Buffer;
import com.zusmart.base.network.ChannelContext;
import com.zusmart.base.network.handler.ChannelContextHandlerContext;
import com.zusmart.base.network.message.Message;
import com.zusmart.base.network.message.MessageProtocol;

public class DefaultRecognizeHandler extends DefaultChannelContextHandler{

	public static final String NAME = "__AUTO_RECOGNIZE__";

	private final MessageProtocol messageProtocol;

	public DefaultRecognizeHandler(MessageProtocol messageProtocol) {
		this.messageProtocol = messageProtocol;
	}
	
	@Override
	public void onReader(ChannelContext channelContext, ChannelContextHandlerContext handlerContext, Buffer buffer) throws IOException {
		while (buffer.hasRemaining()) {
			Buffer slice = buffer.asReadOnlyBuffer().slice();
			try {
				Message message = this.messageProtocol.decode(slice);
				if (null == message) {
					break;
				}
				buffer.skip(slice.position());
				handlerContext.getChain().fireOnMessage(message);
			} catch (Exception e) {
				handlerContext.getChain().fireOnException(e);
			}
		}
	}
	
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy