Batchman


Source link: https://github.com/flipkart-incubator/batchman

BatchMan

Branch Build Status
master
develop

BatchMan (short for batch manager) is an android library implementation responsible for batching of events based on the configurations done by the client, and giving the batch back to the client.

The library has been written in a more flexible way, so that the client can plugin his own implementations for batching.

  • BatchManager : It is the entry point to the library, where in the client will use the instance of the batch manager to push in data to the library for batching.

  • BatchingStrategy : It is an interface, where all the batching logic comes in. The library has 4 batching strategies on its own, or the client can implement the interface, and provide his/her own logic for batching.

  • PersistenceStrategy : It is an interface, where all the persistence logic comes in. The library has 3 persistence strategies on its own, or the client can provide his/her own persistence layer to persist the events, just to make sure that there is no loss of events (in case of app crash)

  • OnBatchReadyListener : It is a interface, which gives a callback, whenever the batch is ready. The client can consume the batch, and can make a network call to the server. There are various types of OnBatchReadyListener which will be discussed later.

  • Data : It is an abstract class, wherein the client will need to extend this class for his events.

Get BatchMan

Add it in your root build.gradle at the end of repositories :

 allprojects {

repositories {

 ...
 maven {
 url "https://jitpack.io" 
}

}
  
}

Add the dependencies :

  • Library :
 dependencies {

 compile 'com.github.flipkart-incubator.batchman:batching:1.3.6'  
}
  • GSON Serialization :
 dependencies {

 compile 'com.github.flipkart-incubator.batchman:batching-gson:1.3.6'  
}

How to use

Step 1 :

Initialize persistence strategy, batching strategy will take persistence strategy as one of it's parameters.

// Using inMemoryPersistenceStrategy PersistenceStrategy persistenceStrategy = new InMemoryPersistenceStrategy();
 

Step 2 :

Initialize batching strategy with a max batch size and persistence strategy.

int MAX_BATCH_SIZE = 5;  // Using SizeBatchingStrategy. Whenever the number of events is 5, a batch is formed SizeBatchingStrategy sizeBatchingStrategy = new SizeBatchingStrategy(MAX_BATCH_SIZE, persistenceStrategy);
 

Step 3 :

Initialize serialization strategy and background handler thread. To include GsonSerializationStrategy, you must have its dependency in your gradle file. To get dependency, look into the Getting Started section.

// Initialize serialization strategy SerializationStrategy gsonSerializationStrategy = new GsonSerializationStrategy();
  // Handler for doing heavy operations like read/write from disk HandlerThread handlerThread = new HandlerThread("bg");
 handlerThread.start();
 Handler backgroundHandler = new Handler(handlerThread.getLooper());
 

Step 4 :

Build batch manager with all the strategies and handler thread we initialized in previous steps. Batch manger will also take a listener for giving callbacks when a batch is ready.

// Initialize batch manager BatchManager batchManager = new BatchManager.Builder<>()

  .setBatchingStrategy(sizeBatchingStrategy)

  .setSerializationStrategy(gsonSerializationStrategy)

  .setHandler(backgroundHandler)

  //to enable logging while debug

  .enableLogging()

  .setOnBatchReadyListener(new OnBatchReadyListener() {

@Override

public void onReady(BatchingStrategy causingStrategy, Batch batch) {

 //Callback with batch when it's ready

}

  
}
).build(this);
 

Step 5 :

Use addToBatch() for adding events to batch manager.

// Push data to batch manager batchManager.addToBatch(Collections.singleton(new EventData()));
 

Getting Started

Wiki

Dependencies

License

The MIT License (MIT)  Copyright (c) 2017 Flipkart Internet Pvt. Ltd.  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 

Resources

Thirty different easing animation interpolators for Android.

Library that implements the floating action button to sheet transition from Google's Material Design documentation.

This library allows launching a custom activity when your app crashes, instead of showing the hated "Unfortunately, X has stopped" dialog.

Simple example showing how to use WearableListview for Android Wear. Implements OnCenterProximityListener interface to change view style when focus on some list items.

Parallax on Android in the simplest way.

An circle view, similar to Android's ProgressBar. Can be used in 'value mode' or 'spinning mode'.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes