diff --git a/accsoft-nxcals-monitoring-producer/src/main/java/cern/accsoft/nxcals/monitoring/producer/Application.java b/accsoft-nxcals-monitoring-producer/src/main/java/cern/accsoft/nxcals/monitoring/producer/Application.java index b6cbae2c3c3d121c6d705b69724bf9043e27e75a..b5eac46bb5572612a2aa7d6d0bbd19e638646bfd 100644 --- a/accsoft-nxcals-monitoring-producer/src/main/java/cern/accsoft/nxcals/monitoring/producer/Application.java +++ b/accsoft-nxcals-monitoring-producer/src/main/java/cern/accsoft/nxcals/monitoring/producer/Application.java @@ -5,36 +5,33 @@ package cern.accsoft.nxcals.monitoring.producer; import cern.accsoft.nxcals.monitoring.producer.service.DataPublisher; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import lombok.extern.slf4j.Slf4j; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.system.ApplicationPidFileWriter; import org.springframework.context.ApplicationContext; +/** + * Represents an application class that bootstraps and launches a Spring application from a Java main + * method. + */ @SpringBootApplication +@Slf4j public class Application { static { System.setProperty("log4j.debug", "true"); - // System.setProperty("log4j.configuration", "extr-log4j.properties"); - } - private static final Logger LOGGER = LoggerFactory.getLogger(Application.class); - public static void main(String[] args) throws Exception { try { - SpringApplication app = new SpringApplication(Application.class); app.addListeners(new ApplicationPidFileWriter()); ApplicationContext ctx = app.run(); DataPublisher dataPublisher = ctx.getBean(DataPublisher.class); dataPublisher.start(); - - } catch (Throwable e) { - e.printStackTrace(); - LOGGER.error("Exception while running publisher app", e); + } catch (Exception ex) { + log.error("Exception while running publisher app", ex); System.exit(1); } diff --git a/accsoft-nxcals-monitoring-producer/src/main/java/cern/accsoft/nxcals/monitoring/producer/service/DataPublisherImpl.java b/accsoft-nxcals-monitoring-producer/src/main/java/cern/accsoft/nxcals/monitoring/producer/service/DataPublisherImpl.java index dbb4d7140170dff6678050b93024382127446a7d..f3fa73bfd61345ee20c89585049d6b95fd5ddfce 100644 --- a/accsoft-nxcals-monitoring-producer/src/main/java/cern/accsoft/nxcals/monitoring/producer/service/DataPublisherImpl.java +++ b/accsoft-nxcals-monitoring-producer/src/main/java/cern/accsoft/nxcals/monitoring/producer/service/DataPublisherImpl.java @@ -68,16 +68,15 @@ public class DataPublisherImpl implements DataPublisher { long timestamp = (timeInMillis + i * 1000) * 1_000_000; ImmutableData data = valueCreator .createData(recordConfig.getRecordKeys(), recordConfig.getTimestampKeyName(), timestamp); - //log.debug("Publishing value {}", data); Publisher<ImmutableData> publisher = publishers .computeIfAbsent(recordConfig.getSystem(), this.publisherCreator); CompletableFuture<Result> future = publisher.publishAsync(data); - future.whenComplete((v, e) -> { - if (e != null) { + future.whenComplete((result, throwable) -> { + if (throwable != null) { log.error("Cannot send data with keys={} for timestamp={}", recordConfig.getRecordKeys(), - timestamp, e); + timestamp, throwable); } }); //This sleep is needed to avoid messages order problem when schema changes diff --git a/accsoft-nxcals-monitoring-producer/src/main/java/cern/accsoft/nxcals/monitoring/producer/service/ValueCreatorImpl.java b/accsoft-nxcals-monitoring-producer/src/main/java/cern/accsoft/nxcals/monitoring/producer/service/ValueCreatorImpl.java index a1c973598925ec02dc36ce61a55a6aac048c2f15..b81df5f62df436eb11f74c482603ff55ed0b718f 100644 --- a/accsoft-nxcals-monitoring-producer/src/main/java/cern/accsoft/nxcals/monitoring/producer/service/ValueCreatorImpl.java +++ b/accsoft-nxcals-monitoring-producer/src/main/java/cern/accsoft/nxcals/monitoring/producer/service/ValueCreatorImpl.java @@ -19,7 +19,6 @@ public class ValueCreatorImpl implements ValueCreator { public ValueCreatorImpl() { this.random = new Random(); - } private String getRandomFieldName(long timestamp) { @@ -32,7 +31,7 @@ public class ValueCreatorImpl implements ValueCreator { DataBuilder builder = ImmutableData.builder(); - requiredKeyValues.forEach((key, value) -> builder.add(key, value)); + requiredKeyValues.forEach(builder::add); builder.add(timestampKeyName, timestamp) .add("boolField", random.nextBoolean()) @@ -45,7 +44,8 @@ public class ValueCreatorImpl implements ValueCreator { //those 2 fields should not be checked for logging .add("longField3_DoNotLog", 1L) .add("longField4_DoNotLog", 1L) - //This is a random field that is changed to generate schema changes, this is not logged anyway as it is random name and not visible nor set in the CCDB editor. + //This is a random field that is changed to generate schema changes, this is not logged anyway + //as it is random name and not visible nor set in the CCDB editor. //This field will nevertheless be in the schema and change the schema if changed. .add(getRandomFieldName(timestamp), 0) @@ -73,52 +73,6 @@ public class ValueCreatorImpl implements ValueCreator { return builder.build(); - // No multiarray in JAPC. - // data.appendMultiArray("boolMultiArrayField1", new boolean[]{true, false, true, false}, new int[]{2, 2}); - // data.appendMultiArray("byteMultiArrayField1", new byte[]{1, 2, 3, 4}, new int[]{2, 2}); - // data.appendMultiArray("shortMultiArrayField1", new short[]{1, 2, 3, 4}, new int[]{2, 2}); - // data.appendMultiArray("intMultiArrayField1", new int[]{1, 2, 3, 4}, new int[]{2, 2}); - // data.appendMultiArray("longMultiArrayField1", new long[]{1, 2, 3, 4}, new int[]{2, 2}); - // data.appendMultiArray("doubleMultiArrayField1", new double[]{1, 2, 3, 4}, new int[]{2, 2}); - // data.appendMultiArray("floatMultiArrayField1", new float[]{1, 2, 3, 4}, new int[]{2, 2}); - // data.appendMultiArray("stringMultiArrayField1", new String[]{"aaaa", "bbbb", "cccc", "dddd"}, - // new int[]{2, 2}); - // data.appendMultiArray("stringMultiArrayField2", new String[]{"aaaa", "bbbb", "cccc", "dddd"}, - // new int[]{2, 2}); - - // Currently a bug - https://issues.cern.ch/browse/CALS-4955 - //data.setDiscreteFunction("ddfField1", DomainValueFactory.newDiscreteFunction(new double[]{1.0, 2.0}, new double[]{1.0, 2.0})); - //data.setDiscreteFunction("ddfField2", DomainValueFactory.newDiscreteFunction(new double[]{1.0, 2.0}, new double[]{1.0, 2.0})); - - // data.setDiscreteFunctionList("ddfArrayField1", - // DomainValueFactory.newDiscreteFunctionList( - // DomainValueFactory.newDiscreteFunction(new double[]{1.0, 2.0}, new double[]{1.0, 2.0}), - // DomainValueFactory.newDiscreteFunction(new double[]{1.0, 2.0, 3.0}, new double[]{1.0, 2.0, 3.0}))); - // - // data.setDiscreteFunctionList("ddfArrayField2", - // DomainValueFactory.newDiscreteFunctionList( - // DomainValueFactory.newDiscreteFunction(new double[]{1.0, 2.0}, new double[]{1.0, 2.0}), - // DomainValueFactory.newDiscreteFunction(new double[]{1.0, 2.0, 3.0}, new double[]{1.0, 2.0, 3.0}))); - - // No nested data in JAPC. - // Data secondNestedData = DataFactory.createData(); - // secondNestedData.append("longField1", 1L); - // secondNestedData.append("discreteFunctionField", - // DataFactory.createDiscreteFunction(new double[]{1.0, 2.0}, new double[]{1.0, 2.0})); - // secondNestedData.appendMultiArray("multiArrayLong", new short[]{1, 2, 3, 4}, new int[]{2, 2}); - // - // Data nestedData = DataFactory.createData(); - // nestedData.append("boolField", true); - // nestedData.append("longField", 1L); - // // here nothing happens, the record version is ignored. - // nestedData.append("record_version1", "ver1"); - // nestedData.append("record_version2", 12); - // nestedData.appendArray2D("boolArray2DField2", new boolean[]{true, false}, 1, 2); - // nestedData.appendArray("byteArrayField", new byte[]{1, 2, 3, 4}); - // nestedData.append("dataField", secondNestedData); - // - // data.append("dataField", nestedData); - } }