Removed redundant interface

This commit is contained in:
danidemi 2016-11-07 21:21:28 +01:00
parent d0e95dfbdd
commit 9ae723f5ab
9 changed files with 30 additions and 51 deletions

View File

@ -1,9 +0,0 @@
package com.baeldung.mdc;
public interface IBusinessService {
/** Sample service transferring a given amount of money.
* @return {@code true} when the transfer complete successfully, {@code false} otherwise. */
boolean transfer(long amount);
}

View File

@ -1,18 +1,14 @@
package com.baeldung.mdc;
import java.util.Date;
public class Transaction {
private String transactionId;
private String owner;
private Date createdAt;
private Long amount;
public Transaction(String transactionId, String owner, long amount) {
this.transactionId = transactionId;
this.owner = owner;
this.createdAt = new Date();
this.amount = amount;
}
@ -24,10 +20,6 @@ public class Transaction {
return transactionId;
}
public Date getCreatedAt() {
return createdAt;
}
public Long getAmount() {
return amount;
}

View File

@ -3,8 +3,10 @@ package com.baeldung.mdc;
/**
* A fake {@link IBusinessService} simulating an actual one.
*/
public abstract class BusinessService implements IBusinessService {
public abstract class TransferService {
/** Sample service transferring a given amount of money.
* @return {@code true} when the transfer complete successfully, {@code false} otherwise. */
public boolean transfer(long amount) {
beforeTransfer(amount);
// exchange messages with a remote system to transfer the money

View File

@ -2,9 +2,9 @@ package com.baeldung.mdc.log4j;
import org.apache.log4j.Logger;
import com.baeldung.mdc.BusinessService;
import com.baeldung.mdc.TransferService;
public class Log4JBusinessService extends BusinessService {
public class Log4JBusinessService extends TransferService {
private Logger logger = Logger.getLogger(Log4JBusinessService.class);

View File

@ -1,10 +1,8 @@
package com.baeldung.mdc.log4j;
import org.apache.log4j.MDC;
import org.apache.logging.log4j.ThreadContext;
import com.baeldung.mdc.Transaction;
import com.baeldung.mdc.log4j2.Log4J2BusinessService;
public class Log4JRunnable implements Runnable {
@ -19,7 +17,6 @@ public class Log4JRunnable implements Runnable {
MDC.put("transaction.id", tx.getTransactionId());
MDC.put("transaction.owner", tx.getOwner());
MDC.put("transaction.createdAt", tx.getCreatedAt());
log4jBusinessService.transfer(tx.getAmount());

View File

@ -3,9 +3,9 @@ package com.baeldung.mdc.log4j2;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.baeldung.mdc.BusinessService;
import com.baeldung.mdc.TransferService;
public class Log4J2BusinessService extends BusinessService {
public class Log4J2BusinessService extends TransferService {
private static final Logger logger = LogManager.getLogger();

View File

@ -14,10 +14,8 @@ public class Log4J2Runnable implements Runnable {
public void run() {
ThreadContext.put("transaction.id", tx.getTransactionId());
ThreadContext.put("transaction.id", tx.getTransactionId());
ThreadContext.put("transaction.owner", tx.getOwner());
ThreadContext.put("transaction.createdAt", tx.getCreatedAt().toString());
log4j2BusinessService.transfer(tx.getAmount());

View File

@ -3,9 +3,9 @@ package com.baeldung.mdc.slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.baeldung.mdc.BusinessService;
import com.baeldung.mdc.TransferService;
final class Slf4jBusinessService extends BusinessService {
final class Slf4jBusinessService extends TransferService {
private static final Logger logger = LoggerFactory.getLogger(Slf4jBusinessService.class);

View File

@ -15,7 +15,6 @@ public class Slf4jRunnable implements Runnable {
MDC.put("transaction.id", tx.getTransactionId());
MDC.put("transaction.owner", tx.getOwner());
MDC.put("transaction.createdAt", tx.getCreatedAt().toString());
new Slf4jBusinessService().transfer(tx.getAmount());