Skip to content

Commit 9ae723f

Browse files
committed
Removed redundant interface
1 parent d0e95df commit 9ae723f

9 files changed

Lines changed: 30 additions & 51 deletions

File tree

‎log-mdc-ndc/src/main/java/com/baeldung/mdc/IBusinessService.java‎

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,27 @@
11
package com.baeldung.mdc;
22

3-
import java.util.Date;
4-
53
public class Transaction {
6-
7-
private String transactionId;
8-
private String owner;
9-
private Date createdAt;
10-
private Long amount;
11-
12-
public Transaction(String transactionId, String owner, long amount) {
13-
this.transactionId = transactionId;
14-
this.owner = owner;
15-
this.createdAt = new Date();
16-
this.amount = amount;
17-
}
184

19-
public String getOwner() {
20-
return owner;
21-
}
5+
private String transactionId;
6+
private String owner;
7+
private Long amount;
8+
9+
public Transaction(String transactionId, String owner, long amount) {
10+
this.transactionId = transactionId;
11+
this.owner = owner;
12+
this.amount = amount;
13+
}
14+
15+
public String getOwner() {
16+
return owner;
17+
}
18+
19+
public String getTransactionId() {
20+
return transactionId;
21+
}
22+
23+
public Long getAmount() {
24+
return amount;
25+
}
2226

23-
public String getTransactionId() {
24-
return transactionId;
25-
}
26-
27-
public Date getCreatedAt() {
28-
return createdAt;
29-
}
30-
31-
public Long getAmount() {
32-
return amount;
33-
}
34-
3527
}

log-mdc-ndc/src/main/java/com/baeldung/mdc/BusinessService.java renamed to log-mdc-ndc/src/main/java/com/baeldung/mdc/TransferService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
/**
44
* A fake {@link IBusinessService} simulating an actual one.
55
*/
6-
public abstract class BusinessService implements IBusinessService {
6+
public abstract class TransferService {
77

8+
/** Sample service transferring a given amount of money.
9+
* @return {@code true} when the transfer complete successfully, {@code false} otherwise. */
810
public boolean transfer(long amount) {
911
beforeTransfer(amount);
1012
// exchange messages with a remote system to transfer the money

‎log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JBusinessService.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
import org.apache.log4j.Logger;
44

5-
import com.baeldung.mdc.BusinessService;
5+
import com.baeldung.mdc.TransferService;
66

7-
public class Log4JBusinessService extends BusinessService {
7+
public class Log4JBusinessService extends TransferService {
88

99
private Logger logger = Logger.getLogger(Log4JBusinessService.class);
1010

‎log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JRunnable.java‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package com.baeldung.mdc.log4j;
22

33
import org.apache.log4j.MDC;
4-
import org.apache.logging.log4j.ThreadContext;
54

65
import com.baeldung.mdc.Transaction;
7-
import com.baeldung.mdc.log4j2.Log4J2BusinessService;
86

97
public class Log4JRunnable implements Runnable {
108

@@ -19,7 +17,6 @@ public void run() {
1917

2018
MDC.put("transaction.id", tx.getTransactionId());
2119
MDC.put("transaction.owner", tx.getOwner());
22-
MDC.put("transaction.createdAt", tx.getCreatedAt());
2320

2421
log4jBusinessService.transfer(tx.getAmount());
2522

‎log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2BusinessService.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import org.apache.logging.log4j.LogManager;
44
import org.apache.logging.log4j.Logger;
55

6-
import com.baeldung.mdc.BusinessService;
6+
import com.baeldung.mdc.TransferService;
77

8-
public class Log4J2BusinessService extends BusinessService {
8+
public class Log4J2BusinessService extends TransferService {
99

1010
private static final Logger logger = LogManager.getLogger();
1111

‎log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2Runnable.java‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@ public Log4J2Runnable(Transaction tx) {
1414

1515
public void run() {
1616

17-
ThreadContext.put("transaction.id", tx.getTransactionId());
1817
ThreadContext.put("transaction.id", tx.getTransactionId());
1918
ThreadContext.put("transaction.owner", tx.getOwner());
20-
ThreadContext.put("transaction.createdAt", tx.getCreatedAt().toString());
2119

2220
log4j2BusinessService.transfer(tx.getAmount());
2321

‎log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4jBusinessService.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import org.slf4j.Logger;
44
import org.slf4j.LoggerFactory;
55

6-
import com.baeldung.mdc.BusinessService;
6+
import com.baeldung.mdc.TransferService;
77

8-
final class Slf4jBusinessService extends BusinessService {
8+
final class Slf4jBusinessService extends TransferService {
99

1010
private static final Logger logger = LoggerFactory.getLogger(Slf4jBusinessService.class);
1111

‎log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4jRunnable.java‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ public void run() {
1515

1616
MDC.put("transaction.id", tx.getTransactionId());
1717
MDC.put("transaction.owner", tx.getOwner());
18-
MDC.put("transaction.createdAt", tx.getCreatedAt().toString());
1918

2019
new Slf4jBusinessService().transfer(tx.getAmount());
2120

0 commit comments

Comments
 (0)