Renaming following article review

This commit is contained in:
danidemi 2016-11-07 22:44:09 +01:00
parent 9ae723f5ab
commit b27a8cff06
10 changed files with 31 additions and 31 deletions

View File

@ -10,11 +10,11 @@ public class TransactionFactory {
private static final String[] NAMES = {"John", "Susan", "Marc", "Samantha"};
private static long nextId = 1;
public Transaction newInstance() {
public Transfer newInstance() {
String transactionId = String.valueOf( nextId++ );
String owner = NAMES[ (int) floor(random()*NAMES.length) ];
long amount = (long) (random()*1500 + 500);
Transaction tx = new Transaction(transactionId, owner, amount);
Transfer tx = new Transfer(transactionId, owner, amount);
return tx;
}

View File

@ -1,19 +1,19 @@
package com.baeldung.mdc;
public class Transaction {
public class Transfer {
private String transactionId;
private String owner;
private String sender;
private Long amount;
public Transaction(String transactionId, String owner, long amount) {
public Transfer(String transactionId, String sender, long amount) {
this.transactionId = transactionId;
this.owner = owner;
this.sender = sender;
this.amount = amount;
}
public String getOwner() {
return owner;
public String getSender() {
return sender;
}
public String getTransactionId() {

View File

@ -9,7 +9,7 @@ import com.baeldung.mdc.log4j.Log4JRunnable;
import com.baeldung.mdc.log4j2.Log4J2Runnable;
import com.baeldung.mdc.slf4j.Slf4jRunnable;
public class GenericApp {
public class TransferDemo {
public static void main(String[] args) {
@ -17,7 +17,7 @@ public class GenericApp {
TransactionFactory transactionFactory = new TransactionFactory();
for (int i = 0; i < 10; i++) {
final Transaction tx = transactionFactory.newInstance();
Transfer tx = transactionFactory.newInstance();
//Runnable task = new Log4JRunnable(tx);
//Runnable task = new Log4J2Runnable(tx);

View File

@ -1,7 +1,7 @@
package com.baeldung.mdc;
/**
* A fake {@link IBusinessService} simulating an actual one.
* A fake transfer service simulating an actual one.
*/
public abstract class TransferService {

View File

@ -2,21 +2,21 @@ package com.baeldung.mdc.log4j;
import org.apache.log4j.MDC;
import com.baeldung.mdc.Transaction;
import com.baeldung.mdc.Transfer;
public class Log4JRunnable implements Runnable {
private Transaction tx;
private static Log4JBusinessService log4jBusinessService = new Log4JBusinessService();
private Transfer tx;
private static Log4JTransferService log4jBusinessService = new Log4JTransferService();
public Log4JRunnable(Transaction tx) {
public Log4JRunnable(Transfer tx) {
this.tx = tx;
}
public void run() {
MDC.put("transaction.id", tx.getTransactionId());
MDC.put("transaction.owner", tx.getOwner());
MDC.put("transaction.owner", tx.getSender());
log4jBusinessService.transfer(tx.getAmount());

View File

@ -4,9 +4,9 @@ import org.apache.log4j.Logger;
import com.baeldung.mdc.TransferService;
public class Log4JBusinessService extends TransferService {
public class Log4JTransferService extends TransferService {
private Logger logger = Logger.getLogger(Log4JBusinessService.class);
private Logger logger = Logger.getLogger(Log4JTransferService.class);
@Override
protected void beforeTransfer(long amount) {

View File

@ -2,20 +2,20 @@ package com.baeldung.mdc.log4j2;
import org.apache.logging.log4j.ThreadContext;
import com.baeldung.mdc.Transaction;
import com.baeldung.mdc.Transfer;
public class Log4J2Runnable implements Runnable {
private final Transaction tx;
private Log4J2BusinessService log4j2BusinessService = new Log4J2BusinessService();
private final Transfer tx;
private Log4J2TransferService log4j2BusinessService = new Log4J2TransferService();
public Log4J2Runnable(Transaction tx) {
public Log4J2Runnable(Transfer tx) {
this.tx = tx;
}
public void run() {
ThreadContext.put("transaction.id", tx.getTransactionId());
ThreadContext.put("transaction.owner", tx.getOwner());
ThreadContext.put("transaction.owner", tx.getSender());
log4j2BusinessService.transfer(tx.getAmount());

View File

@ -5,7 +5,7 @@ import org.apache.logging.log4j.Logger;
import com.baeldung.mdc.TransferService;
public class Log4J2BusinessService extends TransferService {
public class Log4J2TransferService extends TransferService {
private static final Logger logger = LogManager.getLogger();

View File

@ -5,9 +5,9 @@ import org.slf4j.LoggerFactory;
import com.baeldung.mdc.TransferService;
final class Slf4jBusinessService extends TransferService {
final class Slf4TransferService extends TransferService {
private static final Logger logger = LoggerFactory.getLogger(Slf4jBusinessService.class);
private static final Logger logger = LoggerFactory.getLogger(Slf4TransferService.class);
@Override
protected void beforeTransfer(long amount) {

View File

@ -2,21 +2,21 @@ package com.baeldung.mdc.slf4j;
import org.slf4j.MDC;
import com.baeldung.mdc.Transaction;
import com.baeldung.mdc.Transfer;
public class Slf4jRunnable implements Runnable {
private final Transaction tx;
private final Transfer tx;
public Slf4jRunnable(Transaction tx) {
public Slf4jRunnable(Transfer tx) {
this.tx = tx;
}
public void run() {
MDC.put("transaction.id", tx.getTransactionId());
MDC.put("transaction.owner", tx.getOwner());
MDC.put("transaction.owner", tx.getSender());
new Slf4jBusinessService().transfer(tx.getAmount());
new Slf4TransferService().transfer(tx.getAmount());
MDC.clear();