private void process(FixtureConfig fixtureConfig) { log.debug("Processing " + fixtureConfig); String sourceClassStr = fixtureConfig.getSourceClass(); String sourceProcessorClassStr = fixtureConfig.getSourceProcessorClass(); try { Class<?> sourceClassInst = Class.forName(sourceClassStr); IStatsSource source = (IStatsSource) sourceClassInst.newInstance(); Class<?> sourceProcClassInst = Class.forName(sourceProcessorClassStr); IStatsProcessor sourceProcessor = (IStatsProcessor) sourceProcClassInst.newInstance(); sourceProcessor.process(source); List<FixtureDTO> fixtures = sourceProcessor.getFixtures(); Collections.sort(fixtures, new FootballAPIComparator()); for (FixtureDTO fixtureDTO : fixtures) { Fixture match = fixtureRepo.findByMatchId(fixtureDTO.getMatchId()); if (match != null) { log.debug("Found same match. Updating the match id : [ " + match.getId() + " ]"); fixtureDTO.setId(match.getId()); } else { log.debug("Found new fixture. Creating a new match [ " + fixtureDTO + " ]"); } fixtureRepo.save(fixtureMapper.fixtureDTOToFixture(fixtureDTO)); } } catch (Exception e) { log.error("Error.. ", e); } }
@Override public void run() { while (continuePolling) { log.debug("Fixture processor processing started.."); List<FixtureConfig> configs = fixtureCfgRepo.findAll(); for (FixtureConfig fixtureConf : configs) { if (fixtureConf.getActive()) { process(fixtureConf); break; } } try { log.debug("Fixture processor is going to sleep for 4 seconds"); Thread.sleep(4500L); } catch (InterruptedException e) { } } log.debug("Fixture processor stopped"); }