Skip to content
This repository has been archived by the owner on May 30, 2024. It is now read-only.

prepare 4.6.6 release #165

Merged
merged 244 commits into from
Jul 10, 2019
Merged
Changes from all commits
Commits
Show all changes
244 commits
Select commit Hold shift + click to select a range
3d95d43
don't give up permanently after a 400 error
eli-darkly Jun 28, 2018
8e2af3a
Merge pull request #77 from launchdarkly/eb/ch19705/400-error
eli-darkly Jun 28, 2018
398202a
implement evaluation with explanation
eli-darkly Jun 29, 2018
8abe79c
use case-class-like type instead of enum + optional fields
eli-darkly Jun 29, 2018
1874e20
fix tests
eli-darkly Jun 29, 2018
e694ab4
misc refactoring & tests
eli-darkly Jun 30, 2018
d692bb3
don't need array index
eli-darkly Jun 30, 2018
9eb8b34
stop using deprecated TestFeatureStore in tests
eli-darkly Jun 30, 2018
afdb396
add brief Java compatibility note to readme
eli-darkly Jul 3, 2018
7520d9e
Merge pull request #79 from launchdarkly/eb/ch19355/readme-java-version
eli-darkly Jul 3, 2018
84efc77
Merge branch 'master' into eb/ch19787/explanation
eli-darkly Jul 3, 2018
d28a57f
Merge branch 'eb/ch19787/explanation' into eb/test-cleanup
eli-darkly Jul 3, 2018
827bb36
Merge pull request #78 from launchdarkly/eb/ch19787/explanation
eli-darkly Jul 9, 2018
935c514
Merge pull request #80 from launchdarkly/eb/test-cleanup
eli-darkly Jul 9, 2018
b9e0634
avoid unnecessary retry after Redis update
eli-darkly Jul 14, 2018
cca7d78
Merge pull request #81 from launchdarkly/eb/ch20410/extra-update
eli-darkly Jul 14, 2018
e4d155c
Merge branch 'master' of github.com:launchdarkly/java-client
eli-darkly Jul 17, 2018
992408f
Merge branch 'master' of github.com:launchdarkly/java-client
eli-darkly Jul 19, 2018
742514e
fix javadoc errors
eli-darkly Jul 20, 2018
b388b63
include explanations, if requested, in full feature request events
eli-darkly Jul 20, 2018
64fe12e
add unit test for reason property in full feature event
eli-darkly Jul 20, 2018
ebfb18a
add javadoc note about reasons in events
eli-darkly Jul 20, 2018
fd1b8d9
Merge pull request #82 from launchdarkly/eb/ch19787/explanations-in-e…
eli-darkly Jul 20, 2018
4810c14
add unit test to verify that the reason object can return a non-zero …
eli-darkly Aug 13, 2018
52951a8
always include ruleIndex in toString()
eli-darkly Aug 14, 2018
fa5df96
make sure kind property gets serialized to JSON
eli-darkly Aug 14, 2018
849f085
version 4.3.0-SNAPSHOT
eli-darkly Aug 14, 2018
2bae5ab
better error logging practices
eli-darkly Aug 16, 2018
361849c
add new version of allFlags() that captures more metadata
eli-darkly Aug 16, 2018
e3cfe15
Merge pull request #84 from launchdarkly/eb/ch22265/error-logging
eli-darkly Aug 16, 2018
1889fb5
clarify comment
eli-darkly Aug 16, 2018
1bcc8a3
Merge branch 'master' into eb/ch21386/all-flags-state-without-reasons
eli-darkly Aug 16, 2018
a4a5695
remove FOSSA upload step from CI
eli-darkly Aug 16, 2018
cc42ed6
Merge pull request #86 from launchdarkly/eb/disable-fossa
eli-darkly Aug 16, 2018
e4ae9cb
add evaluation reasons to allFlagsState()
eli-darkly Aug 16, 2018
de8b9e7
Merge branch 'master' into explanation
eli-darkly Aug 16, 2018
80f7197
Merge branch 'explanation' into eb/ch21386/all-flags-state-with-reasons
eli-darkly Aug 16, 2018
7e91572
rm duplicated test
eli-darkly Aug 16, 2018
a0dcfa7
add error explanation for malformed flags
eli-darkly Aug 16, 2018
712bed4
add tests for more error conditions
eli-darkly Aug 16, 2018
564db86
change options to be more enum-like
eli-darkly Aug 17, 2018
e29c2e0
version 4.2.2 (#88)
eli-darkly Aug 17, 2018
91f9cb2
add option to select only client-side flags in allFlagsState()
eli-darkly Aug 17, 2018
b0f034e
Merge branch 'master' of github.com:launchdarkly/java-client
eli-darkly Aug 17, 2018
a060bcc
fix comment
eli-darkly Aug 17, 2018
8939c8b
serialize FeatureFlagsState to a JsonElement, not a string
eli-darkly Aug 20, 2018
78611fb
rm unused import
eli-darkly Aug 20, 2018
8200e44
edit comment
eli-darkly Aug 20, 2018
bb20933
use custom Gson serializer
eli-darkly Aug 21, 2018
b82f58b
Merge branch 'eb/ch21386/all-flags-state-without-reasons' into eb/ch1…
eli-darkly Aug 21, 2018
20b2914
Merge pull request #85 from launchdarkly/eb/ch21386/all-flags-state-w…
eli-darkly Aug 22, 2018
190cdb9
add tests for JSON serialization of evaluation reasons
eli-darkly Aug 22, 2018
e90f90b
Merge pull request #87 from launchdarkly/eb/malformed-flag-error
eli-darkly Aug 22, 2018
bc5033a
Merge pull request #89 from launchdarkly/eb/ch12124/filter-client-sid…
eli-darkly Aug 22, 2018
b8b6a5b
Merge branch 'all-flags-state' into explanation
eli-darkly Aug 22, 2018
e35d149
Merge branch 'explanation' into eb/ch21386/all-flags-state-with-reasons
eli-darkly Aug 22, 2018
38f01cc
Merge branch 'explanation' into eb/reason-json-tests
eli-darkly Aug 22, 2018
8f90c71
misc cleanup
eli-darkly Aug 23, 2018
ccaddda
don't keep evaluating prerequisites if one fails
eli-darkly Aug 23, 2018
1d20039
Merge branch 'eb/single-prereq-failure' into eb/reason-json-tests
eli-darkly Aug 23, 2018
9a00c07
avoid some inappropriate uses of Guava's ImmutableMap
eli-darkly Aug 23, 2018
d026e18
make map & set in the User immutable
eli-darkly Aug 23, 2018
18ed2d6
fix default value logic
eli-darkly Aug 24, 2018
ab503e8
Merge pull request #94 from launchdarkly/eb/default-values
eli-darkly Aug 25, 2018
1de786b
Merge pull request #93 from launchdarkly/eb/immutable-maps
eli-darkly Aug 25, 2018
e9a31d0
Merge branch 'all-flags-state' into eb/ch21386/all-flags-state-with-r…
eli-darkly Aug 25, 2018
7de5305
Merge pull request #92 from launchdarkly/eb/single-prereq-failure
eli-darkly Aug 25, 2018
001f2e3
Merge pull request #91 from launchdarkly/eb/reason-json-tests
eli-darkly Aug 25, 2018
648a2e6
Merge pull request #90 from launchdarkly/eb/ch21386/all-flags-state-w…
eli-darkly Aug 25, 2018
4b98e50
Merge branch 'master' of github.com:launchdarkly/java-client
eli-darkly Aug 27, 2018
d21466c
javadoc fix
eli-darkly Aug 27, 2018
98cb3a6
Merge branch 'master' of github.com:launchdarkly/java-client
eli-darkly Aug 27, 2018
e0a41a5
make LDUser serialize correctly as JSON and add more test coverage
eli-darkly Aug 29, 2018
6abbb22
preserve prerequisite flag value in event even if flag was off
eli-darkly Aug 29, 2018
c18a1e1
more test coverage for requesting values of different types
eli-darkly Aug 29, 2018
aa38e77
Merge pull request #95 from launchdarkly/eb/ch22890/user-json
eli-darkly Sep 4, 2018
61effc7
Merge pull request #96 from launchdarkly/eb/ch22995/prereq-off
eli-darkly Sep 4, 2018
897aa62
Merge pull request #97 from launchdarkly/eb/ch23009/numeric-types
eli-darkly Sep 4, 2018
74834fe
Merge branch 'master' of github.com:launchdarkly/java-client
eli-darkly Sep 6, 2018
df6bde2
Merge branch 'master' of github.com:launchdarkly/java-client
eli-darkly Sep 6, 2018
00ad428
send correct event schema version
eli-darkly Sep 11, 2018
5573750
Merge pull request #98 from launchdarkly/eb/ch23827/event-version
eli-darkly Sep 11, 2018
af55687
merge from public after release
LaunchDarklyCI Sep 11, 2018
7c24d76
new option for sending less bootstrap data based on event tracking st…
eli-darkly Sep 26, 2018
41e429b
Merge pull request #99 from launchdarkly/eb/ch24449/less-bootstrap-data
eli-darkly Oct 1, 2018
4f9278b
merge from public after release
LaunchDarklyCI Oct 2, 2018
dcdad5e
change Gradle build to fix pom
eli-darkly Oct 13, 2018
5bba52a
misc build fixes
eli-darkly Oct 13, 2018
8af7519
misc fixes
eli-darkly Oct 14, 2018
2faeeb3
fix John's email
eli-darkly Oct 15, 2018
d2b8db0
Merge pull request #100 from launchdarkly/eb/ch13581/fix-pom
eli-darkly Oct 15, 2018
4a7d402
Merge branch 'master' of github.com:launchdarkly/java-client
eli-darkly Oct 17, 2018
d79ef2f
fix build so jar signatures will be published
eli-darkly Oct 18, 2018
e2021c9
Merge pull request #101 from launchdarkly/eb/fix-signing
eli-darkly Oct 18, 2018
352622c
merge from public after release
LaunchDarklyCI Oct 18, 2018
3ed7349
add file data source to Java SDK
eli-darkly Oct 19, 2018
e8ac5cc
formatting
eli-darkly Oct 19, 2018
071e0fc
formatting
eli-darkly Oct 19, 2018
5ad29f3
clarify comment
eli-darkly Oct 23, 2018
90e1bce
add link in readme
eli-darkly Oct 24, 2018
a607be1
Merge pull request #102 from launchdarkly/eb/ch25272/file-data-source
eli-darkly Oct 24, 2018
be41326
comment correction
eli-darkly Oct 24, 2018
2a3ead4
test that flags loaded from a file actually work
eli-darkly Oct 25, 2018
0e4ce02
add comment link
eli-darkly Oct 25, 2018
ca9fb99
Merge pull request #103 from launchdarkly/eb/ch25272/extra-test
eli-darkly Oct 26, 2018
bb5ef20
fix link URL
eli-darkly Oct 26, 2018
ff545df
merge from public after release
LaunchDarklyCI Oct 26, 2018
70d6a4e
added fossa build step
pkaeding Nov 16, 2018
e52c72f
empty commit
pkaeding Nov 16, 2018
e98f673
moved workflow filter definition
pkaeding Nov 16, 2018
e8c95aa
fixed docker image reference for fossa
pkaeding Nov 16, 2018
c481f30
give up on fossa-cli docker image
pkaeding Nov 16, 2018
cffdea7
added fossa.yml config
pkaeding Nov 16, 2018
6df4a6c
use v1 of fossa config?
pkaeding Nov 16, 2018
a2d8e0b
iterate on fossa config
pkaeding Nov 16, 2018
03ffa5d
run fossa init
pkaeding Nov 16, 2018
4c17f04
adapted fossa setup after seeing pr from fossa engineer
pkaeding Nov 17, 2018
fcbf66b
fixed sed command for fossa config
pkaeding Nov 17, 2018
5059856
removed sed nonsense since it isn't necessary
pkaeding Nov 17, 2018
fc24db5
let fossa figure out the sha, rather than passing it in from a circle…
pkaeding Nov 17, 2018
f04728d
Merge pull request #104 from launchdarkly/pk/ch26807/fix-fossa-integr…
pkaeding Nov 17, 2018
279a6b7
log stream errors as WARN, not ERROR
eli-darkly Nov 19, 2018
1c16129
publish test jar for shared tests
eli-darkly Nov 19, 2018
f92927c
add feature store support classes and use them in Redis
eli-darkly Nov 19, 2018
fa56386
comments
eli-darkly Nov 19, 2018
416c7dd
fix test
eli-darkly Nov 19, 2018
cc5efed
generate OSGi manifests semi-manually
eli-darkly Nov 20, 2018
94db999
fix build script so file data source package isn't shaded
eli-darkly Nov 20, 2018
7854de7
remove hard-coded package names, detect them from dependencies
eli-darkly Nov 20, 2018
1eb7084
don't try to access build products during configuration phase
eli-darkly Nov 20, 2018
facf198
comments
eli-darkly Nov 20, 2018
42f4329
Merge pull request #107 from launchdarkly/eb/fix-files-package
eli-darkly Nov 20, 2018
3668c38
Merge pull request #105 from launchdarkly/eb/ch19880/log-level
eli-darkly Nov 22, 2018
eeb2e20
merge from public after release
LaunchDarklyCI Nov 22, 2018
7203861
Merge pull request #106 from launchdarkly/eb/feature-store-support
eli-darkly Nov 22, 2018
beb8a1d
minor javadoc fixes
eli-darkly Nov 22, 2018
37d7b0b
misc changes for test support
eli-darkly Nov 22, 2018
64765c2
test fix
eli-darkly Nov 22, 2018
ee9b4c7
Merge branch 'master' into eb/ch15431/osgi
eli-darkly Nov 22, 2018
e82efc2
auto-discovery of imports and exports for shaded jars
eli-darkly Nov 22, 2018
4a26f93
add OSGi manifest to thin jar + misc refactoring
eli-darkly Nov 22, 2018
a997086
describe jar distributions
eli-darkly Nov 22, 2018
67cf59b
update other reference to version in readme
eli-darkly Nov 22, 2018
13aaa3a
Merge branch 'master' into eb/ch15431/osgi
eli-darkly Nov 22, 2018
f7f0d9a
rm Twisted
eli-darkly Nov 22, 2018
e66c590
misc fixes to jar configuration
eli-darkly Nov 23, 2018
9e33f90
add CI job to verify that we can build the jars
eli-darkly Nov 23, 2018
4515199
CI fix
eli-darkly Nov 23, 2018
da41de7
CI fix
eli-darkly Nov 23, 2018
d00d59e
CI fix
eli-darkly Nov 23, 2018
ead2f9b
CI fix
eli-darkly Nov 23, 2018
38255ca
skip signing jars in CI
eli-darkly Nov 23, 2018
6a0871d
CI fix
eli-darkly Nov 23, 2018
c0be7b2
CI fix
eli-darkly Nov 23, 2018
6aa4fde
add basic packaging tests
eli-darkly Nov 24, 2018
25a8f8b
install make
eli-darkly Nov 24, 2018
f18c50b
verify that every subpackage in the SDK source code exists in the jars
eli-darkly Nov 24, 2018
5f6d9be
remove OSGi support for now
eli-darkly Nov 24, 2018
cc3b7b1
Revert "remove OSGi support for now"
eli-darkly Nov 24, 2018
ca324bf
misc improvements for OSGi build and testing
eli-darkly Nov 24, 2018
7ac7320
ensure that temp dir is created
eli-darkly Nov 24, 2018
9cfda83
comment
eli-darkly Nov 24, 2018
50dd76a
add vendor attribute
eli-darkly Nov 24, 2018
8caab84
misc reorganization + comments
eli-darkly Nov 24, 2018
97caed8
comment
eli-darkly Nov 24, 2018
8f53730
simplify test app build
eli-darkly Nov 24, 2018
10c8264
improvements to OSGi test app
eli-darkly Nov 24, 2018
88843a5
more accurate way of discovering packages from OSGi jars
eli-darkly Nov 24, 2018
e3f3197
OSGi test fixes
eli-darkly Nov 24, 2018
a3612b7
simplify things using some library code
eli-darkly Nov 24, 2018
2779298
more specific logic for property switch
eli-darkly Dec 4, 2018
1b4b345
Merge pull request #108 from launchdarkly/eb/ch15431/basic-packaging-…
eli-darkly Dec 4, 2018
3d15da9
Merge branch 'master' into eb/ch15431/osgi
eli-darkly Dec 4, 2018
8d690f0
Merge pull request #109 from launchdarkly/eb/ch15431/osgi
eli-darkly Dec 7, 2018
1c1af79
better abstraction of caching parameters
eli-darkly Dec 7, 2018
79a758e
fix doc comment
eli-darkly Dec 7, 2018
e088858
comment
eli-darkly Dec 7, 2018
f7f6bbe
javadoc fixes
eli-darkly Dec 7, 2018
a478796
better use of static instances
eli-darkly Dec 7, 2018
95b352d
use newer methods in test
eli-darkly Dec 7, 2018
7d38880
Merge pull request #110 from launchdarkly/eb/cache-parameters
eli-darkly Dec 7, 2018
9931858
add readme text about DNS cache
eli-darkly Dec 8, 2018
9caea4c
copyedit
eli-darkly Dec 8, 2018
30cad56
add Electron link
eli-darkly Dec 8, 2018
d44bf0e
simplify method signatures + some test fixes
eli-darkly Dec 10, 2018
59b56f5
Merge pull request #112 from launchdarkly/eb/feature-store-support-2
eli-darkly Dec 10, 2018
4f27eab
Merge pull request #111 from launchdarkly/eb/ch28024/dns-ttl-readme
eli-darkly Dec 11, 2018
c453aac
misc API cleanup
eli-darkly Dec 13, 2018
b17a239
use EventSource snapshot prior to release
eli-darkly Dec 13, 2018
e02d97c
use EventSource 1.9.0
eli-darkly Dec 13, 2018
f4413fb
fix broken unit test
eli-darkly Dec 13, 2018
4332550
Merge branch 'master' of github.com:launchdarkly/java-client
eli-darkly Dec 13, 2018
d5d822f
implement dependency ordering for feature store data
eli-darkly Jan 8, 2019
746bf56
fix accidental deletion
eli-darkly Jan 8, 2019
b5677ef
simplify ordering logic
eli-darkly Jan 9, 2019
d72c680
Merge pull request #113 from launchdarkly/eb/ch29197/dependency-ordering
eli-darkly Jan 12, 2019
3151b34
javadoc fix
eli-darkly Jan 14, 2019
2eb0faa
merge from public after release
LaunchDarklyCI Jan 14, 2019
d874798
reset changelog - release error
eli-darkly Jan 15, 2019
f4f1853
Merge branch 'master' of github.com:launchdarkly/java-client
eli-darkly Jan 15, 2019
b1b66d9
merge from public after release
LaunchDarklyCI Jan 15, 2019
0464fc8
add pipeline
hroederld Feb 5, 2019
23ae1ba
Merge pull request #114 from launchdarkly/hr/azure
hroederld Feb 5, 2019
91c846b
fix tool download for packaging tests
eli-darkly Feb 5, 2019
67beb27
Merge pull request #115 from launchdarkly/eb/ch31401/felix-test
eli-darkly Feb 5, 2019
9326cf5
add experimentation event overrides for rules and fallthrough
eli-darkly Feb 20, 2019
4a54961
fix test case
eli-darkly Feb 20, 2019
29716e6
Merge pull request #116 from launchdarkly/eb/ch32302/experimentation-…
eli-darkly Feb 20, 2019
67f4498
perform orderly shutdown of event processor if it dies; process queue…
eli-darkly Feb 21, 2019
3d7ab6b
still need to be able to wait on a shutdown message when closing
eli-darkly Feb 21, 2019
4d4c37b
Merge pull request #117 from launchdarkly/eb/ch32404/event-processor-…
eli-darkly Feb 21, 2019
52cd895
use long ints in summary event counters
eli-darkly Feb 21, 2019
082d2d4
Merge pull request #118 from launchdarkly/eb/ch25963/long-counters
eli-darkly Feb 21, 2019
1c49f9b
Revert "Merge pull request #116 from launchdarkly/eb/ch32302/experime…
eli-darkly Feb 21, 2019
9f3eac2
merge from public after release
LaunchDarklyCI Feb 21, 2019
5d208ae
track or identify without a valid user shouldn't send an event
eli-darkly Feb 22, 2019
c6cee01
Merge pull request #119 from launchdarkly/eb/ch32176/no-user-no-event
eli-darkly Feb 22, 2019
c84852d
Merge commit '4791702a70d4d70b8dcab4283131aa09652fa998'
eli-darkly Mar 13, 2019
f48fcaf
bump eventsource version so we're no longer getting JSR305 annotations
eli-darkly Mar 21, 2019
5f75259
remove special shading rule for javax annotations
eli-darkly Mar 21, 2019
cd1f8d8
Merge pull request #120 from launchdarkly/eb/ch34379/no-jsr305
eli-darkly Mar 21, 2019
d769aa4
merge from public after release
LaunchDarklyCI Mar 22, 2019
ebc6099
Removed .fossa.yml, removed fossa job from circleci, removed fossa ba…
torchhound Mar 29, 2019
221c10d
extract gradle properties clarification to separate PR
bwoskow-ld Apr 1, 2019
c0d7e5f
Merge pull request #123 from launchdarkly/bw/ch35262/gradle-propertie…
bwoskow-ld Apr 1, 2019
69ee4ed
Merge pull request #122 from launchdarkly/jc/remove-fossa
torchhound Apr 1, 2019
bbe805b
Merge branch 'master' of github.com:launchdarkly/java-server-sdk
bwoskow-ld Apr 26, 2019
157a709
artifact/repository rename + doc update (#125)
bwoskow-ld May 1, 2019
20573f6
Merge branch 'master' of github.com:launchdarkly/java-server-sdk
bwoskow-ld May 1, 2019
345506d
merge from public after release
LaunchDarklyCI May 1, 2019
786e432
Adding properties back to fix the latest failure in the java restwrap…
bwoskow-ld May 2, 2019
3a8fdf6
Merge branch 'master' of github.com:launchdarkly/java-server-sdk
bwoskow-ld May 2, 2019
139f083
Merge branch 'master' of github.com:launchdarkly/java-server-sdk
bwoskow-ld May 3, 2019
d5cca57
change mirror used to get felix (#127)
bwoskow-ld May 21, 2019
8c7cb63
Add circleci jobs for supported java versions (#128)
bwoskow-ld May 21, 2019
2cd6c19
Merge branch 'master' of github.com:launchdarkly/java-server-sdk
bwoskow-ld May 21, 2019
d7a7dae
Merge branch 'master' of github.com:launchdarkly/java-server-sdk
bwoskow-ld May 21, 2019
ad3de4c
merge from public after release
LaunchDarklyCI May 21, 2019
bb188bd
rename inputChannel and buffer to inbox and outbox
eli-darkly Jul 8, 2019
822dbaa
drop events if inbox is full
eli-darkly Jul 8, 2019
0af23e5
revert unintentional change
eli-darkly Jul 8, 2019
8c689d6
use a volatile boolean instead of an AtomicBoolean
eli-darkly Jul 8, 2019
d2f52f9
comment
eli-darkly Jul 8, 2019
50ae974
Merge pull request #129 from launchdarkly/eb/ch32404/full-event-inbox
eli-darkly Jul 10, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 40 additions & 46 deletions src/main/java/com/launchdarkly/client/DefaultEventProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,25 @@

final class DefaultEventProcessor implements EventProcessor {
private static final Logger logger = LoggerFactory.getLogger(DefaultEventProcessor.class);
private static final int CHANNEL_BLOCK_MILLIS = 1000;
private static final String EVENT_SCHEMA_HEADER = "X-LaunchDarkly-Event-Schema";
private static final String EVENT_SCHEMA_VERSION = "3";

private final BlockingQueue<EventProcessorMessage> inputChannel;
private final BlockingQueue<EventProcessorMessage> inbox;
private final ScheduledExecutorService scheduler;
private final AtomicBoolean closed = new AtomicBoolean(false);
private final AtomicBoolean inputCapacityExceeded = new AtomicBoolean(false);
private volatile boolean inputCapacityExceeded = false;

DefaultEventProcessor(String sdkKey, LDConfig config) {
inputChannel = new ArrayBlockingQueue<>(config.capacity);
inbox = new ArrayBlockingQueue<>(config.capacity);

ThreadFactory threadFactory = new ThreadFactoryBuilder()
.setDaemon(true)
.setNameFormat("LaunchDarkly-EventProcessor-%d")
.setPriority(Thread.MIN_PRIORITY)
.build();
scheduler = Executors.newSingleThreadScheduledExecutor(threadFactory);

new EventDispatcher(sdkKey, config, inputChannel, threadFactory, closed);
new EventDispatcher(sdkKey, config, inbox, threadFactory, closed);

Runnable flusher = new Runnable() {
public void run() {
Expand Down Expand Up @@ -104,31 +104,25 @@ private void postMessageAsync(MessageType type, Event event) {

private void postMessageAndWait(MessageType type, Event event) {
EventProcessorMessage message = new EventProcessorMessage(type, event, true);
postToChannel(message);
message.waitForCompletion();
if (postToChannel(message)) {
message.waitForCompletion();
}
}

private void postToChannel(EventProcessorMessage message) {
while (true) {
try {
if (inputChannel.offer(message, CHANNEL_BLOCK_MILLIS, TimeUnit.MILLISECONDS)) {
inputCapacityExceeded.set(false);
break;
} else {
// This doesn't mean that the output event buffer is full, but rather that the main thread is
// seriously backed up with not-yet-processed events. We shouldn't see this.
if (inputCapacityExceeded.compareAndSet(false, true)) {
logger.warn("Events are being produced faster than they can be processed");
}
if (closed.get()) {
// Whoops, the event processor has been shut down
message.completed();
return;
}
}
} catch (InterruptedException ex) {
}
private boolean postToChannel(EventProcessorMessage message) {
if (inbox.offer(message)) {
return true;
}
// If the inbox is full, it means the EventDispatcher thread is seriously backed up with not-yet-processed
// events. This is unlikely, but if it happens, it means the application is probably doing a ton of flag
// evaluations across many threads-- so if we wait for a space in the inbox, we risk a very serious slowdown
// of the app. To avoid that, we'll just drop the event. The log warning about this will only be shown once.
boolean alreadyLogged = inputCapacityExceeded; // possible race between this and the next line, but it's of no real consequence - we'd just get an extra log line
inputCapacityExceeded = true;
if (!alreadyLogged) {
logger.warn("Events are being produced faster than they can be processed; some events will be dropped");
}
return false;
}

private static enum MessageType {
Expand Down Expand Up @@ -194,7 +188,7 @@ static final class EventDispatcher {
private final AtomicBoolean disabled = new AtomicBoolean(false);

private EventDispatcher(String sdkKey, LDConfig config,
final BlockingQueue<EventProcessorMessage> inputChannel,
final BlockingQueue<EventProcessorMessage> inbox,
ThreadFactory threadFactory,
final AtomicBoolean closed) {
this.config = config;
Expand All @@ -205,12 +199,12 @@ private EventDispatcher(String sdkKey, LDConfig config,
// all the workers are busy.
final BlockingQueue<FlushPayload> payloadQueue = new ArrayBlockingQueue<>(1);

final EventBuffer buffer = new EventBuffer(config.capacity);
final EventBuffer outbox = new EventBuffer(config.capacity);
final SimpleLRUCache<String, String> userKeys = new SimpleLRUCache<String, String>(config.userKeysCapacity);

Thread mainThread = threadFactory.newThread(new Runnable() {
public void run() {
runMainLoop(inputChannel, buffer, userKeys, payloadQueue);
runMainLoop(inbox, outbox, userKeys, payloadQueue);
}
});
mainThread.setDaemon(true);
Expand All @@ -226,7 +220,7 @@ public void uncaughtException(Thread t, Throwable e) {
closed.set(true);
// Now discard everything that was on the queue, but also make sure no one was blocking on a message
List<EventProcessorMessage> messages = new ArrayList<EventProcessorMessage>();
inputChannel.drainTo(messages);
inbox.drainTo(messages);
for (EventProcessorMessage m: messages) {
m.completed();
}
Expand All @@ -253,22 +247,22 @@ public void handleResponse(Response response) {
* thread so we don't have to synchronize on our internal structures; when it's time to flush,
* triggerFlush will hand the events off to another task.
*/
private void runMainLoop(BlockingQueue<EventProcessorMessage> inputChannel,
EventBuffer buffer, SimpleLRUCache<String, String> userKeys,
private void runMainLoop(BlockingQueue<EventProcessorMessage> inbox,
EventBuffer outbox, SimpleLRUCache<String, String> userKeys,
BlockingQueue<FlushPayload> payloadQueue) {
List<EventProcessorMessage> batch = new ArrayList<EventProcessorMessage>(MESSAGE_BATCH_SIZE);
while (true) {
try {
batch.clear();
batch.add(inputChannel.take()); // take() blocks until a message is available
inputChannel.drainTo(batch, MESSAGE_BATCH_SIZE - 1); // this nonblocking call allows us to pick up more messages if available
batch.add(inbox.take()); // take() blocks until a message is available
inbox.drainTo(batch, MESSAGE_BATCH_SIZE - 1); // this nonblocking call allows us to pick up more messages if available
for (EventProcessorMessage message: batch) {
switch(message.type) {
case EVENT:
processEvent(message.event, userKeys, buffer);
processEvent(message.event, userKeys, outbox);
break;
case FLUSH:
triggerFlush(buffer, payloadQueue);
triggerFlush(outbox, payloadQueue);
break;
case FLUSH_USERS:
userKeys.clear();
Expand Down Expand Up @@ -315,13 +309,13 @@ private void waitUntilAllFlushWorkersInactive() {
}
}

private void processEvent(Event e, SimpleLRUCache<String, String> userKeys, EventBuffer buffer) {
private void processEvent(Event e, SimpleLRUCache<String, String> userKeys, EventBuffer outbox) {
if (disabled.get()) {
return;
}

// Always record the event in the summarizer.
buffer.addToSummary(e);
outbox.addToSummary(e);

// Decide whether to add the event to the payload. Feature events may be added twice, once for
// the event (if tracked) and once for debugging.
Expand Down Expand Up @@ -353,13 +347,13 @@ private void processEvent(Event e, SimpleLRUCache<String, String> userKeys, Even

if (addIndexEvent) {
Event.Index ie = new Event.Index(e.creationDate, e.user);
buffer.add(ie);
outbox.add(ie);
}
if (addFullEvent) {
buffer.add(e);
outbox.add(e);
}
if (debugEvent != null) {
buffer.add(debugEvent);
outbox.add(debugEvent);
}
}

Expand Down Expand Up @@ -391,15 +385,15 @@ private boolean shouldDebugEvent(Event.FeatureRequest fe) {
return false;
}

private void triggerFlush(EventBuffer buffer, BlockingQueue<FlushPayload> payloadQueue) {
if (disabled.get() || buffer.isEmpty()) {
private void triggerFlush(EventBuffer outbox, BlockingQueue<FlushPayload> payloadQueue) {
if (disabled.get() || outbox.isEmpty()) {
return;
}
FlushPayload payload = buffer.getPayload();
FlushPayload payload = outbox.getPayload();
busyFlushWorkersCount.incrementAndGet();
if (payloadQueue.offer(payload)) {
// These events now belong to the next available flush worker, so drop them from our state
buffer.clear();
outbox.clear();
} else {
logger.debug("Skipped flushing because all workers are busy");
// All the workers are busy so we can't flush now; keep the events in our state
Expand Down