use of org.yamcs.api.YamcsConnectionProperties in project yamcs-studio by yamcs.
the class YamcsClient method doConnect.
private FutureTask<YamcsConnectionProperties> doConnect() {
if (connected) {
disconnect();
}
restClient = new RestClient(yprops);
restClient.setAutoclose(false);
wsclient = new WebSocketClient(yprops, this);
wsclient.setUserAgent(application);
wsclient.enableReconnection(true);
// Provides compatiblity with old Yamcs instances
wsclient.enableLegacyURLFallback(true);
wsclient.setMaxFramePayloadLength(MAX_FRAME_PAYLOAD_LENGTH);
FutureTask<YamcsConnectionProperties> future = new FutureTask<>(new Runnable() {
@Override
public void run() {
log.info("Connecting to " + yprops);
int maxAttempts = 10;
try {
if (reconnecting && !retry) {
log.warning("Retries are disabled, cancelling reconnection");
reconnecting = false;
return;
}
connecting = true;
connecting();
for (int i = 0; i < maxAttempts; i++) {
try {
log.fine(String.format("Connecting to %s attempt %d", yprops, i));
instances = restClient.blockingGetYamcsInstances();
if (instances == null || instances.isEmpty()) {
log.warning("No configured yamcs instance");
return;
}
String defaultInstanceName = instances.get(0).getName();
String instanceName = defaultInstanceName;
if (yprops.getInstance() != null) {
// check if the instance saved in properties exists,
// otherwise use the default one
instanceName = instances.stream().map(yi -> yi.getName()).filter(s -> s.equals(yprops.getInstance())).findFirst().orElse(defaultInstanceName);
}
yprops.setInstance(instanceName);
ChannelFuture future = wsclient.connect();
future.get(5000, TimeUnit.MILLISECONDS);
return;
} catch (Exception e) {
// For anything other than a security exception, re-try
if (log.isLoggable(Level.FINEST)) {
log.log(Level.FINEST, String.format("Connection to %s failed (attempt %d of %d)", yprops, i + 1, maxAttempts), e);
} else {
log.warning(String.format("Connection to %s failed (attempt %d of %d)", yprops, i + 1, maxAttempts));
}
Thread.sleep(5000);
}
}
connecting = false;
for (ConnectionListener cl : connectionListeners) {
cl.connectionFailed(null, new YamcsException(maxAttempts + " connection attempts failed, giving up."));
}
log.warning(maxAttempts + " connection attempts failed, giving up.");
} catch (InterruptedException e) {
log.info("Connection cancelled by user");
connecting = false;
for (ConnectionListener cl : connectionListeners) {
cl.connectionFailed(null, new YamcsException("Thread interrupted", e));
}
}
}
}, yprops);
executor.submit(future);
// Add Progress indicator in status bar
String jobName = "Connecting to " + yprops;
scheduleAsJob(jobName, future, Job.SHORT);
return future;
}
use of org.yamcs.api.YamcsConnectionProperties in project yamcs-studio by yamcs.
the class YamcsAuthorizations method isAuthorizationEnabled.
public boolean isAuthorizationEnabled() {
YamcsClient yamcsClient = YamcsPlugin.getYamcsClient();
// TODO we should probably control this from the server, rather than here. Just because
// the creds are null, does not really mean anything. We could also send creds to an
// unsecured yamcs server. It would just ignore it, and then our client state would
// be wrong
YamcsConnectionProperties yprops = yamcsClient.getYamcsConnectionProperties();
return (yprops == null) ? false : yprops.getAuthenticationToken() != null;
}
use of org.yamcs.api.YamcsConnectionProperties in project yamcs-studio by yamcs.
the class AutoConnectHandler method doConnect.
private void doConnect(Shell shell, YamcsConfiguration conf, boolean noPasswordPopup) {
// FIXME get the password out before doing this
ConnectionPreferences.setLastUsedConfiguration(conf);
// Check if authentication is needed
YamcsConnectionProperties yprops = conf.getPrimaryConnectionProperties();
if (conf.isAnonymous()) {
log.fine("Will connect anonymously to " + yprops);
YamcsPlugin.getYamcsClient().connect(yprops);
} else if (conf.isSavePassword() || noPasswordPopup) {
log.fine("Will connect as user '" + conf.getUser() + "' to " + yprops);
YamcsPlugin.getYamcsClient().connect(yprops);
} else {
log.fine("Want to connect to '" + yprops + "' but credentials are needed (not saved and not in dialog). Show password dialog");
LoginDialog dialog = new LoginDialog(shell, conf);
if (dialog.open() == Dialog.OK) {
conf.setUser(dialog.getUser());
conf.setPassword(dialog.getPassword());
ConnectionUIHelper.connectWithProgressDialog(shell, yprops);
}
}
}
use of org.yamcs.api.YamcsConnectionProperties in project yamcs-studio by yamcs.
the class YamcsConfiguration method getFailoverConnectionProperties.
public YamcsConnectionProperties getFailoverConnectionProperties() {
if (failoverHost != null) {
YamcsConnectionProperties yprops = new YamcsConnectionProperties(failoverHost, failoverPort, instance);
yprops.setProtocol(Protocol.http);
if (!isAnonymous()) {
yprops.setAuthenticationToken(new UsernamePasswordToken(user, password));
}
return yprops;
} else {
return null;
}
}
use of org.yamcs.api.YamcsConnectionProperties in project yamcs-studio by yamcs.
the class ConnectionStringStatusLineContributionItem method onYamcsConnected.
@Override
public void onYamcsConnected() {
YamcsConnectionProperties yprops = YamcsPlugin.getYamcsClient().getYamcsConnectionProperties();
Display.getDefault().asyncExec(() -> {
setErrorText(null, null);
setImage(null);
setText(getConnectionString(yprops));
});
}
Aggregations