-
Notifications
You must be signed in to change notification settings - Fork 292
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2816 from SCADA-LTS/fix/#2628_Fixed_ConcurrentMod…
…ificationException_in_MonitoredValues #2628 Fixed ConcurrentModificationException in MonitoredValues:
- Loading branch information
Showing
16 changed files
with
430 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// Source code recreated from a .class file by IntelliJ IDEA | ||
// (powered by FernFlower decompiler) | ||
// | ||
|
||
package org.scada_lts.monitor; | ||
|
||
import org.scada_lts.monitor.type.ValueMonitor; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
public class ConcurrentMonitoredValues implements IMonitoredValues { | ||
private final Map<String, ValueMonitor<?>> monitors = new ConcurrentHashMap<>(); | ||
|
||
@Override | ||
public <T> ValueMonitor<T> addIfMissingStatMonitor(ValueMonitor<T> monitor) { | ||
monitors.put(monitor.getId(), monitor); | ||
return monitor; | ||
} | ||
|
||
@Override | ||
public ValueMonitor<?> getValueMonitor(String id) { | ||
return monitors.get(id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.scada_lts.monitor; | ||
|
||
import org.scada_lts.monitor.type.ValueMonitor; | ||
|
||
public interface IMonitoredValues { | ||
<T> ValueMonitor<T> addIfMissingStatMonitor(ValueMonitor<T> monitor); | ||
ValueMonitor<?> getValueMonitor(String id); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.scada_lts.monitor.type; | ||
|
||
public class DoubleMonitor extends ValueMonitor<Double> { | ||
private double value; | ||
|
||
public DoubleMonitor(String id, String name) { | ||
this(id, name, 0.0); | ||
} | ||
|
||
public DoubleMonitor(String id, String name, double initialValue) { | ||
super(id, name); | ||
this.value = initialValue; | ||
} | ||
|
||
public Double getValue() { | ||
return this.value; | ||
} | ||
|
||
public void setValue(double value) { | ||
this.value = value; | ||
} | ||
|
||
public void addValue(double value) { | ||
this.value += value; | ||
} | ||
|
||
public void setValueIfGreater(double value) { | ||
if (this.value < value) { | ||
this.value = value; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.scada_lts.monitor.type; | ||
|
||
public class FloatMonitor extends ValueMonitor<Float> { | ||
private float value; | ||
|
||
public FloatMonitor(String id, String name) { | ||
this(id, name, 0.0F); | ||
} | ||
|
||
public FloatMonitor(String id, String name, float initialValue) { | ||
super(id, name); | ||
this.value = initialValue; | ||
} | ||
|
||
public Float getValue() { | ||
return this.value; | ||
} | ||
|
||
public void setValue(float value) { | ||
this.value = value; | ||
} | ||
|
||
public void addValue(float value) { | ||
this.value += value; | ||
} | ||
|
||
public void setValueIfGreater(float value) { | ||
if (this.value < value) { | ||
this.value = value; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.scada_lts.monitor.type; | ||
|
||
public class IntegerMonitor extends ValueMonitor<Integer> { | ||
protected int value; | ||
|
||
public IntegerMonitor(String id, String name) { | ||
this(id, name, 0); | ||
} | ||
|
||
public IntegerMonitor(String id, String name, int initialValue) { | ||
super(id, name); | ||
this.value = initialValue; | ||
} | ||
|
||
public Integer getValue() { | ||
return this.value; | ||
} | ||
|
||
public void setValue(int value) { | ||
this.value = value; | ||
} | ||
|
||
public void addValue(int value) { | ||
this.value += value; | ||
} | ||
|
||
public void setValueIfGreater(int value) { | ||
if (this.value < value) { | ||
this.value = value; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.scada_lts.monitor.type; | ||
|
||
public class LongMonitor extends ValueMonitor<Long> { | ||
private long value; | ||
|
||
public LongMonitor(String id, String name) { | ||
this(id, name, 0L); | ||
} | ||
|
||
public LongMonitor(String id, String name, long initialValue) { | ||
super(id, name); | ||
this.value = initialValue; | ||
} | ||
|
||
public Long getValue() { | ||
return this.value; | ||
} | ||
|
||
public void setValue(long value) { | ||
this.value = value; | ||
} | ||
|
||
public void addValue(long value) { | ||
this.value += value; | ||
} | ||
|
||
public void setValueIfGreater(long value) { | ||
if (this.value < value) { | ||
this.value = value; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.scada_lts.monitor.type; | ||
|
||
public class ObjectMonitor<T> extends ValueMonitor<T> { | ||
private T value; | ||
|
||
public ObjectMonitor(String id, String name) { | ||
this(id, name, null); | ||
} | ||
|
||
public ObjectMonitor(String id, String name, T initialValue) { | ||
super(id, name); | ||
this.value = initialValue; | ||
} | ||
|
||
public T getValue() { | ||
return this.value; | ||
} | ||
|
||
public void setValue(T value) { | ||
this.value = value; | ||
} | ||
|
||
public String stringValue() { | ||
return this.value == null ? null : this.value.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.scada_lts.monitor.type; | ||
|
||
|
||
public abstract class ValueMonitor<T> { | ||
private static final long serialVersionUID = 3992668527962817285L; | ||
private final String id; | ||
private final String name; | ||
|
||
public ValueMonitor(String id, String name) { | ||
this.id = id; | ||
this.name = name; | ||
} | ||
|
||
public String getId() { | ||
return this.id; | ||
} | ||
|
||
public String getName() { | ||
return this.name; | ||
} | ||
|
||
public T getValue() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
test/org/scada_lts/monitor/ConcurrentMonitoredValuesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.scada_lts.monitor; | ||
|
||
import org.junit.Test; | ||
import org.scada_lts.monitor.type.ObjectMonitor; | ||
import utils.TestConcurrentUtils; | ||
|
||
|
||
public class ConcurrentMonitoredValuesTest { | ||
|
||
@Test | ||
public void when_addIfMissingStatMonitor_in_ConcurrentMonitoredValues_then_non_exception() throws Throwable { | ||
//given: | ||
IMonitoredValues concurrentMonitoredValues = new ConcurrentMonitoredValues(); | ||
|
||
//when | ||
TestConcurrentUtils.functionCheck(16, concurrentMonitoredValues::addIfMissingStatMonitor, | ||
new ObjectMonitor<>("id", "name")); | ||
} | ||
|
||
} |
Oops, something went wrong.