diff --git a/release/lib/openfin-desktop-java-example-9.2.2.jar b/release/lib/openfin-desktop-java-example-9.2.2.jar new file mode 100644 index 0000000..dea5aac Binary files /dev/null and b/release/lib/openfin-desktop-java-example-9.2.2.jar differ diff --git a/release/profile.bat b/release/profile.bat new file mode 100644 index 0000000..9e1cf11 --- /dev/null +++ b/release/profile.bat @@ -0,0 +1,2 @@ +java -Xmx100m -Xms100m -cp lib/hamcrest-core-1.3.jar;lib/hamcrest-library-1.1.jar;lib/jetty-client-9.4.18.v20190429.jar;lib/jetty-http-9.4.18.v20190429.jar;lib/jetty-io-9.4.18.v20190429.jar;lib/jetty-util-9.4.18.v20190429.jar;lib/jetty-xml-9.4.18.v20190429.jar;lib/jna-4.5.1.jar;lib/jna-platform-4.5.1.jar;lib/json-20160810.jar;lib/junit-4.11.jar;lib/mockito-core-1.9.5.jar;lib/objenesis-1.0.jar;lib/openfin-desktop-java-adapter-9.2.3-SNAPSHOT.jar;lib/openfin-desktop-java-example-9.0.1-tests.jar;lib/openfin-desktop-java-example-9.2.2.jar;lib/slf4j-api-1.7.21.jar;lib/slf4j-jdk14-1.6.1.jar;lib/slf4j-log4j12-1.7.18.jar;lib/TableLayout-20050920.jar;lib/websocket-api-9.4.18.v20190429.jar;lib/websocket-client-9.4.18.v20190429.jar;lib/websocket-common-9.4.18.v20190429.jar -Djava.util.logging.config.file=logging.properties -Dcom.openfin.temp=%LocalAppData%\OpenFin\temp -Dcom.openfin.demo.version=stable -Dcom.openfin.demo.licenseKey=123456 com.openfin.desktop.demo.MemoryProfile + diff --git a/src/main/java/com/openfin/desktop/demo/MemoryProfile.java b/src/main/java/com/openfin/desktop/demo/MemoryProfile.java new file mode 100644 index 0000000..0b22811 --- /dev/null +++ b/src/main/java/com/openfin/desktop/demo/MemoryProfile.java @@ -0,0 +1,96 @@ +package com.openfin.desktop.demo; + +import com.openfin.desktop.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; + + +/** + * This class can be used to profile memory usage of Java Adapter for communicating with Runtime. The initial version + * just keeps calling getMachineId API. It can easily extended to test other APIs. + * + * VisualVM, available from https://visualvm.github.io/, can be used to monitor memory usgage while this code is running + */ + +public class MemoryProfile { + private final static Logger logger = LoggerFactory.getLogger(MemoryProfile.class.getName()); + + public static void main(String[] args) { + RuntimeConfiguration runtimeConfiguration = new RuntimeConfiguration(); + String connectionUuid = MemoryProfile.class.getName(); + String desktopVersion = java.lang.System.getProperty("com.openfin.demo.version"); + if (desktopVersion == null) { + desktopVersion = "stable"; + } + runtimeConfiguration.setRuntimeVersion(desktopVersion); + try { + final DesktopConnection desktopConnection = new DesktopConnection(connectionUuid); + DesktopStateListener listener = new DesktopStateListener() { + @Override + public void onReady() { + launchThread(desktopConnection); + } + @Override + public void onClose(String error) { + + } + @Override + public void onError(String reason) { + logger.error(String.format("onError %s", reason)); + } + + @Override + public void onMessage(String message) { + } + @Override + public void onOutgoingMessage(String message) { + } + }; + desktopConnection.connect(runtimeConfiguration, listener, 50); + } catch (Exception e) { + logger.error("", e); + } + } + + private static void launchThread(DesktopConnection desktopConnection) { + Thread t = new Thread() { + @Override + public void run() { + OpenFinRuntime openfinSystem = new OpenFinRuntime(desktopConnection); + AtomicInteger callCount = new AtomicInteger(); + AtomicBoolean shouldRun = new AtomicBoolean(true); + while (shouldRun.get()) { + try { + CountDownLatch latch = new CountDownLatch(1); + openfinSystem.getMachineId(new AckListener() { + @Override + public void onSuccess(Ack ack) { + if (ack.isSuccessful()) { + logger.info(String.format("API call count %d", callCount.incrementAndGet())); + latch.countDown(); + } else { + logger.error(String.format("API failed %s", ack.getReason())); + shouldRun.set(false); + } + } + @Override + public void onError(Ack ack) { + logger.error(String.format("API failed %s", ack.getReason())); + shouldRun.set(false); + } + }); + latch.await(1, TimeUnit.SECONDS); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + } + }; + t.start(); + } +}