@Test public void testAddDomainLinks() throws Exception { List<DomainLink> domainLinks = new ArrayList<>(); DomainURL domain1 = new DomainURL("d1", "n1"); domainLinks.add(new DomainLink(domain1, new SimpleURL("url1", "n1", "new"))); domainLinks.add(new DomainLink(domain1, new SimpleURL("url2", "n2", "new"))); DomainURL domain2 = new DomainURL("d2", "n2"); domainLinks.add(new DomainLink(domain2, new SimpleURL("url3", "n1", "new"))); domainLinks.add(new DomainLink(domain2, new SimpleURL("url4", "n2", "new"))); service.addDomainLinks(domainLinks); assertEquals(4, urlRepo.count()); assertEquals(2, domainRepo.count()); }
@Override public void addDomainLinks(List<DomainLink> domainLinks) { final Timer.Context context = domainLinksTimer.time(); try { Map<String, DomainURL> domainURLs = new HashMap<>(); Map<String, Set<String>> simpleURLs = new HashMap<>(); String status = null; for (DomainLink domainLink : domainLinks) { String domain = domainLink.getDomainURL().getAddress(); domainURLs.put(domain, domainLink.getDomainURL()); Set<String> urls = simpleURLs.get(domain); if (urls == null) { urls = new HashSet<>(); simpleURLs.put(domain, urls); } SimpleURL simpleURL = domainLink.getSimpleURL(); status = simpleURL.getStatus(); urls.add(simpleURL.getUrl()); } for (DomainURL domainURL : domainURLs.values()) { addDomainUrl(domainURL.getName(), domainURL.getAddress(), domainURL.getCoolDownPeriod()); } for (Map.Entry<String, Set<String>> entry : simpleURLs.entrySet()) { DomainURL domainURL = domainURLs.get(entry.getKey()); addSimpleUrls(new ArrayList<>(entry.getValue()), status, domainURL.getAddress(), null ); } } finally { context.stop(); } }
MongoUrlServiceImpl implements UrlService { @Override public void addDomainLinks(List<DomainLink> domainLinks) { final Timer.Context context = domainLinksTimer.time(); try { Map<String, DomainURL> domainURLs = new HashMap<>(); Map<String, Set<String>> simpleURLs = new HashMap<>(); String status = null; for (DomainLink domainLink : domainLinks) { String domain = domainLink.getDomainURL().getAddress(); domainURLs.put(domain, domainLink.getDomainURL()); Set<String> urls = simpleURLs.get(domain); if (urls == null) { urls = new HashSet<>(); simpleURLs.put(domain, urls); } SimpleURL simpleURL = domainLink.getSimpleURL(); status = simpleURL.getStatus(); urls.add(simpleURL.getUrl()); } for (DomainURL domainURL : domainURLs.values()) { addDomainUrl(domainURL.getName(), domainURL.getAddress(), domainURL.getCoolDownPeriod()); } for (Map.Entry<String, Set<String>> entry : simpleURLs.entrySet()) { DomainURL domainURL = domainURLs.get(entry.getKey()); addSimpleUrls(new ArrayList<>(entry.getValue()), status, domainURL.getAddress(), null ); } } finally { context.stop(); } } }
MongoUrlServiceImpl implements UrlService { @Override public void addDomainLinks(List<DomainLink> domainLinks) { final Timer.Context context = domainLinksTimer.time(); try { Map<String, DomainURL> domainURLs = new HashMap<>(); Map<String, Set<String>> simpleURLs = new HashMap<>(); String status = null; for (DomainLink domainLink : domainLinks) { String domain = domainLink.getDomainURL().getAddress(); domainURLs.put(domain, domainLink.getDomainURL()); Set<String> urls = simpleURLs.get(domain); if (urls == null) { urls = new HashSet<>(); simpleURLs.put(domain, urls); } SimpleURL simpleURL = domainLink.getSimpleURL(); status = simpleURL.getStatus(); urls.add(simpleURL.getUrl()); } for (DomainURL domainURL : domainURLs.values()) { addDomainUrl(domainURL.getName(), domainURL.getAddress(), domainURL.getCoolDownPeriod()); } for (Map.Entry<String, Set<String>> entry : simpleURLs.entrySet()) { DomainURL domainURL = domainURLs.get(entry.getKey()); addSimpleUrls(new ArrayList<>(entry.getValue()), status, domainURL.getAddress(), null ); } } finally { context.stop(); } }  }
MongoUrlServiceImpl implements UrlService { @Override public void addDomainLinks(List<DomainLink> domainLinks) { final Timer.Context context = domainLinksTimer.time(); try { Map<String, DomainURL> domainURLs = new HashMap<>(); Map<String, Set<String>> simpleURLs = new HashMap<>(); String status = null; for (DomainLink domainLink : domainLinks) { String domain = domainLink.getDomainURL().getAddress(); domainURLs.put(domain, domainLink.getDomainURL()); Set<String> urls = simpleURLs.get(domain); if (urls == null) { urls = new HashSet<>(); simpleURLs.put(domain, urls); } SimpleURL simpleURL = domainLink.getSimpleURL(); status = simpleURL.getStatus(); urls.add(simpleURL.getUrl()); } for (DomainURL domainURL : domainURLs.values()) { addDomainUrl(domainURL.getName(), domainURL.getAddress(), domainURL.getCoolDownPeriod()); } for (Map.Entry<String, Set<String>> entry : simpleURLs.entrySet()) { DomainURL domainURL = domainURLs.get(entry.getKey()); addSimpleUrls(new ArrayList<>(entry.getValue()), status, domainURL.getAddress(), null ); } } finally { context.stop(); } }  @PostConstruct void init(); DomainURL addDomainUrl(String domainName, String domainUrl, long coolDownPeriod); @Override void addSimpleUrls(List<String> urls, String status, String domainURL, String sourceDomainName); @Override void addDomainLinks(List<DomainLink> domainLinks); @Override List<DomainURL> findDomains(Pageable pageable); @Override Collection<SimpleURL> findURLs(String address, String status, int pageNo, int pageSize); @Override Collection<SimpleURL> findExternalURLs(String address, String status, int pageNo, int pageSize); void removeSimpleUrl(String url); @Override void updateSimpleUrlsStatus(List<String> urls, String status); @Override void updateSimpleUrlErrorStatus(String url, int errorDelta); void removeDomainUrl(String domainURL); @Override void removeDomains(); @Override List<Entries> query(String query); @Override long countAllNodes(); @Override long countAllDomains(); @Override long countAllLinks(); @Override long countDomainLinks(String domainUrl); }
MongoUrlServiceImpl implements UrlService { @Override public void addDomainLinks(List<DomainLink> domainLinks) { final Timer.Context context = domainLinksTimer.time(); try { Map<String, DomainURL> domainURLs = new HashMap<>(); Map<String, Set<String>> simpleURLs = new HashMap<>(); String status = null; for (DomainLink domainLink : domainLinks) { String domain = domainLink.getDomainURL().getAddress(); domainURLs.put(domain, domainLink.getDomainURL()); Set<String> urls = simpleURLs.get(domain); if (urls == null) { urls = new HashSet<>(); simpleURLs.put(domain, urls); } SimpleURL simpleURL = domainLink.getSimpleURL(); status = simpleURL.getStatus(); urls.add(simpleURL.getUrl()); } for (DomainURL domainURL : domainURLs.values()) { addDomainUrl(domainURL.getName(), domainURL.getAddress(), domainURL.getCoolDownPeriod()); } for (Map.Entry<String, Set<String>> entry : simpleURLs.entrySet()) { DomainURL domainURL = domainURLs.get(entry.getKey()); addSimpleUrls(new ArrayList<>(entry.getValue()), status, domainURL.getAddress(), null ); } } finally { context.stop(); } }  @PostConstruct void init(); DomainURL addDomainUrl(String domainName, String domainUrl, long coolDownPeriod); @Override void addSimpleUrls(List<String> urls, String status, String domainURL, String sourceDomainName); @Override void addDomainLinks(List<DomainLink> domainLinks); @Override List<DomainURL> findDomains(Pageable pageable); @Override Collection<SimpleURL> findURLs(String address, String status, int pageNo, int pageSize); @Override Collection<SimpleURL> findExternalURLs(String address, String status, int pageNo, int pageSize); void removeSimpleUrl(String url); @Override void updateSimpleUrlsStatus(List<String> urls, String status); @Override void updateSimpleUrlErrorStatus(String url, int errorDelta); void removeDomainUrl(String domainURL); @Override void removeDomains(); @Override List<Entries> query(String query); @Override long countAllNodes(); @Override long countAllDomains(); @Override long countAllLinks(); @Override long countDomainLinks(String domainUrl); @Autowired
    public MetricsConfig metricsConfig; @Autowired
    public MongoConfig mongoConfig; public MongoCollection domainRepo; public MongoCollection urlRepo; }