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

Commit

Permalink
Add missing final
Browse files Browse the repository at this point in the history
  • Loading branch information
dethi committed Dec 9, 2017
1 parent 620e5df commit 3c815d2
Show file tree
Hide file tree
Showing 21 changed files with 56 additions and 56 deletions.
2 changes: 1 addition & 1 deletion domain/src/main/java/com/epita/domain/RawDocument.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
public class RawDocument {
public final Document doc;

public RawDocument(Document doc) {
public RawDocument(final Document doc) {
this.doc = doc;
}
}
2 changes: 1 addition & 1 deletion domain/src/main/java/com/epita/domain/SimpleCrawler.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public RawDocument crawl(final String url) {
try {
LOGGER.info("crawling {}", url);
return new RawDocument(Jsoup.connect(url).get());
} catch (IOException e) {
} catch (final IOException e) {
LOGGER.error(e.getMessage());
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
public class NettyClientInitializer extends ChannelInitializer<SocketChannel> {
private final Consumer<EventMessage> consumer;

public NettyClientInitializer(Consumer<EventMessage> c) {
public NettyClientInitializer(final Consumer<EventMessage> c) {
this.consumer = c;
}

@Override
public void initChannel(SocketChannel ch) {
public void initChannel(final SocketChannel ch) {
final ChannelPipeline pipeline = ch.pipeline();

pipeline.addLast(new DelimiterBasedFrameDecoder(1048576 * 2, Delimiters.lineDelimiter()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public boolean start() {
.handler(new NettyClientInitializer(this::trigger));

nettyChannel = bootstrap.connect(host, port).sync().channel();
} catch (Exception e) {
} catch (final Exception e) {
LOGGER.error("Impossible to connect to {}:{}", host, port);
return false;
}
Expand Down Expand Up @@ -100,7 +100,7 @@ public void publish(final NettyEventBusClient.Message message) {
final String msg = new ObjectMapper().writeValueAsString(message);
nettyChannel.writeAndFlush(msg + "\r\n");
LOGGER.info("Sent message on '{}'", message.getChannel());
} catch (Exception e) {
} catch (final Exception e) {
LOGGER.error("Impossible to publish: {}", e.getMessage());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void run(final int port) {
LOGGER.info("NettyServer: running on port {}", port);

f.channel().closeFuture().sync();
} catch (InterruptedException e) {
} catch (final InterruptedException e) {
LOGGER.error("NettyServer: an error occurred while running: {}", e.getMessage());
} finally {
bossGroup.shutdownGracefully();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected void channelRead0(final ChannelHandlerContext channelHandlerContext, f
}

@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) {
cause.printStackTrace();
ctx.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public class ServerInitializer extends ChannelInitializer<SocketChannel> {

@Override
protected void initChannel(SocketChannel socketChannel) {
protected void initChannel(final SocketChannel socketChannel) {
final ChannelPipeline pipeline = socketChannel.pipeline();

pipeline.addLast(new DelimiterBasedFrameDecoder(1048576 * 2, Delimiters.lineDelimiter()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void dispatch(final Event<?> event) {
}

private void reduceAll(final Event<?> event) {
for (Reducer reducer : reducers) {
for (final Reducer reducer : reducers) {
reducer.reduce(event);
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/epita/guereza/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
public class Main {
private static final int NETTY_PORT = 8000;

public static void main(String[] args) {
public static void main(final String[] args) {
if (args.length != 2) {
System.out.println("usage: ./bin [crawler | indexer | store | server] SERVER_HOST");
exit(1);
Expand Down Expand Up @@ -54,7 +54,7 @@ private static Scope createScope(final String host, final int port) {
.register(new Singleton<>(EventBusClient.class, new NettyEventBusClient(host, port)));
}

private static void runCrawler(Scope scope) {
private static void runCrawler(final Scope scope) {
final Function<Scope, App> newCrawlerApp = (s) -> new CrawlerApp(
s.instanceOf(EventBusClient.class), s.instanceOf(Crawler.class));

Expand All @@ -63,7 +63,7 @@ private static void runCrawler(Scope scope) {
.block(Main::runApp);
}

private static void runIndexer(Scope scope) {
private static void runIndexer(final Scope scope) {
final Function<Scope, App> newIndexerApp = (s) -> new IndexerApp(
s.instanceOf(EventBusClient.class), s.instanceOf(Indexer.class), s.instanceOf(Crawler.class));

Expand All @@ -72,7 +72,7 @@ private static void runIndexer(Scope scope) {
.block(Main::runApp);
}

private static void runStore(Scope scope) {
private static void runStore(final Scope scope) {
final Function<Scope, UrlStore> newUrlStore = (s) -> new UrlStore(s.instanceOf(EventBusClient.class));
final Function<Scope, App> newEventStoreApp = (s) -> new EventStoreApp(
s.instanceOf(EventBusClient.class), s.instanceOf(EventStore.class));
Expand All @@ -89,8 +89,8 @@ private static void runStore(Scope scope) {
.block(Main::runApp);
}

private static void runApp(Scope scope) {
boolean ok = scope.instanceOf(EventBusClient.class).start();
private static void runApp(final Scope scope) {
final boolean ok = scope.instanceOf(EventBusClient.class).start();
if (ok) {
scope.instanceOf(App.class).run();
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/epita/guereza/application/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,23 @@ protected void sendMessage(final String channel, final Object obj) {
try {
final EventMessage em = new EventMessage(channel, obj);
eventBus.publish(em);
} catch (JsonProcessingException e) {
} catch (final JsonProcessingException e) {
LOGGER.error("Impossible to send message: {}", e.getMessage());
}
}

protected void retryIn(final int seconds, Runnable consumer) {
protected void retryIn(final int seconds, final Runnable consumer) {
LOGGER.info("Retry fetching url in {}seconds", seconds);
final ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
executor.schedule(consumer, seconds, TimeUnit.SECONDS);
executor.shutdownNow();
}

protected Object mappingObject(EventBusClient.Message message) {
protected Object mappingObject(final EventBusClient.Message message) {
try {
Class c = ClassLoader.getSystemClassLoader().loadClass(message.getMessageType());
final Class c = ClassLoader.getSystemClassLoader().loadClass(message.getMessageType());
return new ObjectMapper().readValue(message.getContent(), c);
} catch (Exception e) {
} catch (final Exception e) {
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private void storeUrls(final String[] urls) {
public void run() {
eventBus.subscribe(subscribeUrl, msg -> {
if (msg != null) {
String url = (String) mappingObject(msg);
final String url = (String) mappingObject(msg);
if (url != null) {
LOGGER.info("Receive url: {}", url);
final String[] urls = crawlAndExtract(url);
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/com/epita/guereza/application/EventStoreApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class EventStoreApp extends App {

private final EventStore eventStore;

public EventStoreApp(EventBusClient eventBus, EventStore eventStore) {
public EventStoreApp(final EventBusClient eventBus, final EventStore eventStore) {
super(eventBus);

this.eventStore = eventStore;
Expand All @@ -25,12 +25,12 @@ public EventStoreApp(EventBusClient eventBus, EventStore eventStore) {
private void extractThen(final EventBusClient.Message msg, final Consumer<Object> consumer) {
try {
LOGGER.info("Message Type: {}", msg.getMessageType());
Class c = ClassLoader.getSystemClassLoader().loadClass(msg.getMessageType());
Object o = new ObjectMapper().readValue(msg.getContent(), c);
final Class c = ClassLoader.getSystemClassLoader().loadClass(msg.getMessageType());
final Object o = new ObjectMapper().readValue(msg.getContent(), c);
if (o != null) {
consumer.accept(o);
}
} catch (Exception e) {
} catch (final Exception e) {
LOGGER.error("Impossible to extract object from message: {}", e);
}
}
Expand All @@ -39,19 +39,19 @@ private void extractThen(final EventBusClient.Message msg, final Consumer<Object
@Override
public void run() {
eventBus.subscribe("/request/crawler/url", msg -> extractThen(msg, o -> {
Event<String> ev = new Event<>("CRAWLER_REQUEST_URL", (String) o);
final Event<String> ev = new Event<>("CRAWLER_REQUEST_URL", (String) o);
eventStore.dispatch(ev);
}));
eventBus.subscribe("/request/indexer/url", msg -> extractThen(msg, o -> {
Event<String> ev = new Event<>("INDEXER_REQUEST_URL", (String) o);
final Event<String> ev = new Event<>("INDEXER_REQUEST_URL", (String) o);
eventStore.dispatch(ev);
}));
eventBus.subscribe("/store/crawler", msg -> extractThen(msg, o -> {
Event<StringListWrapper> ev = new Event<>("ADD_URLS", (StringListWrapper) o);
final Event<StringListWrapper> ev = new Event<>("ADD_URLS", (StringListWrapper) o);
eventStore.dispatch(ev);
}));
eventBus.subscribe("/store/indexer", msg -> extractThen(msg, o -> {
Event<Document> ev = new Event<>("ADD_DOCUMENT", (Document) o);
final Event<Document> ev = new Event<>("ADD_DOCUMENT", (Document) o);
eventStore.dispatch(ev);
}));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private void requestNextUrl() {
public void run() {
eventBus.subscribe(subscribeUrl, msg -> {
if (msg != null) {
String url = (String) mappingObject(msg);
final String url = (String) mappingObject(msg);
if (url != null) {
LOGGER.info("Receive url: {}", url);
indexAndPublish(url);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/epita/guereza/application/ServerApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class ServerApp {
private final NettyServer ns = new NettyServer();
private final int port;

public ServerApp(int port) {
public ServerApp(final int port) {
this.port = port;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/epita/guereza/reducer/RetroIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void reduce(final Event<?> event) {
}
}

private void addDocument(Event<Document> event) {
private void addDocument(final Event<Document> event) {
index.docs.add(event.obj);
LOGGER.info("added a document to the index");
}
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/com/epita/guereza/reducer/UrlStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public void reduce(final Event<?> event) {
}
}

private void store(List<String> urls) {
for (String url : urls) {
private void store(final List<String> urls) {
for (final String url : urls) {
if (url == null || url.isEmpty())
continue;

Expand All @@ -59,25 +59,25 @@ private void store(List<String> urls) {
}
}

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

private void crawlerRequestUrl(Event<String> event) {
private void crawlerRequestUrl(final Event<String> event) {
try {
LOGGER.info("Still {} urls to crawl", crawlerTodo.size());
eventBus.publish(new EventMessage(event.obj, crawlerTodo.poll()));
} catch (JsonProcessingException e) {
} catch (final JsonProcessingException e) {
LOGGER.error("cannot serialize: {}", e.getMessage());
}
}

private void indexerRequestUrl(Event<String> event) {
private void indexerRequestUrl(final Event<String> event) {
try {
LOGGER.info("Still {} urls to index", indexerTodo.size());
eventBus.publish(new EventMessage(event.obj, indexerTodo.poll()));
} catch (JsonProcessingException e) {
} catch (final JsonProcessingException e) {
LOGGER.error("cannot serialize: {}", e.getMessage());
}
}
Expand Down
12 changes: 6 additions & 6 deletions winter/src/main/java/com/epita/winter/Scope.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static <BEAN_TYPE> Method getMethod(final Class<BEAN_TYPE> klass,
final Class<?>... parameterTypes) {
try {
return klass.getMethod(name, parameterTypes);
} catch (NoSuchMethodException e) {
} catch (final NoSuchMethodException e) {
throw new NoSuchElementException();
}
}
Expand All @@ -46,8 +46,8 @@ public <BEAN_TYPE> BEAN_TYPE instanceOf(final Class<BEAN_TYPE> klass) {
return parent.instanceOf(klass);
}

Provider<BEAN_TYPE> provider = (Provider<BEAN_TYPE>) providers.get(klass);
BEAN_TYPE instance = provider.getInstance(klass, this);
final Provider<BEAN_TYPE> provider = (Provider<BEAN_TYPE>) providers.get(klass);
final BEAN_TYPE instance = provider.getInstance(klass, this);
if (isBlock) {
instances.put(instance, klass);
}
Expand All @@ -67,16 +67,16 @@ public <BEAN_TYPE> Scope unregister(final Class<BEAN_TYPE> klass) {
@SuppressWarnings("unchecked")
private <BEAN_TYPE> void release(final Class<? extends BEAN_TYPE> klass, final BEAN_TYPE target) {
if (providers.containsKey(klass)) {
Provider<BEAN_TYPE> provider = (Provider<BEAN_TYPE>) providers.get(klass);
final Provider<BEAN_TYPE> provider = (Provider<BEAN_TYPE>) providers.get(klass);
provider.callAfterDestroy(this, target);
}
}

public void block(Consumer<Scope> consumer) {
public void block(final Consumer<Scope> consumer) {
isBlock = true;
consumer.accept(this);

for (Map.Entry<Object, Class<?>> entry : instances.entrySet()) {
for (final Map.Entry<Object, Class<?>> entry : instances.entrySet()) {
release(entry.getValue(), entry.getKey());
}
instances.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public AspectContext(final BEAN_TYPE target, final Method method, final Object[]
}

Object invoke() {
AspectContext<BEAN_TYPE> context =
final AspectContext<BEAN_TYPE> context =
new AspectContext<>(target, method, args, functions.subList(1, functions.size()));

return functions.get(0).apply(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ public AspectInvocationHandler(final Map<Method, List<BiConsumer<Scope, BEAN_TYP
@Override
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
if (beforeConsumers.containsKey(method)) {
for (BiConsumer<Scope, BEAN_TYPE> consumer : beforeConsumers.get(method)) {
for (final BiConsumer<Scope, BEAN_TYPE> consumer : beforeConsumers.get(method)) {
consumer.accept(scope, target);
}
}

Object res;
final Object res;
if (aroundFunctions.containsKey(method)) {
AspectContext<BEAN_TYPE> context =
final AspectContext<BEAN_TYPE> context =
new AspectContext<>(target, method, args, aroundFunctions.get(method));

res = context.invoke();
Expand All @@ -49,7 +49,7 @@ public Object invoke(final Object proxy, final Method method, final Object[] arg
}

if (afterConsumers.containsKey(method)) {
for (BiConsumer<Scope, BEAN_TYPE> consumer : afterConsumers.get(method)) {
for (final BiConsumer<Scope, BEAN_TYPE> consumer : afterConsumers.get(method)) {
consumer.accept(scope, target);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ public Class<BEAN_TYPE> getInstanceClass() {
}

public BEAN_TYPE getInstance(final Class<BEAN_TYPE> klass, final Scope scope) {
BEAN_TYPE target = createInstance(scope);
final BEAN_TYPE target = createInstance(scope);
if (beforeConsumers.size() == 0 && afterConsumers.size() == 0) {
return target;
}

Object proxy = Proxy.newProxyInstance(
final Object proxy = Proxy.newProxyInstance(
klass.getClassLoader(), new Class<?>[]{klass}, getAspectInvocationHandler(scope, target));
return klass.cast(proxy);
}
Expand Down Expand Up @@ -71,7 +71,7 @@ public Provider<BEAN_TYPE> beforeDestroy(final BiConsumer<Scope, BEAN_TYPE> cons
}

public void callAfterDestroy(final Scope scope, final BEAN_TYPE target) {
for (BiConsumer<Scope, BEAN_TYPE> consumer : beforeDestroyConsumers) {
for (final BiConsumer<Scope, BEAN_TYPE> consumer : beforeDestroyConsumers) {
consumer.accept(scope, target);
}
}
Expand All @@ -83,7 +83,7 @@ private AspectInvocationHandler getAspectInvocationHandler(final Scope scope, fi
}

void callAfterCreate(final Scope scope, final BEAN_TYPE target) {
for (BiConsumer<Scope, BEAN_TYPE> consumer : afterCreateConsumers) {
for (final BiConsumer<Scope, BEAN_TYPE> consumer : afterCreateConsumers) {
consumer.accept(scope, target);
}
}
Expand Down
Loading

0 comments on commit 3c815d2

Please sign in to comment.