mirror of
https://github.com/alibaba/canal.git
synced 2026-11-04 00:30:15 +08:00
rdb专用的的ClassExtensionLoader,默认canal client logger example配置
This commit is contained in:
@@ -40,6 +40,8 @@ public class ExtensionLoader<T> {
|
|||||||
|
|
||||||
private static final ConcurrentMap<Class<?>, Object> EXTENSION_INSTANCES = new ConcurrentHashMap<>();
|
private static final ConcurrentMap<Class<?>, Object> EXTENSION_INSTANCES = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
private static final ConcurrentMap<String, Object> EXTENSION_KEY_INSTANCES = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
private final Class<?> type;
|
private final Class<?> type;
|
||||||
|
|
||||||
private final String classLoaderPolicy;
|
private final String classLoaderPolicy;
|
||||||
@@ -116,6 +118,30 @@ public class ExtensionLoader<T> {
|
|||||||
return (T) instance;
|
return (T) instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public T getExtension(String name, String key) {
|
||||||
|
if (name == null || name.length() == 0) throw new IllegalArgumentException("Extension name == null");
|
||||||
|
if ("true".equals(name)) {
|
||||||
|
return getDefaultExtension();
|
||||||
|
}
|
||||||
|
Holder<Object> holder = cachedInstances.get(name + "-" + key);
|
||||||
|
if (holder == null) {
|
||||||
|
cachedInstances.putIfAbsent(name + "-" + key, new Holder<>());
|
||||||
|
holder = cachedInstances.get(name + "-" + key);
|
||||||
|
}
|
||||||
|
Object instance = holder.get();
|
||||||
|
if (instance == null) {
|
||||||
|
synchronized (holder) {
|
||||||
|
instance = holder.get();
|
||||||
|
if (instance == null) {
|
||||||
|
instance = createExtension(name, key);
|
||||||
|
holder.set(instance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (T) instance;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回缺省的扩展,如果没有设置则返回<code>null</code>
|
* 返回缺省的扩展,如果没有设置则返回<code>null</code>
|
||||||
*/
|
*/
|
||||||
@@ -149,14 +175,19 @@ public class ExtensionLoader<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public T newInstance(String name) {
|
private T createExtension(String name, String key) {
|
||||||
Class<?> clazz = getExtensionClasses().get(name);
|
Class<?> clazz = getExtensionClasses().get(name);
|
||||||
if (clazz == null) {
|
if (clazz == null) {
|
||||||
throw new IllegalStateException("Extension instance(name: " + name + ", class: " + type
|
throw new IllegalStateException("Extension instance(name: " + name + ", class: " + type
|
||||||
+ ") could not be instantiated: class could not be found");
|
+ ") could not be instantiated: class could not be found");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return (T) clazz.newInstance();
|
T instance = (T) EXTENSION_KEY_INSTANCES.get(name + "-" + key);
|
||||||
|
if (instance == null) {
|
||||||
|
EXTENSION_KEY_INSTANCES.putIfAbsent(name + "-" + key, clazz.newInstance());
|
||||||
|
instance = (T) EXTENSION_KEY_INSTANCES.get(name + "-" + key);
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
throw new IllegalStateException("Extension instance(name: " + name + ", class: " + type
|
throw new IllegalStateException("Extension instance(name: " + name + ", class: " + type
|
||||||
+ ") could not be instantiated: " + t.getMessage(),
|
+ ") could not be instantiated: " + t.getMessage(),
|
||||||
@@ -164,6 +195,24 @@ public class ExtensionLoader<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
// public T newInstance(String name) {
|
||||||
|
// Class<?> clazz = getExtensionClasses().get(name);
|
||||||
|
// if (clazz == null) {
|
||||||
|
// throw new IllegalStateException("Extension instance(name: " + name + ",
|
||||||
|
// class: " + type
|
||||||
|
// + ") could not be instantiated: class could not be found");
|
||||||
|
// }
|
||||||
|
// try {
|
||||||
|
// return (T) clazz.newInstance();
|
||||||
|
// } catch (Throwable t) {
|
||||||
|
// throw new IllegalStateException("Extension instance(name: " + name + ",
|
||||||
|
// class: " + type
|
||||||
|
// + ") could not be instantiated: " + t.getMessage(),
|
||||||
|
// t);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
private Map<String, Class<?>> getExtensionClasses() {
|
private Map<String, Class<?>> getExtensionClasses() {
|
||||||
Map<String, Class<?>> classes = cachedClasses.get();
|
Map<String, Class<?>> classes = cachedClasses.get();
|
||||||
if (classes == null) {
|
if (classes == null) {
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
</fileSet>
|
</fileSet>
|
||||||
<fileSet>
|
<fileSet>
|
||||||
<directory>./src/main/resources</directory>
|
<directory>./src/main/resources</directory>
|
||||||
<outputDirectory>/config</outputDirectory>
|
<outputDirectory>/conf</outputDirectory>
|
||||||
<includes>
|
<includes>
|
||||||
<include>**/*</include>
|
<include>**/*</include>
|
||||||
|
|
||||||
@@ -31,21 +31,21 @@
|
|||||||
</fileSet>
|
</fileSet>
|
||||||
<fileSet>
|
<fileSet>
|
||||||
<directory>../elasticsearch/src/main/resources/es</directory>
|
<directory>../elasticsearch/src/main/resources/es</directory>
|
||||||
<outputDirectory>/config/es</outputDirectory>
|
<outputDirectory>/conf/es</outputDirectory>
|
||||||
<includes>
|
<includes>
|
||||||
<include>**/*</include>
|
<include>**/*</include>
|
||||||
</includes>
|
</includes>
|
||||||
</fileSet>
|
</fileSet>
|
||||||
<fileSet>
|
<fileSet>
|
||||||
<directory>../hbase/src/main/resources/hbase</directory>
|
<directory>../hbase/src/main/resources/hbase</directory>
|
||||||
<outputDirectory>/config/hbase</outputDirectory>
|
<outputDirectory>/conf/hbase</outputDirectory>
|
||||||
<includes>
|
<includes>
|
||||||
<include>**/*</include>
|
<include>**/*</include>
|
||||||
</includes>
|
</includes>
|
||||||
</fileSet>
|
</fileSet>
|
||||||
<fileSet>
|
<fileSet>
|
||||||
<directory>../rdb/src/main/resources/</directory>
|
<directory>../rdb/src/main/resources/</directory>
|
||||||
<outputDirectory>/config</outputDirectory>
|
<outputDirectory>/conf</outputDirectory>
|
||||||
<excludes>
|
<excludes>
|
||||||
<exclude>META-INF/**</exclude>
|
<exclude>META-INF/**</exclude>
|
||||||
</excludes>
|
</excludes>
|
||||||
|
|||||||
@@ -10,8 +10,6 @@ case "`uname`" in
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
base=${bin_abs_path}/..
|
base=${bin_abs_path}/..
|
||||||
#canal_conf=$base/config/canal.properties
|
|
||||||
#logback_configurationFile=$base/conf/logback.xml
|
|
||||||
export LANG=en_US.UTF-8
|
export LANG=en_US.UTF-8
|
||||||
export BASE=$base
|
export BASE=$base
|
||||||
|
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ public class CanalAdapterLoader {
|
|||||||
try {
|
try {
|
||||||
OuterAdapter adapter;
|
OuterAdapter adapter;
|
||||||
if ("rdb".equalsIgnoreCase(config.getName())) {
|
if ("rdb".equalsIgnoreCase(config.getName())) {
|
||||||
adapter = loader.newInstance(config.getName());
|
adapter = loader.getExtension(config.getName(), config.getKey());
|
||||||
} else {
|
} else {
|
||||||
adapter = loader.getExtension(config.getName());
|
adapter = loader.getExtension(config.getName());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,16 +11,16 @@ spring:
|
|||||||
time-zone: GMT+8
|
time-zone: GMT+8
|
||||||
default-property-inclusion: non_null
|
default-property-inclusion: non_null
|
||||||
|
|
||||||
#canal.conf:
|
canal.conf:
|
||||||
# canalServerHost: 127.0.0.1:11111
|
canalServerHost: 127.0.0.1:11111
|
||||||
# zookeeperHosts: slave1:2181
|
# zookeeperHosts: slave1:2181
|
||||||
# bootstrapServers: slave1:6667 #or rocketmq
|
# bootstrapServers: slave1:6667 #or rocketmq
|
||||||
# flatMessage: true
|
# flatMessage: true
|
||||||
# canalInstances:
|
canalInstances:
|
||||||
# - instance: example
|
- instance: example
|
||||||
# groups:
|
groups:
|
||||||
# - outAdapters:
|
- outAdapters:
|
||||||
# - name: logger
|
- name: logger
|
||||||
# - name: rdb
|
# - name: rdb
|
||||||
# key: oracle1
|
# key: oracle1
|
||||||
# properties:
|
# properties:
|
||||||
|
|||||||
Reference in New Issue
Block a user