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

org.bdware.doip.SemaphoreController Maven / Gradle / Ivy

There is a newer version: 1.5.4
Show newest version
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();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy