1111 * Analysys Java SDK
1212 */
1313public class AnalysysJavaSdk {
14- private final String SDK_VERSION = "4.1.1 " ;
14+ private final String SDK_VERSION = "4.1.2 " ;
1515 private final Collecter collecter ;
1616 private final String appId ;
1717 private final Map <String , Object > egBaseProperties ;
@@ -49,8 +49,9 @@ public AnalysysJavaSdk(Collecter collecter, String appId, Boolean autoDelParam){
4949 * Debug模式
5050 * @param debug Debug级别
5151 */
52- public void setDebugMode (DEBUG debug ) {
52+ public boolean setDebugMode (DEBUG debug ) {
5353 this .debugMode = debug .getCode ();
54+ return true ;
5455 }
5556
5657 private boolean isDebug (){
@@ -70,7 +71,7 @@ public void initBaseProperties() {
7071 * 注册超级属性,注册后每次发送的消息体中都包含该属性值
7172 * @param params 属性
7273 */
73- public void registerSuperProperties (Map <String , Object > params ) throws AnalysysException {
74+ public boolean registerSuperProperties (Map <String , Object > params ) throws AnalysysException {
7475 int num = 100 ;
7576 if (params .entrySet ().size () > num ){
7677 throw new AnalysysException ("Too many super properties. max number is 100." );
@@ -80,21 +81,23 @@ public void registerSuperProperties(Map<String, Object> params) throws AnalysysE
8081 this .xcontextSuperProperties .put (key , params .get (key ));
8182 }
8283 if (isDebug ()){
83- System . out . println ("registerSuperProperties success" );
84+ AnalysysLogger . print ("registerSuperProperties success" );
8485 }
86+ return true ;
8587 }
8688
8789 /**
8890 * 移除超级属性
8991 * @param key 属性key
9092 */
91- public void unRegisterSuperProperty (String key ) {
93+ public boolean unRegisterSuperProperty (String key ) {
9294 if (this .xcontextSuperProperties .containsKey (key )){
9395 this .xcontextSuperProperties .remove (key );
9496 }
9597 if (isDebug ()){
96- System . out . println (String .format ("unRegisterSuperProperty %s success" , key ));
98+ AnalysysLogger . print (String .format ("unRegisterSuperProperty %s success" , key ));
9799 }
100+ return true ;
98101 }
99102
100103 /**
@@ -120,18 +123,20 @@ public Map<String, Object> getSuperProperties(){
120123 /**
121124 * 清除超级属性
122125 */
123- public void clearSuperProperties (){
126+ public boolean clearSuperProperties (){
124127 this .xcontextSuperProperties .clear ();
125128 if (isDebug ()){
126- System . out . println ("clearSuperProperties success" );
129+ AnalysysLogger . print ("clearSuperProperties success" );
127130 }
131+ return true ;
128132 }
129133
130134 /**
131135 * 立即发送所有收集的信息到服务器
132136 */
133- public void flush () {
137+ public boolean flush () {
134138 this .collecter .flush ();
139+ return true ;
135140 }
136141
137142 public void shutdown () {
@@ -146,11 +151,11 @@ public void shutdown() {
146151 * @param platform 平台类型
147152 * @throws AnalysysException 自定义异常
148153 */
149- public void profileSet (String distinctId , boolean isLogin , Map <String , Object > properties , String platform ) throws AnalysysException {
150- upload (distinctId , isLogin , EventName .P_SET .getValue (), properties , platform , null );
154+ public boolean profileSet (String distinctId , boolean isLogin , Map <String , Object > properties , String platform ) throws AnalysysException {
155+ return upload (distinctId , isLogin , EventName .P_SET .getValue (), properties , platform , null );
151156 }
152- public void profileSet (String distinctId , boolean isLogin , Map <String , Object > properties , String platform , String xwhen ) throws AnalysysException {
153- upload (distinctId , isLogin , EventName .P_SET .getValue (), properties , platform , xwhen );
157+ public boolean profileSet (String distinctId , boolean isLogin , Map <String , Object > properties , String platform , String xwhen ) throws AnalysysException {
158+ return upload (distinctId , isLogin , EventName .P_SET .getValue (), properties , platform , xwhen );
154159 }
155160
156161 /**
@@ -161,11 +166,11 @@ public void profileSet(String distinctId, boolean isLogin, Map<String, Object> p
161166 * @param platform 平台类型
162167 * @throws AnalysysException 自定义异常
163168 */
164- public void profileSetOnce (String distinctId , boolean isLogin , Map <String , Object > properties , String platform ) throws AnalysysException {
165- upload (distinctId , isLogin , EventName .P_SET_ONE .getValue (), properties , platform , null );
169+ public boolean profileSetOnce (String distinctId , boolean isLogin , Map <String , Object > properties , String platform ) throws AnalysysException {
170+ return upload (distinctId , isLogin , EventName .P_SET_ONE .getValue (), properties , platform , null );
166171 }
167- public void profileSetOnce (String distinctId , boolean isLogin , Map <String , Object > properties , String platform , String xwhen ) throws AnalysysException {
168- upload (distinctId , isLogin , EventName .P_SET_ONE .getValue (), properties , platform , xwhen );
172+ public boolean profileSetOnce (String distinctId , boolean isLogin , Map <String , Object > properties , String platform , String xwhen ) throws AnalysysException {
173+ return upload (distinctId , isLogin , EventName .P_SET_ONE .getValue (), properties , platform , xwhen );
169174 }
170175
171176 /**
@@ -176,11 +181,11 @@ public void profileSetOnce(String distinctId, boolean isLogin, Map<String, Objec
176181 * @param platform 平台类型
177182 * @throws AnalysysException 自定义异常
178183 */
179- public void profileIncrement (String distinctId , boolean isLogin , Map <String , Object > properties , String platform ) throws AnalysysException {
180- upload (distinctId , isLogin , EventName .P_IN .getValue (), properties , platform , null );
184+ public boolean profileIncrement (String distinctId , boolean isLogin , Map <String , Object > properties , String platform ) throws AnalysysException {
185+ return upload (distinctId , isLogin , EventName .P_IN .getValue (), properties , platform , null );
181186 }
182- public void profileIncrement (String distinctId , boolean isLogin , Map <String , Object > properties , String platform , String xwhen ) throws AnalysysException {
183- upload (distinctId , isLogin , EventName .P_IN .getValue (), properties , platform , xwhen );
187+ public boolean profileIncrement (String distinctId , boolean isLogin , Map <String , Object > properties , String platform , String xwhen ) throws AnalysysException {
188+ return upload (distinctId , isLogin , EventName .P_IN .getValue (), properties , platform , xwhen );
184189 }
185190
186191 /**
@@ -191,11 +196,11 @@ public void profileIncrement(String distinctId, boolean isLogin, Map<String, Obj
191196 * @param platform 平台类型
192197 * @throws AnalysysException 自定义异常
193198 */
194- public void profileAppend (String distinctId , boolean isLogin , Map <String , Object > properties , String platform ) throws AnalysysException {
195- upload (distinctId , isLogin , EventName .P_APP .getValue (), properties , platform , null );
199+ public boolean profileAppend (String distinctId , boolean isLogin , Map <String , Object > properties , String platform ) throws AnalysysException {
200+ return upload (distinctId , isLogin , EventName .P_APP .getValue (), properties , platform , null );
196201 }
197- public void profileAppend (String distinctId , boolean isLogin , Map <String , Object > properties , String platform , String xwhen ) throws AnalysysException {
198- upload (distinctId , isLogin , EventName .P_APP .getValue (), properties , platform , xwhen );
202+ public boolean profileAppend (String distinctId , boolean isLogin , Map <String , Object > properties , String platform , String xwhen ) throws AnalysysException {
203+ return upload (distinctId , isLogin , EventName .P_APP .getValue (), properties , platform , xwhen );
199204 }
200205
201206 /**
@@ -206,15 +211,15 @@ public void profileAppend(String distinctId, boolean isLogin, Map<String, Object
206211 * @param platform 平台类型
207212 * @throws AnalysysException 自定义异常
208213 */
209- public void profileUnSet (String distinctId , boolean isLogin , String property , String platform ) throws AnalysysException {
214+ public boolean profileUnSet (String distinctId , boolean isLogin , String property , String platform ) throws AnalysysException {
210215 Map <String , Object > properties = new HashMap <String , Object >(2 );
211216 properties .put (property , "" );
212- upload (distinctId , isLogin , EventName .P_UN .getValue (), properties , platform , null );
217+ return upload (distinctId , isLogin , EventName .P_UN .getValue (), properties , platform , null );
213218 }
214- public void profileUnSet (String distinctId , boolean isLogin , String property , String platform , String xwhen ) throws AnalysysException {
219+ public boolean profileUnSet (String distinctId , boolean isLogin , String property , String platform , String xwhen ) throws AnalysysException {
215220 Map <String , Object > properties = new HashMap <String , Object >(2 );
216221 properties .put (property , "" );
217- upload (distinctId , isLogin , EventName .P_UN .getValue (), properties , platform , xwhen );
222+ return upload (distinctId , isLogin , EventName .P_UN .getValue (), properties , platform , xwhen );
218223 }
219224
220225 /**
@@ -224,11 +229,11 @@ public void profileUnSet(String distinctId, boolean isLogin, String property, St
224229 * @param platform 平台类型
225230 * @throws AnalysysException 自定义异常
226231 */
227- public void profileDelete (String distinctId , boolean isLogin , String platform ) throws AnalysysException {
228- upload (distinctId , isLogin , EventName .P_DEL .getValue (), new HashMap <String , Object >(1 ), platform , null );
232+ public boolean profileDelete (String distinctId , boolean isLogin , String platform ) throws AnalysysException {
233+ return upload (distinctId , isLogin , EventName .P_DEL .getValue (), new HashMap <String , Object >(1 ), platform , null );
229234 }
230- public void profileDelete (String distinctId , boolean isLogin , String platform , String xwhen ) throws AnalysysException {
231- upload (distinctId , isLogin , EventName .P_DEL .getValue (), new HashMap <String , Object >(1 ), platform , xwhen );
235+ public boolean profileDelete (String distinctId , boolean isLogin , String platform , String xwhen ) throws AnalysysException {
236+ return upload (distinctId , isLogin , EventName .P_DEL .getValue (), new HashMap <String , Object >(1 ), platform , xwhen );
232237 }
233238
234239 /**
@@ -238,15 +243,15 @@ public void profileDelete(String distinctId, boolean isLogin, String platform,
238243 * @param platform 平台类型
239244 * @throws AnalysysException 自定义异常
240245 */
241- public void alias (String aliasId , String distinctId , String platform ) throws AnalysysException {
246+ public boolean alias (String aliasId , String distinctId , String platform ) throws AnalysysException {
242247 Map <String , Object > param = new HashMap <String , Object >(2 );
243248 param .put ("$original_id" , distinctId );
244- upload (aliasId , true , EventName .ALIAS .getValue (), param , platform , null );
249+ return upload (aliasId , true , EventName .ALIAS .getValue (), param , platform , null );
245250 }
246- public void alias (String aliasId , String distinctId , String platform , String xwhen ) throws AnalysysException {
251+ public boolean alias (String aliasId , String distinctId , String platform , String xwhen ) throws AnalysysException {
247252 Map <String , Object > param = new HashMap <String , Object >(2 );
248253 param .put ("$original_id" , distinctId );
249- upload (aliasId , true , EventName .ALIAS .getValue (), param , platform , xwhen );
254+ return upload (aliasId , true , EventName .ALIAS .getValue (), param , platform , xwhen );
250255 }
251256
252257 /**
@@ -258,11 +263,11 @@ public void alias(String aliasId, String distinctId, String platform, String xwh
258263 * @param platform 平台类型
259264 * @throws AnalysysException 自定义异常
260265 */
261- public void track (String distinctId , boolean isLogin , String eventName , Map <String , Object > properties , String platform ) throws AnalysysException {
262- upload (distinctId , isLogin , eventName , properties , platform , null );
266+ public boolean track (String distinctId , boolean isLogin , String eventName , Map <String , Object > properties , String platform ) throws AnalysysException {
267+ return upload (distinctId , isLogin , eventName , properties , platform , null );
263268 }
264- public void track (String distinctId , boolean isLogin , String eventName , Map <String , Object > properties , String platform , String xwhen ) throws AnalysysException {
265- upload (distinctId , isLogin , eventName , properties , platform , xwhen );
269+ public boolean track (String distinctId , boolean isLogin , String eventName , Map <String , Object > properties , String platform , String xwhen ) throws AnalysysException {
270+ return upload (distinctId , isLogin , eventName , properties , platform , xwhen );
266271 }
267272
268273 /**
@@ -275,7 +280,7 @@ public void track(String distinctId, boolean isLogin, String eventName, Map<Stri
275280 * @param xwhen 时间戳
276281 * @throws AnalysysException 自定义异常
277282 */
278- private void upload (String distinctId , boolean isLogin , String eventName , Map <String , Object > properties , String platform , String xwhen ) throws AnalysysException {
283+ private boolean upload (String distinctId , boolean isLogin , String eventName , Map <String , Object > properties , String platform , String xwhen ) throws AnalysysException {
279284 HashMap <String , Object > targetProperties = new HashMap <String , Object >();
280285 if (properties != null ){
281286 targetProperties .putAll (properties );
@@ -322,22 +327,23 @@ private void upload(String distinctId, boolean isLogin, String eventName, Map<St
322327 this .collecter .debug (isDebug ());
323328 boolean ret = this .collecter .send (eventMap );
324329 if (eventName != null && eventName .startsWith (profile ) && isDebug () && ret ){
325- System . out . println (String .format ("%s success." , eventName ));
330+ AnalysysLogger . print (String .format ("%s success." , eventName ));
326331 }
332+ return ret ;
327333 }
328334
329335 private String getPlatForm (String platform ){
330336 if (PlatForm .JS .getValue ().equalsIgnoreCase (platform )) {return PlatForm .JS .getValue ();}
331337 if (PlatForm .WeChat .getValue ().equalsIgnoreCase (platform )) {return PlatForm .WeChat .getValue ();}
332338 if (PlatForm .Android .getValue ().equalsIgnoreCase (platform )) {return PlatForm .Android .getValue ();}
333339 if (PlatForm .iOS .getValue ().equalsIgnoreCase (platform )) {return PlatForm .iOS .getValue ();}
334- System . out . println (String .format ("Warning: param platform:%s Your input are not:iOS/Android/JS/WeChat." , platform == null ? "" : platform ));
340+ AnalysysLogger . print (String .format ("Warning: param platform:%s Your input are not:iOS/Android/JS/WeChat." , platform == null ? "" : platform ));
335341 if (PlatForm .Java .getValue ().equalsIgnoreCase (platform )) {return PlatForm .Java .getValue ();}
336342 if (PlatForm .python .getValue ().equalsIgnoreCase (platform )) {return PlatForm .python .getValue ();}
337343 if (PlatForm .Node .getValue ().equalsIgnoreCase (platform )) {return PlatForm .Node .getValue ();}
338344 if (PlatForm .PHP .getValue ().equalsIgnoreCase (platform )) {return PlatForm .PHP .getValue ();}
339345 if (platform == null || platform .trim ().length () == 0 ) {
340- System . out . println (String .format ("Warning: param platform is empty, will use default value: %s." , PlatForm .Java .getValue ()));
346+ AnalysysLogger . print (String .format ("Warning: param platform is empty, will use default value: %s." , PlatForm .Java .getValue ()));
341347 return PlatForm .Java .getValue ();
342348 }
343349 return platform ;
0 commit comments