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];
}
}
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);
}
}
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();
}
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();
}
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");
}
}
Aggregations