This is an automated email from the ASF dual-hosted git repository.

riemer pushed a commit to branch 1598-jseval
in repository https://gitbox.apache.org/repos/asf/streampipes.git


The following commit(s) were added to refs/heads/1598-jseval by this push:
     new eb6473179 Migrate JsEval and SizeMeasure processors (#1598)(#1599)
eb6473179 is described below

commit eb6473179b92b7fa1ba84aa4b230cc4bc4f65d25
Author: Dominik Riemer <[email protected]>
AuthorDate: Fri May 26 13:58:36 2023 +0200

    Migrate JsEval and SizeMeasure processors (#1598)(#1599)
---
 .../processors/enricher/jvm/EnricherJvmInit.java   |  8 +--
 .../jvm/processor/jseval/JSEvalController.java     | 61 -------------------
 .../jvm/processor/jseval/JSEvalParameters.java     | 35 -----------
 .../jseval/{JSEval.java => JSEvalProcessor.java}   | 47 ++++++++++++---
 .../jvm/processor/sizemeasure/SizeMeasure.java     | 70 ----------------------
 .../sizemeasure/SizeMeasureParameters.java         | 36 -----------
 ...reController.java => SizeMeasureProcessor.java} | 58 ++++++++++++++----
 7 files changed, 89 insertions(+), 226 deletions(-)

diff --git 
a/streampipes-extensions/streampipes-processors-enricher-jvm/src/main/java/org/apache/streampipes/processors/enricher/jvm/EnricherJvmInit.java
 
b/streampipes-extensions/streampipes-processors-enricher-jvm/src/main/java/org/apache/streampipes/processors/enricher/jvm/EnricherJvmInit.java
index b2ce66f19..7fbb7368a 100644
--- 
a/streampipes-extensions/streampipes-processors-enricher-jvm/src/main/java/org/apache/streampipes/processors/enricher/jvm/EnricherJvmInit.java
+++ 
b/streampipes-extensions/streampipes-processors-enricher-jvm/src/main/java/org/apache/streampipes/processors/enricher/jvm/EnricherJvmInit.java
@@ -27,10 +27,10 @@ import 
org.apache.streampipes.extensions.management.model.SpServiceDefinitionBui
 import org.apache.streampipes.messaging.jms.SpJmsProtocolFactory;
 import org.apache.streampipes.messaging.kafka.SpKafkaProtocolFactory;
 import org.apache.streampipes.messaging.mqtt.SpMqttProtocolFactory;
-import 
org.apache.streampipes.processors.enricher.jvm.processor.jseval.JSEvalController;
+import 
org.apache.streampipes.processors.enricher.jvm.processor.jseval.JSEvalProcessor;
 import 
org.apache.streampipes.processors.enricher.jvm.processor.math.MathOpProcessor;
 import 
org.apache.streampipes.processors.enricher.jvm.processor.math.staticmathop.StaticMathOpProcessor;
-import 
org.apache.streampipes.processors.enricher.jvm.processor.sizemeasure.SizeMeasureController;
+import 
org.apache.streampipes.processors.enricher.jvm.processor.sizemeasure.SizeMeasureProcessor;
 import 
org.apache.streampipes.processors.enricher.jvm.processor.trigonometry.TrigonometryProcessor;
 import 
org.apache.streampipes.processors.enricher.jvm.processor.valuechange.ValueChangeProcessor;
 import org.apache.streampipes.service.extensions.ExtensionsModelSubmitter;
@@ -47,8 +47,8 @@ public class EnricherJvmInit extends ExtensionsModelSubmitter 
{
             "Processors Enricher JVM",
             "",
             8090)
-        .registerPipelineElements(new SizeMeasureController(),
-            new JSEvalController(),
+        .registerPipelineElements(new SizeMeasureProcessor(),
+            new JSEvalProcessor(),
             new MathOpProcessor(),
             new StaticMathOpProcessor(),
             new TrigonometryProcessor(),
diff --git 
a/streampipes-extensions/streampipes-processors-enricher-jvm/src/main/java/org/apache/streampipes/processors/enricher/jvm/processor/jseval/JSEvalController.java
 
b/streampipes-extensions/streampipes-processors-enricher-jvm/src/main/java/org/apache/streampipes/processors/enricher/jvm/processor/jseval/JSEvalController.java
deleted file mode 100644
index 70e83d752..000000000
--- 
a/streampipes-extensions/streampipes-processors-enricher-jvm/src/main/java/org/apache/streampipes/processors/enricher/jvm/processor/jseval/JSEvalController.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.streampipes.processors.enricher.jvm.processor.jseval;
-
-import org.apache.streampipes.model.DataProcessorType;
-import org.apache.streampipes.model.graph.DataProcessorDescription;
-import org.apache.streampipes.model.graph.DataProcessorInvocation;
-import org.apache.streampipes.sdk.builder.ProcessingElementBuilder;
-import org.apache.streampipes.sdk.builder.StreamRequirementsBuilder;
-import 
org.apache.streampipes.sdk.extractor.ProcessingElementParameterExtractor;
-import org.apache.streampipes.sdk.helpers.CodeLanguage;
-import org.apache.streampipes.sdk.helpers.EpRequirements;
-import org.apache.streampipes.sdk.helpers.Labels;
-import org.apache.streampipes.sdk.helpers.Locales;
-import org.apache.streampipes.sdk.helpers.OutputStrategies;
-import org.apache.streampipes.sdk.utils.Assets;
-import org.apache.streampipes.wrapper.standalone.ConfiguredEventProcessor;
-import 
org.apache.streampipes.wrapper.standalone.declarer.StandaloneEventProcessingDeclarer;
-
-public class JSEvalController extends 
StandaloneEventProcessingDeclarer<JSEvalParameters> {
-
-  private static final String JS_FUNCTION = "jsFunction";
-
-  @Override
-  public DataProcessorDescription declareModel() {
-    return 
ProcessingElementBuilder.create("org.apache.streampipes.processors.enricher.jvm.jseval")
-        .category(DataProcessorType.SCRIPTING)
-        .withAssets(Assets.DOCUMENTATION, Assets.ICON)
-        .withLocales(Locales.EN)
-        .requiredStream(StreamRequirementsBuilder
-            .create()
-            .requiredProperty(EpRequirements.anyProperty())
-            .build())
-        .requiredCodeblock(Labels.withId(JS_FUNCTION), CodeLanguage.Javascript)
-        .outputStrategy(OutputStrategies.userDefined())
-        .build();
-  }
-
-  @Override
-  public ConfiguredEventProcessor<JSEvalParameters> 
onInvocation(DataProcessorInvocation graph,
-                                                                 
ProcessingElementParameterExtractor extractor) {
-    String code = extractor.codeblockValue(JS_FUNCTION);
-    JSEvalParameters parameters = new JSEvalParameters(graph, code);
-    return new ConfiguredEventProcessor<>(parameters, JSEval::new);
-  }
-}
diff --git 
a/streampipes-extensions/streampipes-processors-enricher-jvm/src/main/java/org/apache/streampipes/processors/enricher/jvm/processor/jseval/JSEvalParameters.java
 
b/streampipes-extensions/streampipes-processors-enricher-jvm/src/main/java/org/apache/streampipes/processors/enricher/jvm/processor/jseval/JSEvalParameters.java
deleted file mode 100644
index 6a75b4099..000000000
--- 
a/streampipes-extensions/streampipes-processors-enricher-jvm/src/main/java/org/apache/streampipes/processors/enricher/jvm/processor/jseval/JSEvalParameters.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.streampipes.processors.enricher.jvm.processor.jseval;
-
-import org.apache.streampipes.model.graph.DataProcessorInvocation;
-import 
org.apache.streampipes.wrapper.params.binding.EventProcessorBindingParams;
-
-public class JSEvalParameters extends EventProcessorBindingParams {
-
-  private String code;
-
-  public JSEvalParameters(DataProcessorInvocation graph, String code) {
-    super(graph);
-    this.code = code;
-  }
-
-  public String getCode() {
-    return code;
-  }
-}
diff --git 
a/streampipes-extensions/streampipes-processors-enricher-jvm/src/main/java/org/apache/streampipes/processors/enricher/jvm/processor/jseval/JSEval.java
 
b/streampipes-extensions/streampipes-processors-enricher-jvm/src/main/java/org/apache/streampipes/processors/enricher/jvm/processor/jseval/JSEvalProcessor.java
similarity index 54%
rename from 
streampipes-extensions/streampipes-processors-enricher-jvm/src/main/java/org/apache/streampipes/processors/enricher/jvm/processor/jseval/JSEval.java
rename to 
streampipes-extensions/streampipes-processors-enricher-jvm/src/main/java/org/apache/streampipes/processors/enricher/jvm/processor/jseval/JSEvalProcessor.java
index 34660f153..fe7c6e007 100644
--- 
a/streampipes-extensions/streampipes-processors-enricher-jvm/src/main/java/org/apache/streampipes/processors/enricher/jvm/processor/jseval/JSEval.java
+++ 
b/streampipes-extensions/streampipes-processors-enricher-jvm/src/main/java/org/apache/streampipes/processors/enricher/jvm/processor/jseval/JSEvalProcessor.java
@@ -18,10 +18,21 @@
 package org.apache.streampipes.processors.enricher.jvm.processor.jseval;
 
 import org.apache.streampipes.commons.exceptions.SpRuntimeException;
+import org.apache.streampipes.model.DataProcessorType;
+import org.apache.streampipes.model.graph.DataProcessorDescription;
 import org.apache.streampipes.model.runtime.Event;
+import org.apache.streampipes.sdk.builder.ProcessingElementBuilder;
+import org.apache.streampipes.sdk.builder.StreamRequirementsBuilder;
+import org.apache.streampipes.sdk.helpers.CodeLanguage;
+import org.apache.streampipes.sdk.helpers.EpRequirements;
+import org.apache.streampipes.sdk.helpers.Labels;
+import org.apache.streampipes.sdk.helpers.Locales;
+import org.apache.streampipes.sdk.helpers.OutputStrategies;
+import org.apache.streampipes.sdk.utils.Assets;
 import org.apache.streampipes.wrapper.context.EventProcessorRuntimeContext;
 import org.apache.streampipes.wrapper.routing.SpOutputCollector;
-import org.apache.streampipes.wrapper.runtime.EventProcessor;
+import org.apache.streampipes.wrapper.standalone.ProcessorParams;
+import org.apache.streampipes.wrapper.standalone.StreamPipesDataProcessor;
 
 import org.graalvm.polyglot.Context;
 import org.graalvm.polyglot.Value;
@@ -30,20 +41,39 @@ import org.graalvm.polyglot.proxy.ProxyObject;
 import java.util.HashMap;
 import java.util.Map;
 
-public class JSEval implements EventProcessor<JSEvalParameters> {
+public class JSEvalProcessor extends StreamPipesDataProcessor {
+
+  private static final String JS_FUNCTION = "jsFunction";
+
   private Context polyglot;
   private Value function;
 
   @Override
-  public void onInvocation(JSEvalParameters parameters, SpOutputCollector 
spOutputCollector,
+  public DataProcessorDescription declareModel() {
+    return 
ProcessingElementBuilder.create("org.apache.streampipes.processors.enricher.jvm.jseval")
+        .category(DataProcessorType.SCRIPTING)
+        .withAssets(Assets.DOCUMENTATION, Assets.ICON)
+        .withLocales(Locales.EN)
+        .requiredStream(StreamRequirementsBuilder
+            .create()
+            .requiredProperty(EpRequirements.anyProperty())
+            .build())
+        .requiredCodeblock(Labels.withId(JS_FUNCTION), CodeLanguage.Javascript)
+        .outputStrategy(OutputStrategies.userDefined())
+        .build();
+  }
+
+  @Override
+  public void onInvocation(ProcessorParams parameters,
+                           SpOutputCollector spOutputCollector,
                            EventProcessorRuntimeContext runtimeContext) throws 
SpRuntimeException {
     polyglot = Context.create();
-    String code = parameters.getCode();
+    String code = parameters.extractor().codeblockValue(JS_FUNCTION);
     function = polyglot.eval("js", "(" + code + ")");
   }
 
   @Override
-  public void onEvent(Event event, SpOutputCollector outputCollector) throws 
SpRuntimeException {
+  public void onEvent(Event event, SpOutputCollector collector) throws 
SpRuntimeException {
     // create new event with input event's source info and schema info.
     Event outEvent = new Event(new HashMap<>(), event.getSourceInfo(), 
event.getSchemaInfo());
     try {
@@ -54,7 +84,7 @@ public class JSEval implements 
EventProcessor<JSEvalParameters> {
       Map<String, Object> resultEvent = ((Value) 
result).as(java.util.Map.class);
       if (resultEvent != null) {
         resultEvent.forEach(outEvent::addField);
-        outputCollector.collect(outEvent);
+        collector.collect(outEvent);
       }
 
     } catch (ClassCastException e) {
@@ -63,8 +93,7 @@ public class JSEval implements 
EventProcessor<JSEvalParameters> {
   }
 
   @Override
-  public void onDetach() {
-    // do nothing.
-  }
+  public void onDetach() throws SpRuntimeException {
 
+  }
 }
diff --git 
a/streampipes-extensions/streampipes-processors-enricher-jvm/src/main/java/org/apache/streampipes/processors/enricher/jvm/processor/sizemeasure/SizeMeasure.java
 
b/streampipes-extensions/streampipes-processors-enricher-jvm/src/main/java/org/apache/streampipes/processors/enricher/jvm/processor/sizemeasure/SizeMeasure.java
deleted file mode 100644
index 2d82e1828..000000000
--- 
a/streampipes-extensions/streampipes-processors-enricher-jvm/src/main/java/org/apache/streampipes/processors/enricher/jvm/processor/sizemeasure/SizeMeasure.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.streampipes.processors.enricher.jvm.processor.sizemeasure;
-
-import org.apache.streampipes.model.runtime.Event;
-import org.apache.streampipes.wrapper.context.EventProcessorRuntimeContext;
-import org.apache.streampipes.wrapper.routing.SpOutputCollector;
-import org.apache.streampipes.wrapper.runtime.EventProcessor;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.ObjectOutputStream;
-
-public class SizeMeasure implements EventProcessor<SizeMeasureParameters> {
-
-  private SizeMeasureParameters sizeMeasureParameters;
-
-  @Override
-  public void onInvocation(SizeMeasureParameters sizeMeasureParameters, 
SpOutputCollector spOutputCollector,
-                           EventProcessorRuntimeContext runtimeContext) {
-    this.sizeMeasureParameters = sizeMeasureParameters;
-  }
-
-  @Override
-  public void onDetach() {
-  }
-
-  @Override
-  public void onEvent(Event event, SpOutputCollector spOutputCollector) {
-    try {
-      double size = getSizeInBytes(event.getRaw());
-      if 
(sizeMeasureParameters.getSizeUnit().equals(SizeMeasureController.KILOBYTE_SIZE))
 {
-        size /= 1024;
-      } else if 
(sizeMeasureParameters.getSizeUnit().equals(SizeMeasureController.MEGABYTE_SIZE))
 {
-        size /= 1048576;
-      }
-      event.addField(SizeMeasureController.EVENT_SIZE, size);
-      spOutputCollector.collect(event);
-    } catch (IOException e) {
-      e.printStackTrace();
-    }
-  }
-
-  private int getSizeInBytes(Object map) throws IOException {
-    // Measuring the size by serializing it and then measuring the bytes
-    ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
-    ObjectOutputStream out = new ObjectOutputStream(byteStream);
-
-    out.writeObject(map);
-    out.close();
-
-    return byteStream.toByteArray().length;
-  }
-}
diff --git 
a/streampipes-extensions/streampipes-processors-enricher-jvm/src/main/java/org/apache/streampipes/processors/enricher/jvm/processor/sizemeasure/SizeMeasureParameters.java
 
b/streampipes-extensions/streampipes-processors-enricher-jvm/src/main/java/org/apache/streampipes/processors/enricher/jvm/processor/sizemeasure/SizeMeasureParameters.java
deleted file mode 100644
index 8c39ac962..000000000
--- 
a/streampipes-extensions/streampipes-processors-enricher-jvm/src/main/java/org/apache/streampipes/processors/enricher/jvm/processor/sizemeasure/SizeMeasureParameters.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.streampipes.processors.enricher.jvm.processor.sizemeasure;
-
-import org.apache.streampipes.model.graph.DataProcessorInvocation;
-import 
org.apache.streampipes.wrapper.params.binding.EventProcessorBindingParams;
-
-public class SizeMeasureParameters extends EventProcessorBindingParams {
-
-  private String sizeUnit;
-
-  public SizeMeasureParameters(DataProcessorInvocation graph, String sizeUnit) 
{
-    super(graph);
-    this.sizeUnit = sizeUnit;
-  }
-
-  public String getSizeUnit() {
-    return sizeUnit;
-  }
-}
diff --git 
a/streampipes-extensions/streampipes-processors-enricher-jvm/src/main/java/org/apache/streampipes/processors/enricher/jvm/processor/sizemeasure/SizeMeasureController.java
 
b/streampipes-extensions/streampipes-processors-enricher-jvm/src/main/java/org/apache/streampipes/processors/enricher/jvm/processor/sizemeasure/SizeMeasureProcessor.java
similarity index 60%
rename from 
streampipes-extensions/streampipes-processors-enricher-jvm/src/main/java/org/apache/streampipes/processors/enricher/jvm/processor/sizemeasure/SizeMeasureController.java
rename to 
streampipes-extensions/streampipes-processors-enricher-jvm/src/main/java/org/apache/streampipes/processors/enricher/jvm/processor/sizemeasure/SizeMeasureProcessor.java
index df1e27dd7..80d4b4ce9 100644
--- 
a/streampipes-extensions/streampipes-processors-enricher-jvm/src/main/java/org/apache/streampipes/processors/enricher/jvm/processor/sizemeasure/SizeMeasureController.java
+++ 
b/streampipes-extensions/streampipes-processors-enricher-jvm/src/main/java/org/apache/streampipes/processors/enricher/jvm/processor/sizemeasure/SizeMeasureProcessor.java
@@ -18,12 +18,12 @@
 
 package org.apache.streampipes.processors.enricher.jvm.processor.sizemeasure;
 
+import org.apache.streampipes.commons.exceptions.SpRuntimeException;
 import org.apache.streampipes.model.DataProcessorType;
 import org.apache.streampipes.model.graph.DataProcessorDescription;
-import org.apache.streampipes.model.graph.DataProcessorInvocation;
+import org.apache.streampipes.model.runtime.Event;
 import org.apache.streampipes.sdk.builder.ProcessingElementBuilder;
 import org.apache.streampipes.sdk.builder.StreamRequirementsBuilder;
-import 
org.apache.streampipes.sdk.extractor.ProcessingElementParameterExtractor;
 import org.apache.streampipes.sdk.helpers.EpProperties;
 import org.apache.streampipes.sdk.helpers.EpRequirements;
 import org.apache.streampipes.sdk.helpers.Labels;
@@ -32,10 +32,16 @@ import org.apache.streampipes.sdk.helpers.Options;
 import org.apache.streampipes.sdk.helpers.OutputStrategies;
 import org.apache.streampipes.sdk.helpers.Tuple2;
 import org.apache.streampipes.sdk.utils.Assets;
-import org.apache.streampipes.wrapper.standalone.ConfiguredEventProcessor;
-import 
org.apache.streampipes.wrapper.standalone.declarer.StandaloneEventProcessingDeclarer;
+import org.apache.streampipes.wrapper.context.EventProcessorRuntimeContext;
+import org.apache.streampipes.wrapper.routing.SpOutputCollector;
+import org.apache.streampipes.wrapper.standalone.ProcessorParams;
+import org.apache.streampipes.wrapper.standalone.StreamPipesDataProcessor;
 
-public class SizeMeasureController extends 
StandaloneEventProcessingDeclarer<SizeMeasureParameters> {
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+
+public class SizeMeasureProcessor extends StreamPipesDataProcessor {
 
   private static final String SIZE_UNIT = "sizeUnit";
   static final String BYTE_SIZE = "BYTE";
@@ -44,6 +50,8 @@ public class SizeMeasureController extends 
StandaloneEventProcessingDeclarer<Siz
 
   static final String EVENT_SIZE = "eventSize";
 
+  private String sizeUnit;
+
   @Override
   public DataProcessorDescription declareModel() {
     return 
ProcessingElementBuilder.create("org.apache.streampipes.processors.enricher.jvm.sizemeasure")
@@ -66,13 +74,41 @@ public class SizeMeasureController extends 
StandaloneEventProcessingDeclarer<Siz
   }
 
   @Override
-  public ConfiguredEventProcessor<SizeMeasureParameters> onInvocation(
-      DataProcessorInvocation graph,
-      ProcessingElementParameterExtractor extractor) {
+  public void onInvocation(ProcessorParams parameters,
+                           SpOutputCollector spOutputCollector,
+                           EventProcessorRuntimeContext runtimeContext) throws 
SpRuntimeException {
+    this.sizeUnit = 
parameters.extractor().selectedSingleValueInternalName(SIZE_UNIT, String.class);
+  }
+
+  @Override
+  public void onEvent(Event event, SpOutputCollector collector) throws 
SpRuntimeException {
+    try {
+      double size = getSizeInBytes(event.getRaw());
+      if (sizeUnit.equals(KILOBYTE_SIZE)) {
+        size /= 1024;
+      } else if (sizeUnit.equals(MEGABYTE_SIZE)) {
+        size /= 1048576;
+      }
+      event.addField(EVENT_SIZE, size);
+      collector.collect(event);
+    } catch (IOException e) {
+      e.printStackTrace();
+    }
+  }
+
+  @Override
+  public void onDetach() throws SpRuntimeException {
+
+  }
+
+  private int getSizeInBytes(Object map) throws IOException {
+    // Measuring the size by serializing it and then measuring the bytes
+    ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
+    ObjectOutputStream out = new ObjectOutputStream(byteStream);
 
-    String sizeUnit = extractor.selectedSingleValueInternalName(SIZE_UNIT, 
String.class);
-    SizeMeasureParameters staticParam = new SizeMeasureParameters(graph, 
sizeUnit);
+    out.writeObject(map);
+    out.close();
 
-    return new ConfiguredEventProcessor<>(staticParam, SizeMeasure::new);
+    return byteStream.toByteArray().length;
   }
 }

Reply via email to