Merge pull request #277 from spring-projects/keepchecking-manual-jmx

Keepchecking manual jmx
This commit is contained in:
Kris De Volder
2019-04-16 13:04:29 -07:00
committed by GitHub
4 changed files with 84 additions and 19 deletions

View File

@@ -143,39 +143,61 @@ public class DelegatingStreamConnectionProvider implements StreamConnectionProvi
}
public class RemoteBootAppData {
private String jmxurl;
private String host;
private String urlScheme = "https";
private String port = "443";
private boolean keepChecking = true;
//keepChecking defaults to true. Boot dash automatic remote apps should override this explicitly.
//Reason. All other 'sources' of remote apps are 'manual' and we want them to default to
//'keepChecking' even if the user doesn't set this to true manually.
public RemoteBootAppData(String jmxurl, String host) {
super();
this.jmxurl = jmxurl;
this.host = host;
}
public String getJmxurl() {
return jmxurl;
}
public void setJmxurl(String jmxurl) {
this.jmxurl = jmxurl;
}
public String getHost() {
return host;
}
public void setHost(String host) {
this.host = host;
}
public String getUrlScheme() {
return urlScheme;
}
public void setUrlScheme(String urlScheme) {
this.urlScheme = urlScheme;
}
public String getPort() {
return port;
}
public void setPort(String port) {
this.port = port;
}
public boolean isKeepChecking() {
return keepChecking;
}
public void setKeepChecking(boolean keepChecking) {
this.keepChecking = keepChecking;
}
}
private void sendConfiguration() {
@@ -227,6 +249,11 @@ public class DelegatingStreamConnectionProvider implements StreamConnectionProvi
app.setUrlScheme(urlScheme);
}
}
//keepChecking attribute added in STS 4.2.1
if (list.size()>=5) {
String keepChecking = list.get(4);
app.setKeepChecking("true".equals(keepChecking));
}
return app;
}
throw new IllegalArgumentException("Invalid remote app data: "+incomingData);

View File

@@ -281,7 +281,7 @@ public abstract class AbstractSpringBootApp implements SpringBootApp {
return hasJmxBeans != null ? hasJmxBeans : false;
}
private boolean containsSpringJmxBeans() throws Exception {
protected boolean containsSpringJmxBeans() throws Exception {
return withTimeout(TIMEOUT_CHECKFORSPRINGAPPS, () -> withJmxConnector(jmxConnector -> {
MBeanServerConnection connection = jmxConnector.getMBeanServerConnection();

View File

@@ -20,20 +20,23 @@ import org.springframework.ide.vscode.commons.util.MemoizingProxy;
public class RemoteSpringBootApp extends AbstractSpringBootApp {
private String jmxUrl;
private String host = null;
private String port = "443";
private String urlScheme = "https";
private final String jmxUrl;
private final String host;
private final String port;
private final String urlScheme;
private boolean keepChecking;
protected RemoteSpringBootApp(String jmxUrl, String host, String port, String urlScheme) {
public static SpringBootApp create(String jmxUrl, String host, String port, String urlScheme, boolean keepChecking) {
return MemoizingProxy.create(RemoteSpringBootApp.class, Duration.ofMillis(4900), new Class[] {String.class, String.class, String.class, String.class, boolean.class},
jmxUrl, host, port, urlScheme, keepChecking);
}
protected RemoteSpringBootApp(String jmxUrl, String host, String port, String urlScheme, boolean keepChecking) {
this.jmxUrl = jmxUrl;
this.host = host;
this.port = port;
this.urlScheme = urlScheme;
}
public void setHost(String host) {
this.host = host;
this.keepChecking = keepChecking;
}
@Override
@@ -94,18 +97,26 @@ public class RemoteSpringBootApp extends AbstractSpringBootApp {
return "Unknown";
}
public static SpringBootApp create(String jmxUrl, String host, String port, String urlScheme) {
return MemoizingProxy.create(RemoteSpringBootApp.class, Duration.ofMillis(4900), new Class[] {String.class, String.class, String.class, String.class},
jmxUrl, host, port, urlScheme);
}
@Override
public String getUrlScheme() {
return urlScheme;
}
public void setUrlScheme(String urlScheme) {
this.urlScheme = urlScheme;
@Override
public boolean hasUsefulJmxBeans() {
if (keepChecking) {
try {
logger.info("checking for spring jmx beans, continuously trying -- " + this.toString());
return super.containsSpringJmxBeans();
}
catch (Exception e) {
logger.info("no spring jmx beans found, continuously trying -- " + this.toString());
return false;
}
}
else {
return super.hasUsefulJmxBeans();
}
}
}

View File

@@ -30,50 +30,74 @@ import org.springframework.ide.vscode.commons.util.CollectorUtil;
public class RemoteRunningAppsProvider implements RunningAppProvider {
public static class RemoteBootAppData {
private String jmxurl;
private String host;
private String urlScheme = "https";
private String port = "443";
private boolean keepChecking = true;
//keepChecking defaults to true. Boot dash automatic remote apps should override this explicitly.
//Reason. All other 'sources' of remote apps are 'manual' and we want them to default to
//'keepChecking' even if the user doesn't set this to true manually.
public String getJmxurl() {
return jmxurl;
}
public void setJmxurl(String jmxurl) {
this.jmxurl = jmxurl;
}
public String getHost() {
return host;
}
public void setHost(String host) {
this.host = host;
}
public String getUrlScheme() {
return urlScheme;
}
public void setUrlScheme(String urlScheme) {
this.urlScheme = urlScheme;
}
public String getPort() {
return port;
}
public void setPort(String port) {
this.port = port;
}
public boolean isKeepChecking() {
return keepChecking;
}
public void setKeepChecking(boolean keepChecking) {
this.keepChecking = keepChecking;
}
@Override
public String toString() {
return "RemoteBootAppData [jmxurl=" + jmxurl + ", host=" + host + ", urlScheme=" + urlScheme + ", port="
+ port + "]";
+ port + ", keepChecking=" + keepChecking + "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((host == null) ? 0 : host.hashCode());
result = prime * result + ((jmxurl == null) ? 0 : jmxurl.hashCode());
result = prime * result + (keepChecking ? 1231 : 1237);
result = prime * result + ((port == null) ? 0 : port.hashCode());
result = prime * result + ((urlScheme == null) ? 0 : urlScheme.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
@@ -93,6 +117,8 @@ public class RemoteRunningAppsProvider implements RunningAppProvider {
return false;
} else if (!jmxurl.equals(other.jmxurl))
return false;
if (keepChecking != other.keepChecking)
return false;
if (port == null) {
if (other.port != null)
return false;
@@ -105,6 +131,7 @@ public class RemoteRunningAppsProvider implements RunningAppProvider {
return false;
return true;
}
}
private static Logger logger = LoggerFactory.getLogger(RemoteRunningAppsProvider.class);
@@ -149,7 +176,7 @@ public class RemoteRunningAppsProvider implements RunningAppProvider {
for (RemoteBootAppData key : newAppData) {
remoteAppInstances.computeIfAbsent(key, (_key) -> {
logger.info("Creating RemoteStringBootApp: "+_key);
return RemoteSpringBootApp.create(key.getJmxurl(), key.getHost(), key.getPort(), key.getUrlScheme());
return RemoteSpringBootApp.create(key.getJmxurl(), key.getHost(), key.getPort(), key.getUrlScheme(), key.isKeepChecking());
});
}
}