@@ -35,6 +35,8 @@ public abstract class RetryScheduler<T> {
3535 private ScheduledFuture <?> scheduledFuture ;
3636 private AtomicBoolean start = new AtomicBoolean (false );
3737 private FailStore failStore ;
38+ // 名称主要是用来记录日志
39+ private String name ;
3840
3941 // 批量发送的消息数
4042 private int batchSize = 5 ;
@@ -47,6 +49,7 @@ public RetryScheduler(Application application, String storePath) {
4749 FailStoreFactory failStoreFactory = ExtensionLoader .getExtensionLoader (FailStoreFactory .class ).getAdaptiveExtension ();
4850 failStore = failStoreFactory .getFailStore (application .getConfig (), storePath );
4951 }
52+
5053 public RetryScheduler (Application application , String storePath , int batchSize ) {
5154 this (application , storePath );
5255 this .batchSize = batchSize ;
@@ -57,15 +60,19 @@ protected RetryScheduler(Application application, int batchSize) {
5760 this .batchSize = batchSize ;
5861 }
5962
63+ public void setName (String name ) {
64+ this .name = name ;
65+ }
66+
6067 public void start () {
6168 try {
6269 if (start .compareAndSet (false , true )) {
6370 // 这个时间后面再去优化
6471 scheduledFuture = RETRY_EXECUTOR_SERVICE .scheduleWithFixedDelay (new CheckRunner (), 10 , 30 , TimeUnit .SECONDS );
65- LOGGER .error ("Start retry scheduler success!" );
72+ LOGGER .info ("Start {} retry scheduler success!" , name );
6673 }
6774 } catch (Throwable t ) {
68- LOGGER .error ("Start retry scheduler failed!" , t );
75+ LOGGER .error ("Start {} retry scheduler failed!" , name , t );
6976 }
7077 }
7178
@@ -74,10 +81,10 @@ public void stop() {
7481 if (start .compareAndSet (false , true )) {
7582 scheduledFuture .cancel (true );
7683 RETRY_EXECUTOR_SERVICE .shutdown ();
77- LOGGER .error ("Stop retry scheduler success!" );
84+ LOGGER .info ("Stop {} retry scheduler success!" , name );
7885 }
7986 } catch (Throwable t ) {
80- LOGGER .error ("Stop retry scheduler failed!" , t );
87+ LOGGER .error ("Stop {} retry scheduler failed!" , name , t );
8188 }
8289 }
8390
@@ -117,7 +124,7 @@ public void run() {
117124 values .add (kvPair .getValue ());
118125 }
119126 if (retry (values )) {
120- LOGGER .info ("本地数据发送成功 , {}" , JSONUtils .toJSONString (values ));
127+ LOGGER .info ("{} local files send success , {}" , name , JSONUtils .toJSONString (values ));
121128 failStore .delete (keys );
122129 } else {
123130 break ;
@@ -137,7 +144,7 @@ public void run() {
137144 } while (CollectionUtils .isNotEmpty (kvPairs ));
138145
139146 } catch (Throwable e ) {
140- LOGGER .error (e . getMessage () , e );
147+ LOGGER .error ("Run {} retry scheduler error." , name , e );
141148 }
142149 }
143150
@@ -152,7 +159,7 @@ public void inSchedule(String key, T value) {
152159 failStore .close ();
153160 }
154161 } catch (FailStoreException e ) {
155- LOGGER .error (e . getMessage () , e );
162+ LOGGER .error ("{} in schedule error. " , e );
156163 }
157164 }
158165
0 commit comments