Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscribe to events on CLI #3

Open
leftiness opened this issue Feb 6, 2021 · 7 comments
Open

Subscribe to events on CLI #3

leftiness opened this issue Feb 6, 2021 · 7 comments
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@leftiness
Copy link
Owner

leftiness commented Feb 6, 2021

todo

  • mycli with no options launches hello world GUI
  • mycli subscribe [channel] subscribes to a CometD server and prints events on stdout. Save authentication for later if possible.
  • mycli help prints CLI usage. Or something similar like --help.
  • Write a CLI guide page on the wiki. Put the CLI usage text there at least.
  • Interrupt command to stop subscription.
  • Add a docker-compose.yaml that can turn on a CometD server for testing.

notes

  • Need to make unit tests. OutputStreamListener needs a test.
  • Javadocs
  • OutputStreamListener can't just disconnect. Somehow he needs to send an exit code back up to the subscribe command. I could throw an unchecked exception and use Picocli IExitCodeExceptionMapper. Feels bad tbh. Also needs to distinguish between (JsonGenerationException, JsonMappingException, IOException) with that exit code.
  • Logging. OutputStreamListener should log that IOException at debug level. Not just disconnect and exit. Maybe even log at error level? Not sure about CLI etiquette. Don't want to spam. Exit code is good enough for default, and you can opt in to debug logs?
  • SubscribeCommand has wrong exit code logic. If Long.MAX_VALUE passes, and you don't yet have State.DISCONNECTED, then this is ERROR_SUBSCRIBE_HEAT_DEATH not ERROR_SUBSCRIBE_DISCONNECTED. If you eventually have State.DISCONNECTED, then this is ERROR_SUBSCRIBE_DISCONNECTED not OK.

links

@leftiness leftiness added documentation Improvements or additions to documentation enhancement New feature or request labels Feb 6, 2021
leftiness added a commit that referenced this issue Feb 7, 2021
@leftiness
Copy link
Owner Author

Work in progress.

[brandon@localhost cometd-client]$ ./gradlew run --quiet --args='s /test'
/test

@leftiness
Copy link
Owner Author

Working on BayeuxClient things.

notes

  • I want to use OkHttp. Looks like Jetty needs enterprise Java things.
  • OkHttp has some kind of bug. He fails to compile unless I explicitly import the Kotlin standard library in my Gradle and add it to my module-info. They say they closed the bug. Maybe it's a regression. I'm ok with "depending" on Kotlin as a workaround because I think I can remove it from the final build with jlink. I should add comments about actually this is a bug in okhttp. Maybe I should tell them about this problem also.

links

leftiness added a commit that referenced this issue Feb 14, 2021
@leftiness
Copy link
Owner Author

leftiness commented Feb 14, 2021

Making progress.

[brandon@localhost cometd-client]$ ./gradlew run --quiet --args='subscribe http://localhost:8080/cometd /chat/**'
SLF4J: No SLF4J providers were found.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#noProviders for further details.
{chat=brandon has joined, membership=join, user=brandon}
{chat=hello, user=brandon}
{chat=goodbye, user=brandon}
{chat=brandon has left, membership=leave, user=brandon}
<==========---> 80% EXECUTING [16s]
> :app:run

leftiness added a commit that referenced this issue Feb 14, 2021
leftiness added a commit that referenced this issue Feb 15, 2021
@leftiness
Copy link
Owner Author

[brandon@localhost cometd-client]$ ./gradlew run --quiet --args='subscribe http://localhost:8080/cometd /chat/**'
SLF4J: No SLF4J providers were found.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#noProviders for further details.
DEAD
ESTABLISHED
ALIVE
ALIVE
LOST
DEAD
DEAD
DEAD
DEAD
{chat=asdf has joined, membership=join, user=asdf}
ESTABLISHED
ALIVE
ALIVE
ALIVE

@leftiness
Copy link
Owner Author

Doesn't make sense to add a listener to log connection status. It's already there in debug logs.

[brandon@localhost cometd-client]$ ./gradlew run -P logLevel=debug --quiet --args='subscribe http://localhost:8080/cometd /chat/**' 2>&1 | grep 'State updated'
[main] DEBUG org.cometd.client.BayeuxClient.437da279 - State updated: DISCONNECTED -> HANDSHAKING
[OkHttp http://localhost:8080/...] DEBUG org.cometd.client.BayeuxClient.437da279 - State updated: HANDSHAKING -> HANDSHAKEN
[OkHttp http://localhost:8080/...] DEBUG org.cometd.client.BayeuxClient.437da279 - State updated: HANDSHAKEN -> CONNECTING
[OkHttp http://localhost:8080/...] DEBUG org.cometd.client.BayeuxClient.437da279 - State updated: CONNECTING -> CONNECTED
[OkHttp http://localhost:8080/...] DEBUG org.cometd.client.BayeuxClient.437da279 - State updated: CONNECTED -> CONNECTED
[OkHttp http://localhost:8080/...] DEBUG org.cometd.client.BayeuxClient.437da279 - State updated: CONNECTED -> UNCONNECTED
[pool-1-thread-1] DEBUG org.cometd.client.BayeuxClient.437da279 - State updated: UNCONNECTED -> UNCONNECTED
[pool-1-thread-1] DEBUG org.cometd.client.BayeuxClient.437da279 - State updated: UNCONNECTED -> UNCONNECTED
[OkHttp http://localhost:8080/...] DEBUG org.cometd.client.BayeuxClient.437da279 - State updated: UNCONNECTED -> REHANDSHAKING
[OkHttp http://localhost:8080/...] DEBUG org.cometd.client.BayeuxClient.437da279 - State updated: REHANDSHAKING -> HANDSHAKEN
[OkHttp http://localhost:8080/...] DEBUG org.cometd.client.BayeuxClient.437da279 - State updated: HANDSHAKEN -> CONNECTING
[OkHttp http://localhost:8080/...] DEBUG org.cometd.client.BayeuxClient.437da279 - State updated: CONNECTING -> CONNECTED

leftiness added a commit that referenced this issue Feb 16, 2021
@leftiness
Copy link
Owner Author

Don't use a Gradle project property. Use java -D.

[brandon@localhost cometd-client]$ JAVA_OPTS='-Dorg.slf4j.simpleLogger.defaultLogLevel=debug' ./app/build/distributions/app/bin/app subscribe http://localhost:8080/cometd /chat/**/ 2>&1 | grep 'State updated'
[main] DEBUG org.cometd.client.BayeuxClient.1725dc0f - State updated: DISCONNECTED -> HANDSHAKING
[OkHttp http://localhost:8080/...] DEBUG org.cometd.client.BayeuxClient.1725dc0f - State updated: HANDSHAKING -> HANDSHAKEN
[OkHttp http://localhost:8080/...] DEBUG org.cometd.client.BayeuxClient.1725dc0f - State updated: HANDSHAKEN -> CONNECTING
[OkHttp http://localhost:8080/...] DEBUG org.cometd.client.BayeuxClient.1725dc0f - State updated: CONNECTING -> CONNECTED

leftiness added a commit that referenced this issue May 7, 2021
leftiness added a commit that referenced this issue May 7, 2021
leftiness added a commit that referenced this issue May 7, 2021
leftiness added a commit that referenced this issue May 8, 2021
leftiness added a commit that referenced this issue May 8, 2021
@leftiness
Copy link
Owner Author

Now I have tests for SubscribeCommand. Kind of repetitive. Maybe I want to use parameterized tests, but I need to figure out Java modules.

[brandon@localhost cometd-client]$ ./gradlew test

> Configure project :app
Project :app => 'cometd.client' Java module

BUILD SUCCESSFUL in 408ms
3 actionable tasks: 3 up-to-date

leftiness added a commit that referenced this issue May 8, 2021
leftiness added a commit that referenced this issue May 8, 2021
leftiness added a commit that referenced this issue May 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant