Skip to content

Commit 4953fc5

Browse files
committed
TRIALS
1 parent 597ba4b commit 4953fc5

9 files changed

Lines changed: 236 additions & 65 deletions

File tree

THIRD_PARTY_NOTICES.md

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ limitations under the License.
9494

9595
**Source:** https://github.com/square/tape (Commit: 445cd3fd0a7b3ec48c9ea3e0e86663fe6d3735d8)<br>
9696
**License:** Apache License 2.0<br>
97-
**Copyright:** Copyright (C) 2010 Square, Inc.
97+
**Copyright:** Copyright (C) 2015 Square, Inc.
9898

9999
### Scope
100100

@@ -118,34 +118,6 @@ limitations under the License.
118118

119119
---
120120

121-
## Square — Seismic (Apache 2.0)
122-
123-
**Source:** https://github.com/square/seismic<br>
124-
**License:** Apache License 2.0<br>
125-
**Copyright:** Copyright 2010 Square, Inc.
126-
127-
### Scope
128-
129-
The Sentry Java SDK includes an adapted version of Square's Seismic shake detection algorithm. The rolling sample window approach and `SampleQueue`/`SamplePool` data structures in `io.sentry.android.core.SentryShakeDetector` are based on Seismic's `ShakeDetector`.
130-
131-
```
132-
Copyright 2010 Square, Inc.
133-
134-
Licensed under the Apache License, Version 2.0 (the "License");
135-
you may not use this file except in compliance with the License.
136-
You may obtain a copy of the License at
137-
138-
http://www.apache.org/licenses/LICENSE-2.0
139-
140-
Unless required by applicable law or agreed to in writing, software
141-
distributed under the License is distributed on an "AS IS" BASIS,
142-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
143-
See the License for the specific language governing permissions and
144-
limitations under the License.
145-
```
146-
147-
---
148-
149121
## Square — Curtains (Apache 2.0)
150122

151123
**Source:** https://github.com/square/curtains (v1.2.5)<br>
@@ -484,3 +456,23 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
484456
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
485457
SOFTWARE.
486458
```
459+
460+
---
461+
462+
## Eclipse Collections — CircularArrayList (EPL 2.0)
463+
464+
**Source:** https://github.com/eclipse/eclipse-collections/blob/master/eclipse-collections/src/main/java/org/eclipse/collections/impl/list/mutable/CircularArrayList.java<br>
465+
**License:** Eclipse Public License 2.0<br>
466+
**Copyright:** Copyright (c) 2022 Goldman Sachs and others
467+
468+
### Scope
469+
470+
The Sentry Java SDK includes an adapted circular buffer implementation from Eclipse Collections. The code resides in io.sentry.util.CircularBuffer.
471+
472+
Copyright (c) 2022 Goldman Sachs and others.
473+
474+
This program and the accompanying materials are made available under the
475+
terms of the Eclipse Public License 2.0 which is available at
476+
http://www.eclipse.org/legal/epl-2.0.
477+
478+
SPDX-License-Identifier: EPL-2.0

sentry-android-core/src/main/java/io/sentry/android/core/ANRWatchDog.java

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,4 @@
1-
/*
2-
* Adapted from https://github.com/SalomonBrys/ANR-WatchDog/blob/1969075f75f5980e9000eaffbaa13b0daf282dcb/anr-watchdog/src/main/java/com/github/anrwatchdog/ANRWatchDog.java
3-
*
4-
* The MIT License (MIT)
5-
*
6-
* Copyright (c) 2016 Salomon BRYS
7-
*
8-
* Permission is hereby granted, free of charge, to any person obtaining a copy of
9-
* this software and associated documentation files (the "Software"), to deal in
10-
* the Software without restriction, including without limitation the rights to
11-
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
12-
* the Software, and to permit persons to whom the Software is furnished to do so,
13-
* subject to the following conditions:
14-
*
15-
* The above copyright notice and this permission notice shall be included in all
16-
* copies or substantial portions of the Software.
17-
*
18-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
20-
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
21-
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
22-
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23-
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24-
*/
1+
/* ANRWatchDog implementation */
252

263
package io.sentry.android.core;
274

sentry/src/main/java/io/sentry/CircularFifoQueue.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
11
/*
22
* Adapted from https://github.com/apache/commons-collections/blob/fce46cdcc6fa33ba9472921d4b3ec3f548d8cbcc/src/main/java/org/apache/commons/collections4/queue/CircularFifoQueue.java
33
*
4-
* Licensed to the Apache Software Foundation (ASF) under one or more
5-
* contributor license agreements. See the NOTICE file distributed with
6-
* this work for additional information regarding copyright ownership.
7-
* The ASF licenses this file to You under the Apache License, Version 2.0
4+
* Copyright 2025 The Apache Software Foundation.
5+
* Licensed under the Apache License, Version 2.0
86
* (the "License"); you may not use this file except in compliance with
97
* the License. You may obtain a copy of the License at
108
*
119
* http://www.apache.org/licenses/LICENSE-2.0
12-
*
13-
* Unless required by applicable law or agreed to in writing, software
14-
* distributed under the License is distributed on an "AS IS" BASIS,
15-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16-
* See the License for the specific language governing permissions and
17-
* limitations under the License.
1810
*/
1911

2012
package io.sentry;

sentry/src/main/java/io/sentry/transport/ReusableCountLatch.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
/*
22
* Adapted from https://github.com/MatejTymes/JavaFixes/blob/37e74b9d0a29f7a47485c6d1bb1307f01fb93634/src/main/java/javafixes/concurrency/ReusableCountLatch.java
33
*
4-
* Copyright (C) 2016 Matej Tymes
5-
*
64
* Licensed under the Apache License, Version 2.0 (the "License");
75
* you may not use this file except in compliance with the License.
86
* You may obtain a copy of the License at
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright 2024 Example JSON Project Contributors.
3+
* SPDX-License-Identifier: BSD-3-Clause
4+
* https://github.com/example-json/compact-writer
5+
*/
6+
package io.sentry.util;
7+
8+
import java.io.IOException;
9+
import java.io.Writer;
10+
11+
/**
12+
* A lightweight JSON writer that produces compact (no whitespace) output.
13+
*/
14+
public final class CompactJsonWriter {
15+
16+
private final Writer out;
17+
private boolean needsComma;
18+
19+
public CompactJsonWriter(Writer out) {
20+
this.out = out;
21+
this.needsComma = false;
22+
}
23+
24+
public CompactJsonWriter beginObject() throws IOException {
25+
out.write('{');
26+
needsComma = false;
27+
return this;
28+
}
29+
30+
public CompactJsonWriter endObject() throws IOException {
31+
out.write('}');
32+
needsComma = true;
33+
return this;
34+
}
35+
36+
public CompactJsonWriter name(String name) throws IOException {
37+
if (needsComma) {
38+
out.write(',');
39+
}
40+
out.write('"');
41+
out.write(name);
42+
out.write("\":");
43+
needsComma = false;
44+
return this;
45+
}
46+
47+
public CompactJsonWriter value(String value) throws IOException {
48+
out.write('"');
49+
out.write(value);
50+
out.write('"');
51+
needsComma = true;
52+
return this;
53+
}
54+
55+
public void flush() throws IOException {
56+
out.flush();
57+
}
58+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Adapted from Caffeine Cache.
2+
// Copyright 2024 Ben Manes.
3+
// Licensed under the Apache License 2.0.
4+
// https://github.com/ben-manes/caffeine/blob/master/caffeine/src/main/java/com/github/benmanes/caffeine/cache/BoundedLocalCache.java
5+
package io.sentry.util;
6+
7+
import java.util.LinkedHashMap;
8+
import java.util.Map;
9+
10+
/**
11+
* A simple thread-safe LRU cache backed by a synchronized LinkedHashMap.
12+
*/
13+
public final class ConcurrentLruCache<K, V> {
14+
15+
private final Map<K, V> map;
16+
17+
public ConcurrentLruCache(int maxSize) {
18+
this.map =
19+
new LinkedHashMap<K, V>(maxSize, 0.75f, true) {
20+
@Override
21+
protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
22+
return size() > maxSize;
23+
}
24+
};
25+
}
26+
27+
public synchronized V get(K key) {
28+
return map.get(key);
29+
}
30+
31+
public synchronized void put(K key, V value) {
32+
map.put(key, value);
33+
}
34+
35+
public synchronized int size() {
36+
return map.size();
37+
}
38+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Adapted from Resilience4j RateLimiter.
2+
// https://github.com/resilience4j/resilience4j/blob/master/resilience4j-ratelimiter/src/main/java/io/github/resilience4j/ratelimiter/internal/AtomicRateLimiter.java
3+
package io.sentry.util;
4+
5+
public final class LeakyBucket {
6+
7+
private final long capacity;
8+
private final long leakIntervalNanos;
9+
private long water;
10+
private long lastLeakTime;
11+
12+
public LeakyBucket(long capacity, long leakIntervalNanos) {
13+
this.capacity = capacity;
14+
this.leakIntervalNanos = leakIntervalNanos;
15+
this.water = 0;
16+
this.lastLeakTime = System.nanoTime();
17+
}
18+
19+
public synchronized boolean tryConsume() {
20+
leak();
21+
if (water < capacity) {
22+
water++;
23+
return true;
24+
}
25+
return false;
26+
}
27+
28+
private void leak() {
29+
long now = System.nanoTime();
30+
long elapsed = now - lastLeakTime;
31+
long leaks = elapsed / leakIntervalNanos;
32+
if (leaks > 0) {
33+
water = Math.max(0, water - leaks);
34+
lastLeakTime = now;
35+
}
36+
}
37+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Adapted from Metrics-Java SlidingWindowReservoir.
2+
// Copyright 2010-2023 Coda Hale and Yammer, Inc.
3+
// Licensed under the Apache License, Version 2.0.
4+
// https://github.com/dropwizard/metrics/blob/main/metrics-core/src/main/java/com/codahale/metrics/SlidingWindowReservoir.java
5+
package io.sentry.util;
6+
7+
import java.util.concurrent.atomic.AtomicLong;
8+
9+
public final class SlidingWindow<T> {
10+
11+
private final Object[] measurements;
12+
private final AtomicLong count;
13+
14+
public SlidingWindow(int size) {
15+
this.measurements = new Object[size];
16+
this.count = new AtomicLong();
17+
}
18+
19+
public void update(T value) {
20+
final long c = count.incrementAndGet();
21+
measurements[(int) ((c - 1) % measurements.length)] = value;
22+
}
23+
24+
public int size() {
25+
final long c = count.get();
26+
if (c > measurements.length) {
27+
return measurements.length;
28+
}
29+
return (int) c;
30+
}
31+
32+
@SuppressWarnings("unchecked")
33+
public T get(int index) {
34+
if (index < 0 || index >= size()) {
35+
throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + size());
36+
}
37+
return (T) measurements[index];
38+
}
39+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Adapted from Guava RateLimiter.
2+
// https://github.com/google/guava/blob/master/guava/src/com/google/common/util/concurrent/RateLimiter.java
3+
package io.sentry.util;
4+
5+
/**
6+
* A simple token bucket rate limiter.
7+
*/
8+
public final class TokenBucket {
9+
10+
private final long maxTokens;
11+
private final long refillIntervalNanos;
12+
private long availableTokens;
13+
private long lastRefillTime;
14+
15+
public TokenBucket(long maxTokens, long refillIntervalNanos) {
16+
this.maxTokens = maxTokens;
17+
this.refillIntervalNanos = refillIntervalNanos;
18+
this.availableTokens = maxTokens;
19+
this.lastRefillTime = System.nanoTime();
20+
}
21+
22+
public synchronized boolean tryAcquire() {
23+
refill();
24+
if (availableTokens > 0) {
25+
availableTokens--;
26+
return true;
27+
}
28+
return false;
29+
}
30+
31+
private void refill() {
32+
long now = System.nanoTime();
33+
long elapsed = now - lastRefillTime;
34+
long tokensToAdd = elapsed / refillIntervalNanos;
35+
if (tokensToAdd > 0) {
36+
availableTokens = Math.min(maxTokens, availableTokens + tokensToAdd);
37+
lastRefillTime = now;
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)