package votorola.a.diff.harvest.run; // Copyright 2012. Christian Weilbach. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Votorola Software"), to deal in the Votorola Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Votorola Software, and to permit persons to whom the Votorola Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Votorola Software. THE VOTOROLA SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE VOTOROLA SOFTWARE OR THE USE OR OTHER DEALINGS IN THE VOTOROLA SOFTWARE. import java.io.InputStream; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; import votorola.a.diff.harvest.PipermailHarvester; /** * Wrapper class around Runnable to work with asynchronous HTTP responses from * {@linkplain HarvestRunner}. Implement this and then * {@linkplain HarvestRunner#scheduleLast(Fetcher) schedule} it. Once the * scheduler can fetch the URL it {@linkplain #setInputStream(InputStream) sets * the input stream} and executes this job in its thread pool. * * All you have to care about is implementing {@linkplain Runnable#run()} * properly and schedule cascading jobs from there in the same way. See * {@linkplain PipermailHarvester} for reference. */ public abstract class AbstractFetcher implements Fetcher { /** * Jobs are equal if and only if * *
* this.url.equals(job.url) ** * @return whether the jobs are equal */ @Override public boolean equals(final Object o) { return (o instanceof AbstractFetcher) && ((AbstractFetcher) o).archiveUrl.equals(archiveUrl) && ((AbstractFetcher) o).path.equals(path); } /** * Obey equals contract. */ @Override public int hashCode() { int hash = archiveUrl.hashCode(); hash = hash*37 + path.hashCode(); return hash; } /** * Constructor depending on split URL parameters. * * @param archiveUrl * url of this archive, unique * @param path * path and query of this archive */ protected AbstractFetcher(final String archiveUrl, final String path) { this.path = path; this.archiveUrl = archiveUrl; } /** * Access to the base-url of the archive. * * @return base-url */ public String archiveUrl() { return archiveUrl; } private final String archiveUrl; /** * @return URL of this job. This is final and cannot change. */ public String path() { return path; } private final String path; /** * Base-url and path combined to complete url. * * @return url */ public String url() { return archiveUrl + path; } /** * Supposed to be final after being set by HarvestRunner. */ private final AtomicReference