(中文版本请参看这里)
DataReporter is a cross-platform infrastructure component developed by luojisiwei dedao ebook Team. It is proved to be effective by tens of millions of dedao users.
Start with sample usage here.
Preparation Condition:
step:
/**
* Create a Reporter instance, the instance is native, saved in the returned int value
* @param uuid Business unique id, defined by the user as a unique id
* @param cachePath Cache path, must be globally unique, different paths for different services
* @param encryptKey Cache Encrypt Key
* @param reportImp Reporting implementation interface
* @return
*/
public static native long makeReporter(String uuid, String cachePath, String encryptKey, IReport reportImp);
/**
* Set the number of data to be reported in a single time, and call it before start
*
* @param nativeReporter return by makeReporter
* @param count Number of data reported at one time
*/
public static native void setReportCount(long nativeReporter, int count);
/**
* Set the maximum size limit of the cache file single file, the default value is 10k
*
* @param nativeReporter return by makeReporter
* @param fileMaxSize Cache file maximum size
*/
public static native void setFileMaxSize(long nativeReporter, int fileMaxSize);
/**
* Set the cache file validity period
*
* @param nativeReporter return by makeReporter
* @param expiredTime Data validity period
*/
public static native void setExpiredTime(long nativeReporter, long expiredTime);
/**
* Set the reporting interval
*
* @param nativeReporter return by makeReporter
* @param reportingInterval Reporting interval
*/
public static native void setReportingInterval(long nativeReporter, long reportingInterval);
/**
* Start reporting thread After setting the relevant parameters, execute it once.
*
* @param nativeReporter return by makeReporter
*/
public static native void start(long nativeReporter);
/**
* Wake up the report, call when the network status is good or other wake up scene call
*
* @param nativeReporter return by makeReporter
*/
public static native void reaWaken(long nativeReporter);
/**
* Data reporting call interface
*
* @param nativeReporter return by makeReporter
* @param data Data to be reported
*/
public static native void push(long nativeReporter, byte[] data);
/**
* Call this method after the report is successful
*
* @param nativeReporter return by makeReporter
* @param key The value returned by the escalation implementation interface
*/
public static native void uploadSucess(long nativeReporter, long key);
/**
* Call this method after the report fails
*
* @param nativeReporter return by makeReporter
* @param key The value returned by the escalation implementation interface
*/
public static native void uploadFailed(long nativeReporter, long key);
/**
* Release the report instance, other methods can not be called after release
*
* @param nativeReporter return by makeReporter
*/
public static native void releaseReporter(long nativeReporter);
-keep class com.iget.datareporter.**{*;}
Preparation Condition:
step:
/**
* Create a Reporter instance
* @param uuid Business unique id, defined by the user as a unique id
* @param cachePath Cache path, must be globally unique, different paths for different services
* @param encryptKey Cache Encrypt Key
* @param reportImp Reporting implementation interface
* @return
*/
(void *)MakeReporter:(NSString *)uuid cachePath:(NSString *)cachePath encryptKey:(NSString *)encryptKey uploadBlock:(void(^)(int64_t key, NSArray *dataArray))uploadBlock;
/**
* Set the number of data to be reported in a single time, and call it before start
* @param nativeReporter The value returned by makeReporter
* @param count Number of data reported at one time
*/
(void)SetReportCount:(void *)nativeReporter count:(NSInteger)count;
/**
*Set the maximum size limit of the cache file single file, the default value is 10k
* @param nativeReporter The value returned by makeReporter
* @param fileMaxSize Cache file maximum size
*/
(void)SetFileMaxSize:(void *)nativeReporter fileMaxSize:(NSUInteger)fileMaxSize;
/**
* Set the cache effective time in seconds
* @param nativeReporter The value returned by makeReporter
* @param expiredTime Validity period is the unit
*/
(void)SetExpiredTime:(void *)nativeReporter expiredTime:(int64_t)expiredTime;
/**
* Set the reporting interval
* @param nativeReporter The value returned by makeReporter
* @param reportingInterval Report interval, in seconds
*/
(void)SetReportingInterval:(void *)nativeReporter reportingInterval:(int64_t)reportingInterval;
/**
* Start reporting thread After setting the relevant parameters, execute it once.
*
* @param nativeReporter The value returned by makeReporter
*/
(void)Start:(void *)nativeReporter;
/**
* Wake up the report, call when the network status is good or other wake up scene call
*
* @param nativeReporter The value returned by makeReporter
*/
(void)ReaWaken:(void *)nativeReporter;
/**
* Data reporting call interface
*
* @param nativeReporter The value returned by makeReporter
* @param data Data to be reported
*/
(void)Push:(void *)nativeReporter byteArray:(NSData *)byteArray;
/**
* Call this method after the report is successful
*
* @param nativeReporter The value returned by makeReporter
* @param key The value returned by the escalation implementation interface
*/
(void)UploadSucess:(void *)nativeReporter key:(NSInteger)key;
/**
* Call this method after the report fails
*
* @param nativeReporter The value returned by makeReporter
* @param key The value returned by the escalation implementation interface
*/
(void)UploadFailed:(void *)nativeReporter key:(NSInteger)key;
/**
* Release the report instance, other methods can not be called after release
*
* @param nativeReporter The value returned by makeReporter
*/
(void)ReleaseReporter:(void *)nativeReporter;
DataReporter 是基于mmap的数据实时上报组件 主要用于数据的高性能实时上报,网络情况不好时,数据会缓存到本地。网络状态转好,马上上报。保证数据顺序上报。防数据丢失,即使应用发生崩溃,缓存数据不会丢失。
数据通过调用接口进入DataReporter,先缓存到数据缓冲区,缓冲区实现是mmap,即使发生crash数据不丢失。然后启动线程进行上报。上报开始调用上报接口。成功后调用者通知上报完成,开始进行下一批数据上报。当上层调用过快,缓冲区数据达到指定阈值,数据开始下沉写入文件。写文件缓冲区同样采用mmap实现,防止数据丢失。上报优先级是先取文件数据,然后再取内存数据。保证数据顺序与调用顺序相同。
demo 的使用请参考这里。
准备条件:
步骤:
/**
* 创建Reporter实例,实例是native的,保存在返回的int值中
*
* @param uuid 业务唯一id,由使用者定义一个唯一id
* @param cachePath 缓存路径,必须全局唯一,不同业务不同路径
* @param encryptKey 缓存加密key
* @param reportImp 上报实现接口
* @return
*/
public static native long makeReporter(String uuid, String cachePath, String encryptKey, IReport reportImp);
/**
* 设置单次上报的数据条数,在start之前调用
*
* @param nativeReporter 由makeReporter返回的值
* @param count 一次上报的数据条数
*/
public static native void setReportCount(long nativeReporter, int count);
/**
* 设置缓存文件单文件最大大小限制,默认值为10k
*
* @param nativeReporter 由makeReporter返回的值
* @param fileMaxSize 缓存文件最大大小
*/
public static native void setFileMaxSize(long nativeReporter, int fileMaxSize);
/**
* 设置缓存文件有效期
*
* @param nativeReporter 由makeReporter返回的值
* @param expiredTime 数据有效期
*/
public static native void setExpiredTime(long nativeReporter, long expiredTime);
/**
* 设置上报间隔
*
* @param nativeReporter 由makeReporter返回的值
* @param reportingInterval 上报间隔
*/
public static native void setReportingInterval(long nativeReporter, long reportingInterval);
/**
* 开始上报线程 设置完相关参数之后,执行一次。
*
* @param nativeReporter 由makeReporter返回的值
*/
public static native void start(long nativeReporter);
/**
* 唤醒上报,在网络状态转好时调用或者其他想唤醒场景调用
*
* @param nativeReporter 由makeReporter返回的值
*/
public static native void reaWaken(long nativeReporter);
/**
* 数据上报调用接口
*
* @param nativeReporter 由makeReporter返回的值
* @param data 需要上报的数据
*/
public static native void push(long nativeReporter, byte[] data);
/**
* 上报成功后调用该方法
*
* @param nativeReporter 由makeReporter返回的值
* @param key 由上报实现接口返回的值
*/
public static native void uploadSucess(long nativeReporter, long key);
/**
* 上报失败后调用该方法
*
* @param nativeReporter 由makeReporter返回的值
* @param key 由上报实现接口返回的值
*/
public static native void uploadFailed(long nativeReporter, long key);
/**
* 释放上报实例,释放后其他方法都不可以调用
*
* @param nativeReporter 由makeReporter返回的值
*/
public static native void releaseReporter(long nativeReporter);
-keep class com.iget.datareporter.**{*;}
准备条件:
步骤:
/**
* 创建Reporter实例
*
* @param uuid 业务唯一id,由使用者定义一个唯一id
* @param cachePath 缓存路径,必须全局唯一,不同业务不同路径
* @param encryptKey 缓存加密key
* @param reportImp 上报实现接口
* @return
*/
(void *)MakeReporter:(NSString *)uuid cachePath:(NSString *)cachePath encryptKey:(NSString *)encryptKey uploadBlock:(void(^)(int64_t key, NSArray *dataArray))uploadBlock;
/**
* 设置单次上报的数据条数,在start之前调用
*
* @param nativeReporter 由makeReporter返回的值
* @param count 一次上报的数据条数
*/
(void)SetReportCount:(void *)nativeReporter count:(NSInteger)count;
/**
* 设置缓存文件单文件最大大小限制,默认值为10k
*
* @param nativeReporter 由makeReporter返回的值
* @param fileMaxSize 缓存文件最大大小
*/
(void)SetFileMaxSize:(void *)nativeReporter fileMaxSize:(NSUInteger)fileMaxSize;
/**
* 设置缓存有效时间,秒为单位
*
* @param nativeReporter 由makeReporter返回的值
* @param expiredTime 有效期 秒为单位
*/
(void)SetExpiredTime:(void *)nativeReporter expiredTime:(int64_t)expiredTime;
/**
* 设置上报间隔
*
* @param nativeReporter 由makeReporter返回的值
* @param reportingInterval 上报间隔,秒为单位
*/
(void)SetReportingInterval:(void *)nativeReporter reportingInterval:(int64_t)reportingInterval;
/**
* 开始上报线程 设置完相关参数之后,执行一次。
*
* @param nativeReporter 由makeReporter返回的值
*/
(void)Start:(void *)nativeReporter;
/**
* 唤醒上报,在网络状态转好时调用或者其他想唤醒场景调用
*
* @param nativeReporter 由makeReporter返回的值
*/
(void)ReaWaken:(void *)nativeReporter;
/**
* 数据上报调用接口
*
* @param nativeReporter 由makeReporter返回的值
* @param data 需要上报的数据
*/
(void)Push:(void *)nativeReporter byteArray:(NSData *)byteArray;
/**
* 上报成功后调用该方法
*
* @param nativeReporter 由makeReporter返回的值
* @param key 由上报实现接口返回的值
*/
(void)UploadSucess:(void *)nativeReporter key:(NSInteger)key;
/**
* 上报失败后调用该方法
*
* @param nativeReporter 由makeReporter返回的值
* @param key 由上报实现接口返回的值
*/
(void)UploadFailed:(void *)nativeReporter key:(NSInteger)key;
/**
* 释放上报实例,释放后其他方法都不可以调用
*
* @param nativeReporter 由makeReporter返回的值
*/
(void)ReleaseReporter:(void *)nativeReporter;
还有其他问题?
感谢腾讯团队开源的MMKV项目。本项目借鉴了部分源码。 感谢开源。
DataReporter 使用的 MIT 协议,详细请参考 LICENSE。
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。