|  |  | 
 |  |  | import javax.sip.Dialog; | 
 |  |  | import javax.sip.DialogState; | 
 |  |  | import javax.sip.ResponseEvent; | 
 |  |  | import java.util.Timer; | 
 |  |  | import java.util.TimerTask; | 
 |  |  |  | 
 |  |  | /** | 
 |  |  |  * 移动位置订阅的定时更新 | 
 |  |  | 
 |  |  |     private  ISIPCommander sipCommander; | 
 |  |  |     private Dialog dialog; | 
 |  |  |  | 
 |  |  |     private Timer timer ; | 
 |  |  |  | 
 |  |  |     public MobilePositionSubscribeTask(Device device, ISIPCommander sipCommander) { | 
 |  |  |         this.device = device; | 
 |  |  |         this.sipCommander = sipCommander; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Async | 
 |  |  |     @Override | 
 |  |  |     public void run() { | 
 |  |  |         if (timer != null ) { | 
 |  |  |             timer.cancel(); | 
 |  |  |             timer = null; | 
 |  |  |         } | 
 |  |  |         sipCommander.mobilePositionSubscribe(device, dialog, eventResult -> { | 
 |  |  |             if (eventResult.dialog != null || eventResult.dialog.getState().equals(DialogState.CONFIRMED)) { | 
 |  |  |                 dialog = eventResult.dialog; | 
 |  |  |             } | 
 |  |  | //            if (eventResult.dialog != null || eventResult.dialog.getState().equals(DialogState.CONFIRMED)) { | 
 |  |  | //                dialog = eventResult.dialog; | 
 |  |  | //            } | 
 |  |  |             ResponseEvent event = (ResponseEvent) eventResult.event; | 
 |  |  |             if (event.getResponse().getRawContent() != null) { | 
 |  |  |                 // 成功 | 
 |  |  | 
 |  |  |             dialog = null; | 
 |  |  |             // 失败 | 
 |  |  |             logger.warn("[移动位置订阅]失败,信令发送失败: {}-{} ", device.getDeviceId(), eventResult.msg); | 
 |  |  |             timer = new Timer(); | 
 |  |  |             timer.schedule(new TimerTask() { | 
 |  |  |                 @Override | 
 |  |  |                 public void run() { | 
 |  |  |                     MobilePositionSubscribeTask.this.run(); | 
 |  |  |                 } | 
 |  |  |             }, 2000); | 
 |  |  |         }); | 
 |  |  |  | 
 |  |  |     } | 
 |  |  | 
 |  |  |          * COMPLETED-> Completed Dialog状态-已完成 | 
 |  |  |          * TERMINATED-> Terminated Dialog状态-终止 | 
 |  |  |          */ | 
 |  |  |         if (timer != null ) { | 
 |  |  |             timer.cancel(); | 
 |  |  |             timer = null; | 
 |  |  |         } | 
 |  |  |         if (dialog != null && dialog.getState().equals(DialogState.CONFIRMED)) { | 
 |  |  |             logger.info("取消移动订阅时dialog状态为{}", dialog.getState()); | 
 |  |  |             device.setSubscribeCycleForMobilePosition(0); |