org.bdware.doip.SemaphoreController Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of doip-audit-tool Show documentation
Show all versions of doip-audit-tool Show documentation
doip audit tool developed by bdware
package org.bdware.doip;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import org.bdware.doip.codec.doipMessage.DoipMessage;
import java.util.concurrent.Semaphore;
public class SemaphoreController extends SimpleChannelInboundHandler {
Semaphore semaphore = new Semaphore(20);
SimpleChannelInboundHandler handler;
public SemaphoreController(SimpleChannelInboundHandler handler) {
this.handler = handler;
}
@Override
protected void channelRead0(ChannelHandlerContext channelHandlerContext, DoipMessage irpMessage) throws Exception {
semaphore.acquire();
try {
handler.channelRead(channelHandlerContext, irpMessage);
} catch (Exception e) {
e.printStackTrace();
} finally {
semaphore.release();
}
}
}