Skip to content

Commit

Permalink
Update to last Server API
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuel-keller committed Aug 26, 2017
1 parent e4cf78d commit 0b15bed
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
**/
package com.qwazr.crawler.common;

import com.qwazr.utils.ExceptionUtils;
import com.qwazr.utils.TimeTracker;
import org.apache.commons.lang3.exception.ExceptionUtils;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/qwazr/crawler/common/CrawlThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ protected void script(final EventEnum event, final CurrentCrawl currentCrawl) {
try {
scriptRunThread = manager.scriptService.runSync(script.name, attributes);
} catch (IOException | ClassNotFoundException e) {
throw new ServerException(e);
throw ServerException.of(e);
}
if (scriptRunThread.getException() != null)
throw new ServerException(scriptRunThread.getException());
throw ServerException.of(scriptRunThread.getException());
} finally {
timeTracker.next("Event: " + event.name());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,26 @@
import com.fasterxml.jackson.core.type.TypeReference;
import com.qwazr.server.RemoteService;
import com.qwazr.server.client.JsonClientAbstract;
import com.qwazr.utils.LoggerUtils;
import com.qwazr.utils.UBuilder;
import com.qwazr.utils.http.HttpRequest;

import javax.ws.rs.core.Response;
import java.util.TreeMap;
import java.util.logging.Logger;

abstract public class CrawlerSingleClient<D extends CrawlDefinition, S extends CrawlStatus<D>>
extends JsonClientAbstract implements CrawlerServiceInterface<D, S> {

private final static Logger LOGGER = LoggerUtils.getLogger(JsonClientAbstract.class);

private final String pathPrefix;
private final Class<S> crawlStatusClass;
private final TypeReference<TreeMap<String, S>> mapStatusType;

protected CrawlerSingleClient(final RemoteService remote, final String pathPrefix, Class<S> crawlStatusClass,
TypeReference<TreeMap<String, S>> mapStatusType) {
super(remote);
super(remote, LOGGER);
this.pathPrefix = pathPrefix;
this.crawlStatusClass = crawlStatusClass;
this.mapStatusType = mapStatusType;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/qwazr/crawler/file/FileCrawlThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import com.qwazr.crawler.common.CrawlSessionImpl;
import com.qwazr.crawler.common.CrawlThread;
import com.qwazr.crawler.common.EventEnum;
import com.qwazr.utils.ExceptionUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;

import java.io.IOException;
import java.nio.file.FileVisitResult;
Expand Down
23 changes: 4 additions & 19 deletions src/main/java/com/qwazr/crawler/web/WebCrawlerMultiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
import com.qwazr.server.RemoteService;
import com.qwazr.server.ServerException;
import com.qwazr.server.client.MultiClient;
import com.qwazr.utils.ExceptionUtils;
import com.qwazr.utils.LoggerUtils;
import com.qwazr.utils.http.HttpResponseEntityException;

import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
Expand Down Expand Up @@ -76,7 +74,7 @@ public WebCrawlStatus getSession(String sessionName) {
throw e;
}
}
throw new ServerException(Status.NOT_FOUND, "Session " + sessionName + " not found").getJsonException();
throw new ServerException(Status.NOT_FOUND, "Session " + sessionName + " not found").getJsonException(false);
}

@Override
Expand All @@ -97,22 +95,9 @@ public Response abortSession(String sessionName, String reason) {
}

@Override
public WebCrawlStatus runSession(final String session_name, final WebCrawlDefinition crawlDefinition) {
final ExceptionUtils.Holder exceptionHolder = new ExceptionUtils.Holder(logger);
for (WebCrawlerSingleClient client : this) {
try {
return client.runSession(session_name, crawlDefinition);
} catch (WebApplicationException e) {
exceptionHolder.switchAndWarn(e);
}
}
final WebApplicationException e = exceptionHolder.getException();
if (e == null)
return null;
final HttpResponseEntityException hree = HttpResponseEntityException.findFirstCause(e);
if (hree != null)
throw ServerException.getServerException(hree).getJsonException();
throw e;
public WebCrawlStatus runSession(final String sessionName, final WebCrawlDefinition crawlDefinition) {
return firstRandomSuccess(c -> c.runSession(sessionName, crawlDefinition), logger);

}

@Override
Expand Down

0 comments on commit 0b15bed

Please sign in to comment.