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);
}
}
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);
}
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);
}
}
Aggregations