From 3c815d237487e6413296e50f03e0f608f925f28f Mon Sep 17 00:00:00 2001 From: Thibault Deutsch Date: Sat, 9 Dec 2017 23:30:35 +0100 Subject: [PATCH] Add missing final --- .../main/java/com/epita/domain/RawDocument.java | 2 +- .../java/com/epita/domain/SimpleCrawler.java | 2 +- .../eventbus/client/NettyClientInitializer.java | 4 ++-- .../eventbus/client/NettyEventBusClient.java | 4 ++-- .../com/epita/eventbus/server/NettyServer.java | 2 +- .../com/epita/eventbus/server/ServerHandler.java | 2 +- .../epita/eventbus/server/ServerInitializer.java | 2 +- .../java/com/epita/eventsourcing/EventStore.java | 2 +- src/main/java/com/epita/guereza/Main.java | 12 ++++++------ .../java/com/epita/guereza/application/App.java | 10 +++++----- .../epita/guereza/application/CrawlerApp.java | 2 +- .../epita/guereza/application/EventStoreApp.java | 16 ++++++++-------- .../epita/guereza/application/IndexerApp.java | 2 +- .../com/epita/guereza/application/ServerApp.java | 2 +- .../com/epita/guereza/reducer/RetroIndex.java | 2 +- .../java/com/epita/guereza/reducer/UrlStore.java | 14 +++++++------- winter/src/main/java/com/epita/winter/Scope.java | 12 ++++++------ .../com/epita/winter/aspect/AspectContext.java | 2 +- .../winter/aspect/AspectInvocationHandler.java | 8 ++++---- .../com/epita/winter/provider/AnyProvider.java | 8 ++++---- .../com/epita/winter/provider/Prototype.java | 2 +- 21 files changed, 56 insertions(+), 56 deletions(-) diff --git a/domain/src/main/java/com/epita/domain/RawDocument.java b/domain/src/main/java/com/epita/domain/RawDocument.java index 34984f7..b770755 100644 --- a/domain/src/main/java/com/epita/domain/RawDocument.java +++ b/domain/src/main/java/com/epita/domain/RawDocument.java @@ -5,7 +5,7 @@ public class RawDocument { public final Document doc; - public RawDocument(Document doc) { + public RawDocument(final Document doc) { this.doc = doc; } } diff --git a/domain/src/main/java/com/epita/domain/SimpleCrawler.java b/domain/src/main/java/com/epita/domain/SimpleCrawler.java index eb2e57a..21a74fe 100644 --- a/domain/src/main/java/com/epita/domain/SimpleCrawler.java +++ b/domain/src/main/java/com/epita/domain/SimpleCrawler.java @@ -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; } diff --git a/eventbus/src/main/java/com/epita/eventbus/client/NettyClientInitializer.java b/eventbus/src/main/java/com/epita/eventbus/client/NettyClientInitializer.java index 19e3a0a..d38b7cb 100644 --- a/eventbus/src/main/java/com/epita/eventbus/client/NettyClientInitializer.java +++ b/eventbus/src/main/java/com/epita/eventbus/client/NettyClientInitializer.java @@ -14,12 +14,12 @@ public class NettyClientInitializer extends ChannelInitializer { private final Consumer consumer; - public NettyClientInitializer(Consumer c) { + public NettyClientInitializer(final Consumer 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())); diff --git a/eventbus/src/main/java/com/epita/eventbus/client/NettyEventBusClient.java b/eventbus/src/main/java/com/epita/eventbus/client/NettyEventBusClient.java index 7f5ddc9..7dde444 100644 --- a/eventbus/src/main/java/com/epita/eventbus/client/NettyEventBusClient.java +++ b/eventbus/src/main/java/com/epita/eventbus/client/NettyEventBusClient.java @@ -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; } @@ -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()); } } diff --git a/eventbus/src/main/java/com/epita/eventbus/server/NettyServer.java b/eventbus/src/main/java/com/epita/eventbus/server/NettyServer.java index 6d53475..2c23a5b 100644 --- a/eventbus/src/main/java/com/epita/eventbus/server/NettyServer.java +++ b/eventbus/src/main/java/com/epita/eventbus/server/NettyServer.java @@ -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(); diff --git a/eventbus/src/main/java/com/epita/eventbus/server/ServerHandler.java b/eventbus/src/main/java/com/epita/eventbus/server/ServerHandler.java index 9a5b3a6..3ed8918 100644 --- a/eventbus/src/main/java/com/epita/eventbus/server/ServerHandler.java +++ b/eventbus/src/main/java/com/epita/eventbus/server/ServerHandler.java @@ -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(); } diff --git a/eventbus/src/main/java/com/epita/eventbus/server/ServerInitializer.java b/eventbus/src/main/java/com/epita/eventbus/server/ServerInitializer.java index 5a057b5..a09f38e 100644 --- a/eventbus/src/main/java/com/epita/eventbus/server/ServerInitializer.java +++ b/eventbus/src/main/java/com/epita/eventbus/server/ServerInitializer.java @@ -11,7 +11,7 @@ public class ServerInitializer extends ChannelInitializer { @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())); diff --git a/eventsourcing/src/main/java/com/epita/eventsourcing/EventStore.java b/eventsourcing/src/main/java/com/epita/eventsourcing/EventStore.java index b2b0be6..1ce1020 100644 --- a/eventsourcing/src/main/java/com/epita/eventsourcing/EventStore.java +++ b/eventsourcing/src/main/java/com/epita/eventsourcing/EventStore.java @@ -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); } } diff --git a/src/main/java/com/epita/guereza/Main.java b/src/main/java/com/epita/guereza/Main.java index 78e40e6..847e1ce 100644 --- a/src/main/java/com/epita/guereza/Main.java +++ b/src/main/java/com/epita/guereza/Main.java @@ -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); @@ -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 newCrawlerApp = (s) -> new CrawlerApp( s.instanceOf(EventBusClient.class), s.instanceOf(Crawler.class)); @@ -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 newIndexerApp = (s) -> new IndexerApp( s.instanceOf(EventBusClient.class), s.instanceOf(Indexer.class), s.instanceOf(Crawler.class)); @@ -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 newUrlStore = (s) -> new UrlStore(s.instanceOf(EventBusClient.class)); final Function newEventStoreApp = (s) -> new EventStoreApp( s.instanceOf(EventBusClient.class), s.instanceOf(EventStore.class)); @@ -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(); } diff --git a/src/main/java/com/epita/guereza/application/App.java b/src/main/java/com/epita/guereza/application/App.java index 397c5f4..f1359a5 100644 --- a/src/main/java/com/epita/guereza/application/App.java +++ b/src/main/java/com/epita/guereza/application/App.java @@ -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; } } diff --git a/src/main/java/com/epita/guereza/application/CrawlerApp.java b/src/main/java/com/epita/guereza/application/CrawlerApp.java index ebf9062..8ce9927 100644 --- a/src/main/java/com/epita/guereza/application/CrawlerApp.java +++ b/src/main/java/com/epita/guereza/application/CrawlerApp.java @@ -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); diff --git a/src/main/java/com/epita/guereza/application/EventStoreApp.java b/src/main/java/com/epita/guereza/application/EventStoreApp.java index e622af4..0901e53 100644 --- a/src/main/java/com/epita/guereza/application/EventStoreApp.java +++ b/src/main/java/com/epita/guereza/application/EventStoreApp.java @@ -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; @@ -25,12 +25,12 @@ public EventStoreApp(EventBusClient eventBus, EventStore eventStore) { private void extractThen(final EventBusClient.Message msg, final Consumer 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); } } @@ -39,19 +39,19 @@ private void extractThen(final EventBusClient.Message msg, final Consumer extractThen(msg, o -> { - Event ev = new Event<>("CRAWLER_REQUEST_URL", (String) o); + final Event ev = new Event<>("CRAWLER_REQUEST_URL", (String) o); eventStore.dispatch(ev); })); eventBus.subscribe("/request/indexer/url", msg -> extractThen(msg, o -> { - Event ev = new Event<>("INDEXER_REQUEST_URL", (String) o); + final Event ev = new Event<>("INDEXER_REQUEST_URL", (String) o); eventStore.dispatch(ev); })); eventBus.subscribe("/store/crawler", msg -> extractThen(msg, o -> { - Event ev = new Event<>("ADD_URLS", (StringListWrapper) o); + final Event ev = new Event<>("ADD_URLS", (StringListWrapper) o); eventStore.dispatch(ev); })); eventBus.subscribe("/store/indexer", msg -> extractThen(msg, o -> { - Event ev = new Event<>("ADD_DOCUMENT", (Document) o); + final Event ev = new Event<>("ADD_DOCUMENT", (Document) o); eventStore.dispatch(ev); })); } diff --git a/src/main/java/com/epita/guereza/application/IndexerApp.java b/src/main/java/com/epita/guereza/application/IndexerApp.java index f2297c6..996f252 100644 --- a/src/main/java/com/epita/guereza/application/IndexerApp.java +++ b/src/main/java/com/epita/guereza/application/IndexerApp.java @@ -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); diff --git a/src/main/java/com/epita/guereza/application/ServerApp.java b/src/main/java/com/epita/guereza/application/ServerApp.java index b7359ca..b7f343d 100644 --- a/src/main/java/com/epita/guereza/application/ServerApp.java +++ b/src/main/java/com/epita/guereza/application/ServerApp.java @@ -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; } diff --git a/src/main/java/com/epita/guereza/reducer/RetroIndex.java b/src/main/java/com/epita/guereza/reducer/RetroIndex.java index 74fffaf..4984b95 100644 --- a/src/main/java/com/epita/guereza/reducer/RetroIndex.java +++ b/src/main/java/com/epita/guereza/reducer/RetroIndex.java @@ -22,7 +22,7 @@ public void reduce(final Event event) { } } - private void addDocument(Event event) { + private void addDocument(final Event event) { index.docs.add(event.obj); LOGGER.info("added a document to the index"); } diff --git a/src/main/java/com/epita/guereza/reducer/UrlStore.java b/src/main/java/com/epita/guereza/reducer/UrlStore.java index 76b7691..d83e6af 100644 --- a/src/main/java/com/epita/guereza/reducer/UrlStore.java +++ b/src/main/java/com/epita/guereza/reducer/UrlStore.java @@ -46,8 +46,8 @@ public void reduce(final Event event) { } } - private void store(List urls) { - for (String url : urls) { + private void store(final List urls) { + for (final String url : urls) { if (url == null || url.isEmpty()) continue; @@ -59,25 +59,25 @@ private void store(List urls) { } } - private void addUrls(Event event) { + private void addUrls(final Event event) { store(event.obj.list); LOGGER.info("added URLs to the repo"); } - private void crawlerRequestUrl(Event event) { + private void crawlerRequestUrl(final Event 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 event) { + private void indexerRequestUrl(final Event 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()); } } diff --git a/winter/src/main/java/com/epita/winter/Scope.java b/winter/src/main/java/com/epita/winter/Scope.java index 36dba78..7c4cdd8 100644 --- a/winter/src/main/java/com/epita/winter/Scope.java +++ b/winter/src/main/java/com/epita/winter/Scope.java @@ -28,7 +28,7 @@ public static Method getMethod(final Class klass, final Class... parameterTypes) { try { return klass.getMethod(name, parameterTypes); - } catch (NoSuchMethodException e) { + } catch (final NoSuchMethodException e) { throw new NoSuchElementException(); } } @@ -46,8 +46,8 @@ public BEAN_TYPE instanceOf(final Class klass) { return parent.instanceOf(klass); } - Provider provider = (Provider) providers.get(klass); - BEAN_TYPE instance = provider.getInstance(klass, this); + final Provider provider = (Provider) providers.get(klass); + final BEAN_TYPE instance = provider.getInstance(klass, this); if (isBlock) { instances.put(instance, klass); } @@ -67,16 +67,16 @@ public Scope unregister(final Class klass) { @SuppressWarnings("unchecked") private void release(final Class klass, final BEAN_TYPE target) { if (providers.containsKey(klass)) { - Provider provider = (Provider) providers.get(klass); + final Provider provider = (Provider) providers.get(klass); provider.callAfterDestroy(this, target); } } - public void block(Consumer consumer) { + public void block(final Consumer consumer) { isBlock = true; consumer.accept(this); - for (Map.Entry> entry : instances.entrySet()) { + for (final Map.Entry> entry : instances.entrySet()) { release(entry.getValue(), entry.getKey()); } instances.clear(); diff --git a/winter/src/main/java/com/epita/winter/aspect/AspectContext.java b/winter/src/main/java/com/epita/winter/aspect/AspectContext.java index a69dc30..18d6e9d 100644 --- a/winter/src/main/java/com/epita/winter/aspect/AspectContext.java +++ b/winter/src/main/java/com/epita/winter/aspect/AspectContext.java @@ -23,7 +23,7 @@ public AspectContext(final BEAN_TYPE target, final Method method, final Object[] } Object invoke() { - AspectContext context = + final AspectContext context = new AspectContext<>(target, method, args, functions.subList(1, functions.size())); return functions.get(0).apply(context); diff --git a/winter/src/main/java/com/epita/winter/aspect/AspectInvocationHandler.java b/winter/src/main/java/com/epita/winter/aspect/AspectInvocationHandler.java index 42f1d29..3672b88 100644 --- a/winter/src/main/java/com/epita/winter/aspect/AspectInvocationHandler.java +++ b/winter/src/main/java/com/epita/winter/aspect/AspectInvocationHandler.java @@ -33,14 +33,14 @@ public AspectInvocationHandler(final Map consumer : beforeConsumers.get(method)) { + for (final BiConsumer consumer : beforeConsumers.get(method)) { consumer.accept(scope, target); } } - Object res; + final Object res; if (aroundFunctions.containsKey(method)) { - AspectContext context = + final AspectContext context = new AspectContext<>(target, method, args, aroundFunctions.get(method)); res = context.invoke(); @@ -49,7 +49,7 @@ public Object invoke(final Object proxy, final Method method, final Object[] arg } if (afterConsumers.containsKey(method)) { - for (BiConsumer consumer : afterConsumers.get(method)) { + for (final BiConsumer consumer : afterConsumers.get(method)) { consumer.accept(scope, target); } } diff --git a/winter/src/main/java/com/epita/winter/provider/AnyProvider.java b/winter/src/main/java/com/epita/winter/provider/AnyProvider.java index 7fdfe0d..c067162 100644 --- a/winter/src/main/java/com/epita/winter/provider/AnyProvider.java +++ b/winter/src/main/java/com/epita/winter/provider/AnyProvider.java @@ -27,12 +27,12 @@ public Class getInstanceClass() { } public BEAN_TYPE getInstance(final Class 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); } @@ -71,7 +71,7 @@ public Provider beforeDestroy(final BiConsumer cons } public void callAfterDestroy(final Scope scope, final BEAN_TYPE target) { - for (BiConsumer consumer : beforeDestroyConsumers) { + for (final BiConsumer consumer : beforeDestroyConsumers) { consumer.accept(scope, target); } } @@ -83,7 +83,7 @@ private AspectInvocationHandler getAspectInvocationHandler(final Scope scope, fi } void callAfterCreate(final Scope scope, final BEAN_TYPE target) { - for (BiConsumer consumer : afterCreateConsumers) { + for (final BiConsumer consumer : afterCreateConsumers) { consumer.accept(scope, target); } } diff --git a/winter/src/main/java/com/epita/winter/provider/Prototype.java b/winter/src/main/java/com/epita/winter/provider/Prototype.java index 2fb9563..e5f08e0 100644 --- a/winter/src/main/java/com/epita/winter/provider/Prototype.java +++ b/winter/src/main/java/com/epita/winter/provider/Prototype.java @@ -14,7 +14,7 @@ public Prototype(final Class klass, final Function @Override protected BEAN_TYPE createInstance(final Scope scope) { - BEAN_TYPE target = initiator.apply(scope); + final BEAN_TYPE target = initiator.apply(scope); callAfterCreate(scope, target); return target; }