Removed redundant interface
This commit is contained in:
parent
d0e95dfbdd
commit
9ae723f5ab
|
@ -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);
|
||||
|
||||
}
|
|
@ -1,35 +1,27 @@
|
|||
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;
|
||||
}
|
||||
|
||||
public String getOwner() {
|
||||
return owner;
|
||||
}
|
||||
private String transactionId;
|
||||
private String owner;
|
||||
private Long amount;
|
||||
|
||||
public Transaction(String transactionId, String owner, long amount) {
|
||||
this.transactionId = transactionId;
|
||||
this.owner = owner;
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public String getOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
public String getTransactionId() {
|
||||
return transactionId;
|
||||
}
|
||||
|
||||
public Long getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public String getTransactionId() {
|
||||
return transactionId;
|
||||
}
|
||||
|
||||
public Date getCreatedAt() {
|
||||
return createdAt;
|
||||
}
|
||||
|
||||
public Long getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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());
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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());
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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());
|
||||
|
||||
|
|
Loading…
Reference in New Issue