+ @Override
+ public CONTEXT_STATE getState() {
+ return this.state;
+ }
+
+ @Override
+ public ServiceGroupIdentifier getServiceIdentifier() {
+ return this.deviceInfo.getServiceIdentifier();
+ }
+
+ @Override
+ public DeviceInfo getDeviceInfo() {
+ return this.deviceInfo;
+ }
+
+ @Override
+ public ListenableFuture<Void> stopClusterServices() {
+ if (CONTEXT_STATE.TERMINATION.equals(getState())) {
+ return Futures.immediateCancelledFuture();
+ }
+
+ return Futures.transform(Futures.immediateFuture(null), new Function<Object, Void>() {
+ @Nullable
+ @Override
+ public Void apply(@Nullable Object input) {
+ schedulingEnabled = false;
+ stopGatheringData();
+ return null;
+ }
+ });
+ }
+
+ @Override
+ public DeviceState gainDeviceState() {
+ return gainDeviceContext().getDeviceState();
+ }
+
+ @Override
+ public DeviceContext gainDeviceContext() {
+ return this.lifecycleService.getDeviceContext();
+ }
+
+ @Override
+ public void stopGatheringData() {
+ if (Objects.nonNull(this.lastDataGathering)) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Stop the running statistics gathering for node {}", this.deviceInfo.getLOGValue());
+ }
+
+ lastDataGathering.cancel(true);
+ }
+ }
+
+ @Override
+ public void setLifecycleInitializationPhaseHandler(final ClusterInitializationPhaseHandler handler) {
+ this.clusterInitializationPhaseHandler = handler;
+ }
+
+ @Override
+ public boolean onContextInstantiateService(final ConnectionContext connectionContext) {
+ if (connectionContext.getConnectionState().equals(ConnectionContext.CONNECTION_STATE.RIP)) {
+ LOG.warn("Connection on device {} was interrupted, will stop starting master services.", deviceInfo.getLOGValue());
+ return false;
+ }
+
+ LOG.info("Starting statistics context cluster services for node {}", deviceInfo.getLOGValue());
+
+ this.statListForCollectingInitialization();
+ Futures.addCallback(this.initialGatherDynamicData(), new FutureCallback<Boolean>() {
+
+ @Override
+ public void onSuccess(@Nullable Boolean aBoolean) {
+ initialSubmitHandler.initialSubmitTransaction();
+ }
+
+ @Override
+ public void onFailure(Throwable throwable) {
+ LOG.warn("Initial gathering statistics unsuccessful for node {}", deviceInfo.getLOGValue());
+ lifecycleService.closeConnection();
+ }
+ });
+
+ if (this.isStatisticsPollingOn) {
+ myManager.startScheduling(deviceInfo);
+ }
+
+ return this.clusterInitializationPhaseHandler.onContextInstantiateService(connectionContext);
+ }