Skip to content

Commit 465488e

Browse files
qdpham13daymxnmrobervkryachko
authored
Rc realtime (#3730)
* Creates Realtime Http client file. Includes ConfigUpdate Listener & Registration. Also exposes methods to be used by public RC file. * Creates Realtime Http client file. Includes ConfigUpdate Listener & Registration. Also exposes methods to be used by public RC file. * Update stream name * Add copyright info to top of file. * Update comments * Format file. * Creates Realtime Http client file. Includes ConfigUpdate Listener & Registration. Also exposes methods to be used by public RC file. * Update stream name * Add copyright info to top of file. * Update comments * Format file. * Moved ConfigUpdateListener and ConfigUpdateListenerRegistration to public level. * Moved ConfigUpdateListener and ConfigUpdateListenerRegistration to public level. * Format and update comments * Uodate api.txt * Add nonnull and nullable to params * Change registration to interface. * Add author * Update api.txt * Dependabot High severity alerts (#3734) * Dependency updates for `smoke-tests` * Do not attempt to parse empty json files in MetaDataStore (#3735) * Do not attempt to parse empty json files in MetaDataStore * Safely delete corrupt files in MetaDataStore * Disable javadoc for undocumented sdks. (#3738) * Creates Realtime Http client file. Includes ConfigUpdate Listener & Registration. Also exposes methods to be used by public RC file. * Reupdate files. * Make changes based on PR comments; Make internal ConfigUpdateListenerRegistration non-static to access private listener removal method from outer class. Add synchonization to listeners set. * Remove synchronized set and add explicit synchonized to methods. Co-authored-by: Daymon <[email protected]> Co-authored-by: Matthew Robertson <[email protected]> Co-authored-by: Vladimir Kryachko <[email protected]>
1 parent bd761a7 commit 465488e

File tree

4 files changed

+141
-0
lines changed

4 files changed

+141
-0
lines changed

firebase-config/api.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
// Signature format: 2.0
22
package com.google.firebase.remoteconfig {
33

4+
public interface ConfigUpdateListener {
5+
method public void onError(Exception);
6+
method public void onEvent();
7+
}
8+
9+
public interface ConfigUpdateListenerRegistration {
10+
method public void remove();
11+
}
12+
413
public class FirebaseRemoteConfig {
514
method @NonNull public com.google.android.gms.tasks.Task<java.lang.Boolean> activate();
615
method @NonNull public com.google.android.gms.tasks.Task<com.google.firebase.remoteconfig.FirebaseRemoteConfigInfo> ensureInitialized();
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright 2022 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
//
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.google.firebase.remoteconfig;
16+
17+
import javax.annotation.Nonnull;
18+
19+
/**
20+
* Event Listener for Realtime config update callbacks.
21+
*
22+
* @author Quan Pham
23+
*/
24+
public interface ConfigUpdateListener {
25+
/**
26+
* Callback for when a new config has been automatically fetched from the backend. Can be used to
27+
* activate the new config.
28+
*/
29+
void onEvent();
30+
31+
/**
32+
* Call back for when an error occurs during Realtime.
33+
*
34+
* @param error
35+
*/
36+
void onError(@Nonnull Exception error);
37+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2022 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
//
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.google.firebase.remoteconfig;
16+
17+
/**
18+
* Represents a listener that can be removed by calling remove. This is returned when calling
19+
* addOnConfigUpdateListener and should be used when you no longer want to listen for new config
20+
* updates. If this is the last listener it will close the Realtime stream.
21+
*
22+
* @author Quan Pham
23+
*/
24+
public interface ConfigUpdateListenerRegistration {
25+
26+
/**
27+
* Removes the listener being tracked by this 'ConfigUpdateListenerRegistration`. After the
28+
* initial call, subsequent calls have no effect.
29+
*/
30+
public void remove();
31+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright 2022 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
//
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.google.firebase.remoteconfig.internal;
16+
17+
import androidx.annotation.GuardedBy;
18+
import com.google.firebase.remoteconfig.ConfigUpdateListener;
19+
import com.google.firebase.remoteconfig.ConfigUpdateListenerRegistration;
20+
import java.util.LinkedHashSet;
21+
import java.util.Set;
22+
23+
public class ConfigRealtimeHttpClient {
24+
25+
@GuardedBy("this")
26+
private final Set<ConfigUpdateListener> listeners;
27+
28+
public ConfigRealtimeHttpClient() {
29+
listeners = new LinkedHashSet<ConfigUpdateListener>();
30+
}
31+
32+
// Kicks off Http stream listening and autofetch
33+
private void beginRealtime() {}
34+
35+
// Pauses Http stream listening
36+
private void pauseRealtime() {}
37+
38+
public synchronized ConfigUpdateListenerRegistration addRealtimeConfigUpdateListener(
39+
ConfigUpdateListener configUpdateListener) {
40+
listeners.add(configUpdateListener);
41+
beginRealtime();
42+
return new ConfigUpdateListenerRegistrationInternal(configUpdateListener);
43+
}
44+
45+
private synchronized void removeRealtimeConfigUpdateListener(ConfigUpdateListener listener) {
46+
listeners.remove(listener);
47+
if (listeners.isEmpty()) {
48+
pauseRealtime();
49+
}
50+
}
51+
52+
public class ConfigUpdateListenerRegistrationInternal
53+
implements ConfigUpdateListenerRegistration {
54+
private final ConfigUpdateListener listener;
55+
56+
public ConfigUpdateListenerRegistrationInternal(ConfigUpdateListener listener) {
57+
this.listener = listener;
58+
}
59+
60+
public void remove() {
61+
removeRealtimeConfigUpdateListener(listener);
62+
}
63+
}
64+
}

0 commit comments

Comments
 (0)