|
12 | 12 | import com.netease.nim.camellia.hbase.CamelliaHBaseTemplate; |
13 | 13 | import com.netease.nim.camellia.hbase.conf.CamelliaHBaseConf; |
14 | 14 | import com.netease.nim.camellia.hbase.connection.CamelliaHBaseConnectionFactory; |
| 15 | +import com.netease.nim.camellia.hbase.exception.CamelliaHBaseException; |
15 | 16 | import com.netease.nim.camellia.hbase.resource.HBaseResource; |
| 17 | +import com.netease.nim.camellia.hbase.resource.HBaseTemplateResourceTableUpdater; |
16 | 18 | import com.netease.nim.camellia.hbase.util.CamelliaHBaseInitUtil; |
17 | 19 | import com.netease.nim.camellia.hbase.util.HBaseResourceUtil; |
18 | 20 | import com.netease.nim.camellia.tools.utils.FileUtils; |
| 21 | +import org.slf4j.Logger; |
| 22 | +import org.slf4j.LoggerFactory; |
19 | 23 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; |
20 | 24 | import org.springframework.boot.context.properties.EnableConfigurationProperties; |
21 | 25 | import org.springframework.context.annotation.Bean; |
|
31 | 35 | @EnableConfigurationProperties({CamelliaHBaseProperties.class}) |
32 | 36 | public class CamelliaHBaseConfiguration { |
33 | 37 |
|
| 38 | + private static final Logger logger = LoggerFactory.getLogger(CamelliaHBaseConfiguration.class); |
| 39 | + |
34 | 40 | @Bean |
35 | 41 | @ConditionalOnMissingBean(value = {ProxyEnv.class}) |
36 | 42 | public ProxyEnv proxyEnv() { |
@@ -122,8 +128,38 @@ public CamelliaHBaseTemplate hBaseTemplate(CamelliaHBaseProperties properties) { |
122 | 128 | throw new IllegalArgumentException("only support xml/yml"); |
123 | 129 | } |
124 | 130 | return new CamelliaHBaseTemplate(env, camelliaApi, remote.getBid(), remote.getBgroup(), remote.isMonitor(), remote.getCheckIntervalMillis()); |
| 131 | + } else if (type == CamelliaHBaseProperties.Type.CUSTOM) { |
| 132 | + CamelliaHBaseProperties.Custom custom = properties.getCustom(); |
| 133 | + String className = custom.getResourceTableUpdaterClassName(); |
| 134 | + if (className == null) { |
| 135 | + throw new IllegalArgumentException("resourceTableUpdaterClassName missing"); |
| 136 | + } |
| 137 | + HBaseTemplateResourceTableUpdater updater; |
| 138 | + try { |
| 139 | + Class<?> clazz; |
| 140 | + try { |
| 141 | + clazz = Class.forName(className); |
| 142 | + } catch (ClassNotFoundException e) { |
| 143 | + clazz = Thread.currentThread().getContextClassLoader().loadClass(className); |
| 144 | + } |
| 145 | + updater = (HBaseTemplateResourceTableUpdater) clazz.getConstructor().newInstance(); |
| 146 | + logger.info("HBaseTemplateResourceTableUpdater init success, class = {}", className); |
| 147 | + } catch (Exception e) { |
| 148 | + logger.error("HBaseTemplateResourceTableUpdater init error, class = {}", className, e); |
| 149 | + throw new CamelliaHBaseException(e); |
| 150 | + } |
| 151 | + Map<String, String> conf = custom.getConf(); |
| 152 | + CamelliaHBaseConf camelliaHBaseConf = new CamelliaHBaseConf(); |
| 153 | + for (Map.Entry<String, String> entry : conf.entrySet()) { |
| 154 | + camelliaHBaseConf.addConf(entry.getKey(), entry.getValue()); |
| 155 | + } |
| 156 | + CamelliaHBaseEnv env = new CamelliaHBaseEnv.Builder() |
| 157 | + .connectionFactory(new CamelliaHBaseConnectionFactory.DefaultHBaseConnectionFactory(camelliaHBaseConf)) |
| 158 | + .proxyEnv(proxyEnv()) |
| 159 | + .build(); |
| 160 | + return new CamelliaHBaseTemplate(env, updater); |
125 | 161 | } else { |
126 | | - throw new IllegalArgumentException("only support local/remote"); |
| 162 | + throw new IllegalArgumentException("only support local/remote/custom"); |
127 | 163 | } |
128 | 164 | } |
129 | 165 | } |
0 commit comments