Skip to content

Suggestion to reduce the scope of WebSocketClient.setListener to private #1764

@wqbill

Description

@wqbill

Feature description_

  1. Public method setListener in org.web3j.protocol.websocket.WebSocketClient is very confusing.
    Some default and important actions are defined in private method setWebSocketListener in org.web3j.protocol.websocket.WebSocketService which is also called by its connect method.
    I tried to run the code below and always got a timeout error coz requestForId was never used.
        final WebSocketClient webSocketClient = new WebSocketClient(new URI("ws://localhost:8546"));
        webSocketClient.setListener(new WebSocketListener() {
            @Override
            public void onMessage(String message) {

            }

            @Override
            public void onError(Exception e) {

            }

            @Override
            public void onClose() {

            }
        });
        webSocketClient.connectBlocking();
        final WebSocketService webSocketService = new WebSocketService(webSocketClient, false);

I think method setListener in org.web3j.protocol.websocket.WebSocketClient should be private.It's very likely to write that code and cost hours to read the source code.

  1. Listener Chain is needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions