Search in sources :

Example 1 with SyncConfiguration

use of io.realm.SyncConfiguration in project realm-java by realm.

the class SyncObjectServerFacade method getUserAndServerUrl.

@Override
public String[] getUserAndServerUrl(RealmConfiguration config) {
    if (config instanceof SyncConfiguration) {
        SyncConfiguration syncConfig = (SyncConfiguration) config;
        String rosServerUrl = syncConfig.getServerUrl().toString();
        String rosUserIdentity = syncConfig.getUser().getIdentity();
        String syncRealmAuthUrl = syncConfig.getUser().getAuthenticationUrl().toString();
        String rosRefreshToken = syncConfig.getUser().getAccessToken().value();
        return new String[] { rosUserIdentity, rosServerUrl, syncRealmAuthUrl, rosRefreshToken };
    } else {
        return new String[4];
    }
}
Also used : SyncConfiguration(io.realm.SyncConfiguration)

Example 2 with SyncConfiguration

use of io.realm.SyncConfiguration in project realm-java by realm.

the class SyncObjectServerFacade method realmClosed.

@Override
public void realmClosed(RealmConfiguration configuration) {
    // delete the wrapped Java session
    if (configuration instanceof SyncConfiguration) {
        SyncConfiguration syncConfig = (SyncConfiguration) configuration;
        invokeRemoveSession(syncConfig);
    } else {
        throw new IllegalArgumentException(WRONG_TYPE_OF_CONFIGURATION);
    }
}
Also used : SyncConfiguration(io.realm.SyncConfiguration)

Example 3 with SyncConfiguration

use of io.realm.SyncConfiguration in project realm-java by realm.

the class SendOneCommit method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    Realm.init(getApplicationContext());
    SyncUser user = UserFactory.createDefaultUser(Constants.AUTH_URL);
    String realmUrl = Constants.SYNC_SERVER_URL;
    final SyncConfiguration syncConfig = new SyncConfiguration.Builder(user, realmUrl).name(SendOneCommit.class.getSimpleName()).build();
    Realm.deleteRealm(syncConfig);
    Realm realm = Realm.getInstance(syncConfig);
    realm.beginTransaction();
    ProcessInfo processInfo = realm.createObject(ProcessInfo.class);
    processInfo.setName("Background_Process1");
    processInfo.setPid(android.os.Process.myPid());
    processInfo.setThreadId(Thread.currentThread().getId());
    realm.commitTransaction();
    //FIXME the close may not give a chance to the sync client to process/upload the changeset
    realm.close();
}
Also used : SyncUser(io.realm.SyncUser) ProcessInfo(io.realm.objectserver.model.ProcessInfo) Realm(io.realm.Realm) SyncConfiguration(io.realm.SyncConfiguration)

Example 4 with SyncConfiguration

use of io.realm.SyncConfiguration in project realm-java by realm.

the class SendsALot method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    Realm.init(getApplicationContext());
    SyncUser user = UserFactory.createDefaultUser(Constants.AUTH_URL);
    String realmUrl = Constants.SYNC_SERVER_URL_2;
    final SyncConfiguration syncConfig = new SyncConfiguration.Builder(user, realmUrl).name(SendsALot.class.getSimpleName()).build();
    Realm.deleteRealm(syncConfig);
    Realm realm = Realm.getInstance(syncConfig);
    realm.beginTransaction();
    for (int i = 0; i < 100; i++) {
        TestObject testObject = realm.createObject(TestObject.class);
        testObject.setIntProp(i);
        testObject.setStringProp("property " + i);
    }
    realm.commitTransaction();
    //FIXME the close may not give a chance to the sync client to process/upload the changeset
    realm.close();
}
Also used : SyncUser(io.realm.SyncUser) TestObject(io.realm.objectserver.model.TestObject) Realm(io.realm.Realm) SyncConfiguration(io.realm.SyncConfiguration)

Example 5 with SyncConfiguration

use of io.realm.SyncConfiguration in project realm-java by realm.

the class CounterActivity method onStart.

@Override
protected void onStart() {
    super.onStart();
    user = SyncUser.currentUser();
    if (user != null) {
        // Create a RealmConfiguration for our user
        SyncConfiguration config = new SyncConfiguration.Builder(user, REALM_URL).initialData(new Realm.Transaction() {

            @Override
            public void execute(Realm realm) {
                realm.createObject(CRDTCounter.class, 1);
            }
        }).build();
        // This will automatically sync all changes in the background for as long as the Realm is open
        realm = Realm.getInstance(config);
        counter = realm.where(CRDTCounter.class).findFirstAsync();
        counter.addChangeListener(new RealmChangeListener<CRDTCounter>() {

            @Override
            public void onChange(CRDTCounter counter) {
                if (counter.isValid()) {
                    counterView.setText(String.format(Locale.US, "%d", counter.getCount()));
                } else {
                    counterView.setText("-");
                }
            }
        });
        counterView.setText("0");
    }
}
Also used : CRDTCounter(io.realm.examples.objectserver.model.CRDTCounter) Realm(io.realm.Realm) SyncConfiguration(io.realm.SyncConfiguration)

Aggregations

SyncConfiguration (io.realm.SyncConfiguration)10 Realm (io.realm.Realm)8 SyncUser (io.realm.SyncUser)7 ClientResetHandler (io.realm.ClientResetHandler)4 ObjectServerError (io.realm.ObjectServerError)4 SyncSession (io.realm.SyncSession)4 Test (org.junit.Test)4 RealmChangeListener (io.realm.RealmChangeListener)3 RealmResults (io.realm.RealmResults)3 Ignore (org.junit.Ignore)3 Context (android.content.Context)2 Intent (android.content.Intent)2 ProcessInfo (io.realm.objectserver.model.ProcessInfo)2 TestObject (io.realm.objectserver.model.TestObject)2 RunTestInLooperThread (io.realm.rule.RunTestInLooperThread)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ExecutorService (java.util.concurrent.ExecutorService)2 SyncCredentials (io.realm.SyncCredentials)1 SecureUserStore (io.realm.android.SecureUserStore)1 Dog (io.realm.entities.Dog)1