mirror of
https://github.com/alibaba/canal.git
synced 2026-11-04 00:30:15 +08:00
update guava to 18.0, magriate compute map by package level implement
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.alibaba.otter.canal.deployer;
|
||||
|
||||
import com.google.common.collect.MigrateMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
@@ -70,9 +71,11 @@ public class CanalController {
|
||||
}
|
||||
|
||||
public CanalController(final Properties properties){
|
||||
managerClients = new MapMaker().makeComputingMap(new Function<String, CanalConfigClient>() {
|
||||
managerClients = MigrateMap.makeComputingMap(new Function<String, CanalConfigClient>()
|
||||
{
|
||||
|
||||
public CanalConfigClient apply(String managerAddress) {
|
||||
public CanalConfigClient apply(String managerAddress)
|
||||
{
|
||||
return getManagerClient(managerAddress);
|
||||
}
|
||||
});
|
||||
@@ -107,68 +110,88 @@ public class CanalController {
|
||||
|
||||
final ServerRunningData serverData = new ServerRunningData(cid, ip + ":" + port);
|
||||
ServerRunningMonitors.setServerData(serverData);
|
||||
ServerRunningMonitors.setRunningMonitors(new MapMaker().makeComputingMap(new Function<String, ServerRunningMonitor>() {
|
||||
|
||||
public ServerRunningMonitor apply(final String destination) {
|
||||
ServerRunningMonitors.setRunningMonitors(MigrateMap.makeComputingMap(new Function<String, ServerRunningMonitor>()
|
||||
{
|
||||
public ServerRunningMonitor apply(final String destination)
|
||||
{
|
||||
ServerRunningMonitor runningMonitor = new ServerRunningMonitor(serverData);
|
||||
runningMonitor.setDestination(destination);
|
||||
runningMonitor.setListener(new ServerRunningListener() {
|
||||
runningMonitor.setListener(new ServerRunningListener()
|
||||
{
|
||||
|
||||
public void processActiveEnter() {
|
||||
try {
|
||||
public void processActiveEnter()
|
||||
{
|
||||
try
|
||||
{
|
||||
MDC.put(CanalConstants.MDC_DESTINATION, String.valueOf(destination));
|
||||
embededCanalServer.start(destination);
|
||||
} finally {
|
||||
} finally
|
||||
{
|
||||
MDC.remove(CanalConstants.MDC_DESTINATION);
|
||||
}
|
||||
}
|
||||
|
||||
public void processActiveExit() {
|
||||
try {
|
||||
public void processActiveExit()
|
||||
{
|
||||
try
|
||||
{
|
||||
MDC.put(CanalConstants.MDC_DESTINATION, String.valueOf(destination));
|
||||
embededCanalServer.stop(destination);
|
||||
} finally {
|
||||
} finally
|
||||
{
|
||||
MDC.remove(CanalConstants.MDC_DESTINATION);
|
||||
}
|
||||
}
|
||||
|
||||
public void processStart() {
|
||||
try {
|
||||
if (zkclientx != null) {
|
||||
public void processStart()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (zkclientx != null)
|
||||
{
|
||||
final String path = ZookeeperPathUtils.getDestinationClusterNode(destination, ip + ":"
|
||||
+ port);
|
||||
+ port);
|
||||
initCid(path);
|
||||
zkclientx.subscribeStateChanges(new IZkStateListener() {
|
||||
zkclientx.subscribeStateChanges(new IZkStateListener()
|
||||
{
|
||||
|
||||
public void handleStateChanged(KeeperState state) throws Exception {
|
||||
public void handleStateChanged(KeeperState state) throws Exception
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void handleNewSession() throws Exception {
|
||||
public void handleNewSession() throws Exception
|
||||
{
|
||||
initCid(path);
|
||||
}
|
||||
});
|
||||
}
|
||||
} finally {
|
||||
} finally
|
||||
{
|
||||
MDC.remove(CanalConstants.MDC_DESTINATION);
|
||||
}
|
||||
}
|
||||
|
||||
public void processStop() {
|
||||
try {
|
||||
public void processStop()
|
||||
{
|
||||
try
|
||||
{
|
||||
MDC.put(CanalConstants.MDC_DESTINATION, String.valueOf(destination));
|
||||
if (zkclientx != null) {
|
||||
if (zkclientx != null)
|
||||
{
|
||||
final String path = ZookeeperPathUtils.getDestinationClusterNode(destination, ip + ":"
|
||||
+ port);
|
||||
+ port);
|
||||
releaseCid(path);
|
||||
}
|
||||
} finally {
|
||||
} finally
|
||||
{
|
||||
MDC.remove(CanalConstants.MDC_DESTINATION);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
if (zkclientx != null) {
|
||||
if (zkclientx != null)
|
||||
{
|
||||
runningMonitor.setZkClient(zkclientx);
|
||||
}
|
||||
return runningMonitor;
|
||||
@@ -216,25 +239,32 @@ public class CanalController {
|
||||
}
|
||||
};
|
||||
|
||||
instanceConfigMonitors = new MapMaker().makeComputingMap(new Function<InstanceMode, InstanceConfigMonitor>() {
|
||||
instanceConfigMonitors = MigrateMap.makeComputingMap(new Function<InstanceMode, InstanceConfigMonitor>()
|
||||
{
|
||||
|
||||
public InstanceConfigMonitor apply(InstanceMode mode) {
|
||||
int scanInterval = Integer.valueOf(getProperty(properties, CanalConstants.CANAL_AUTO_SCAN_INTERVAL));
|
||||
public InstanceConfigMonitor apply(InstanceMode mode)
|
||||
{
|
||||
int scanInterval = Integer
|
||||
.valueOf(getProperty(properties, CanalConstants.CANAL_AUTO_SCAN_INTERVAL));
|
||||
|
||||
if (mode.isSpring()) {
|
||||
if (mode.isSpring())
|
||||
{
|
||||
SpringInstanceConfigMonitor monitor = new SpringInstanceConfigMonitor();
|
||||
monitor.setScanIntervalInSecond(scanInterval);
|
||||
monitor.setDefaultAction(defaultAction);
|
||||
// 设置conf目录,默认是user.dir + conf目录组成
|
||||
String rootDir = getProperty(properties, CanalConstants.CANAL_CONF_DIR);
|
||||
if (StringUtils.isEmpty(rootDir)) {
|
||||
if (StringUtils.isEmpty(rootDir))
|
||||
{
|
||||
rootDir = "../conf";
|
||||
}
|
||||
monitor.setRootConf(rootDir);
|
||||
return monitor;
|
||||
} else if (mode.isManager()) {
|
||||
} else if (mode.isManager())
|
||||
{
|
||||
return new ManagerInstanceConfigMonitor();
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
throw new UnsupportedOperationException("unknow mode :" + mode + " for monitor");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.alibaba.otter.canal.deployer.monitor;
|
||||
|
||||
import com.google.common.collect.MigrateMap;
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.FilenameFilter;
|
||||
@@ -39,12 +40,14 @@ public class SpringInstanceConfigMonitor extends AbstractCanalLifeCycle implemen
|
||||
private long scanIntervalInSecond = 5;
|
||||
private InstanceAction defaultAction = null;
|
||||
private Map<String, InstanceAction> actions = new MapMaker().makeMap();
|
||||
private Map<String, InstanceConfigFiles> lastFiles = new MapMaker().makeComputingMap(new Function<String, InstanceConfigFiles>() {
|
||||
private Map<String, InstanceConfigFiles> lastFiles = MigrateMap.makeComputingMap(new Function<String, InstanceConfigFiles>()
|
||||
{
|
||||
|
||||
public InstanceConfigFiles apply(String destination) {
|
||||
return new InstanceConfigFiles(destination);
|
||||
}
|
||||
});
|
||||
public InstanceConfigFiles apply(String destination)
|
||||
{
|
||||
return new InstanceConfigFiles(destination);
|
||||
}
|
||||
});
|
||||
private ScheduledExecutorService executor = Executors.newScheduledThreadPool(1,
|
||||
new NamedThreadFactory("canal-instance-scan"));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user