Skip to content

WebSocket Implementation Based on Netty #91

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

Merged
merged 39 commits into from
Nov 22, 2017
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
705abcd
Prototyping Firestore integration for Java
hiranya911 Aug 31, 2017
084453e
Some code cleanup
hiranya911 Aug 31, 2017
39dec4c
Updating comments
hiranya911 Sep 2, 2017
cd8030c
Code cleanup
hiranya911 Sep 2, 2017
9be05c9
Merge branch 'master' into hkj-firestore-java
hiranya911 Sep 7, 2017
dfc6bec
Removed getInstance() methods from FirestoreClient and added getFires…
hiranya911 Sep 7, 2017
ef3881f
Merge branch 'hkj-firestore-java' of github.com:FirebasePrivate/fireb…
hiranya911 Sep 7, 2017
0cf020b
Merged with master
hiranya911 Oct 6, 2017
ab3469a
Minor cleanup
hiranya911 Oct 6, 2017
d64b4f6
Adding Firestore OAuth scopes
hiranya911 Oct 6, 2017
d87f364
Merge branch 'master' into hkj-firestore-java
hiranya911 Oct 9, 2017
8ed4e5f
Some documentation updates
hiranya911 Oct 9, 2017
48104da
Reverted a doc change
hiranya911 Oct 9, 2017
1771a01
Updating GCS dependency version (#89)
hiranya911 Oct 11, 2017
4201ff1
Netty-based websocket impl
hiranya911 Oct 17, 2017
7e7f694
Refactored the Netty stuff to a separate util class
hiranya911 Oct 17, 2017
7a74047
More code clean up and removing tubesock package
hiranya911 Oct 17, 2017
8e90610
Using the SDK ThreadManager for DB websocket threads
hiranya911 Oct 17, 2017
b910380
More code cleanup and error checks
hiranya911 Oct 17, 2017
a227cae
Handling connection drop events
hiranya911 Oct 19, 2017
6d8d90f
Handling connection loss events
hiranya911 Oct 19, 2017
e276f9a
Adding documentation
hiranya911 Oct 19, 2017
c10753d
Removed string list reader
hiranya911 Oct 19, 2017
da73c79
Merged with latest master
hiranya911 Oct 20, 2017
193fcde
Merge branch 'master' into hkj-firestore-java
hiranya911 Oct 20, 2017
a6613ce
Merge branch 'hkj-firestore-java' into hkj-netty-rtdb
hiranya911 Oct 20, 2017
59d1f5a
Removing redundant whitespace
hiranya911 Oct 23, 2017
e03a896
Revert "Using the SDK ThreadManager for DB websocket threads"
hiranya911 Oct 24, 2017
b87f536
src/main/java/com/google/firebase/database/connection/util/StringList…
hiranya911 Oct 24, 2017
4d7c74a
Added StringListReader back
hiranya911 Oct 24, 2017
536eb61
Re-updated websocket client
hiranya911 Oct 24, 2017
83c4e8b
reverting more syntactic changes
hiranya911 Oct 24, 2017
06f5515
Adding new line
hiranya911 Oct 24, 2017
bc74249
Added documentation; Using a more secure trust manager; Other cleanup
hiranya911 Oct 26, 2017
8829759
Removed unused import
hiranya911 Oct 26, 2017
a3411d6
Using the port on URI when available
hiranya911 Oct 27, 2017
3adf4a7
Merged with master
hiranya911 Nov 10, 2017
884bd18
Removing websocket commpression handler
hiranya911 Nov 10, 2017
d4a1438
Declaring Netty dependencies explicitly (using the same version as gRPC)
hiranya911 Nov 22, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,12 @@
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-storage</artifactId>
<version>1.2.1</version>
<version>1.7.0</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-firestore</artifactId>
<version>0.25.0-beta</version>
</dependency>

<!-- Utilities -->
Expand All @@ -367,7 +372,7 @@
<version>1.7.25</version>
</dependency>

<!-- Test dependencies -->
<!-- Test Dependencies -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/com/google/firebase/FirebaseOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ public Map<String, Object> getDatabaseAuthVariableOverride() {
return databaseAuthVariableOverride;
}

/**
* Returns the Google Cloud project ID.
*
* @return The project ID set via {@link Builder#setProjectId(String)}
*/
public String getProjectId() {
return projectId;
}
Expand Down Expand Up @@ -251,7 +256,13 @@ public Builder setDatabaseAuthVariableOverride(
return this;
}

public Builder setProjectId(String projectId) {
/**
* Sets the Google Cloud project ID that should be associated with an app.
*
* @param projectId A non-null, non-empty project ID string.
* @return This <code>Builder</code> instance is returned so subsequent calls can be chained.
*/
public Builder setProjectId(@NonNull String projectId) {
checkArgument(!Strings.isNullOrEmpty(projectId), "Project ID must not be null or empty");
this.projectId = projectId;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ public abstract class BaseCredential implements FirebaseCredential {
"https://www.googleapis.com/auth/identitytoolkit",

// Enables access to Google Cloud Storage.
"https://www.googleapis.com/auth/devstorage.full_control");
"https://www.googleapis.com/auth/devstorage.full_control",

// Enables access to Google Cloud Firestore
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/datastore");

private final GoogleCredentials googleCredentials;

Expand Down
91 changes: 91 additions & 0 deletions src/main/java/com/google/firebase/cloud/FirestoreClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package com.google.firebase.cloud;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;

import com.google.cloud.firestore.Firestore;
import com.google.cloud.firestore.FirestoreOptions;
import com.google.common.base.Strings;
import com.google.firebase.FirebaseApp;
import com.google.firebase.ImplFirebaseTrampolines;
import com.google.firebase.internal.FirebaseService;
import com.google.firebase.internal.NonNull;

/**
* FirestoreClient provides access to Google Cloud Firestore. Use this API to obtain a
* <code>com.google.cloud.firestore.Firestore</code> instance, which provides methods for
* updating and querying data in Firestore.
*
* <p>A Google Cloud project ID is required to access Firestore. FirestoreClient determines the
* project ID from the {@link com.google.firebase.FirebaseOptions} used to initialize the underlying
* {@link FirebaseApp}. If that is not available, it examines the credentials used to initialize
* the app. Finally it attempts to get the project ID by looking up the GCLOUD_PROJECT environment
* variable. If a project ID cannot be determined by any of these methods, this API will throw
* a runtime exception.
*/
public class FirestoreClient {

private final Firestore firestore;

private FirestoreClient(FirebaseApp app) {
checkNotNull(app, "FirebaseApp must not be null");
String projectId = ImplFirebaseTrampolines.getProjectId(app);
checkArgument(!Strings.isNullOrEmpty(projectId),
"Project ID is required for accessing Firestore. Use a service account credential or "
+ "set the project ID explicitly via FirebaseOptions. Alternatively you can also "
+ "set the project ID via the GCLOUD_PROJECT environment variable.");
this.firestore = FirestoreOptions.newBuilder()
.setCredentials(ImplFirebaseTrampolines.getCredentials(app))
.setProjectId(projectId)
.build()
.getService();
}

/**
* Returns the Firestore instance associated with the default Firebase app.
*
* @return A non-null <code>com.google.cloud.firestore.Firestore</code> instance.
*/
@NonNull
public static Firestore getFirestore() {
return getFirestore(FirebaseApp.getInstance());
}

/**
* Returns the Firestore instance associated with the specified Firebase app.
*
* @param app A non-null {@link FirebaseApp}.
* @return A non-null <code>com.google.cloud.firestore.Firestore</code> instance.
*/
@NonNull
public static Firestore getFirestore(FirebaseApp app) {
return getInstance(app).firestore;
}

private static synchronized FirestoreClient getInstance(FirebaseApp app) {
FirestoreClientService service = ImplFirebaseTrampolines.getService(app,
SERVICE_ID, FirestoreClientService.class);
if (service == null) {
service = ImplFirebaseTrampolines.addService(app, new FirestoreClientService(app));
}
return service.getInstance();
}

private static final String SERVICE_ID = FirestoreClient.class.getName();

private static class FirestoreClientService extends FirebaseService<FirestoreClient> {

FirestoreClientService(FirebaseApp app) {
super(SERVICE_ID, new FirestoreClient(app));
}

@Override
public void destroy() {
// NOTE: We don't explicitly tear down anything here (for now). User won't be able to call
// FirestoreClient.getFirestore() any more, but already created Firestore instances will
// continue to work. Request Firestore team to provide a cleanup/teardown method on the
// Firestore object.
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
package com.google.firebase.database.connection;

import com.google.firebase.database.logging.Logger;
import com.google.firebase.database.tubesock.ThreadConfig;

import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory;

public class ConnectionContext {

Expand All @@ -29,7 +29,7 @@ public class ConnectionContext {
private final boolean persistenceEnabled;
private final String clientSdkVersion;
private final String userAgent;
private final ThreadConfig threadConfig;
private final ThreadFactory threadFactory;

public ConnectionContext(
Logger logger,
Expand All @@ -38,14 +38,14 @@ public ConnectionContext(
boolean persistenceEnabled,
String clientSdkVersion,
String userAgent,
ThreadConfig threadConfig) {
ThreadFactory threadFactory) {
this.logger = logger;
this.authTokenProvider = authTokenProvider;
this.executorService = executorService;
this.persistenceEnabled = persistenceEnabled;
this.clientSdkVersion = clientSdkVersion;
this.userAgent = userAgent;
this.threadConfig = threadConfig;
this.threadFactory = threadFactory;
}

public Logger getLogger() {
Expand All @@ -72,7 +72,7 @@ public String getUserAgent() {
return this.userAgent;
}

public ThreadConfig getThreadConfig() {
return threadConfig;
public ThreadFactory getThreadFactory() {
return threadFactory;
}
}
Loading