Skip to content

Commit

Permalink
Merge pull request #3 from larsid/refactor/log
Browse files Browse the repository at this point in the history
Refactor/log
  • Loading branch information
AllanCapistrano authored Jul 17, 2023
2 parents 406e245 + 2844dcf commit e6f0dd1
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 11 deletions.
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>

<repositories>
<repository>
<id>jitpack.io</id>
Expand Down Expand Up @@ -125,6 +125,7 @@
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
Expand Down
1 change: 0 additions & 1 deletion src/main/java/dlt/client/tangle/model/LedgerReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ private void notifyAll(String topic, Object object) {
if (topic != null && !topic.isEmpty()) {
Set<ILedgerSubscriber> subscribers = this.topics.get(topic);
if (subscribers != null && !subscribers.isEmpty()) {

subscribers.forEach(sub -> sub.update(object));
}
}
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/dlt/client/tangle/model/LedgerWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.google.gson.JsonParser;
import com.google.gson.stream.JsonReader;
import dlt.client.tangle.enums.TransactionType;
import dlt.client.tangle.model.transactions.LBDevice;
import dlt.client.tangle.model.transactions.LBReply;
import dlt.client.tangle.model.transactions.Reply;
import dlt.client.tangle.model.transactions.Request;
Expand All @@ -23,6 +24,7 @@
import org.iota.jota.model.Transfer;
import org.iota.jota.utils.SeedRandomGenerator;
import org.iota.jota.utils.TrytesConverter;
import java.util.logging.Logger;

/**
*
Expand All @@ -40,6 +42,7 @@ public class LedgerWriter implements ILedgerWriter, Runnable {
private final int minimumWeightMagnitude;
private final int securityLevel;
private String url;
private static final Logger logger = Logger.getLogger(LedgerWriter.class.getName());

public LedgerWriter(
String protocol,
Expand Down Expand Up @@ -111,8 +114,8 @@ public Transaction getTransactionByHash(String hashTransaction) {
}

private Transaction getTypeTransaction(String transactionJSON) {
System.out.println("JSON Message");
System.out.println(transactionJSON);
logger.info("JSON Message");
logger.info(transactionJSON);

JsonParser jsonparser = new JsonParser();
JsonReader reader = new JsonReader(new StringReader(transactionJSON));
Expand All @@ -137,9 +140,10 @@ private Transaction getTypeTransaction(String transactionJSON) {
return gson.fromJson(reader, Request.class);
} else if (type.equals(TransactionType.LB_STATUS.name())) {
return gson.fromJson(reader, Status.class);
} else {
return gson.fromJson(reader, LBDevice.class);
}

return null;
}

private void writeToTangle(String tagGroup, String message) {
Expand Down Expand Up @@ -169,7 +173,7 @@ private void writeToTangle(String tagGroup, String message) {
null
);
} catch (ArgumentException e) {
System.out.println("Error in arguments!");
logger.info("Error in arguments!");
e.printStackTrace();
}
}
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/dlt/client/tangle/model/ZMQServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class ZMQServer implements Runnable {
private ZMQ.Socket serverListener;
private String socketURL;
private String address;
private static final Logger logger = Logger.getLogger(ZMQServer.class.getName());

public ZMQServer(
int bufferSize,
Expand All @@ -36,7 +37,7 @@ public ZMQServer(

public void start() {
if (this.serverThread == null) {
System.out.println("Socket URL: " + this.socketURL);
logger.info("Socket URL: " + this.socketURL);

this.serverListener.connect(this.socketURL);
this.serverThread = new Thread(this);
Expand All @@ -51,7 +52,7 @@ public void stop() {
}

public void subscribe(String topic) {
System.out.println("Subscribe: " + topic);
logger.info("Subscribe: " + topic);
this.serverListener.subscribe(topic);
}

Expand All @@ -65,7 +66,8 @@ public String take() throws InterruptedException {

@Override
public void run() {
System.out.println("Address: " + address);
logger.info("Address: " + address);

while (!this.serverThread.isInterrupted()) {
byte[] reply = serverListener.recv(0);
String[] data = (new String(reply).split(" "));
Expand All @@ -82,7 +84,7 @@ private void putReceivedMessageBuffer(String receivedMessage) {
try {
this.DLTInboundBuffer.put(receivedMessage);
} catch (InterruptedException ex) {
Logger.getLogger(ZMQServer.class.getName()).log(Level.SEVERE, null, ex);
logger.log(Level.SEVERE, null, ex);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public double getLastLoad() {
return lastLoad;
}

public boolean getAvaible() {
public boolean getAvailable() {
return available;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,15 @@ public final void setPublishedAt(long publishedAt) {
public final long getPublishedAt() {
return this.publishedAt;
}

@Override
public String toString() {
return new StringBuilder("Transaction: ")
.append(this.source)
.append(this.group)
.append(this.type)
.append(this.createdAt)
.append(this.publishedAt)
.toString();
}
}

0 comments on commit e6f0dd1

Please sign in to comment.