From ddbf5d1ac05d0f03f7cbe9275c303541cca945be Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Thu, 8 Nov 2012 17:01:10 +0100 Subject: wip --- .../esper/testing/gitorious/GitoriousImporter.java | 88 +++++++++++++++------- 1 file changed, 62 insertions(+), 26 deletions(-) (limited to 'src/main/java/io/trygvis/esper/testing/gitorious/GitoriousImporter.java') diff --git a/src/main/java/io/trygvis/esper/testing/gitorious/GitoriousImporter.java b/src/main/java/io/trygvis/esper/testing/gitorious/GitoriousImporter.java index 05dfe43..c77d7db 100644 --- a/src/main/java/io/trygvis/esper/testing/gitorious/GitoriousImporter.java +++ b/src/main/java/io/trygvis/esper/testing/gitorious/GitoriousImporter.java @@ -1,6 +1,7 @@ package io.trygvis.esper.testing.gitorious; import io.trygvis.esper.testing.*; +import io.trygvis.esper.testing.ResourceManager.*; import org.apache.abdera.*; import org.apache.abdera.model.*; import org.apache.abdera.protocol.client.*; @@ -11,48 +12,83 @@ import org.codehaus.httpcache4j.client.*; import java.sql.*; import java.util.Date; import java.util.*; +import java.util.concurrent.*; public class GitoriousImporter { private final AbderaClient abderaClient; - private final Connection connection; + private final Connection c; private final AtomDao atomDao; private final GitoriousDao gitoriousDao; - public GitoriousImporter(AbderaClient abderaClient, Connection c) throws SQLException { - this.abderaClient = abderaClient; - this.connection = c; - atomDao = new AtomDao(c); - gitoriousDao = new GitoriousDao(c); - } - public static void main(String[] args) throws Exception { Main.configureLog4j(); + new GitoriousImporter(); + } + + public GitoriousImporter() throws Exception { Abdera abdera = new Abdera(); - AbderaClient abderaClient = new AbderaClient(abdera, new LRUCache(abdera, 1000)); + abderaClient = new AbderaClient(abdera, new LRUCache(abdera, 1000)); - Connection connection = DriverManager.getConnection(DbMain.JDBC_URL, "esper", ""); - connection.setAutoCommit(false); + c = DriverManager.getConnection(DbMain.JDBC_URL, "esper", ""); + c.setAutoCommit(false); + + atomDao = new AtomDao(c); + gitoriousDao = new GitoriousDao(c); HTTPCache httpCache = new HTTPCache(new MemoryCacheStorage(), HTTPClientResponseResolver.createMultithreadedInstance()); - GitoriousClient gitoriousClient = new GitoriousClient(httpCache, "https://gitorious.org"); + final GitoriousClient gitoriousClient = new GitoriousClient(httpCache, "https://gitorious.org"); - List projects = gitoriousClient.findProjects(); +// Set projects = gitoriousClient.findProjects(); +// +// System.out.println("projects.size() = " + projects.size()); +// for (GitoriousProject project : projects) { +// System.out.println("project.repositories = " + project.repositories); +// } - System.out.println("projects.size() = " + projects.size()); - for (GitoriousProject project : projects) { - System.out.println("project.repositories = " + project.repositories); - } +// new GitoriousImporter(abderaClient, c).work(); -// new GitoriousImporter(abderaClient, connection).work(); -// -// ScheduledThreadPoolExecutor service = new ScheduledThreadPoolExecutor(1); -// -// new ResourceManager(Equal.anyEqual(), service, 1000, new Callable>() { -// public List call() throws Exception { -// -// } -// }); + final ScheduledThreadPoolExecutor service = new ScheduledThreadPoolExecutor(1); + + int projectsUpdateInterval = 1000; + final int projectUpdateInterval = 1000; + + ResourceManager gitoriousProjects = new ResourceManager<>(service, 1000, + + new ResourceManagerCallbacks() { + public Set discover() throws Exception { + return gitoriousClient.findProjects(); + } + + public GitoriousProjectResourceManager onNew(GitoriousProject key) { + return new GitoriousProjectResourceManager(service, projectUpdateInterval, key); + } + + public void onGone(GitoriousProject key, GitoriousProjectResourceManager manager) { + System.out.println("Project gone."); + manager.close(); + } + }); + ; + } + + class GitoriousProjectResourceManager extends ResourceManager { + + public GitoriousProjectResourceManager(ScheduledExecutorService executorService, int delay, GitoriousProject key) { + super(executorService, delay, new ResourceManagerCallbacks() { + public Set discover() throws Exception { + key + } + + public GitoriousRepository onNew(GitoriousRepository key) { + throw new RuntimeException("Not implemented"); + } + + public void onGone(GitoriousRepository key, GitoriousRepository value) { + throw new RuntimeException("Not implemented"); + } + }); + } } private void work() throws SQLException, InterruptedException { -- cgit v1.2.3