net.dongliu.prettypb.rpc.client.RpcClientHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of prettypb-rpc Show documentation
Show all versions of prettypb-rpc Show documentation
proto rpc libs, compatible with proto-rpc-pro
/**
* Copyright 2010-2014 Peter Klauser
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.dongliu.prettypb.rpc.client;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;
import net.dongliu.prettypb.rpc.common.TaskCallBack;
import net.dongliu.prettypb.rpc.common.TaskSet;
import net.dongliu.prettypb.rpc.exception.ServiceException;
import net.dongliu.prettypb.rpc.listener.TcpConnectionEventListener;
import net.dongliu.prettypb.rpc.protocol.*;
import net.dongliu.prettypb.runtime.ExtensionRegistry;
import net.dongliu.prettypb.runtime.ProtoBufDecoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
/**
* Handles returning RpcResponse and RpcError messages in the IO-Layer
*
* @author Peter Klauser
* @author Dong Liu
*/
public class RpcClientHandler extends MessageToMessageDecoder {
private static Logger logger = LoggerFactory.getLogger(RpcClientHandler.class);
private final RpcClientChannel rpcClientChannel;
private TcpConnectionEventListener eventListener;
private final TaskSet taskSet = new TaskSet<>();
private final ExtensionRegistry extensionRegistry;
public RpcClientHandler(TcpConnectionEventListener eventListener,
RpcClientChannel rpcClientChannel,
ExtensionRegistry extensionRegistry) {
this.extensionRegistry = extensionRegistry;
if (eventListener == null) {
throw new NullPointerException("eventListener is null");
}
this.eventListener = eventListener;
this.rpcClientChannel = rpcClientChannel;
}
@Override
protected void decode(ChannelHandlerContext ctx, WirePayload payload, List