Skip to content
This repository has been archived by the owner on Jun 2, 2019. It is now read-only.

Commit

Permalink
Re-apply StringListWrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
dethi committed Dec 9, 2017
1 parent 4b59150 commit 47a8e6b
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 11 deletions.
20 changes: 20 additions & 0 deletions src/main/java/com/epita/guereza/StringListWrapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.epita.guereza;

import java.util.Arrays;
import java.util.List;

@SuppressWarnings("ALL")
public class StringListWrapper {
public List<String> list;

public StringListWrapper() {
}

public StringListWrapper(List<String> list) {
this.list = list;
}

public StringListWrapper(String[] array) {
this.list = Arrays.asList(array);
}
}
3 changes: 2 additions & 1 deletion src/main/java/com/epita/guereza/application/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

public abstract class App {
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);

protected final String uid;
protected final EventBusClient eventBus;

Expand All @@ -33,7 +34,7 @@ protected App(final EventBusClient eventBus) {
* @param channel The channel to send message
* @param obj The object to send
*/
public void sendMessage(final String channel, final Object obj) {
protected void sendMessage(final String channel, final Object obj) {
try {
final EventMessage em = new EventMessage(channel, obj);
eventBus.publish(em);
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/com/epita/guereza/application/CrawlerApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import com.epita.domain.Crawler;
import com.epita.domain.RawDocument;
import com.epita.eventbus.client.EventBusClient;
import com.epita.guereza.StringListWrapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Arrays;

public class CrawlerApp extends App {
private static final Logger LOGGER = LoggerFactory.getLogger(CrawlerApp.class);

private final Crawler crawler;
private final String subscribeUrl;

Expand All @@ -35,11 +35,10 @@ private void requestNextUrl() {
private void storeUrls(final String[] urls) {
if (urls != null) {
LOGGER.info("Store {} urls", urls.length);
sendMessage("/store/crawler", Arrays.asList(urls));
sendMessage("/store/crawler", new StringListWrapper(urls));
}
}


@Override
public void run() {
eventBus.subscribe(subscribeUrl, msg -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
import com.epita.eventbus.client.EventBusClient;
import com.epita.eventsourcing.Event;
import com.epita.eventsourcing.EventStore;
import com.epita.guereza.StringListWrapper;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.function.Consumer;

public class EventStoreApp extends App {
private static final Logger LOGGER = LoggerFactory.getLogger(EventStore.class);

private final EventStore eventStore;

public EventStoreApp(EventBusClient eventBus, EventStore eventStore) {
Expand Down Expand Up @@ -46,7 +47,7 @@ public void run() {
eventStore.dispatch(ev);
}));
eventBus.subscribe("/store/crawler", msg -> extractThen(msg, o -> {
Event<List<String>> ev = new Event<>("ADD_URLS", (List<String>) o);
Event<StringListWrapper> ev = new Event<>("ADD_URLS", (StringListWrapper) o);
eventStore.dispatch(ev);
}));
eventBus.subscribe("/store/indexer", msg -> extractThen(msg, o -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

public class IndexerApp extends App {
private static final Logger LOGGER = LoggerFactory.getLogger(IndexerApp.class);

private final Indexer indexer;
private final Crawler crawler;
private final String subscribeUrl;
Expand Down Expand Up @@ -40,7 +41,6 @@ private void requestNextUrl() {
sendMessage("/request/indexer/url", subscribeUrl);
}


@Override
public void run() {
eventBus.subscribe(subscribeUrl, msg -> {
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/com/epita/guereza/reducer/UrlStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.epita.eventbus.client.EventBusClient;
import com.epita.eventsourcing.Event;
import com.epita.eventsourcing.Reducer;
import com.epita.guereza.StringListWrapper;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -23,6 +24,7 @@ public class UrlStore implements Reducer {

public UrlStore(final EventBusClient eventBus) {
this.eventBus = eventBus;

final List<String> initialList = new ArrayList<>();
initialList.add(STARTING_URL);
store(initialList);
Expand All @@ -33,7 +35,7 @@ public UrlStore(final EventBusClient eventBus) {
public void reduce(final Event<?> event) {
switch (event.type) {
case "ADD_URLS":
addUrls((Event<List<String>>) event);
addUrls((Event<StringListWrapper>) event);
break;
case "CRAWLER_REQUEST_URL":
crawlerRequestUrl((Event<String>) event);
Expand All @@ -57,8 +59,8 @@ private void store(List<String> urls) {
}
}

private void addUrls(Event<List<String>> event) {
store(event.obj);
private void addUrls(Event<StringListWrapper> event) {
store(event.obj.list);
LOGGER.info("added URLs to the repo");
}

Expand Down

0 comments on commit 47a8e6b

Please sign in to comment.