Search in sources :

Example 1 with DataGapRouteReader

use of org.jumpmind.symmetric.route.DataGapRouteReader in project symmetric-ds by JumpMind.

the class RouterService method startReading.

protected IDataToRouteReader startReading(ChannelRouterContext context) {
    IDataToRouteReader reader = new DataGapRouteReader(context, engine);
    if (parameterService.is(ParameterConstants.SYNCHRONIZE_ALL_JOBS)) {
        reader.run();
    } else {
        if (readThread == null) {
            readThread = Executors.newCachedThreadPool(new ThreadFactory() {

                final AtomicInteger threadNumber = new AtomicInteger(1);

                final String namePrefix = parameterService.getEngineName().toLowerCase() + "-router-reader-";

                public Thread newThread(Runnable r) {
                    Thread t = new Thread(r);
                    t.setName(namePrefix + threadNumber.getAndIncrement());
                    if (t.isDaemon()) {
                        t.setDaemon(false);
                    }
                    if (t.getPriority() != Thread.NORM_PRIORITY) {
                        t.setPriority(Thread.NORM_PRIORITY);
                    }
                    return t;
                }
            });
        }
        readThread.execute(reader);
    }
    return reader;
}
Also used : IDataToRouteReader(org.jumpmind.symmetric.route.IDataToRouteReader) DataGapRouteReader(org.jumpmind.symmetric.route.DataGapRouteReader) ThreadFactory(java.util.concurrent.ThreadFactory) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 2 with DataGapRouteReader

use of org.jumpmind.symmetric.route.DataGapRouteReader in project symmetric-ds by JumpMind.

the class AbstractRouterServiceTest method testDontSelectOldDataDuringRouting.

public void testDontSelectOldDataDuringRouting() throws Exception {
    NodeChannel testChannel = getConfigurationService().getNodeChannel(TestConstants.TEST_CHANNEL_ID, false);
    testChannel.setUseOldDataToRoute(false);
    testChannel.setMaxBatchSize(50);
    testChannel.setBatchAlgorithm("nontransactional");
    getConfigurationService().saveChannel(testChannel, true);
    TriggerRouter trigger = getTestRoutingTableTrigger(TEST_TABLE_1);
    trigger.getRouter().setRouterType("column");
    trigger.getRouter().setRouterExpression("ROUTING_VARCHAR=:NODE_ID");
    getTriggerRouterService().saveTriggerRouter(trigger);
    // clean setup
    deleteAll(TEST_TABLE_1);
    insert(TEST_TABLE_1, 100, true);
    getRouterService().routeData(true);
    resetBatches();
    // delete
    deleteAll(TEST_TABLE_1);
    ISqlTransaction transaction = getSqlTemplate().startSqlTransaction();
    ChannelRouterContext context = new ChannelRouterContext(TestConstants.TEST_ROOT_EXTERNAL_ID, testChannel, transaction);
    context.setDataGaps(engine.getDataService().findDataGaps());
    DataGapRouteReader reader = new DataGapRouteReader(context, engine);
    reader.run();
    List<Data> list = new ArrayList<Data>();
    do {
        Data data = reader.take();
        if (data != null) {
            list.add(data);
        } else {
            break;
        }
    } while (true);
    transaction.close();
    Assert.assertEquals(100, list.size());
    for (Data data : list) {
        Assert.assertNull(data.toParsedOldData());
        Assert.assertNotNull(data.toParsedPkData());
    }
}
Also used : DataGapRouteReader(org.jumpmind.symmetric.route.DataGapRouteReader) ISqlTransaction(org.jumpmind.db.sql.ISqlTransaction) ChannelRouterContext(org.jumpmind.symmetric.route.ChannelRouterContext) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) ArrayList(java.util.ArrayList) Data(org.jumpmind.symmetric.model.Data) NodeChannel(org.jumpmind.symmetric.model.NodeChannel)

Aggregations

DataGapRouteReader (org.jumpmind.symmetric.route.DataGapRouteReader)2 ArrayList (java.util.ArrayList)1 ThreadFactory (java.util.concurrent.ThreadFactory)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ISqlTransaction (org.jumpmind.db.sql.ISqlTransaction)1 Data (org.jumpmind.symmetric.model.Data)1 NodeChannel (org.jumpmind.symmetric.model.NodeChannel)1 TriggerRouter (org.jumpmind.symmetric.model.TriggerRouter)1 ChannelRouterContext (org.jumpmind.symmetric.route.ChannelRouterContext)1 IDataToRouteReader (org.jumpmind.symmetric.route.IDataToRouteReader)1