com.alibaba.otter.canal.server.embedded.CanalServerWithEmbedded Java Examples

The following examples show how to use com.alibaba.otter.canal.server.embedded.CanalServerWithEmbedded. 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: CanalAdminController.java    From canal with Apache License 2.0 6 votes vote down vote up
@Override
public String getRunningInstances() {
    try {
        Map<String, CanalInstance> instances = CanalServerWithEmbedded.instance().getCanalInstances();
        List<String> runningInstances = new ArrayList<String>();
        instances.forEach((destination, instance) -> {
            if (instance.isStart()) {
                runningInstances.add(destination);
            }
        });

        return Joiner.on(",").join(runningInstances);
    } catch (Throwable e) {
        logger.error(e.getMessage(), e);
    }
    return "";
}
 
Example #2
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 #3
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 #4
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 #5
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 #6
Source File: SessionHandler.java    From canal with Apache License 2.0 4 votes vote down vote up
public SessionHandler(CanalServerWithEmbedded embeddedServer){
    this.embeddedServer = embeddedServer;
}
 
Example #7
Source File: CanalMQStarter.java    From canal with Apache License 2.0 4 votes vote down vote up
public synchronized void start(String destinations) {
    try {
        if (running) {
            return;
        }
        mqProperties = canalMQProducer.getMqProperties();
        // set filterTransactionEntry
        if (mqProperties.isFilterTransactionEntry()) {
            System.setProperty("canal.instance.filter.transaction.entry", "true");
        }

        canalServer = CanalServerWithEmbedded.instance();

        // 对应每个instance启动一个worker线程
        executorService = Executors.newCachedThreadPool();
        logger.info("## start the MQ workers.");

        String[] dsts = StringUtils.split(destinations, ",");
        for (String destination : dsts) {
            destination = destination.trim();
            CanalMQRunnable canalMQRunnable = new CanalMQRunnable(destination);
            canalMQWorks.put(destination, canalMQRunnable);
            executorService.execute(canalMQRunnable);
        }

        running = true;
        logger.info("## the MQ workers is running now ......");

        shutdownThread = new Thread() {

            public void run() {
                try {
                    logger.info("## stop the MQ workers");
                    running = false;
                    executorService.shutdown();
                    canalMQProducer.stop();
                } catch (Throwable e) {
                    logger.warn("##something goes wrong when stopping MQ workers:", e);
                } finally {
                    logger.info("## canal MQ is down.");
                }
            }

        };

        Runtime.getRuntime().addShutdownHook(shutdownThread);
    } catch (Throwable e) {
        logger.error("## Something goes wrong when starting up the canal MQ workers:", e);
    }
}
 
Example #8
Source File: CanalServerWithNetty.java    From canal with Apache License 2.0 4 votes vote down vote up
public void setEmbeddedServer(CanalServerWithEmbedded embeddedServer) {
    this.embeddedServer = embeddedServer;
}
 
Example #9
Source File: CanalServerWithNetty.java    From canal with Apache License 2.0 4 votes vote down vote up
private CanalServerWithNetty(){
    this.embeddedServer = CanalServerWithEmbedded.instance();
    this.childGroups = new DefaultChannelGroup();
}
 
Example #10
Source File: ClientAuthenticationHandler.java    From canal with Apache License 2.0 4 votes vote down vote up
public void setEmbeddedServer(CanalServerWithEmbedded embeddedServer) {
    this.embeddedServer = embeddedServer;
}
 
Example #11
Source File: ClientAuthenticationHandler.java    From canal with Apache License 2.0 4 votes vote down vote up
public ClientAuthenticationHandler(CanalServerWithEmbedded embeddedServer){
    this.embeddedServer = embeddedServer;
}
 
Example #12
Source File: SessionHandler.java    From canal with Apache License 2.0 4 votes vote down vote up
public void setEmbeddedServer(CanalServerWithEmbedded embeddedServer) {
    this.embeddedServer = embeddedServer;
}
 
Example #13
Source File: SessionHandler.java    From canal-1.1.3 with Apache License 2.0 4 votes vote down vote up
public SessionHandler(CanalServerWithEmbedded embeddedServer){
    this.embeddedServer = embeddedServer;
}
 
Example #14
Source File: CanalMQStarter.java    From canal-1.1.3 with Apache License 2.0 4 votes vote down vote up
public synchronized void start(MQProperties properties) {
    try {
        if (running) {
            return;
        }
        this.properties = properties;
        canalMQProducer.init(properties);
        // set filterTransactionEntry
        if (properties.isFilterTransactionEntry()) {
            System.setProperty("canal.instance.filter.transaction.entry", "true");
        }

        canalServer = CanalServerWithEmbedded.instance();

        // 对应每个instance启动一个worker线程
        executorService = Executors.newCachedThreadPool();
        logger.info("## start the MQ workers.");

        String[] destinations = StringUtils.split(System.getProperty("canal.destinations"), ",");
        for (String destination : destinations) {
            destination = destination.trim();
            CanalMQRunnable canalMQRunnable = new CanalMQRunnable(destination);
            canalMQWorks.put(destination, canalMQRunnable);
            executorService.execute(canalMQRunnable);
        }

        running = true;
        logger.info("## the MQ workers is running now ......");

        shutdownThread = new Thread() {

            public void run() {
                try {
                    logger.info("## stop the MQ workers");
                    running = false;
                    executorService.shutdown();
                    canalMQProducer.stop();
                } catch (Throwable e) {
                    logger.warn("##something goes wrong when stopping MQ workers:", e);
                } finally {
                    logger.info("## canal MQ is down.");
                }
            }

        };

        Runtime.getRuntime().addShutdownHook(shutdownThread);
    } catch (Throwable e) {
        logger.error("## Something goes wrong when starting up the canal MQ workers:", e);
    }
}
 
Example #15
Source File: CanalServerWithNetty.java    From canal-1.1.3 with Apache License 2.0 4 votes vote down vote up
public void setEmbeddedServer(CanalServerWithEmbedded embeddedServer) {
    this.embeddedServer = embeddedServer;
}
 
Example #16
Source File: CanalServerWithNetty.java    From canal-1.1.3 with Apache License 2.0 4 votes vote down vote up
private CanalServerWithNetty(){
    this.embeddedServer = CanalServerWithEmbedded.instance();
    this.childGroups = new DefaultChannelGroup();
}
 
Example #17
Source File: ClientAuthenticationHandler.java    From canal-1.1.3 with Apache License 2.0 4 votes vote down vote up
public void setEmbeddedServer(CanalServerWithEmbedded embeddedServer) {
    this.embeddedServer = embeddedServer;
}
 
Example #18
Source File: ClientAuthenticationHandler.java    From canal-1.1.3 with Apache License 2.0 4 votes vote down vote up
public ClientAuthenticationHandler(CanalServerWithEmbedded embeddedServer){
    this.embeddedServer = embeddedServer;
}
 
Example #19
Source File: SessionHandler.java    From canal-1.1.3 with Apache License 2.0 4 votes vote down vote up
public void setEmbeddedServer(CanalServerWithEmbedded embeddedServer) {
    this.embeddedServer = embeddedServer;
}