mirror of
https://github.com/bisq-network/bisq.git
synced 2025-03-26 20:30:55 +01:00
Add value objects and protobuf definitions
Signed-off-by: HenrikJannsen <boilingfrog@gmx.com>
This commit is contained in:
parent
3caf2c2b64
commit
2c84f07ada
6 changed files with 433 additions and 0 deletions
86
core/src/main/java/bisq/core/monitor/DoubleValueItem.java
Normal file
86
core/src/main/java/bisq/core/monitor/DoubleValueItem.java
Normal file
|
@ -0,0 +1,86 @@
|
|||
/*
|
||||
* This file is part of Bisq.
|
||||
*
|
||||
* Bisq is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* Bisq is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package bisq.core.monitor;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
|
||||
public enum DoubleValueItem implements ReportingItem {
|
||||
Unspecified("", "Unspecified"),
|
||||
sentBytesPerSec("network", "sentBytesPerSec"),
|
||||
receivedBytesPerSec("network", "receivedBytesPerSec"),
|
||||
receivedMessagesPerSec("network", "receivedMessagesPerSec"),
|
||||
sentMessagesPerSec("network", "sentMessagesPerSec");
|
||||
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private String key;
|
||||
@Getter
|
||||
@Setter
|
||||
private String group;
|
||||
@Getter
|
||||
@Setter
|
||||
private double value;
|
||||
|
||||
DoubleValueItem(String group, String key) {
|
||||
this.group = group;
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public DoubleValueItem withValue(double value) {
|
||||
setValue(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public static DoubleValueItem from(String key, double value) {
|
||||
DoubleValueItem item;
|
||||
try {
|
||||
item = DoubleValueItem.valueOf(key);
|
||||
} catch (Throwable t) {
|
||||
item = DoubleValueItem.Unspecified;
|
||||
item.setKey(key);
|
||||
}
|
||||
|
||||
item.setValue(value);
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public protobuf.ReportingItem toProtoMessage() {
|
||||
return getBuilder().setDoubleValueItem(protobuf.DoubleValueItem.newBuilder()
|
||||
.setValue(value))
|
||||
.build();
|
||||
}
|
||||
|
||||
public static DoubleValueItem fromProto(protobuf.ReportingItem baseProto, protobuf.DoubleValueItem proto) {
|
||||
return DoubleValueItem.from(baseProto.getKey(), proto.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPath() {
|
||||
return group + "." + key;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name() + "= " + value;
|
||||
}
|
||||
}
|
107
core/src/main/java/bisq/core/monitor/IntegerValueItem.java
Normal file
107
core/src/main/java/bisq/core/monitor/IntegerValueItem.java
Normal file
|
@ -0,0 +1,107 @@
|
|||
/*
|
||||
* This file is part of Bisq.
|
||||
*
|
||||
* Bisq is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* Bisq is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package bisq.core.monitor;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
|
||||
public enum IntegerValueItem implements ReportingItem {
|
||||
Unspecified("", "Unspecified"),
|
||||
OfferPayload("data", "OfferPayload"),
|
||||
MailboxStoragePayload("data", "MailboxStoragePayload"),
|
||||
TradeStatistics3("data", "TradeStatistics3"),
|
||||
AccountAgeWitness("data", "AccountAgeWitness"),
|
||||
SignedWitness("data", "SignedWitness"),
|
||||
Alert("data", "Alert"),
|
||||
Filter("data", "Filter"),
|
||||
Arbitrator("data", "Arbitrator"),
|
||||
Mediator("data", "Mediator"),
|
||||
RefundAgent("data", "RefundAgent"),
|
||||
|
||||
TempProposalPayload("dao", "TempProposalPayload"),
|
||||
ProposalPayload("dao", "ProposalPayload"),
|
||||
BlindVotePayload("dao", "BlindVotePayload"),
|
||||
daoStateChainHeight("dao", "daoStateChainHeight"),
|
||||
blockTimeIsSec("dao", "blockTimeIsSec"),
|
||||
|
||||
maxConnections("network", "maxConnections"),
|
||||
numConnections("network", "numConnections"),
|
||||
peakNumConnections("network", "peakNumConnections"),
|
||||
numAllConnectionsLostEvents("network", "numAllConnectionsLostEvents"),
|
||||
sentBytes("network", "sentBytes"),
|
||||
receivedBytes("network", "receivedBytes"),
|
||||
|
||||
usedMemoryInMB("node", "usedMemoryInMB"),
|
||||
totalMemoryInMB("node", "totalMemoryInMB"),
|
||||
jvmStartTimeInSec("node", "jvmStartTimeInSec");
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private String key;
|
||||
@Getter
|
||||
@Setter
|
||||
private String group;
|
||||
@Getter
|
||||
@Setter
|
||||
private int value;
|
||||
|
||||
IntegerValueItem(String group, String key) {
|
||||
this.group = group;
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public IntegerValueItem withValue(int value) {
|
||||
setValue(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public static IntegerValueItem from(String key, int value) {
|
||||
IntegerValueItem item;
|
||||
try {
|
||||
item = IntegerValueItem.valueOf(key);
|
||||
} catch (Throwable t) {
|
||||
item = IntegerValueItem.Unspecified;
|
||||
item.setKey(key);
|
||||
}
|
||||
|
||||
item.setValue(value);
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public protobuf.ReportingItem toProtoMessage() {
|
||||
return getBuilder().setIntegerValueItem(protobuf.IntegerValueItem.newBuilder()
|
||||
.setValue(value))
|
||||
.build();
|
||||
}
|
||||
|
||||
public static IntegerValueItem fromProto(protobuf.ReportingItem baseProto, protobuf.IntegerValueItem proto) {
|
||||
return IntegerValueItem.from(baseProto.getKey(), proto.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPath() {
|
||||
return group + "." + key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name() + "= " + value;
|
||||
}
|
||||
}
|
51
core/src/main/java/bisq/core/monitor/ReportingItem.java
Normal file
51
core/src/main/java/bisq/core/monitor/ReportingItem.java
Normal file
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* This file is part of Bisq.
|
||||
*
|
||||
* Bisq is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* Bisq is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package bisq.core.monitor;
|
||||
|
||||
import bisq.common.proto.ProtobufferRuntimeException;
|
||||
import bisq.common.proto.network.NetworkPayload;
|
||||
|
||||
public interface ReportingItem extends NetworkPayload {
|
||||
String getKey();
|
||||
|
||||
String getGroup();
|
||||
|
||||
String getPath();
|
||||
|
||||
default protobuf.ReportingItem.Builder getBuilder() {
|
||||
return protobuf.ReportingItem.newBuilder()
|
||||
.setGroup(getGroup())
|
||||
.setKey(getKey());
|
||||
}
|
||||
|
||||
protobuf.ReportingItem toProtoMessage();
|
||||
|
||||
static ReportingItem fromProto(protobuf.ReportingItem proto) {
|
||||
switch (proto.getMessageCase()) {
|
||||
case STRING_VALUE_ITEM:
|
||||
return StringValueItem.fromProto(proto, proto.getStringValueItem());
|
||||
case INTEGER_VALUE_ITEM:
|
||||
return IntegerValueItem.fromProto(proto, proto.getIntegerValueItem());
|
||||
case DOUBLE_VALUE_ITEM:
|
||||
return DoubleValueItem.fromProto(proto, proto.getDoubleValueItem());
|
||||
case MESSAGE_NOT_SET:
|
||||
default:
|
||||
throw new ProtobufferRuntimeException("Unknown message case: " + proto);
|
||||
}
|
||||
}
|
||||
}
|
76
core/src/main/java/bisq/core/monitor/ReportingItems.java
Normal file
76
core/src/main/java/bisq/core/monitor/ReportingItems.java
Normal file
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* This file is part of Bisq.
|
||||
*
|
||||
* Bisq is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* Bisq is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package bisq.core.monitor;
|
||||
|
||||
import bisq.common.proto.network.NetworkPayload;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
public class ReportingItems extends ArrayList<ReportingItem> implements NetworkPayload {
|
||||
@Getter
|
||||
private final String address;
|
||||
|
||||
public ReportingItems(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
@Override
|
||||
public protobuf.ReportingItems toProtoMessage() {
|
||||
return protobuf.ReportingItems.newBuilder()
|
||||
.setAddress(address)
|
||||
.addAllReportingItem(this.stream()
|
||||
.map(ReportingItem::toProtoMessage)
|
||||
.collect(Collectors.toList()))
|
||||
.build();
|
||||
}
|
||||
|
||||
public static ReportingItems fromProto(protobuf.ReportingItems proto) {
|
||||
ReportingItems reportingItems = new ReportingItems(proto.getAddress());
|
||||
reportingItems.addAll(proto.getReportingItemList().stream()
|
||||
.map(ReportingItem::fromProto).collect(Collectors.toList()));
|
||||
return reportingItems;
|
||||
}
|
||||
|
||||
public byte[] toProtoMessageAsBytes() {
|
||||
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
|
||||
toProtoMessage().writeDelimitedTo(outputStream);
|
||||
return outputStream.toByteArray();
|
||||
} catch (Throwable t) {
|
||||
log.error("Error at ", t);
|
||||
throw new RuntimeException(t);
|
||||
}
|
||||
}
|
||||
|
||||
public static ReportingItems fromProtoMessageAsBytes(byte[] protoAsBytes) {
|
||||
try (ByteArrayInputStream inputStream = new ByteArrayInputStream(protoAsBytes)) {
|
||||
protobuf.ReportingItems proto = protobuf.ReportingItems.parseDelimitedFrom(inputStream);
|
||||
return fromProto(proto);
|
||||
} catch (Throwable t) {
|
||||
log.error("Error at ", t);
|
||||
throw new RuntimeException(t);
|
||||
}
|
||||
}
|
||||
}
|
87
core/src/main/java/bisq/core/monitor/StringValueItem.java
Normal file
87
core/src/main/java/bisq/core/monitor/StringValueItem.java
Normal file
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* This file is part of Bisq.
|
||||
*
|
||||
* Bisq is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* Bisq is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package bisq.core.monitor;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
|
||||
public enum StringValueItem implements ReportingItem {
|
||||
Unspecified("", "Unspecified"),
|
||||
|
||||
daoStateHash("dao", "daoStateHash"),
|
||||
proposalHash("dao", "proposalHash"),
|
||||
blindVoteHash("dao", "blindVoteHash"),
|
||||
|
||||
version("node", "version"),
|
||||
commitHash("node", "commitHash");
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private String key;
|
||||
@Getter
|
||||
@Setter
|
||||
private String group;
|
||||
@Getter
|
||||
@Setter
|
||||
private String value;
|
||||
|
||||
StringValueItem(String group, String key) {
|
||||
this.group = group;
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public StringValueItem withValue(String value) {
|
||||
setValue(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public static StringValueItem from(String key, String value) {
|
||||
StringValueItem item;
|
||||
try {
|
||||
item = StringValueItem.valueOf(key);
|
||||
} catch (Throwable t) {
|
||||
item = StringValueItem.Unspecified;
|
||||
item.setKey(key);
|
||||
}
|
||||
|
||||
item.setValue(value);
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPath() {
|
||||
return group + "." + key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public protobuf.ReportingItem toProtoMessage() {
|
||||
return getBuilder().setStringValueItem(protobuf.StringValueItem.newBuilder()
|
||||
.setValue(value))
|
||||
.build();
|
||||
}
|
||||
|
||||
public static StringValueItem fromProto(protobuf.ReportingItem baseProto, protobuf.StringValueItem proto) {
|
||||
return StringValueItem.from(baseProto.getKey(), proto.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name() + "= " + value;
|
||||
}
|
||||
}
|
|
@ -2489,3 +2489,29 @@ message MockPayload {
|
|||
string message_version = 1;
|
||||
string message = 2;
|
||||
}
|
||||
|
||||
message ReportingItem {
|
||||
string key = 1;
|
||||
string group = 2;
|
||||
oneof message {
|
||||
StringValueItem string_value_item = 3;
|
||||
IntegerValueItem integer_value_item = 4;
|
||||
DoubleValueItem double_value_item = 5;
|
||||
}
|
||||
}
|
||||
message StringValueItem {
|
||||
string value = 1;
|
||||
}
|
||||
|
||||
message IntegerValueItem {
|
||||
uint32 value = 1;
|
||||
}
|
||||
|
||||
message DoubleValueItem {
|
||||
double value = 1;
|
||||
}
|
||||
|
||||
message ReportingItems {
|
||||
string address = 1;
|
||||
repeated ReportingItem reporting_item = 2;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue