All Projects → flipkart-incubator → Batchman

flipkart-incubator / Batchman

This library for Android will take any set of events and batch them up before sending it to the server. It also supports persisting the events on disk so that no event gets lost because of an app crash. Typically used for developing any in-house analytics sdk where you have to make a single api call to push events to the server but you want to optimize the calls so that the api call happens only once per x events, or say once per x minutes. It also supports exponential backoff in case of network failures

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Batchman

Bridge Deprecated
[DEPRECATED]: Prefer Retrofit/OkHttp by Square, or Fuel for Kotlin
Stars: ✭ 624 (+1148%)
Mutual labels:  serialization, networking
Qxorm
QxOrm library - C++ Qt ORM (Object Relational Mapping) and ODM (Object Document Mapper) library - Official repository
Stars: ✭ 176 (+252%)
Mutual labels:  serialization, persistence
Netstack
Lightweight toolset for creating concurrent networking systems for multiplayer games
Stars: ✭ 157 (+214%)
Mutual labels:  serialization, networking
Permazen
Language-Natural Persistence Layer for Java
Stars: ✭ 265 (+430%)
Mutual labels:  serialization, persistence
Leopotamgrouplibraryunity
Tools library for unity 3d game engine: animator graph helpers, serialization (json), localization, event routing (eventbus, ui actions), embedded scripting, uGui xml markup, threading, tweening, in-memory protection and other helpers (pure C#)
Stars: ✭ 373 (+646%)
Mutual labels:  analytics, serialization
Swiftqueue
Job Scheduler for IOS with Concurrent run, failure/retry, persistence, repeat, delay and more
Stars: ✭ 276 (+452%)
Mutual labels:  job-scheduler, persistence
perseverance
Make your functions 💪 resilient and 🚥 fail-fast to 💩 failures or ⌚ delays
Stars: ✭ 12 (-76%)
Mutual labels:  persistence, retry
Ceras
Universal binary serializer for a wide variety of scenarios https://discord.gg/FGaCX4c
Stars: ✭ 374 (+648%)
Mutual labels:  serialization, networking
Routine
go routine control, abstraction of the Main and some useful Executors.如果你不会管理Goroutine的话,用它
Stars: ✭ 40 (-20%)
Mutual labels:  job-scheduler, retry
Nff Go
NFF-Go -Network Function Framework for GO (former YANFF)
Stars: ✭ 1,036 (+1972%)
Mutual labels:  networking
Vibe.d
Official vibe.d development
Stars: ✭ 1,043 (+1986%)
Mutual labels:  networking
Kubernetes Nmstate
Declarative node network configuration driven through Kubernetes API.
Stars: ✭ 46 (-8%)
Mutual labels:  networking
Swifty
Swifty is a networking stack designed to serve modern iOS apps
Stars: ✭ 47 (-6%)
Mutual labels:  networking
Nsdb
Natural Series Database
Stars: ✭ 49 (-2%)
Mutual labels:  analytics
Beeschema
Binary Schema Library for C#
Stars: ✭ 46 (-8%)
Mutual labels:  serialization
Jiacrontab
简单可信赖的任务管理工具
Stars: ✭ 1,052 (+2004%)
Mutual labels:  job-scheduler
Wakatime
Command line interface used by all WakaTime text editor plugins.
Stars: ✭ 1,028 (+1956%)
Mutual labels:  analytics
Engine And Editor
Streamr Core backend
Stars: ✭ 44 (-12%)
Mutual labels:  analytics
Tech1 Benchmarks
Java JMH Benchmarks repository. No Longer Supported.
Stars: ✭ 50 (+0%)
Mutual labels:  serialization
Instantobjects
Pupular OOP-OPF Library for Delphi (from D2010 to 10.4 Sydney)
Stars: ✭ 50 (+0%)
Mutual labels:  persistence

BatchMan

Branch Build Status
master Build Status
develop Build Status

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.9'
	}
  • GSON Serialization :
	dependencies {
	        compile 'com.github.flipkart-incubator.batchman:batching-gson:1.3.9'
	}

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 Apache License

Copyright (c) 2017 Flipkart Internet Pvt. Ltd.

Licensed under the Apache License, Version 2.0 (the "License"); 
you may not use this file except in compliance with the License.

You may obtain a copy of the License at

   https://www.apache.org/licenses/LICENSE-2.0 
   
Unless required by applicable law or agreed to in writing, software 
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and 
limitations under the License.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].