Example usage for io.netty.util ReferenceCountUtil release

List of usage examples for io.netty.util ReferenceCountUtil release

Introduction

In this page you can find the example usage for io.netty.util ReferenceCountUtil release.

Prototype

public static boolean release(Object msg) 

Source Link

Document

Try to call ReferenceCounted#release() if the specified message implements ReferenceCounted .

Usage

From source file:com.digitalpetri.modbus.slave.ServiceRequestHandler.java

License:Apache License

default void onWriteSingleCoil(ServiceRequest<WriteSingleCoilRequest, WriteSingleCoilResponse> service) {
    service.sendException(ExceptionCode.IllegalFunction);
    ReferenceCountUtil.release(service.getRequest());
}

From source file:com.digitalpetri.modbus.slave.ServiceRequestHandler.java

License:Apache License

default void onWriteSingleRegister(
        ServiceRequest<WriteSingleRegisterRequest, WriteSingleRegisterResponse> service) {
    service.sendException(ExceptionCode.IllegalFunction);
    ReferenceCountUtil.release(service.getRequest());
}

From source file:com.digitalpetri.modbus.slave.ServiceRequestHandler.java

License:Apache License

default void onWriteMultipleCoils(
        ServiceRequest<WriteMultipleCoilsRequest, WriteMultipleCoilsResponse> service) {
    service.sendException(ExceptionCode.IllegalFunction);
    ReferenceCountUtil.release(service.getRequest());
}

From source file:com.digitalpetri.modbus.slave.ServiceRequestHandler.java

License:Apache License

default void onWriteMultipleRegisters(
        ServiceRequest<WriteMultipleRegistersRequest, WriteMultipleRegistersResponse> service) {
    service.sendException(ExceptionCode.IllegalFunction);
    ReferenceCountUtil.release(service.getRequest());
}

From source file:com.digitalpetri.modbus.slave.ServiceRequestHandler.java

License:Apache License

default void onMaskWriteRegister(ServiceRequest<MaskWriteRegisterRequest, MaskWriteRegisterResponse> service) {
    service.sendException(ExceptionCode.IllegalFunction);
    ReferenceCountUtil.release(service.getRequest());
}

From source file:com.ebay.jetstream.http.netty.client.HttpResponseDispatcher.java

License:MIT License

public void dispatch(String requestid, HttpResponse response) {

    // this method is being called from IO thread - we will dispatch this in
    // a background thread

    ResponseFuture future = (ResponseFuture) m_responseFutureRegistry
            .remove(TimeSlotHashMap.Key.newKey(requestid));
    m_responseCounter.increment();/*from  w ww .j a  va 2s.  c o  m*/
    if (future != null) {
        if (HttpResponseStatus.OK.equals(response.getStatus()))
            future.setSuccess();
        else
            future.setFailure();
        HttpResponseDispatchRequest workRequest = new HttpResponseDispatchRequest(future, response);
        if (!m_workQueue.offer(workRequest)) {
            m_queueFullCounter.increment();
            ReferenceCountUtil.release(response);
        }

    } else {
        m_dropCounter.increment();
    }

}

From source file:com.ebay.jetstream.http.netty.client.HttpResponseDispatchRequest.java

License:MIT License

@Override
public void run() {

    try {/*from  w  w w.j a v  a2  s  .  c om*/
        m_future.operationComplete(m_response);
    } catch (Throwable t) {
        LOGGER.error("Error while dispatching response" + t.getLocalizedMessage());
    } finally {
        ReferenceCountUtil.release(m_response);
    }
}

From source file:com.ebay.jetstream.http.netty.client.HttpResponseHandler.java

License:MIT License

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {

    if (m_perSecRcvCount.addAndGet(1) < 0)
        m_perSecRcvCount.set(0);/* www  .  j a v  a2 s.c o  m*/
    if (m_totalRcvCount.addAndGet(1) < 0)
        m_totalRcvCount.set(0);

    HttpResponse response = (HttpResponse) msg;

    if (response != null) {
        String reqid = response.headers().get("X_EBAY_REQ_ID");
        if (reqid != null) {
            // we should only dispatch if the reqid is  set
            m_httpClient.dispatchResponse(reqid, response);
        } else {

            ReferenceCountUtil.release(response);

        }

    }
}

From source file:com.ebay.jetstream.http.netty.server.HttpErrorRequest.java

License:MIT License

public void processRequest() {
    try {//from   w w  w . j  ava  2 s  .c om
        DefaultHttpServletResponse servletResponse = new DefaultHttpServletResponse(HttpVersion.HTTP_1_1,
                m_status, 0);
        servletResponse.setHeader(CONTENT_TYPE, "text/plain; charset=UTF-8");

        try {
            servletResponse.flushBuffer();
            postResponse(m_channel, m_request, servletResponse.toNettyHttpResponse());

        } catch (Throwable e) {
            LOGGER.error(e.getMessage(), e);
        }
    } finally {
        ReferenceCountUtil.release(m_request);
    }
}

From source file:com.ebay.jetstream.http.netty.server.HttpWorkRequest.java

License:MIT License

public void processRequest() {
    try {/*from  ww w  .ja  v a2s .  c  om*/
        DefaultHttpServletRequest servletRequest = new DefaultHttpServletRequest(m_request, m_channel);
        DefaultHttpServletResponse servletResponse = new DefaultHttpServletResponse(HttpVersion.HTTP_1_1,
                HttpResponseStatus.OK, m_serverConfig.getInitialResponseBufferSize());
        servletResponse.setHeader(CONTENT_TYPE, "text/plain; charset=UTF-8");

        try {
            m_servlet.service(servletRequest, servletResponse);
        } catch (Throwable t) {
            servletResponse.setStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR);
            LOGGER.error("Dropping message - " + t.getLocalizedMessage());

        }

        try {
            servletResponse.flushBuffer();
            postResponse(m_channel, m_request, servletResponse.toNettyHttpResponse());

        } catch (IOException e) {
            LOGGER.error(e.getMessage(), e);
        }
    } finally {
        ReferenceCountUtil.release(m_request);
    }

}