Skip to content

Commit eb7aae8

Browse files
[Sdk 368] Internal limits (#29)
* Events internal limits added * Internal limits Events, Views Crash, Userdetail(in progress) * Config methods fixed! * - trimming methods updated - trimming methods usage commented - internal events configuration commented * Passed limit to trimming utils methods * commit reversed * code format * Logger class init logic updated! * Fixed Log init unit test * code revert * fixed a bug, unit test added * Trimm segment unit test added * Config internal limits properties commented * Logger tweaks in tests --------- Co-authored-by: Zahid Zafar <> Co-authored-by: ArtursK <[email protected]>
1 parent 98a1cfc commit eb7aae8

File tree

11 files changed

+256
-62
lines changed

11 files changed

+256
-62
lines changed

sdk-java/src/main/java/ly/count/sdk/java/Config.java

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,93 @@ public boolean restore(byte[] data) {
481481
*/
482482
protected int requestQueueMaxSize = 1000;
483483

484-
//endregion
484+
// /**
485+
// * Maximum size of all string keys
486+
// */
487+
// protected int maxKeyLength = 128;
488+
//
489+
// /**
490+
// * Maximum size of all values in our key-value pairs
491+
// */
492+
// protected int maxValueSize = 256;
493+
//
494+
// /**
495+
// * Max amount of custom (dev provided) segmentation in one event
496+
// */
497+
// protected int maxSegmentationValues = 30;
498+
//
499+
// /**
500+
// * Limits how many stack trace lines would be recorded per thread
501+
// */
502+
// protected int maxStackTraceLinesPerThread = 30;
503+
//
504+
// /**
505+
// * Limits how many characters are allowed per stack trace line
506+
// */
507+
// protected int maxStackTraceLineLength = 200;
508+
//
509+
// /**
510+
// * Set the maximum amount of breadcrumbs.
511+
// */
512+
// protected int totalBreadcrumbsAllowed = 100;
513+
//
514+
// //endregion
515+
//
516+
// public int getMaxKeyLength() {
517+
// return maxKeyLength;
518+
// }
519+
//
520+
// public Config setMaxKeyLength(int maxKeyLength) {
521+
// this.maxKeyLength = maxKeyLength;
522+
// return this;
523+
// }
524+
//
525+
// public int getMaxValueSize() {
526+
// return maxValueSize;
527+
// }
528+
//
529+
// public Config setMaxValueSize(int maxValueSize) {
530+
// this.maxValueSize = maxValueSize;
531+
// return this;
532+
// }
533+
//
534+
// public int getMaxSegmentationValues() {
535+
// return maxSegmentationValues;
536+
// }
537+
//
538+
// public Config setMaxSegmentationValues(int maxSegmentationValues) {
539+
// this.maxSegmentationValues = maxSegmentationValues;
540+
// return this;
541+
// }
542+
//
543+
// public int getMaxStackTraceLinesPerThread() {
544+
// return maxStackTraceLinesPerThread;
545+
// }
546+
//
547+
// public Config setMaxStackTraceLinesPerThread(int maxStackTraceLinesPerThread) {
548+
// this.maxStackTraceLinesPerThread = maxStackTraceLinesPerThread;
549+
// return this;
550+
//
551+
// }
552+
//
553+
// public int getMaxStackTraceLineLength() {
554+
// return maxStackTraceLineLength;
555+
// }
556+
//
557+
// public Config setMaxStackTraceLineLength(int maxStackTraceLineLength) {
558+
// this.maxStackTraceLineLength = maxStackTraceLineLength;
559+
// return this;
560+
// }
561+
//
562+
// public int getTotalBreadcrumbsAllowed() {
563+
// return totalBreadcrumbsAllowed;
564+
// }
565+
//
566+
// public Config setTotalBreadcrumbsAllowed(int totalBreadcrumbsAllowed) {
567+
// this.totalBreadcrumbsAllowed = totalBreadcrumbsAllowed;
568+
// return this;
569+
//
570+
// }
485571

486572

487573
// TODO: storage limits & configuration

sdk-java/src/main/java/ly/count/sdk/java/Countly.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ else if (directory == null) {
7979
}
8080

8181
InternalConfig internalConfig = new InternalConfig(config);
82-
Log L = new Log(internalConfig);
82+
Log L = new Log(internalConfig.loggingLevel, internalConfig.logListener);
8383
SDK sdk = new SDK();
8484
sdk.init(new CtxCore(sdk, internalConfig, L, directory), L);
8585

sdk-java/src/main/java/ly/count/sdk/java/internal/EventImpl.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package ly.count.sdk.java.internal;
22

3+
import ly.count.sdk.java.Config;
34
import org.json.JSONException;
45
import org.json.JSONObject;
56

@@ -56,7 +57,7 @@ public interface EventRecorder {
5657

5758
@Override
5859
public void record() {
59-
if(SDKCore.instance != null && SDKCore.instance.config.isBackendModeEnabled()) {
60+
if (SDKCore.instance != null && SDKCore.instance.config.isBackendModeEnabled()) {
6061
System.out.println("[EventImpl] record: Skipping event, backend mode is enabled!");
6162
return;
6263
}
@@ -71,7 +72,7 @@ public void record() {
7172

7273
@Override
7374
public void endAndRecord() {
74-
if(SDKCore.instance != null && SDKCore.instance.config.isBackendModeEnabled()) {
75+
if (SDKCore.instance != null && SDKCore.instance.config.isBackendModeEnabled()) {
7576
System.out.println("[EventImpl] endAndRecord: Skipping event, backend mode is enabled!");
7677
return;
7778
}
@@ -190,7 +191,7 @@ public boolean equals(Object obj) {
190191
if (obj == null || !(obj instanceof EventImpl)) {
191192
return false;
192193
}
193-
EventImpl event = (EventImpl)obj;
194+
EventImpl event = (EventImpl) obj;
194195
if (timestamp != event.timestamp) {
195196
return false;
196197
}
@@ -223,6 +224,7 @@ public boolean equals(Object obj) {
223224

224225
/**
225226
* Serialize to JSON format according to Countly server requirements
227+
*
226228
* @return JSON string
227229
*/
228230
public String toJSON() {
@@ -255,6 +257,7 @@ public String toJSON() {
255257

256258
/**
257259
* Deserialize from JSON format according to Countly server requirements
260+
*
258261
* @return JSON string
259262
*/
260263
static EventImpl fromJSON(String jsonString, EventRecorder recorder) {

sdk-java/src/main/java/ly/count/sdk/java/internal/Log.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@
88
*/
99

1010
public class Log {
11-
LogCallback logListener = null;
12-
private Config.LoggingLevel configLevel;
11+
private final LogCallback logListener;
12+
private final Config.LoggingLevel loggingLevel;
1313

1414

15-
public Log(InternalConfig config) {
16-
// let it be specific int and not index for visibility
17-
configLevel = config.getLoggingLevel();
18-
logListener = config.getLogListener();
15+
public Log(Config.LoggingLevel loggingLevel, LogCallback logListener) {
16+
if(loggingLevel == null) {
17+
throw new NullPointerException("Logging level can't null.");
18+
}
19+
this.loggingLevel = loggingLevel;
20+
this.logListener = logListener;
1921
}
2022

2123
/**
@@ -69,7 +71,7 @@ public void v(String logMessage) {
6971
}
7072

7173
private void print(String msg, Config.LoggingLevel level) {
72-
if (level != null && configLevel.prints(level)) {
74+
if (level != null && loggingLevel.prints(level)) {
7375
System.out.println(msg);
7476
}
7577
}

sdk-java/src/main/java/ly/count/sdk/java/internal/SessionImpl.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,10 @@
2020

2121
/**
2222
* This class represents session concept, that is one indivisible usage occasion of your application.
23-
*
2423
* Any data sent to Countly server is processed in a context of Session.
2524
* Only one session can send requests at a time, so even if you create 2 parallel sessions,
2625
* they will be made consequent automatically at the time of Countly SDK choice with no
2726
* correctness guarantees, so please avoid having parallel sessions.
28-
*
2927
*/
3028

3129
public class SessionImpl implements Session, Storable, EventImpl.EventRecorder {
@@ -97,7 +95,7 @@ public SessionImpl(CtxCore ctx, Long id) {
9795

9896
@Override
9997
public Session begin() {
100-
if(ctx.getConfig().isBackendModeEnabled()) {
98+
if (ctx.getConfig().isBackendModeEnabled()) {
10199
L.w("[SessionImpl] begin: Skipping session begin, backend mode is enabled!");
102100
return this;
103101
}
@@ -136,7 +134,7 @@ Future<Boolean> begin(Long now) {
136134

137135
@Override
138136
public Session update() {
139-
if(ctx.getConfig().isBackendModeEnabled()) {
137+
if (ctx.getConfig().isBackendModeEnabled()) {
140138
L.w("[SessionImpl] update: Skipping session update, backend mode is enabled!");
141139
return this;
142140
}
@@ -171,7 +169,7 @@ Future<Boolean> update(Long now) {
171169

172170
@Override
173171
public void end() {
174-
if(ctx.getConfig().isBackendModeEnabled()) {
172+
if (ctx.getConfig().isBackendModeEnabled()) {
175173
L.w("end: Skipping session end, backend mode is enabled!");
176174
return;
177175
}
@@ -264,7 +262,7 @@ public boolean isActive() {
264262
*
265263
* @return calculated session duration to send in seconds
266264
*/
267-
private Long updateDuration(Long now){
265+
private Long updateDuration(Long now) {
268266
now = now == null ? System.nanoTime() : now;
269267
Long duration;
270268

@@ -285,7 +283,9 @@ public Event timedEvent(String key) {
285283
return timedEvents().event(ctx, key);
286284
}
287285

288-
protected TimedEvents timedEvents () { return SDKCore.instance.timedEvents(); }
286+
protected TimedEvents timedEvents() {
287+
return SDKCore.instance.timedEvents();
288+
}
289289

290290
@Override
291291
public void recordEvent(Event event) {
@@ -305,7 +305,7 @@ public void recordEvent(Event event) {
305305
}
306306

307307
Config config = SDKCore.instance.config();
308-
if (config != null && config.getEventsBufferSize() <= events.size()) {
308+
if (config != null && ctx.getConfig().getEventsBufferSize() <= events.size()) {
309309
update();
310310
}
311311
}
@@ -328,7 +328,7 @@ public Session addCrashReport(Throwable t, boolean fatal) {
328328

329329
@Override
330330
public Session addCrashReport(Throwable t, boolean fatal, String name, Map<String, String> segments, String... logs) {
331-
if(ctx.getConfig().isBackendModeEnabled()) {
331+
if (ctx.getConfig().isBackendModeEnabled()) {
332332
L.w("[SessionImpl] addCrashReport: Skipping crash, backend mode is enabled!");
333333
return this;
334334
}
@@ -337,13 +337,15 @@ public Session addCrashReport(Throwable t, boolean fatal, String name, Map<Strin
337337
L.i("[SessionImpl] addCrashReport: Skipping event - feature is not enabled");
338338
return this;
339339
}
340+
340341
SDKCore.instance.onCrash(ctx, t, fatal, name, segments, logs);
341342
return this;
342343
}
343344

344345
@Override
345346
public Session addLocation(double latitude, double longitude) {
346-
if(ctx.getConfig().isBackendModeEnabled()) {
347+
348+
if (ctx.getConfig().isBackendModeEnabled()) {
347349
L.w("[SessionImpl] addLocation: Skipping location, backend mode is enabled!");
348350
return this;
349351
}
@@ -353,7 +355,7 @@ public Session addLocation(double latitude, double longitude) {
353355
L.i("[SessionImpl] addLocation: Skipping event - feature is not enabled");
354356
return this;
355357
}
356-
return addParam("location", latitude + "," + longitude);
358+
return (Session) addParam("location", latitude + "," + longitude);
357359
}
358360

359361
public View view(String name, boolean start) {
@@ -365,7 +367,9 @@ public View view(String name, boolean start) {
365367
if (currentView != null) {
366368
currentView.stop(false);
367369
}
370+
368371
currentView = new ViewImpl(this, name, L);
372+
369373
currentView.start(start);
370374
startView = false;
371375
return currentView;
@@ -401,7 +405,7 @@ public Usage resetDeviceId(String id) {
401405

402406
@Override
403407
public Usage changeDeviceIdWithMerge(String id) {
404-
if(ctx.getConfig().isBackendModeEnabled()) {
408+
if (ctx.getConfig().isBackendModeEnabled()) {
405409
L.w("[SessionImpl] changeDeviceIdWithMerge: Skipping change device id with merge, backend mode is enabled!");
406410
return this;
407411
}
@@ -413,7 +417,7 @@ public Usage changeDeviceIdWithMerge(String id) {
413417

414418
@Override
415419
public Usage changeDeviceIdWithoutMerge(String id) {
416-
if(ctx.getConfig().isBackendModeEnabled()) {
420+
if (ctx.getConfig().isBackendModeEnabled()) {
417421
L.w("[SessionImpl] changeDeviceIdWithoutMerge: Skipping change device id without merge, backend mode is enabled!");
418422
return this;
419423
}
@@ -573,7 +577,7 @@ public boolean equals(Object obj) {
573577
return false;
574578
}
575579

576-
SessionImpl session = (SessionImpl)obj;
580+
SessionImpl session = (SessionImpl) obj;
577581
if (!id.equals(session.id)) {
578582
return false;
579583
}

sdk-java/src/main/java/ly/count/sdk/java/internal/UserEditorImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ void perform(JSONObject changes, Set<String> cohortsAdded, Set<String> cohortsRe
309309
cohortsRemoved.addAll(cohortsToRemove);
310310
}
311311

312+
312313
@Override
313314
public UserEditor set(String key, Object value) {
314315
sets.put(key, value);

0 commit comments

Comments
 (0)