Skip to content

refactor: improve Socket Client #2676

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

Open
wants to merge 2 commits into
base: development
Choose a base branch
from

Conversation

marcnause
Copy link
Contributor

@marcnause marcnause commented May 10, 2025

Changes

  • simplify loop which reads data from socket
  • derive TAG from class
  • improve logging

Screenshots / Recordings

N/A

Checklist:

  • No hard coding: I have used resources from strings.xml, dimens.xml and colors.xml without hard coding any value.
  • No end of file edits: No modifications done at end of resource files strings.xml, dimens.xml or colors.xml.
  • Code reformatting: I have reformatted code and fixed indentation in every file included in this pull request.
  • No extra space: My code does not contain any extra lines or extra spaces than the ones that are necessary.

Summary by Sourcery

Refactor the SocketClient class to streamline data reading, enhance logging, and improve maintainability.

Enhancements:

  • Simplify socket data reading loop and buffer management.
  • Derive logging tag from class name instead of hardcoding.
  • Improve logging for connection, read operations, and error handling.

@marcnause marcnause added the Enhancement Improvement to an existing feature label May 10, 2025
Copy link

sourcery-ai bot commented May 10, 2025

Reviewer's Guide

This pull request refactors the SocketClient class by simplifying the socket read loop, improving buffer management, enhancing logging (including timing and error reporting), and cleaning up code structure and TAG definition.

File-Level Changes

Change Details Files
Simplified socket read loop and improved buffer handling.
  • Replaced use of a fixed buffer with direct reading into receivedData array sized to bytesToBeRead.
  • Removed unnecessary System.arraycopy and buffer usage in read loop.
  • Simplified loop logic for reading data from the socket.
app/src/main/java/io/pslab/communication/SocketClient.java
Improved logging and error handling.
  • Enhanced log messages to include timing and byte counts for read operations.
  • Replaced printStackTrace with Log.e for error reporting in closeConnection.
  • Standardized logging to use TAG derived from class name.
app/src/main/java/io/pslab/communication/SocketClient.java
Refactored TAG definition and minor code cleanup.
  • Changed TAG to be derived from class name using getSimpleName().
  • Removed redundant static initialization and unused buffer fields.
  • Minor code reformatting and cleanup.
app/src/main/java/io/pslab/communication/SocketClient.java

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@marcnause marcnause changed the title Improve Socket Client refactor: improve Socket Client May 10, 2025
@marcnause marcnause force-pushed the improveSocketClient branch from 334da74 to 5f2d81e Compare May 10, 2025 16:57
@marcnause marcnause enabled auto-merge (squash) May 10, 2025 17:00
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We encountered an error and are unable to review this PR. We have been notified and are working to fix it.

You can try again by commenting this pull request with @sourcery-ai review, or contact us for help.

Copy link

Build failed

@marcnause
Copy link
Contributor Author

Build failed

For some reason the screenshot action does not work correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Improvement to an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant