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

Commit

Permalink
use server url from argument
Browse files Browse the repository at this point in the history
  • Loading branch information
T4ze committed Dec 9, 2017
1 parent 5baf404 commit 6bb2221
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ public interface EventBusClient {
/**
* Start the client
*
* @param host The host of the server
* @param port The port of the server
* @return Whether or not the run succeed
*/
boolean start(final String host, final int port);
boolean start();

/**
* Subscribe to the given channel.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,19 @@ public class NettyEventBusClient implements EventBusClient {
private final Map<String, List<Subscription>> subscriptionsMap;
private io.netty.channel.Channel nettyChannel;
private EventLoopGroup group;
private final String host;
private final int port;

public NettyEventBusClient() {
public NettyEventBusClient(final String host, final int port) {
subscriptionsMap = new HashMap<>();
group = new NioEventLoopGroup();
nettyChannel = null;
this.host = host;
this.port = port;
}

@Override
public boolean start(final String host, final int port) {
public boolean start() {
if (nettyChannel != null)
return false;

Expand Down
13 changes: 6 additions & 7 deletions src/main/java/com/epita/guereza/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@
import static java.lang.System.exit;

public class Main {
private static final String NETTY_HOST = "localhost";
private static final int NETTY_PORT = 8000;

public static void main(String[] args) {
if (args.length != 1) {
System.out.println("usage: ./bin [ crawler | indexer | store | server");
if (args.length < 1) {
System.out.println("usage: ./bin [crawler | indexer | store | server] server_url");
exit(1);
}

final String module = args[0];
final Scope scope = createScope();
final Scope scope = createScope(args[1], NETTY_PORT);

switch (module) {
case "crawler":
Expand All @@ -48,11 +47,11 @@ public static void main(String[] args) {
}
}

private static Scope createScope() {
private static Scope createScope(final String host, final int port) {
return new Scope()
.register(new Singleton<>(Crawler.class, new CrawlerService()))
.register(new Singleton<>(Indexer.class, new IndexerService()))
.register(new Singleton<>(EventBusClient.class, new NettyEventBusClient()));
.register(new Singleton<>(EventBusClient.class, new NettyEventBusClient(host, port)));
}

private static void runCrawler(Scope scope) {
Expand Down Expand Up @@ -96,7 +95,7 @@ private static void runStore(Scope scope) {
}

private static void runApp(Scope scope) {
boolean ok = scope.instanceOf(EventBusClient.class).start(NETTY_HOST, NETTY_PORT);
boolean ok = scope.instanceOf(EventBusClient.class).start();
if (ok) {
scope.instanceOf(App.class).run();
}
Expand Down

0 comments on commit 6bb2221

Please sign in to comment.