com.envision.energy.connective.protobuf.AuthResMessageProcessor Maven / Gradle / Ivy
package com.envision.energy.connective.protobuf;
import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import com.envision.energy.connective.protobuf.generated.Sdk.SDKAuthRes;
import com.envision.energy.eos.sdk.ProxyManager;
@Sharable
public class AuthResMessageProcessor extends ChannelInboundHandlerAdapter {
public AuthResMessageProcessor() {
}
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg)
throws Exception {
//to next handler
if(msg == null || msg.getClass() != SDKAuthRes.class) {
ctx.fireChannelRead(msg);
return;
}
SDKAuthRes data = (SDKAuthRes)msg;
if(data.getSvrTime() < 0) {
ProxyManager.INSTANCE.closeTransport();
} else {
if(data.hasToken()) {
ProxyManager.INSTANCE.setToken(data.getToken());
}
ProxyManager.INSTANCE.subscribe(); //subuscribe.
}
}
}