Skip to content

Commit

Permalink
Implements new registering methods
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuel-keller committed Mar 12, 2017
1 parent 598dd1a commit 9ac095f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/qwazr/crawler/web/CurrentSessionImpl.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2014-2016 Emmanuel Keller / QWAZR
* Copyright 2015-2017 Emmanuel Keller / QWAZR
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,7 +16,7 @@
package com.qwazr.crawler.web;

import com.qwazr.utils.TimeTracker;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections4.CollectionUtils;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
Expand Down
19 changes: 12 additions & 7 deletions src/main/java/com/qwazr/crawler/web/WebCrawlerManager.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2014-2016 Emmanuel Keller / QWAZR
* Copyright 2015-2017 Emmanuel Keller / QWAZR
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -46,20 +46,25 @@ public class WebCrawlerManager {
private WebCrawlerServiceImpl service;

public WebCrawlerManager(final ClusterManager clusterManager, final ScriptManager scriptManager,
final ExecutorService executor, final GenericServer.Builder builder)
throws IOException, URISyntaxException {
final ExecutorService executor) throws IOException, URISyntaxException {
this.scriptManager = scriptManager;
this.clusterManager = clusterManager;
myAddress = clusterManager.getServiceBuilder().local().getStatus().me;
this.executorService = executor;
crawlSessionMap = new HashMap<>();
if (builder != null) {
builder.webService(WebCrawlerServiceImpl.class);
builder.contextAttribute(this);
}
service = new WebCrawlerServiceImpl(this);
}

public WebCrawlerManager registerContextAttribute(final GenericServer.Builder builder) {
builder.contextAttribute(this);
return this;
}

public WebCrawlerManager registerWebService(final GenericServer.Builder builder) {
builder.webService(WebCrawlerServiceImpl.class);
return registerContextAttribute(builder);
}

public WebCrawlerServiceInterface getService() {
return service;
}
Expand Down
20 changes: 13 additions & 7 deletions src/main/java/com/qwazr/crawler/web/WebCrawlerServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,22 @@ public class WebCrawlerServer implements BaseServer {

private WebCrawlerServer(final ServerConfiguration configuration) throws IOException, URISyntaxException {
final ExecutorService executorService = Executors.newCachedThreadPool();
final GenericServer.Builder builder = GenericServer.of(configuration, executorService);
builder.webService(WelcomeShutdownService.class);
final GenericServer.Builder builder =
GenericServer.of(configuration, executorService).webService(WelcomeShutdownService.class);
final ClassLoaderManager classLoaderManager =
new ClassLoaderManager(configuration.dataDirectory, Thread.currentThread());
final ClusterManager clusterManager = new ClusterManager(builder, executorService);
final LibraryManager libraryManager = new LibraryManager(classLoaderManager, null, builder);
new ClassLoaderManager(configuration.dataDirectory, Thread.currentThread()).registerContextAttribute(
builder);
final ClusterManager clusterManager =
new ClusterManager(executorService, configuration).registerHttpClientMonitoringThread(builder)
.registerProtocolListener(builder)
.registerWebService(builder);
final LibraryManager libraryManager = new LibraryManager(classLoaderManager, null, configuration.dataDirectory,
configuration.getEtcFiles()).registerWebService(builder);
final ScriptManager scriptManager =
new ScriptManager(executorService, classLoaderManager, clusterManager, libraryManager, builder);
new ScriptManager(executorService, classLoaderManager, clusterManager, libraryManager,
configuration.dataDirectory).registerWebService(builder);
final WebCrawlerManager webCrawlerManager =
new WebCrawlerManager(clusterManager, scriptManager, executorService, builder);
new WebCrawlerManager(clusterManager, scriptManager, executorService).registerWebService(builder);
serviceBuilder = new WebCrawlerServiceBuilder(clusterManager, webCrawlerManager);
server = builder.build();
}
Expand Down

0 comments on commit 9ac095f

Please sign in to comment.