battery usage • Push Notifications • Nobody likes polling • Real-time features • Likes, comments, shares • Prices • Analytics • Lets use those cores THE EMERGENCE OF NEW ARCHITECTURES FOR MOBILE APPS
• Queuing • Filtering • Batching • Persistence • Performance controlled via • Queue depth • Number of consumers • ‘Bandwidth’ of bus THE EMERGENCE OF NEW ARCHITECTURES FOR MOBILE APPS
for system and app-internal notifications • One notification center instance per app* • Notifications are posted by calling thread • Unless Notification Queue is used • On receive notification, explicitly choose your thread • Block style keeps it all in one place • Coalescing THE EMERGENCE OF NEW ARCHITECTURES FOR MOBILE APPS
mMessageReceiver to receive messages. LocalBroadcastManager.getInstance(this). registerReceiver(mMessageReceiver, new IntentFilter("my-event")); } // handler for received Intents for the "my-event" event private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { // Extract data included in the Intent String message = intent.getStringExtra("message"); Log.d("receiver", "Got message: " + message); } }; THE EMERGENCE OF NEW ARCHITECTURES FOR MOBILE APPS http://www.vogella.com/tutorials/AndroidBroadcastReceiver/article.html
as a Singleton (doesn’t have to be) • Create your Bus with a ThreadEnforcer • Prefers annotations over interfaces THE EMERGENCE OF NEW ARCHITECTURES FOR MOBILE APPS
an initial value for location based on the last known position. return new LocationChangedEvent(lastLatitude, lastLongitude); } @Subscribe public void onLocationChanged(LocationChangedEvent event) { locationEvents.add(0, event.toString()); if (adapter != null) { adapter.notifyDataSetChanged(); } } THE EMERGENCE OF NEW ARCHITECTURES FOR MOBILE APPS https://github.com/square/otto
NetFlix • Observables (like Iterables, but pushed) • Parameterized concurrency • Kinda ugly since functions aren’t first class in Java • Looks better in Groovy THE EMERGENCE OF NEW ARCHITECTURES FOR MOBILE APPS
{ return Observable.create( new Observable.OnSubscribeFunc<WeatherData>() { @Override public Subscription onSubscribe(Observer<? super WeatherData> observer) { try { observer.onNext(apiManager.getWeather(city, "metric")); observer.onCompleted(); } catch (Exception e) { observer.onError(e); } return Subscriptions.empty(); } }).subscribeOn(Schedulers.threadPoolForIO()); } THE EMERGENCE OF NEW ARCHITECTURES FOR MOBILE APPS http://howrobotswork.wordpress.com/2013/10/28/using-rxjava-in-android/
.mapMany(new Func1<String, Observable<WeatherData>>() { @Override public Observable<WeatherData> call(String s) { return ApiManager.getWeatherData(s); } }) .subscribeOn(Schedulers.threadPoolForIO()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Action1<WeatherData>() { @Override public void call(WeatherData weatherData) { // do your work } }); THE EMERGENCE OF NEW ARCHITECTURES FOR MOBILE APPS http://howrobotswork.wordpress.com/2013/10/28/using-rxjava-in-android/
{ return [newName hasPrefix:@"j"]; }] subscribeNext:^(NSString *newName) { NSLog(@"%@", newName); }]; THE EMERGENCE OF NEW ARCHITECTURES FOR MOBILE APPS https://github.com/ReactiveCocoa/ReactiveCocoa
deliverOn:[RACScheduler scheduler]] map:^(User *user) { // Download the avatar (this is done on a background queue). return [[NSImage alloc] initWithContentsOfURL:user.avatarURL]; }] // Now the assignment will be done on the main thread. deliverOn:RACScheduler.mainThreadScheduler]; THE EMERGENCE OF NEW ARCHITECTURES FOR MOBILE APPS https://github.com/ReactiveCocoa/ReactiveCocoa
plusOnes = $('#plusOne').asEventStream('click').map(1) var score = minusOnes.merge(plusOnes) .scan(0, function(sum, value) { return sum + value }) score.assign($('#score'), 'text'); THE EMERGENCE OF NEW ARCHITECTURES FOR MOBILE APPS http://latentflip.com/bacon-talk-realtimeconfeu/
• Broadcasts • Nothing too noisy • Programming ‘in the large’ • Reactive • UI • Composing local streams • Fire hose please! THE EMERGENCE OF NEW ARCHITECTURES FOR MOBILE APPS
your subscriptions • Consider pushing unsubscribe events • Whole new set of bugs caused by events publishing before you’ve subscribed THE EMERGENCE OF NEW ARCHITECTURES FOR MOBILE APPS