syncbase/src/main/java/io/v/syncbase/Syncbase.java
/**
     * Logs in the user associated with the given OAuth token and provider and starts Syncbase;
     * creates default database if needed; performs create-or-join for "userdata" syncgroup if
     * needed. The passed callback is called on the current thread.
     *
     * <p/>
     * A mapping of providers and OAuth token scopes are listed below:
     * google: https://www.googleapis.com/auth/userinfo.email
     * <p/>
     * Note: Unlisted providers are unsupported.
     *
     * @param authToken The OAuth token for the user to be logged in.
     * @param provider  The provider of the OAuth token.
     * @param cb        The callback to call when the login was done.
     * @throws IllegalArgumentException if provider is not one of those listed above
     */
Logs in the user associated with the given OAuth token and provider and starts Syncbase;
creates default database if needed; performs create-or-join for "userdata" syncgroup if
needed. The passed callback is called on the current thread.



@param authToken The OAuth token for the user to be logged in.
@param provider  The provider of the OAuth token.
@param cb        The callback to call when the login was done.
@throws IllegalArgumentException if provider is not one of those listed above
Logs in the user associated with the given OAuth token and provider and starts Syncbase ; creates default database if needed ; performs create - or - join for " userdata " syncgroup if needed . The passed callback is called on the current thread . @param authToken The OAuth token for the user to be logged in . @param provider The provider of the OAuth token . @param cb The callback to call when the login was done . @throws IllegalArgumentException if provider is not one of those listed above
public static void login(final String authToken, final String provider, final LoginCallback cb) {
        if (!(provider.equals(User.PROVIDER_GOOGLE) || provider.equals(User.PROVIDER_NONE))) {
            throw new IllegalArgumentException("Unsupported provider: " + provider);
        }
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    io.v.syncbase.internal.Service.Login(provider, authToken);
                    sDatabase = database();
                    if (sDatabase==null) {
                        cb.onError(new IllegalStateException("not logged in"));
                        return;
                    }
                    sDatabase.createIfMissing();
                    Collection userdata = sDatabase.createNamedCollection(
                            USERDATA_NAME,
                            new DatabaseHandle.CollectionOptions().setWithoutSyncgroup(true));
                    if (!sOpts.mDisableUserdataSyncgroup) {
                        Syncgroup syncgroup = userdata.getSyncgroup();
                        try {
                            syncgroup.join();
                        } catch(VError e) {
                            syncgroup.createIfMissing(ImmutableList.of(userdata));
                        }
                        Database.AddWatchChangeHandlerOptions opts = new Database
                                .AddWatchChangeHandlerOptions.Builder().
                                setShowUserdataCollectionRow(true).build();
                        sDatabase.addWatchChangeHandler(new UserdataWatchHandler(), opts);
                    }
                    sOpts.mCallbackExecutor.execute(new Runnable() {
                        @Override
                        public void run() {
                            cb.onSuccess();
                        }
                    });
                } catch (Throwable e) {
                    cb.onError(e);
                }
            }
        }).start();
    }
public static void login ( final String authToken , final String provider , final LoginCallback cb ) { if ( ! ( provider . equals ( User . PROVIDER_GOOGLE ) || provider . equals ( User . PROVIDER_NONE ) ) ) { throw new IllegalArgumentException ( "Unsupported provider: " + provider ) ; } new Thread ( new Runnable ( ) { @ Override public void run ( ) { try { io . v . syncbase . internal . Service . Login ( provider , authToken ) ; sDatabase = database ( ) ; if ( sDatabase == null ) { cb . onError ( new IllegalStateException ( "not logged in" ) ) ; return ; } sDatabase . createIfMissing ( ) ; Collection userdata = sDatabase . createNamedCollection ( USERDATA_NAME , new DatabaseHandle . CollectionOptions ( ) . setWithoutSyncgroup ( true ) ) ; if ( ! sOpts . mDisableUserdataSyncgroup ) { Syncgroup syncgroup = userdata . getSyncgroup ( ) ; try { syncgroup . join ( ) ; } catch ( VError e ) { syncgroup . createIfMissing ( ImmutableList . of ( userdata ) ) ; } Database . AddWatchChangeHandlerOptions opts = new Database . AddWatchChangeHandlerOptions . Builder ( ) . setShowUserdataCollectionRow ( true ) . build ( ) ; sDatabase . addWatchChangeHandler ( new UserdataWatchHandler ( ) , opts ) ; } sOpts . mCallbackExecutor . execute ( new Runnable ( ) { @ Override public void run ( ) { cb . onSuccess ( ) ; } } ) ; } catch ( Throwable e ) { cb . onError ( e ) ; } } } ) . start ( ) ; }
Logs in the user associated with the given OAuth token and provider and starts Syncbase;
 creates default database if needed; performs create-or-join for "userdata" syncgroup if
 needed.
Logs in the user associated with the given OAuth token and provider and starts Syncbase ; creates default database if needed ; performs create - or - join for " userdata " syncgroup if needed .
// Join-Or-Create pattern. If join fails, create the syncgroup instead. // Note: Syncgroup merge does not exist yet, so this may potentially lead // to split-brain syncgroups. This is exacerbated by lack of cloud instance.