final boolean requestClusterState(final boolean display) { try { Settings settings = ElasticsearchPreferences.getInstance().toSettings(); ClusterStatsResponse stats = new Elasticsearch(settings).stats(); String desiredCluster = this.clusterName.getStringValue(); String receivedCluster = stats.getClusterNameAsString(); String message; if (!desiredCluster.equals(receivedCluster)) { message = "Connected to cluster " + desiredCluster; message += " instead of " + receivedCluster + ". "; message += "Please correct the Cluster name setting."; throw new IllegalStateException(message); } if (display) { message = "Cluster " + receivedCluster + ", "; message += "status " + stats.getStatus() + "."; MessageDialog.openInformation(this.getShell(), "Elasticsearch status", message.toString()); } return true; } catch (Exception failure) { String title, message, toggle; if (failure instanceof ElasticsearchException) { ElasticsearchException exception = (ElasticsearchException) failure; title = "Elasticsearch error"; message = exception.getDetailedMessage() + ", status " + exception.status(); } else { title = failure instanceof IllegalStateException ? "Elasticsearch error" : "Unknown error"; message = failure.getMessage(); } toggle = "Always request cluster status on confirmation"; Preference preference = Preference.usingToggleState( this.getPreferenceStore(), this.requestClusterState.getPreferenceName()); boolean state = MessageDialogWithPreference.openError(this.getShell(), title, message, toggle, preference) .getToggleState(); this.requestClusterState.getChangeControl().setSelection(state); return false; } }