mirror of
https://github.com/alibaba/canal.git
synced 2026-11-04 00:30:15 +08:00
fixed code template and format
This commit is contained in:
@@ -38,7 +38,8 @@ public class AddressUtils {
|
||||
private static boolean isValidHostAddress(InetAddress address) {
|
||||
if (address == null || address.isLoopbackAddress()) return false;
|
||||
String name = address.getHostAddress();
|
||||
return (name != null && !EMPTY_IP.equals(name) && !LOCALHOST_IP.equals(name) && IP_PATTERN.matcher(name).matches());
|
||||
return (name != null && !EMPTY_IP.equals(name) && !LOCALHOST_IP.equals(name) && IP_PATTERN.matcher(name)
|
||||
.matches());
|
||||
}
|
||||
|
||||
public static String getHostIp() {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.alibaba.otter.canal.common.zookeeper;
|
||||
|
||||
import com.google.common.collect.MigrateMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.I0Itec.zkclient.IZkConnection;
|
||||
@@ -13,7 +12,7 @@ import org.I0Itec.zkclient.serialize.ZkSerializer;
|
||||
import org.apache.zookeeper.CreateMode;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.MapMaker;
|
||||
import com.google.common.collect.MigrateMap;
|
||||
|
||||
/**
|
||||
* 使用自定义的ZooKeeperx for zk connection
|
||||
@@ -24,14 +23,12 @@ import com.google.common.collect.MapMaker;
|
||||
public class ZkClientx extends ZkClient {
|
||||
|
||||
// 对于zkclient进行一次缓存,避免一个jvm内部使用多个zk connection
|
||||
private static Map<String, ZkClientx> clients = MigrateMap.makeComputingMap(new Function<String, ZkClientx>()
|
||||
{
|
||||
private static Map<String, ZkClientx> clients = MigrateMap.makeComputingMap(new Function<String, ZkClientx>() {
|
||||
|
||||
public ZkClientx apply(String servers)
|
||||
{
|
||||
return new ZkClientx(servers);
|
||||
}
|
||||
});
|
||||
public ZkClientx apply(String servers) {
|
||||
return new ZkClientx(servers);
|
||||
}
|
||||
});
|
||||
|
||||
public static ZkClientx getZkClient(String servers) {
|
||||
return clients.get(servers);
|
||||
@@ -65,10 +62,12 @@ public class ZkClientx extends ZkClient {
|
||||
* Create a persistent Sequential node.
|
||||
*
|
||||
* @param path
|
||||
* @param createParents if true all parent dirs are created as well and no {@link ZkNodeExistsException} is thrown
|
||||
* in case the path already exists
|
||||
* @throws ZkInterruptedException if operation was interrupted, or a required reconnection got interrupted
|
||||
* @throws IllegalArgumentException if called from anything except the ZooKeeper event thread
|
||||
* @param createParents if true all parent dirs are created as well and no
|
||||
* {@link ZkNodeExistsException} is thrown in case the path already exists
|
||||
* @throws ZkInterruptedException if operation was interrupted, or a
|
||||
* required reconnection got interrupted
|
||||
* @throws IllegalArgumentException if called from anything except the
|
||||
* ZooKeeper event thread
|
||||
* @throws ZkException if any ZooKeeper exception occurred
|
||||
* @throws RuntimeException if any other exception occurs
|
||||
*/
|
||||
@@ -92,10 +91,12 @@ public class ZkClientx extends ZkClient {
|
||||
*
|
||||
* @param path
|
||||
* @param data
|
||||
* @param createParents if true all parent dirs are created as well and no {@link ZkNodeExistsException} is thrown
|
||||
* in case the path already exists
|
||||
* @throws ZkInterruptedException if operation was interrupted, or a required reconnection got interrupted
|
||||
* @throws IllegalArgumentException if called from anything except the ZooKeeper event thread
|
||||
* @param createParents if true all parent dirs are created as well and no
|
||||
* {@link ZkNodeExistsException} is thrown in case the path already exists
|
||||
* @throws ZkInterruptedException if operation was interrupted, or a
|
||||
* required reconnection got interrupted
|
||||
* @throws IllegalArgumentException if called from anything except the
|
||||
* ZooKeeper event thread
|
||||
* @throws ZkException if any ZooKeeper exception occurred
|
||||
* @throws RuntimeException if any other exception occurs
|
||||
*/
|
||||
@@ -121,10 +122,12 @@ public class ZkClientx extends ZkClient {
|
||||
*
|
||||
* @param path
|
||||
* @param data
|
||||
* @param createParents if true all parent dirs are created as well and no {@link ZkNodeExistsException} is thrown
|
||||
* in case the path already exists
|
||||
* @throws ZkInterruptedException if operation was interrupted, or a required reconnection got interrupted
|
||||
* @throws IllegalArgumentException if called from anything except the ZooKeeper event thread
|
||||
* @param createParents if true all parent dirs are created as well and no
|
||||
* {@link ZkNodeExistsException} is thrown in case the path already exists
|
||||
* @throws ZkInterruptedException if operation was interrupted, or a
|
||||
* required reconnection got interrupted
|
||||
* @throws IllegalArgumentException if called from anything except the
|
||||
* ZooKeeper event thread
|
||||
* @throws ZkException if any ZooKeeper exception occurred
|
||||
* @throws RuntimeException if any other exception occurs
|
||||
*/
|
||||
|
||||
@@ -15,8 +15,8 @@ import org.apache.zookeeper.ClientCnxn;
|
||||
import org.apache.zookeeper.CreateMode;
|
||||
import org.apache.zookeeper.KeeperException;
|
||||
import org.apache.zookeeper.Watcher;
|
||||
import org.apache.zookeeper.ZooKeeper;
|
||||
import org.apache.zookeeper.ZooDefs.Ids;
|
||||
import org.apache.zookeeper.ZooKeeper;
|
||||
import org.apache.zookeeper.ZooKeeper.States;
|
||||
import org.apache.zookeeper.client.ConnectStringParser;
|
||||
import org.apache.zookeeper.client.HostProvider;
|
||||
@@ -39,7 +39,7 @@ public class ZooKeeperx implements IZkConnection {
|
||||
private static final Field clientCnxnField = ReflectionUtils.findField(ZooKeeper.class, "cnxn");
|
||||
private static final Field hostProviderField = ReflectionUtils.findField(ClientCnxn.class, "hostProvider");
|
||||
private static final Field serverAddressesField = ReflectionUtils.findField(StaticHostProvider.class,
|
||||
"serverAddresses");
|
||||
"serverAddresses");
|
||||
private static final int DEFAULT_SESSION_TIMEOUT = 90000;
|
||||
|
||||
private ZooKeeper _zk = null;
|
||||
@@ -159,9 +159,8 @@ public class ZooKeeperx implements IZkConnection {
|
||||
// 强制获取zk中的地址信息
|
||||
ClientCnxn cnxn = (ClientCnxn) ReflectionUtils.getField(clientCnxnField, zk);
|
||||
HostProvider hostProvider = (HostProvider) ReflectionUtils.getField(hostProviderField, cnxn);
|
||||
List<InetSocketAddress> serverAddrs = (List<InetSocketAddress>) ReflectionUtils.getField(
|
||||
serverAddressesField,
|
||||
hostProvider);
|
||||
List<InetSocketAddress> serverAddrs = (List<InetSocketAddress>) ReflectionUtils.getField(serverAddressesField,
|
||||
hostProvider);
|
||||
// 添加第二组集群列表
|
||||
serverAddrs.addAll(new ConnectStringParser(cluster).getServerAddresses());
|
||||
}
|
||||
|
||||
@@ -120,8 +120,10 @@ public class ZookeeperPathUtils {
|
||||
}
|
||||
|
||||
public static String getBatchMarkWithIdPath(String destinationName, short clientId, Long batchId) {
|
||||
return MessageFormat.format(DESTINATION_CLIENTID_BATCH_MARK_WITH_ID_PATH, destinationName,
|
||||
String.valueOf(clientId), getBatchMarkNode(batchId));
|
||||
return MessageFormat.format(DESTINATION_CLIENTID_BATCH_MARK_WITH_ID_PATH,
|
||||
destinationName,
|
||||
String.valueOf(clientId),
|
||||
getBatchMarkNode(batchId));
|
||||
}
|
||||
|
||||
public static String getCursorPath(String destination, short clientId) {
|
||||
|
||||
@@ -11,7 +11,8 @@ import java.util.Map;
|
||||
public class ServerRunningMonitors {
|
||||
|
||||
private static ServerRunningData serverData;
|
||||
private static Map runningMonitors; // <String, ServerRunningMonitor>
|
||||
private static Map runningMonitors; // <String,
|
||||
// ServerRunningMonitor>
|
||||
|
||||
public static ServerRunningData getServerData() {
|
||||
return serverData;
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
package com.google.common.collect;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
public class MigrateMap
|
||||
{
|
||||
public static <K, V> ConcurrentMap<K, V> makeComputingMap(MapMaker maker, Function<? super K, ? extends V> computingFunction)
|
||||
{
|
||||
import com.google.common.base.Function;
|
||||
|
||||
public class MigrateMap {
|
||||
|
||||
public static <K, V> ConcurrentMap<K, V> makeComputingMap(MapMaker maker,
|
||||
Function<? super K, ? extends V> computingFunction) {
|
||||
return maker.makeComputingMap(computingFunction);
|
||||
}
|
||||
|
||||
public static <K, V> ConcurrentMap<K, V> makeComputingMap(Function<? super K, ? extends V> computingFunction)
|
||||
{
|
||||
public static <K, V> ConcurrentMap<K, V> makeComputingMap(Function<? super K, ? extends V> computingFunction) {
|
||||
return new MapMaker().makeComputingMap(computingFunction);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user