mirror of
https://github.com/alibaba/canal.git
synced 2026-11-04 00:30:15 +08:00
typo, javadoc,code cleanup
This commit is contained in:
@@ -11,7 +11,7 @@ import com.alibaba.otter.canal.server.exception.CanalServerException;
|
||||
*/
|
||||
public interface CanalServer extends CanalLifeCycle {
|
||||
|
||||
public void start() throws CanalServerException;
|
||||
void start() throws CanalServerException;
|
||||
|
||||
public void stop() throws CanalServerException;
|
||||
void stop() throws CanalServerException;
|
||||
}
|
||||
|
||||
@@ -50,8 +50,7 @@ public class CanalServerWithEmbedded extends AbstractCanalLifeCycle implements C
|
||||
canalInstances = new MapMaker().makeComputingMap(new Function<String, CanalInstance>() {
|
||||
|
||||
public CanalInstance apply(String destination) {
|
||||
CanalInstance canalInstance = canalInstanceGenerator.generate(destination);
|
||||
return canalInstance;
|
||||
return canalInstanceGenerator.generate(destination);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -74,7 +73,7 @@ public class CanalServerWithEmbedded extends AbstractCanalLifeCycle implements C
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error(String.format("stop cannalInstance[%s] has an error", entry.getKey()), e);
|
||||
logger.error(String.format("stop CanalInstance[%s] has an error", entry.getKey()), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -357,7 +356,7 @@ public class CanalServerWithEmbedded extends AbstractCanalLifeCycle implements C
|
||||
}
|
||||
|
||||
/**
|
||||
* 回滚到未进行 {@link ack} 的地方,下次fetch的时候,可以从最后一个没有 {@link ack} 的地方开始拿
|
||||
* 回滚到未进行 {@link #ack} 的地方,下次fetch的时候,可以从最后一个没有 {@link #ack} 的地方开始拿
|
||||
*/
|
||||
public void rollback(ClientIdentity clientIdentity) throws CanalServerException {
|
||||
checkStart(clientIdentity.getDestination());
|
||||
@@ -378,7 +377,7 @@ public class CanalServerWithEmbedded extends AbstractCanalLifeCycle implements C
|
||||
}
|
||||
|
||||
/**
|
||||
* 回滚到未进行 {@link ack} 的地方,下次fetch的时候,可以从最后一个没有 {@link ack} 的地方开始拿
|
||||
* 回滚到未进行 {@link #ack} 的地方,下次fetch的时候,可以从最后一个没有 {@link #ack} 的地方开始拿
|
||||
*/
|
||||
public void rollback(ClientIdentity clientIdentity, Long batchId) throws CanalServerException {
|
||||
checkStart(clientIdentity.getDestination());
|
||||
|
||||
@@ -33,14 +33,14 @@ public class ClientAuthenticationHandler extends SimpleChannelHandler {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ClientAuthenticationHandler.class);
|
||||
private final int SUPPORTED_VERSION = 3;
|
||||
private final int defaultSubscriptorDisconnectIdleTimeout = 5 * 60 * 1000;
|
||||
private CanalServerWithEmbedded embededServer;
|
||||
private CanalServerWithEmbedded embeddedServer;
|
||||
|
||||
public ClientAuthenticationHandler(){
|
||||
|
||||
}
|
||||
|
||||
public ClientAuthenticationHandler(CanalServerWithEmbedded embededServer){
|
||||
this.embededServer = embededServer;
|
||||
public ClientAuthenticationHandler(CanalServerWithEmbedded embeddedServer){
|
||||
this.embeddedServer = embeddedServer;
|
||||
}
|
||||
|
||||
public void messageReceived(final ChannelHandlerContext ctx, MessageEvent e) throws Exception {
|
||||
@@ -58,10 +58,10 @@ public class ClientAuthenticationHandler extends SimpleChannelHandler {
|
||||
clientAuth.getFilter());
|
||||
try {
|
||||
MDC.put("destination", clientIdentity.getDestination());
|
||||
embededServer.subscribe(clientIdentity);
|
||||
embeddedServer.subscribe(clientIdentity);
|
||||
ctx.setAttachment(clientIdentity);// 设置状态数据
|
||||
// 尝试启动,如果已经启动,忽略
|
||||
if (!embededServer.isStart(clientIdentity.getDestination())) {
|
||||
if (!embeddedServer.isStart(clientIdentity.getDestination())) {
|
||||
ServerRunningMonitor runningMonitor = ServerRunningMonitors.getRunningMonitor(clientIdentity
|
||||
.getDestination());
|
||||
if (!runningMonitor.isStart()) {
|
||||
@@ -115,8 +115,8 @@ public class ClientAuthenticationHandler extends SimpleChannelHandler {
|
||||
}
|
||||
}
|
||||
|
||||
public void setEmbededServer(CanalServerWithEmbedded embededServer) {
|
||||
this.embededServer = embededServer;
|
||||
public void setEmbeddedServer(CanalServerWithEmbedded embeddedServer) {
|
||||
this.embeddedServer = embeddedServer;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -43,14 +43,12 @@ import com.alibaba.otter.canal.server.netty.NettyUtils;
|
||||
public class SessionHandler extends SimpleChannelHandler {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(SessionHandler.class);
|
||||
private CanalServerWithEmbedded embededServer;
|
||||
private CanalServerWithEmbedded embeddedServer;
|
||||
|
||||
public SessionHandler(){
|
||||
public SessionHandler(){ }
|
||||
|
||||
}
|
||||
|
||||
public SessionHandler(CanalServerWithEmbedded embededServer){
|
||||
this.embededServer = embededServer;
|
||||
public SessionHandler(CanalServerWithEmbedded embeddedServer){
|
||||
this.embeddedServer = embeddedServer;
|
||||
}
|
||||
|
||||
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
|
||||
@@ -66,10 +64,10 @@ public class SessionHandler extends SimpleChannelHandler {
|
||||
clientIdentity = new ClientIdentity(sub.getDestination(), Short.valueOf(sub.getClientId()),
|
||||
sub.getFilter());
|
||||
MDC.put("destination", clientIdentity.getDestination());
|
||||
embededServer.subscribe(clientIdentity);
|
||||
embeddedServer.subscribe(clientIdentity);
|
||||
|
||||
// 尝试启动,如果已经启动,忽略
|
||||
if (!embededServer.isStart(clientIdentity.getDestination())) {
|
||||
if (!embeddedServer.isStart(clientIdentity.getDestination())) {
|
||||
ServerRunningMonitor runningMonitor = ServerRunningMonitors.getRunningMonitor(clientIdentity.getDestination());
|
||||
if (!runningMonitor.isStart()) {
|
||||
runningMonitor.start();
|
||||
@@ -90,7 +88,7 @@ public class SessionHandler extends SimpleChannelHandler {
|
||||
clientIdentity = new ClientIdentity(unsub.getDestination(), Short.valueOf(unsub.getClientId()),
|
||||
unsub.getFilter());
|
||||
MDC.put("destination", clientIdentity.getDestination());
|
||||
embededServer.unsubscribe(clientIdentity);
|
||||
embeddedServer.unsubscribe(clientIdentity);
|
||||
stopCanalInstanceIfNecessary(clientIdentity);// 尝试关闭
|
||||
NettyUtils.ack(ctx.getChannel(), null);
|
||||
} else {
|
||||
@@ -108,17 +106,17 @@ public class SessionHandler extends SimpleChannelHandler {
|
||||
|
||||
// if (get.getAutoAck()) {
|
||||
// if (get.getTimeout() == -1) {//是否是初始值
|
||||
// message = embededServer.get(clientIdentity, get.getFetchSize());
|
||||
// message = embeddedServer.get(clientIdentity, get.getFetchSize());
|
||||
// } else {
|
||||
// TimeUnit unit = convertTimeUnit(get.getUnit());
|
||||
// message = embededServer.get(clientIdentity, get.getFetchSize(), get.getTimeout(), unit);
|
||||
// message = embeddedServer.get(clientIdentity, get.getFetchSize(), get.getTimeout(), unit);
|
||||
// }
|
||||
// } else {
|
||||
if (get.getTimeout() == -1) {//是否是初始值
|
||||
message = embededServer.getWithoutAck(clientIdentity, get.getFetchSize());
|
||||
message = embeddedServer.getWithoutAck(clientIdentity, get.getFetchSize());
|
||||
} else {
|
||||
TimeUnit unit = convertTimeUnit(get.getUnit());
|
||||
message = embededServer.getWithoutAck(clientIdentity, get.getFetchSize(), get.getTimeout(),
|
||||
message = embeddedServer.getWithoutAck(clientIdentity, get.getFetchSize(), get.getTimeout(),
|
||||
unit);
|
||||
}
|
||||
// }
|
||||
@@ -153,7 +151,7 @@ public class SessionHandler extends SimpleChannelHandler {
|
||||
// donothing
|
||||
} else {
|
||||
clientIdentity = new ClientIdentity(ack.getDestination(), Short.valueOf(ack.getClientId()));
|
||||
embededServer.ack(clientIdentity, ack.getBatchId());
|
||||
embeddedServer.ack(clientIdentity, ack.getBatchId());
|
||||
}
|
||||
} else {
|
||||
NettyUtils.error(401,
|
||||
@@ -169,9 +167,9 @@ public class SessionHandler extends SimpleChannelHandler {
|
||||
clientIdentity = new ClientIdentity(rollback.getDestination(),
|
||||
Short.valueOf(rollback.getClientId()));
|
||||
if (rollback.getBatchId() == 0L) {
|
||||
embededServer.rollback(clientIdentity);// 回滚所有批次
|
||||
embeddedServer.rollback(clientIdentity);// 回滚所有批次
|
||||
} else {
|
||||
embededServer.rollback(clientIdentity, rollback.getBatchId()); // 只回滚单个批次
|
||||
embeddedServer.rollback(clientIdentity, rollback.getBatchId()); // 只回滚单个批次
|
||||
}
|
||||
} else {
|
||||
NettyUtils.error(401,
|
||||
@@ -212,7 +210,7 @@ public class SessionHandler extends SimpleChannelHandler {
|
||||
}
|
||||
|
||||
private void stopCanalInstanceIfNecessary(ClientIdentity clientIdentity) {
|
||||
List<ClientIdentity> clientIdentitys = embededServer.listAllSubscribe(clientIdentity.getDestination());
|
||||
List<ClientIdentity> clientIdentitys = embeddedServer.listAllSubscribe(clientIdentity.getDestination());
|
||||
if (clientIdentitys != null && clientIdentitys.size() == 1 && clientIdentitys.contains(clientIdentity)) {
|
||||
ServerRunningMonitor runningMonitor = ServerRunningMonitors.getRunningMonitor(clientIdentity.getDestination());
|
||||
if (runningMonitor.isStart()) {
|
||||
@@ -242,8 +240,8 @@ public class SessionHandler extends SimpleChannelHandler {
|
||||
}
|
||||
}
|
||||
|
||||
public void setEmbededServer(CanalServerWithEmbedded embededServer) {
|
||||
this.embededServer = embededServer;
|
||||
public void setEmbeddedServer(CanalServerWithEmbedded embeddedServer) {
|
||||
this.embeddedServer = embeddedServer;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -49,16 +49,18 @@ public class CanalServerWithNettyTest {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
CanalServerWithEmbedded embededServer = new CanalServerWithEmbedded();
|
||||
embededServer.setCanalInstanceGenerator(new CanalInstanceGenerator() {
|
||||
CanalServerWithEmbedded embeddedServer = new CanalServerWithEmbedded();
|
||||
embeddedServer.setCanalInstanceGenerator(new CanalInstanceGenerator()
|
||||
{
|
||||
|
||||
public CanalInstance generate(String destination) {
|
||||
public CanalInstance generate(String destination)
|
||||
{
|
||||
Canal canal = buildCanal();
|
||||
return new CanalInstanceWithManager(canal, FILTER);
|
||||
}
|
||||
});
|
||||
|
||||
nettyServer = new CanalServerWithNetty(embededServer);
|
||||
nettyServer = new CanalServerWithNetty(embeddedServer);
|
||||
nettyServer.setPort(1088);
|
||||
nettyServer.start();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user