Search in sources :

Example 1 with InboundWaitResponse

use of org.dcache.xrootd.tpc.protocol.messages.InboundWaitResponse in project xrootd4j by dCache.

the class AbstractClientRequestHandler method responseReceived.

protected void responseReceived(ChannelHandlerContext ctx, XrootdInboundResponse response) {
    try {
        if (response instanceof InboundWaitResponse) {
            doOnWaitResponse(ctx, (InboundWaitResponse) response);
            return;
        }
        if (response instanceof InboundWaitRespResponse) {
            doOnWaitRespResponse(ctx, (InboundWaitRespResponse) response);
            return;
        }
        if (response instanceof InboundErrorResponse) {
            doOnErrorResponse(ctx, (InboundErrorResponse) response);
            return;
        }
        if (response instanceof InboundRedirectResponse) {
            doOnRedirectResponse(ctx, (InboundRedirectResponse) response);
            return;
        }
        if (response instanceof InboundAttnResponse) {
            doOnAttnResponse(ctx, (InboundAttnResponse) response);
            return;
        }
        int streamId = response.getStreamId();
        ChannelId id = ctx.channel().id();
        int requestId = response.getRequestId();
        switch(requestId) {
            case kXR_auth:
                LOGGER.debug("responseReceived, channel {}, stream {}, " + "requestId = kXR_auth.", id, streamId);
                doOnAuthenticationResponse(ctx, (InboundAuthenticationResponse) response);
                break;
            case kXR_close:
                LOGGER.debug("responseReceived, channel {}, stream {}, " + "requestId = kXR_close.", id, streamId);
                doOnCloseResponse(ctx, (InboundCloseResponse) response);
                break;
            case kXR_endsess:
                LOGGER.debug("responseReceived, channel {}, stream {}, " + "requestId = kXR_endsess.", id, streamId);
                LOGGER.debug("endsession response received.");
                // will not attempt disconnect twice
                client.disconnect();
                break;
            case kXR_handshake:
                LOGGER.debug("responseReceived, channel {}, stream {}, " + "requestId = kXR_handshake.", id, streamId);
                doOnHandshakeResponse(ctx, (InboundHandshakeResponse) response);
                break;
            case kXR_login:
                LOGGER.debug("responseReceived, channel {}, stream {}, " + "requestId = kXR_login.", id, streamId);
                doOnLoginResponse(ctx, (InboundLoginResponse) response);
                break;
            case kXR_open:
                LOGGER.debug("responseReceived, channel {}, stream {}, " + "requestId = kXR_open.", id, streamId);
                doOnOpenResponse(ctx, (InboundOpenReadOnlyResponse) response);
                break;
            case kXR_protocol:
                LOGGER.debug("responseReceived, channel {}, stream {}, " + "requestId = kXR_protocol.", id, streamId);
                doOnProtocolResponse(ctx, (InboundProtocolResponse) response);
                break;
            case kXR_query:
                LOGGER.debug("responseReceived, channel {}, stream {}, " + "requestId = kXR_query.", id, streamId);
                doOnChecksumResponse(ctx, (InboundChecksumResponse) response);
                break;
            case kXR_read:
                LOGGER.debug("responseReceived, channel {}, stream {}, " + "requestId = kXR_read.", id, streamId);
                doOnReadResponse(ctx, (InboundReadResponse) response);
                break;
            default:
                String error = String.format("Response (channel %s, stream %d, " + "request %s) " + "should not have " + "been received " + "by tpc client; " + "this is a bug;" + "please report to " + "support@dcache.org.", id, streamId, requestId);
                throw new RuntimeException(error);
        }
    } catch (Throwable t) {
        exceptionCaught(ctx, t);
    }
}
Also used : InboundWaitRespResponse(org.dcache.xrootd.tpc.protocol.messages.InboundWaitRespResponse) InboundWaitResponse(org.dcache.xrootd.tpc.protocol.messages.InboundWaitResponse) InboundErrorResponse(org.dcache.xrootd.tpc.protocol.messages.InboundErrorResponse) ChannelId(io.netty.channel.ChannelId) InboundAttnResponse(org.dcache.xrootd.tpc.protocol.messages.InboundAttnResponse) InboundRedirectResponse(org.dcache.xrootd.tpc.protocol.messages.InboundRedirectResponse)

Example 2 with InboundWaitResponse

use of org.dcache.xrootd.tpc.protocol.messages.InboundWaitResponse in project xrootd4j by dCache.

the class AbstractClientRequestHandler method getWaitInSeconds.

protected int getWaitInSeconds(AbstractXrootdInboundResponse response) {
    int wsec = 0;
    int msec = 0;
    if (response instanceof InboundWaitResponse) {
        msec = ((InboundWaitResponse) response).getMaxWaitInSeconds();
        wsec = 10;
    } else if (response instanceof InboundWaitRespResponse) {
        msec = ((InboundWaitRespResponse) response).getMaxWaitInSeconds();
        wsec = msec;
    } else if (response instanceof InboundAttnResponse) {
        InboundAttnResponse attnResponse = (InboundAttnResponse) response;
        wsec = attnResponse.getWsec();
        msec = wsec;
    }
    return Math.min(wsec, msec);
}
Also used : InboundWaitRespResponse(org.dcache.xrootd.tpc.protocol.messages.InboundWaitRespResponse) InboundWaitResponse(org.dcache.xrootd.tpc.protocol.messages.InboundWaitResponse) InboundAttnResponse(org.dcache.xrootd.tpc.protocol.messages.InboundAttnResponse)

Example 3 with InboundWaitResponse

use of org.dcache.xrootd.tpc.protocol.messages.InboundWaitResponse in project xrootd4j by dCache.

the class XrootdClientDecoder method decode.

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) {
    ChannelId id = ctx.channel().id();
    int readable = in.readableBytes();
    if (readable < SERVER_RESPONSE_LEN) {
        return;
    }
    int pos = in.readerIndex();
    int headerFrameLength = in.getInt(pos + 4);
    if (headerFrameLength < 0) {
        LOGGER.error("Decoder {}, channel {}: received illegal " + "frame length in " + "xrootd header: {}." + " Closing channel.", sourceUrn, id, headerFrameLength);
        ctx.channel().close();
        return;
    }
    int length = SERVER_RESPONSE_LEN + headerFrameLength;
    if (readable < length) {
        return;
    }
    ByteBuf frame = in.readSlice(length);
    int requestId = client.getExpectedResponse();
    try {
        switch(frame.getUnsignedShort(2)) {
            case kXR_error:
                LOGGER.debug("Decoder {}, channel {}: adding error response.", sourceUrn, id);
                out.add(new InboundErrorResponse(frame));
                return;
            case kXR_wait:
                LOGGER.debug("Decoder {}, channel {}: adding wait response.", sourceUrn, id);
                out.add(new InboundWaitResponse(frame, requestId));
                return;
            case kXR_waitresp:
                LOGGER.debug("Decoder {}, channel {}: adding waitresp response.", sourceUrn, id);
                out.add(new InboundWaitRespResponse(frame, requestId));
                return;
            case kXR_redirect:
                LOGGER.debug("Decoder {}, channel {}: adding redirect response.", sourceUrn, id);
                out.add(new InboundRedirectResponse(frame, requestId));
                return;
            case kXR_attn:
                LOGGER.debug("Decoder {}, channel {}: adding attn response.", sourceUrn, id);
                out.add(new InboundAttnResponse(frame, requestId));
                return;
        }
        switch(requestId) {
            case kXR_handshake:
                LOGGER.debug("Decoder {}, channel {}: adding handshake response.", sourceUrn, id);
                out.add(new InboundHandshakeResponse(frame));
                break;
            case kXR_protocol:
                LOGGER.debug("Decoder {}, channel {}: adding protocol response.", sourceUrn, id);
                out.add(new InboundProtocolResponse(frame));
                break;
            case kXR_login:
                LOGGER.debug("Decoder {}, channel {}: adding login response.", sourceUrn, id);
                out.add(new InboundLoginResponse(frame));
                break;
            case kXR_auth:
                LOGGER.debug("Decoder {}, channel {}: adding authentication response.", sourceUrn, id);
                out.add(new InboundAuthenticationResponse(frame));
                break;
            case kXR_open:
                LOGGER.debug("Decoder {}, channel {}: adding open response.", sourceUrn, id);
                out.add(new InboundOpenReadOnlyResponse(frame));
                break;
            case kXR_read:
                LOGGER.debug("Decoder {}, channel {}: adding read response.", sourceUrn, id);
                out.add(new InboundReadResponse(frame));
                break;
            case kXR_query:
                LOGGER.debug("Decoder {}, channel {}: adding query response.", sourceUrn, id);
                out.add(new InboundChecksumResponse(frame));
                break;
            case kXR_close:
                LOGGER.debug("Decoder {}, channel {}: adding close response.", sourceUrn, id);
                out.add(new InboundCloseResponse(frame));
                break;
            case kXR_endsess:
                LOGGER.debug("Decoder {}, channel {}: adding endsess response.", sourceUrn, id);
                out.add(new InboundEndSessionResponse(frame));
                break;
            default:
                LOGGER.debug("Decoder {}, channel {}, received incorrect " + "response of request type {}.", sourceUrn, id, requestId);
                throw new XrootdException(kXR_error, "received incorrect response type.");
        }
    } catch (ParseException | XrootdException e) {
        LOGGER.error("Decoder {}, channel {}: error for request type {}: {}. " + "Closing channel.", requestId, id, e.getMessage());
        client.setError(e);
        client.shutDown(ctx);
    }
}
Also used : InboundReadResponse(org.dcache.xrootd.tpc.protocol.messages.InboundReadResponse) InboundProtocolResponse(org.dcache.xrootd.tpc.protocol.messages.InboundProtocolResponse) InboundCloseResponse(org.dcache.xrootd.tpc.protocol.messages.InboundCloseResponse) InboundChecksumResponse(org.dcache.xrootd.tpc.protocol.messages.InboundChecksumResponse) InboundErrorResponse(org.dcache.xrootd.tpc.protocol.messages.InboundErrorResponse) InboundWaitResponse(org.dcache.xrootd.tpc.protocol.messages.InboundWaitResponse) InboundHandshakeResponse(org.dcache.xrootd.tpc.protocol.messages.InboundHandshakeResponse) InboundLoginResponse(org.dcache.xrootd.tpc.protocol.messages.InboundLoginResponse) ChannelId(io.netty.channel.ChannelId) ByteBuf(io.netty.buffer.ByteBuf) InboundAttnResponse(org.dcache.xrootd.tpc.protocol.messages.InboundAttnResponse) InboundRedirectResponse(org.dcache.xrootd.tpc.protocol.messages.InboundRedirectResponse) InboundWaitRespResponse(org.dcache.xrootd.tpc.protocol.messages.InboundWaitRespResponse) InboundEndSessionResponse(org.dcache.xrootd.tpc.protocol.messages.InboundEndSessionResponse) InboundOpenReadOnlyResponse(org.dcache.xrootd.tpc.protocol.messages.InboundOpenReadOnlyResponse) ParseException(org.dcache.xrootd.util.ParseException) XrootdException(org.dcache.xrootd.core.XrootdException) InboundAuthenticationResponse(org.dcache.xrootd.tpc.protocol.messages.InboundAuthenticationResponse)

Aggregations

InboundAttnResponse (org.dcache.xrootd.tpc.protocol.messages.InboundAttnResponse)3 InboundWaitRespResponse (org.dcache.xrootd.tpc.protocol.messages.InboundWaitRespResponse)3 InboundWaitResponse (org.dcache.xrootd.tpc.protocol.messages.InboundWaitResponse)3 ChannelId (io.netty.channel.ChannelId)2 InboundErrorResponse (org.dcache.xrootd.tpc.protocol.messages.InboundErrorResponse)2 InboundRedirectResponse (org.dcache.xrootd.tpc.protocol.messages.InboundRedirectResponse)2 ByteBuf (io.netty.buffer.ByteBuf)1 XrootdException (org.dcache.xrootd.core.XrootdException)1 InboundAuthenticationResponse (org.dcache.xrootd.tpc.protocol.messages.InboundAuthenticationResponse)1 InboundChecksumResponse (org.dcache.xrootd.tpc.protocol.messages.InboundChecksumResponse)1 InboundCloseResponse (org.dcache.xrootd.tpc.protocol.messages.InboundCloseResponse)1 InboundEndSessionResponse (org.dcache.xrootd.tpc.protocol.messages.InboundEndSessionResponse)1 InboundHandshakeResponse (org.dcache.xrootd.tpc.protocol.messages.InboundHandshakeResponse)1 InboundLoginResponse (org.dcache.xrootd.tpc.protocol.messages.InboundLoginResponse)1 InboundOpenReadOnlyResponse (org.dcache.xrootd.tpc.protocol.messages.InboundOpenReadOnlyResponse)1 InboundProtocolResponse (org.dcache.xrootd.tpc.protocol.messages.InboundProtocolResponse)1 InboundReadResponse (org.dcache.xrootd.tpc.protocol.messages.InboundReadResponse)1 ParseException (org.dcache.xrootd.util.ParseException)1