diff --git a/hazelcast/src/main/java/com/hazelcast/impl/base/SystemLogService.java b/hazelcast/src/main/java/com/hazelcast/impl/base/SystemLogService.java index 7de8ac2d4cc6..cc4e7940cc0a 100644 --- a/hazelcast/src/main/java/com/hazelcast/impl/base/SystemLogService.java +++ b/hazelcast/src/main/java/com/hazelcast/impl/base/SystemLogService.java @@ -30,6 +30,8 @@ public class SystemLogService { + private static final int MAX_LOG_ENTRIES = 10000; + public enum Level { NONE("none"), DEFAULT("default"), @@ -60,13 +62,13 @@ else if(level.equals("info")) private final ConcurrentMap mapCallStates = new ConcurrentHashMap(100, 0.75f, 32); - private final Queue joinLogs = new LinkedBlockingQueue(10000); + private final Queue joinLogs = new LinkedBlockingQueue(MAX_LOG_ENTRIES); - private final Queue connectionLogs = new LinkedBlockingQueue(10000); + private final Queue connectionLogs = new LinkedBlockingQueue(MAX_LOG_ENTRIES); - private final Queue partitionLogs = new LinkedBlockingQueue(10000); + private final Queue partitionLogs = new LinkedBlockingQueue(MAX_LOG_ENTRIES); - private final Queue nodeLogs = new LinkedBlockingQueue(10000); + private final Queue nodeLogs = new LinkedBlockingQueue(MAX_LOG_ENTRIES); private volatile Level currentLevel = Level.DEFAULT; @@ -118,11 +120,14 @@ public CallState getOrCreateCallState(long callId, Address callerAddress, int ca CallState callBefore = mapCallStates.get(callKey); if (callBefore == null) { CallState callStateNew = new CallState(callId, callerAddress, callerThreadId); - mapCallStates.put(callKey, callStateNew); - int callStatesCount = mapCallStates.size(); - if (callStatesCount > 10000) { + int size = mapCallStates.size(); + if(size < MAX_LOG_ENTRIES){ + //there is a potential race problem here, but it can only lead to have a bit more entries in the mapCallStates + //than MAX_LOG_ENTRIES. + mapCallStates.put(callKey, callStateNew); + } else{ String msg = " CallStates created! You might have too many threads accessing Hazelcast!"; - logNode(callStatesCount + msg); + logNode(size + msg); } return callStateNew; } else { @@ -255,19 +260,27 @@ public void trace(CallStateAware callStateAware, String msg) { } public void info(CallStateAware callStateAware, String msg, Object arg1) { - logState(callStateAware, Level.INFO, new SystemArgsLog(msg, arg1)); + if(shouldInfo()){ + logState(callStateAware, Level.INFO, new SystemArgsLog(msg, arg1)); + } } public void info(CallStateAware callStateAware, String msg, Object arg1, Object arg2) { - logState(callStateAware, Level.INFO, new SystemArgsLog(msg, arg1, arg2)); + if(shouldInfo()){ + logState(callStateAware, Level.INFO, new SystemArgsLog(msg, arg1, arg2)); + } } public void trace(CallStateAware callStateAware, String msg, Object arg1) { - logState(callStateAware, Level.TRACE, new SystemArgsLog(msg, arg1)); + if(shouldTrace()){ + logState(callStateAware, Level.TRACE, new SystemArgsLog(msg, arg1)); + } } public void trace(CallStateAware callStateAware, String msg, Object arg1, Object arg2) { - logState(callStateAware, Level.TRACE, new SystemArgsLog(msg, arg1, arg2)); + if(shouldTrace()){ + logState(callStateAware, Level.TRACE, new SystemArgsLog(msg, arg1, arg2)); + } } public void logObject(CallStateAware callStateAware, Level level, Object obj) {