Skip to content

Commit d0561be

Browse files
author
Wenjun Che
committed
RUN-1077: add example for direct connect to a port
1 parent d87e10a commit d0561be

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

src/main/java/com/openfin/desktop/demo/OpenFinDesktopDemo.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public class OpenFinDesktopDemo extends JPanel implements ActionListener, Window
5353
InterApplicationBus bus;
5454

5555
protected DesktopConnection desktopConnection;
56+
protected int desktopPort = -1; // if set, assuming Runtime is already running on the port
5657
protected System openfinSystem;
5758
protected AppCreateDialog appCreateDialog;
5859
protected LoadAppsDialog loadAppsDialog;
@@ -64,7 +65,15 @@ public class OpenFinDesktopDemo extends JPanel implements ActionListener, Window
6465

6566
public OpenFinDesktopDemo(final String securityRealm) {
6667
try {
67-
this.desktopConnection = new DesktopConnection("OpenFinDesktopDemoJava");
68+
69+
if (java.lang.System.getProperty("com.openfin.demo.port") != null) {
70+
this.desktopPort = Integer.parseInt(java.lang.System.getProperty("com.openfin.demo.port"));
71+
}
72+
if (this.desktopPort > 0) {
73+
this.desktopConnection = new DesktopConnection("OpenFinDesktopDemoJava", "localhost", this.desktopPort);
74+
} else {
75+
this.desktopConnection = new DesktopConnection("OpenFinDesktopDemoJava");
76+
}
6877
if (securityRealm != null) {
6978
this.desktopConnection.setRuntimeSecurityRealm(securityRealm);
7079
}
@@ -437,7 +446,17 @@ public void onOutgoingMessage(String message) {
437446
};
438447

439448
try {
440-
desktopConnection.connectToVersion("stable", listener, 10000);
449+
if (this.desktopPort > 0) {
450+
updateMessagePanel("Connecting to Runtime already running at port " + this.desktopPort);
451+
desktopConnection.connect(listener);
452+
} else {
453+
String desktopVersion = java.lang.System.getProperty("com.openfin.demo.version");
454+
if (desktopVersion == null) {
455+
desktopVersion = "stable";
456+
}
457+
updateMessagePanel("Connecting to version " + desktopVersion);
458+
desktopConnection.connectToVersion(desktopVersion, listener, 10000);
459+
}
441460
} catch (Exception ex) {
442461
ex.printStackTrace();
443462
}

0 commit comments

Comments
 (0)