Skip to content

Commit

Permalink
* fix #hazelcast#325
Browse files Browse the repository at this point in the history
* some minor improvements for object creation prevent if no logging needed
* some minor code cleanup (extract constant)
  • Loading branch information
pveentjer committed Jun 27, 2013
1 parent 164e4cc commit 3ed5648
Showing 1 changed file with 25 additions and 12 deletions.
Expand Up @@ -30,6 +30,8 @@

public class SystemLogService {

private static final int MAX_LOG_ENTRIES = 10000;

public enum Level {
NONE("none"),
DEFAULT("default"),
Expand Down Expand Up @@ -60,13 +62,13 @@ else if(level.equals("info"))

private final ConcurrentMap<CallKey, CallState> mapCallStates = new ConcurrentHashMap<CallKey, CallState>(100, 0.75f, 32);

private final Queue<SystemLog> joinLogs = new LinkedBlockingQueue<SystemLog>(10000);
private final Queue<SystemLog> joinLogs = new LinkedBlockingQueue<SystemLog>(MAX_LOG_ENTRIES);

private final Queue<SystemLog> connectionLogs = new LinkedBlockingQueue<SystemLog>(10000);
private final Queue<SystemLog> connectionLogs = new LinkedBlockingQueue<SystemLog>(MAX_LOG_ENTRIES);

private final Queue<SystemLog> partitionLogs = new LinkedBlockingQueue<SystemLog>(10000);
private final Queue<SystemLog> partitionLogs = new LinkedBlockingQueue<SystemLog>(MAX_LOG_ENTRIES);

private final Queue<SystemLog> nodeLogs = new LinkedBlockingQueue<SystemLog>(10000);
private final Queue<SystemLog> nodeLogs = new LinkedBlockingQueue<SystemLog>(MAX_LOG_ENTRIES);

private volatile Level currentLevel = Level.DEFAULT;

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 3ed5648

Please sign in to comment.