com.alibaba.otter.canal.instance.core.CanalInstanceGenerator Java Examples

The following examples show how to use com.alibaba.otter.canal.instance.core.CanalInstanceGenerator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CanalServerWithNettyTest.java    From canal-1.1.3 with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
    CanalServerWithEmbedded embeddedServer = new CanalServerWithEmbedded();
    embeddedServer.setCanalInstanceGenerator(new CanalInstanceGenerator() {

        public CanalInstance generate(String destination) {
            Canal canal = buildCanal();
            return new CanalInstanceWithManager(canal, FILTER);
        }
    });

    nettyServer = CanalServerWithNetty.instance();
    nettyServer.setEmbeddedServer(embeddedServer);
    nettyServer.setPort(1088);
    nettyServer.start();
}
 
Example #2
Source File: SpringCanalInstanceGenerator.java    From canal with Apache License 2.0 6 votes vote down vote up
public CanalInstance generate(String destination) {
    synchronized (CanalInstanceGenerator.class) {
        try {
            // 设置当前正在加载的通道,加载spring查找文件时会用到该变量
            System.setProperty("canal.instance.destination", destination);
            this.beanFactory = getBeanFactory(springXml);
            String beanName = destination;
            if (!beanFactory.containsBean(beanName)) {
                beanName = defaultName;
            }

            return (CanalInstance) beanFactory.getBean(beanName);
        } catch (Throwable e) {
            logger.error("generator instance failed.", e);
            throw new CanalException(e);
        } finally {
            System.setProperty("canal.instance.destination", "");
        }
    }
}
 
Example #3
Source File: CanalServerTest.java    From canal with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
    CanalServerWithEmbedded embeddedServer = new CanalServerWithEmbedded();
    embeddedServer.setCanalInstanceGenerator(new CanalInstanceGenerator() {

        public CanalInstance generate(String destination) {
            Canal canal = buildCanal();
            return new CanalInstanceWithManager(canal, FILTER);
        }
    });

    nettyServer = CanalServerWithNetty.instance();
    nettyServer.setEmbeddedServer(embeddedServer);
    nettyServer.setPort(1088);
    nettyServer.start();
}
 
Example #4
Source File: MemorySpringInstanceTest.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
@Test
public void testInstance() {
    CanalInstanceGenerator generator = (CanalInstanceGenerator) context.getBean("canalInstanceGenerator");
    CanalInstance canalInstance = generator.generate("instance");
    Assert.notNull(canalInstance);

    canalInstance.start();
    try {
        Thread.sleep(10 * 1000);
    } catch (InterruptedException e) {
    }
    canalInstance.stop();
}
 
Example #5
Source File: GroupSpringInstanceTest.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
@Test
public void testInstance() {
    CanalInstanceGenerator generator = (CanalInstanceGenerator) context.getBean("canalInstanceGenerator");
    CanalInstance canalInstance = generator.generate("instance");
    Assert.notNull(canalInstance);

    canalInstance.start();
    try {
        Thread.sleep(10 * 1000);
    } catch (InterruptedException e) {
    }
    canalInstance.stop();
}
 
Example #6
Source File: DefaultSpringInstanceTest.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
@Test
public void testInstance() {
    CanalInstanceGenerator generator = (CanalInstanceGenerator) context.getBean("canalInstanceGenerator");
    CanalInstance canalInstance = generator.generate("instance");
    Assert.notNull(canalInstance);

    canalInstance.start();
    try {
        Thread.sleep(10 * 1000);
    } catch (InterruptedException e) {
    }
    canalInstance.stop();
}
 
Example #7
Source File: BaseCanalServerWithEmbededTest.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    server = CanalServerWithEmbedded.instance();
    server.setCanalInstanceGenerator(new CanalInstanceGenerator() {

        public CanalInstance generate(String destination) {
            Canal canal = buildCanal();
            return new CanalInstanceWithManager(canal, FILTER);
        }
    });
    server.start();
    server.start(DESTINATION);
}
 
Example #8
Source File: MemorySpringInstanceTest.java    From canal with Apache License 2.0 5 votes vote down vote up
@Test
public void testInstance() {
    CanalInstanceGenerator generator = (CanalInstanceGenerator) context.getBean("canalInstanceGenerator");
    CanalInstance canalInstance = generator.generate("instance");
    Assert.notNull(canalInstance);

    canalInstance.start();
    try {
        Thread.sleep(10 * 1000);
    } catch (InterruptedException e) {
    }
    canalInstance.stop();
}
 
Example #9
Source File: GroupSpringInstanceTest.java    From canal with Apache License 2.0 5 votes vote down vote up
@Test
public void testInstance() {
    CanalInstanceGenerator generator = (CanalInstanceGenerator) context.getBean("canalInstanceGenerator");
    CanalInstance canalInstance = generator.generate("instance");
    Assert.notNull(canalInstance);

    canalInstance.start();
    try {
        Thread.sleep(10 * 1000);
    } catch (InterruptedException e) {
    }
    canalInstance.stop();
}
 
Example #10
Source File: DefaultSpringInstanceTest.java    From canal with Apache License 2.0 5 votes vote down vote up
@Test
public void testInstance() {
    CanalInstanceGenerator generator = (CanalInstanceGenerator) context.getBean("canalInstanceGenerator");
    CanalInstance canalInstance = generator.generate("instance");
    Assert.notNull(canalInstance);

    canalInstance.start();
    try {
        Thread.sleep(10 * 1000);
    } catch (InterruptedException e) {
    }
    canalInstance.stop();
}
 
Example #11
Source File: PlainCanalInstanceGenerator.java    From canal with Apache License 2.0 5 votes vote down vote up
public CanalInstance generate(String destination) {
    synchronized (CanalInstanceGenerator.class) {
        try {
            PlainCanal canal = canalConfigClient.findInstance(destination, null);
            if (canal == null) {
                throw new CanalException("instance : " + destination + " config is not found");
            }
            Properties properties = canal.getProperties();
            // merge local
            properties.putAll(canalConfig);

            // 设置动态properties,替换掉本地properties
            com.alibaba.otter.canal.instance.spring.support.PropertyPlaceholderConfigurer.propertiesLocal.set(properties);
            // 设置当前正在加载的通道,加载spring查找文件时会用到该变量
            System.setProperty("canal.instance.destination", destination);
            this.beanFactory = getBeanFactory(springXml);
            String beanName = destination;
            if (!beanFactory.containsBean(beanName)) {
                beanName = defaultName;
            }

            return (CanalInstance) beanFactory.getBean(beanName);
        } catch (Throwable e) {
            logger.error("generator instance failed.", e);
            throw new CanalException(e);
        } finally {
            System.setProperty("canal.instance.destination", "");
        }
    }
}
 
Example #12
Source File: BaseCanalServerWithEmbededTest.java    From canal with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    server = CanalServerWithEmbedded.instance();
    server.setCanalInstanceGenerator(new CanalInstanceGenerator() {

        public CanalInstance generate(String destination) {
            Canal canal = buildCanal();
            return new CanalInstanceWithManager(canal, FILTER);
        }
    });
    server.start();
    server.start(DESTINATION);
}
 
Example #13
Source File: CanalServerWithEmbedded.java    From canal-1.1.3 with Apache License 2.0 4 votes vote down vote up
public void setCanalInstanceGenerator(CanalInstanceGenerator canalInstanceGenerator) {
    this.canalInstanceGenerator = canalInstanceGenerator;
}
 
Example #14
Source File: CanalServerWithEmbedded.java    From canal with Apache License 2.0 4 votes vote down vote up
public void setCanalInstanceGenerator(CanalInstanceGenerator canalInstanceGenerator) {
    this.canalInstanceGenerator = canalInstanceGenerator;
}