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

Add callbacks to be notified of connect/disconnect/error events #34

Merged
merged 1 commit into from
Mar 27, 2017

Conversation

jhansche
Copy link
Contributor

This enables a partial fix/workaround for #6, which otherwise wouldn't even
be possible in its current state.

Future changes will allow the client to automatically reconnect when the
connection has been broken for any reason other than explicit disconnect().

This enables a partial fix/workaround for parse-community#6, which otherwise wouldn't even
be possible in its current state.

Future changes will allow the client to automatically reconnect when the
connection has been broken for any reason other than explicit disconnect().
@@ -498,6 +539,30 @@ private static JSONObject createObjectDeleteMessage(int requestId, ParseObject p
return jsonObject;
}

private static class LoggingCallbacks implements ParseLiveQueryClientCallbacks {
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be non-static given how you instantiate it in each test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think static vs non-static is relevant based on how it's instantiated here. It's declared static because it does not rely on anything from the outer/containing class (so it doesn't require an instance of the containing class).

It's probably not relevant in a unit test, but in general I prefer static inner class, unless it is explicitly required that the inner class instance must be associated with an instance of the outer class (such as a callback method that has to invoke something from the containing class). Not declaring the class static, even if you don't need make any calls to the outer class, can result in memory leaks since that instance of the inner class necessarily holds a reference to the instance of the outer class that created it.

Copy link
Contributor

@rogerhu rogerhu Mar 27, 2017

Choose a reason for hiding this comment

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

I was more worried that the use of transcript could be misused if the class isn't instantiated but it looks to be declared private so can't be accessed directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah. Yeah the class still needs to be instantiated in order to use Transcript. It's declared final, but not static. So it is still a new Transcript instance for every instance of LoggingCallbacks (as it should be, in order to properly test that the callbacks are invoked when they're supposed to be).

Just want to make sure we're on the same page about the class and field declarations. The class being declared static does not mean that the transcript is a static field. It's still an instance field.

Copy link
Contributor

Choose a reason for hiding this comment

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

Gotcha, thanks for the clarification.

@@ -341,11 +385,13 @@ public Void then(Task<Void> task) {
@Override
public void onClose() {
Log.v(LOG_TAG, "Socket onClose");
dispatchDisconnected();
Copy link
Contributor

@rogerhu rogerhu Mar 27, 2017

Choose a reason for hiding this comment

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

Do you need to put dispatchConnected() on onOpen()}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

dispatchConnected() happens only when the server responds with the op=connected message

Copy link
Contributor

Choose a reason for hiding this comment

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

gotcha

@jhansche jhansche merged commit 5ee79d9 into parse-community:master Mar 27, 2017
@jhansche jhansche deleted the pr/register-callbacks branch March 27, 2017 22:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants