@ -22,15 +22,34 @@ public class TriggerCallbackThread {
return instance ;
}
/ * *
* job results callback queue
* /
private LinkedBlockingQueue < HandleCallbackParam > callBackQueue = new LinkedBlockingQueue < HandleCallbackParam > ( ) ;
public static void pushCallBack ( HandleCallbackParam callback ) {
getInstance ( ) . callBackQueue . add ( callback ) ;
logger . debug ( ">>>>>>>>>>> xxl-job, push callback request, logId:{}" , callback . getLogId ( ) ) ;
}
/ * *
* callback thread
* /
private Thread triggerCallbackThread ;
private boolean toStop = false ;
private volatile boolean toStop = false ;
public void start ( ) {
// valid
if ( XxlJobExecutor . getAdminBizList ( ) = = null ) {
logger . warn ( ">>>>>>>>>>>> xxl-job, executor callback config fail, adminAddresses is null." ) ;
return ;
}
triggerCallbackThread = new Thread ( new Runnable ( ) {
@Override
public void run ( ) {
// normal callback
while ( ! toStop ) {
try {
HandleCallbackParam callback = getInstance ( ) . callBackQueue . take ( ) ;
@ -41,34 +60,27 @@ public class TriggerCallbackThread {
int drainToNum = getInstance ( ) . callBackQueue . drainTo ( callbackParamList ) ;
callbackParamList . add ( callback ) ;
// valid
if ( XxlJobExecutor . getAdminBizList ( ) = = null ) {
logger . warn ( ">>>>>>>>>>>> xxl-job callback fail, adminAddresses is null, callbackParamList:{}" , callbackParamList ) ;
continue ;
}
// callback, will retry if error
for ( AdminBiz adminBiz : XxlJobExecutor . getAdminBizList ( ) ) {
try {
ReturnT < String > callbackResult = adminBiz . callback ( callbackParamList ) ;
if ( callbackResult ! = null & & ReturnT . SUCCESS_CODE = = callbackResult . getCode ( ) ) {
callbackResult = ReturnT . SUCCESS ;
logger . info ( ">>>>>>>>>>> xxl-job callback success, callbackParamList:{}, callbackResult:{}" , new Object [ ] { callbackParamList , callbackResult } ) ;
break ;
} else {
logger . info ( ">>>>>>>>>>> xxl-job callback fail, callbackParamList:{}, callbackResult:{}" , new Object [ ] { callbackParamList , callbackResult } ) ;
}
} catch ( Exception e ) {
logger . error ( ">>>>>>>>>>> xxl-job callback error, callbackParamList:{}" , callbackParamList , e ) ;
//getInstance().callBackQueue.addAll(callbackParamList);
}
if ( callbackParamList ! = null & & callbackParamList . size ( ) > 0 ) {
doCallback ( callbackParamList ) ;
}
}
} catch ( Exception e ) {
logger . error ( e . getMessage ( ) , e ) ;
}
}
// last callback
try {
List < HandleCallbackParam > callbackParamList = new ArrayList < HandleCallbackParam > ( ) ;
int drainToNum = getInstance ( ) . callBackQueue . drainTo ( callbackParamList ) ;
if ( callbackParamList ! = null & & callbackParamList . size ( ) > 0 ) {
doCallback ( callbackParamList ) ;
}
} catch ( Exception e ) {
logger . error ( e . getMessage ( ) , e ) ;
}
}
} ) ;
triggerCallbackThread . setDaemon ( true ) ;
@ -78,9 +90,27 @@ public class TriggerCallbackThread {
toStop = true ;
}
public static void pushCallBack ( HandleCallbackParam callback ) {
getInstance ( ) . callBackQueue . add ( callback ) ;
logger . debug ( ">>>>>>>>>>> xxl-job, push callback request, logId:{}" , callback . getLogId ( ) ) ;
/ * *
* do callback , will retry if error
* @param callbackParamList
* /
private void doCallback ( List < HandleCallbackParam > callbackParamList ) {
// callback, will retry if error
for ( AdminBiz adminBiz : XxlJobExecutor . getAdminBizList ( ) ) {
try {
ReturnT < String > callbackResult = adminBiz . callback ( callbackParamList ) ;
if ( callbackResult ! = null & & ReturnT . SUCCESS_CODE = = callbackResult . getCode ( ) ) {
callbackResult = ReturnT . SUCCESS ;
logger . info ( ">>>>>>>>>>> xxl-job callback success, callbackParamList:{}, callbackResult:{}" , new Object [ ] { callbackParamList , callbackResult } ) ;
break ;
} else {
logger . info ( ">>>>>>>>>>> xxl-job callback fail, callbackParamList:{}, callbackResult:{}" , new Object [ ] { callbackParamList , callbackResult } ) ;
}
} catch ( Exception e ) {
logger . error ( ">>>>>>>>>>> xxl-job callback error, callbackParamList:{}" , callbackParamList , e ) ;
//getInstance().callBackQueue.addAll(callbackParamList);
}
}
}
}