Optimize build and reduce logging (#1772)

* Reduce logging

* Reduce logging

* Reduce logging

* Reduce logging

* Reduce logging

* Optimize build

* Remove testng from core-java
This commit is contained in:
Grzegorz Piwowarek
2017-05-03 09:29:10 +02:00
committed by GitHub
parent c5ddf680a7
commit 6e86dc27ff
60 changed files with 626 additions and 507 deletions

View File

@@ -1,9 +1,15 @@
package com.baeldung.concurrent.sleepwait;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/***
* Example of waking up a waiting thread
*/
public class ThreadA {
private static final Logger LOG = LoggerFactory.getLogger(ThreadA.class);
private static final ThreadB b = new ThreadB();
public static void main(String... args) throws InterruptedException {
@@ -11,11 +17,11 @@ public class ThreadA {
synchronized (b) {
while (b.sum == 0) {
System.out.println("Waiting for ThreadB to complete...");
LOG.debug("Waiting for ThreadB to complete...");
b.wait();
}
System.out.println("ThreadB has completed. Sum from that thread is: " + b.sum);
LOG.debug("ThreadB has completed. Sum from that thread is: " + b.sum);
}
}
}

View File

@@ -1,9 +1,15 @@
package com.baeldung.concurrent.sleepwait;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/***
* Example of wait() and sleep() methods
*/
public class WaitSleepExample {
private static final Logger LOG = LoggerFactory.getLogger(WaitSleepExample.class);
private static final Object LOCK = new Object();
public static void main(String... args) throws InterruptedException {
@@ -12,11 +18,11 @@ public class WaitSleepExample {
private static void sleepWaitInSyncronizedBlocks() throws InterruptedException {
Thread.sleep(1000); // called on the thread
System.out.println("Thread '" + Thread.currentThread().getName() + "' is woken after sleeping for 1 second");
LOG.debug("Thread '" + Thread.currentThread().getName() + "' is woken after sleeping for 1 second");
synchronized (LOCK) {
LOCK.wait(1000); // called on the object, synchronization required
System.out.println("Object '" + LOCK + "' is woken after waiting for 1 second");
LOG.debug("Object '" + LOCK + "' is woken after waiting for 1 second");
}
}

View File

@@ -1,14 +1,19 @@
package com.baeldung.dirmonitoring;
import java.io.File;
import org.apache.commons.io.monitor.FileAlterationListener;
import org.apache.commons.io.monitor.FileAlterationListenerAdaptor;
import org.apache.commons.io.monitor.FileAlterationMonitor;
import org.apache.commons.io.monitor.FileAlterationObserver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
public class DirectoryMonitoringExample {
private static final Logger LOG = LoggerFactory.getLogger(DirectoryMonitoringExample.class);
public static final int POLL_INTERVAL = 500;
public static void main(String[] args) throws Exception {
@@ -17,17 +22,17 @@ public class DirectoryMonitoringExample {
FileAlterationListener listener = new FileAlterationListenerAdaptor() {
@Override
public void onFileCreate(File file) {
System.out.println("File: " + file.getName() + " created");
LOG.debug("File: " + file.getName() + " created");
}
@Override
public void onFileDelete(File file) {
System.out.println("File: " + file.getName() + " deleted");
LOG.debug("File: " + file.getName() + " deleted");
}
@Override
public void onFileChange(File file) {
System.out.println("File: " + file.getName() + " changed");
LOG.debug("File: " + file.getName() + " changed");
}
};
observer.addListener(listener);

View File

@@ -1,9 +1,14 @@
package com.baeldung.doublecolon;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.function.Function;
public class MacbookPro extends Computer {
private static final Logger LOG = LoggerFactory.getLogger(MacbookPro.class);
public MacbookPro(int age, String color) {
super(age, color);
}
@@ -14,12 +19,12 @@ public class MacbookPro extends Computer {
@Override
public void turnOnPc() {
System.out.println("MacbookPro turned on");
LOG.debug("MacbookPro turned on");
}
@Override
public void turnOffPc() {
System.out.println("MacbookPro turned off");
LOG.debug("MacbookPro turned off");
}
@Override
@@ -27,7 +32,7 @@ public class MacbookPro extends Computer {
Function<Double, Double> function = super::calculateValue;
final Double pcValue = function.apply(initialValue);
System.out.println("First value is:" + pcValue);
LOG.debug("First value is:" + pcValue);
return pcValue + (initialValue / 10);
}

View File

@@ -1,6 +1,11 @@
package com.baeldung.java.map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class MyKey {
private static final Logger LOG = LoggerFactory.getLogger(MyKey.class);
private String name;
private int id;
@@ -27,7 +32,7 @@ public class MyKey {
@Override
public int hashCode() {
System.out.println("Calling hashCode()");
LOG.debug("Calling hashCode()");
return id;
}
@@ -38,7 +43,7 @@ public class MyKey {
@Override
public boolean equals(Object obj) {
System.out.println("Calling equals() for key: " + obj);
LOG.debug("Calling equals() for key: " + obj);
if (this == obj)
return true;
if (obj == null)

View File

@@ -1,23 +1,28 @@
package com.baeldung.jmx;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Game implements GameMBean {
private static final Logger LOG = LoggerFactory.getLogger(Game.class);
private String playerName;
@Override
public void playFootball(String clubName) {
System.out.println(this.playerName + " playing football for " + clubName);
LOG.debug(this.playerName + " playing football for " + clubName);
}
@Override
public String getPlayerName() {
System.out.println("Return playerName " + this.playerName);
LOG.debug("Return playerName " + this.playerName);
return playerName;
}
@Override
public void setPlayerName(String playerName) {
System.out.println("Set playerName to value " + playerName);
LOG.debug("Set playerName to value " + playerName);
this.playerName = playerName;
}

View File

@@ -1,19 +1,20 @@
package com.baeldung.jmx;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.management.*;
import java.lang.management.ManagementFactory;
import javax.management.InstanceAlreadyExistsException;
import javax.management.MBeanRegistrationException;
import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
import javax.management.NotCompliantMBeanException;
import javax.management.ObjectName;
public class JMXTutorialMainlauncher {
private static final Logger LOG = LoggerFactory.getLogger(JMXTutorialMainlauncher.class);
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("This is basic JMX tutorial");
LOG.debug("This is basic JMX tutorial");
ObjectName objectName = null;
try {
objectName = new ObjectName("com.baeldung.tutorial:type=basic,name=game");
@@ -27,8 +28,8 @@ public class JMXTutorialMainlauncher {
} catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e) {
e.printStackTrace();
}
System.out.println("Registration for Game mbean with the platform server is successfull");
System.out.println("Please open jconsole to access Game mbean");
LOG.debug("Registration for Game mbean with the platform server is successfull");
LOG.debug("Please open jconsole to access Game mbean");
while (true) {
// to ensure application does not terminate
}

View File

@@ -1,9 +1,16 @@
package com.baeldung.socket;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.*;
import java.net.*;
public class EchoClient {
private static final Logger LOG = LoggerFactory.getLogger(EchoClient.class);
private Socket clientSocket;
private PrintWriter out;
private BufferedReader in;
@@ -14,7 +21,7 @@ public class EchoClient {
out = new PrintWriter(clientSocket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
} catch (IOException e) {
System.out.print(e);
LOG.debug("Error when initializing connection", e);
}
}
@@ -34,7 +41,7 @@ public class EchoClient {
out.close();
clientSocket.close();
} catch (IOException e) {
e.printStackTrace();
LOG.debug("error when closing", e);
}
}

View File

@@ -1,9 +1,15 @@
package com.baeldung.socket;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.*;
import java.io.*;
public class EchoMultiServer {
private static final Logger LOG = LoggerFactory.getLogger(EchoMultiServer.class);
private ServerSocket serverSocket;
public void start(int port) {
@@ -57,7 +63,7 @@ public class EchoMultiServer {
clientSocket.close();
} catch (IOException e) {
e.printStackTrace();
LOG.debug(e.getMessage());
}
}
}

View File

@@ -1,9 +1,15 @@
package com.baeldung.socket;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.*;
import java.io.*;
public class EchoServer {
private static final Logger LOG = LoggerFactory.getLogger(EchoServer.class);
private ServerSocket serverSocket;
private Socket clientSocket;
private PrintWriter out;
@@ -24,7 +30,7 @@ public class EchoServer {
out.println(inputLine);
}
} catch (IOException e) {
e.printStackTrace();
LOG.debug(e.getMessage());
}
}
@@ -36,7 +42,7 @@ public class EchoServer {
clientSocket.close();
serverSocket.close();
} catch (IOException e) {
e.printStackTrace();
LOG.debug(e.getMessage());
}
}

View File

@@ -1,5 +1,8 @@
package com.baeldung.socket;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
@@ -7,6 +10,9 @@ import java.io.PrintWriter;
import java.net.Socket;
public class GreetClient {
private static final Logger LOG = LoggerFactory.getLogger(EchoMultiServer.class);
private Socket clientSocket;
private PrintWriter out;
private BufferedReader in;
@@ -17,7 +23,7 @@ public class GreetClient {
out = new PrintWriter(clientSocket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
} catch (IOException e) {
LOG.debug(e.getMessage());
}
}
@@ -37,7 +43,7 @@ public class GreetClient {
out.close();
clientSocket.close();
} catch (IOException e) {
e.printStackTrace();
LOG.debug(e.getMessage());
}
}

View File

@@ -1,9 +1,15 @@
package com.baeldung.socket;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.*;
import java.io.*;
public class GreetServer {
private static final Logger LOG = LoggerFactory.getLogger(GreetServer.class);
private ServerSocket serverSocket;
private Socket clientSocket;
private PrintWriter out;
@@ -21,7 +27,7 @@ public class GreetServer {
else
out.println("unrecognised greeting");
} catch (IOException e) {
e.printStackTrace();
LOG.debug(e.getMessage());
}
}
@@ -33,7 +39,7 @@ public class GreetServer {
clientSocket.close();
serverSocket.close();
} catch (IOException e) {
e.printStackTrace();
LOG.debug(e.getMessage());
}
}

View File

@@ -1,9 +1,15 @@
package com.baeldung.stream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.stream.Stream;
public class InfiniteStreams {
private static final Logger LOG = LoggerFactory.getLogger(InfiniteStreams.class);
public static void main(String[] args) {
doWhileOldWay();
@@ -15,7 +21,7 @@ public class InfiniteStreams {
int i = 0;
while (i < 10) {
System.out.println(i);
LOG.debug("{}", i);
i++;
}
}

View File

@@ -1,7 +1,11 @@
package com.baeldung.threadlocal;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ThreadLocalWithUserContext implements Runnable {
private static final Logger LOG = LoggerFactory.getLogger(ThreadLocalWithUserContext.class);
private static final ThreadLocal<Context> userContext = new ThreadLocal<>();
private final Integer userId;
private UserRepository userRepository = new UserRepository();
@@ -15,6 +19,6 @@ public class ThreadLocalWithUserContext implements Runnable {
public void run() {
String userName = userRepository.getUserNameForUserId(userId);
userContext.set(new Context(userName));
System.out.println("thread context for given userId: " + userId + " is: " + userContext.get());
LOG.debug("thread context for given userId: " + userId + " is: " + userContext.get());
}
}

View File

@@ -1,9 +1,15 @@
package com.baeldung.transferqueue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.TransferQueue;
import java.util.concurrent.atomic.AtomicInteger;
public class Consumer implements Runnable {
private static final Logger LOG = LoggerFactory.getLogger(Consumer.class);
private final TransferQueue<String> transferQueue;
private final String name;
private final int numberOfMessagesToConsume;
@@ -19,10 +25,10 @@ public class Consumer implements Runnable {
public void run() {
for (int i = 0; i < numberOfMessagesToConsume; i++) {
try {
System.out.println("Consumer: " + name + " is waiting to take element...");
LOG.debug("Consumer: " + name + " is waiting to take element...");
String element = transferQueue.take();
longProcessing(element);
System.out.println("Consumer: " + name + " received element: " + element);
LOG.debug("Consumer: " + name + " received element: " + element);
} catch (InterruptedException e) {
e.printStackTrace();
}

View File

@@ -1,10 +1,15 @@
package com.baeldung.transferqueue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TransferQueue;
import java.util.concurrent.atomic.AtomicInteger;
public class Producer implements Runnable {
private static final Logger LOG = LoggerFactory.getLogger(Producer.class);
private final TransferQueue<String> transferQueue;
private final String name;
private final Integer numberOfMessagesToProduce;
@@ -20,13 +25,13 @@ public class Producer implements Runnable {
public void run() {
for (int i = 0; i < numberOfMessagesToProduce; i++) {
try {
System.out.println("Producer: " + name + " is waiting to transfer...");
LOG.debug("Producer: " + name + " is waiting to transfer...");
boolean added = transferQueue.tryTransfer("A" + i, 4000, TimeUnit.MILLISECONDS);
if (added) {
numberOfProducedMessages.incrementAndGet();
System.out.println("Producer: " + name + " transferred element: A" + i);
LOG.debug("Producer: " + name + " transferred element: A" + i);
} else {
System.out.println("can not add an element due to the timeout");
LOG.debug("can not add an element due to the timeout");
}
} catch (InterruptedException e) {
e.printStackTrace();