changeset 630:a31b75b6d5e2

ST-93
author Devel 2
date Fri, 27 Oct 2017 15:29:48 +0200
parents 290de0f2a667
children db2594ce845a
files stress-tester/src/main/java/com/passus/st/emitter/RuleBasedSessionMapper.java
diffstat 1 files changed, 20 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/emitter/RuleBasedSessionMapper.java	Thu Oct 26 11:48:39 2017 +0200
+++ b/stress-tester/src/main/java/com/passus/st/emitter/RuleBasedSessionMapper.java	Fri Oct 27 15:29:48 2017 +0200
@@ -43,7 +43,9 @@
      */
     public void addRule(String rule) throws ParseException {
         Assert.notEmpty(rule, "rule");
-        rules.add(parseRule(rule));
+        synchronized (this) {
+            rules.add(parseRule(rule));
+        }
     }
 
     public void put(SessionInfo session, SocketAddress remoteAddress) {
@@ -52,28 +54,34 @@
 
     public void put(SessionInfo session, SocketAddress remoteAddress, SocketAddress bindAddress) {
         ConnectionParams params = new ConnectionParams(remoteAddress, bindAddress);
-        map.put(session, params);
+        synchronized (this) {
+            map.put(session, params);
+        }
     }
 
     @Override
     public boolean invalidate(SessionInfo sessionInfo) {
-        return map.remove(sessionInfo) != null;
+        synchronized (this) {
+            return map.remove(sessionInfo) != null;
+        }
     }
 
     @Override
     public ConnectionParams map(SessionInfo sessionInfo) {
-        ConnectionParams params = map.get(sessionInfo);
-        if (params == null) {
-            for (Rule rule : rules) {
-                if (rule.match(sessionInfo)) {
-                    params = new ConnectionParams(rule.getRemoteAddress(), rule.getBindAddress());
-                    map.put(sessionInfo, params);
-                    break;
+        synchronized (this) {
+            ConnectionParams params = map.get(sessionInfo);
+            if (params == null) {
+                for (Rule rule : rules) {
+                    if (rule.match(sessionInfo)) {
+                        params = new ConnectionParams(rule.getRemoteAddress(), rule.getBindAddress());
+                        map.put(sessionInfo, params);
+                        break;
+                    }
                 }
             }
+
+            return params;
         }
-
-        return params;
     }
 
     public static Rule parseRule(String rule) throws ParseException {