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

org.voovan.network.messagesplitter.TimeOutMesssageSplitter Maven / Gradle / Ivy

There is a newer version: 4.3.8
Show newest version
package org.voovan.network.messagesplitter;

import org.voovan.network.IoSession;
import org.voovan.network.MessageSplitter;

import java.nio.ByteBuffer;

public class TimeOutMesssageSplitter implements MessageSplitter {

	private long initTime;
	
	public TimeOutMesssageSplitter(){
		initTime = -1;
	}
	
	@Override
	public int canSplite(IoSession session, ByteBuffer byteBuffer) {
		int timeOut = session.socketContext().getReadTimeout();
		long currentTime = System.currentTimeMillis();
		if(initTime==-1){
			initTime = currentTime;
		} 
		
		if(currentTime-initTime >= timeOut){
			return byteBuffer.limit();
		}else{
			return -1;
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy