diff --git a/src/main/java/com/openfin/desktop/demo/ChannelExample.java b/src/main/java/com/openfin/desktop/demo/ChannelExample.java index 5b91f65..3078a34 100644 --- a/src/main/java/com/openfin/desktop/demo/ChannelExample.java +++ b/src/main/java/com/openfin/desktop/demo/ChannelExample.java @@ -65,7 +65,7 @@ public void onSuccess(ChannelProvider provider) { provider.register("getValue", new ChannelAction() { @Override - public JSONObject invoke(String action, JSONObject payload) { + public JSONObject invoke(String action, JSONObject payload, JSONObject senderIdentity) { logger.info(String.format("provider processing action %s, payload=%s", action, payload.toString())); JSONObject obj = new JSONObject(); obj.put("value", x.get()); @@ -74,7 +74,7 @@ public JSONObject invoke(String action, JSONObject payload) { }); provider.register("increment", new ChannelAction() { @Override - public JSONObject invoke(String action, JSONObject payload) { + public JSONObject invoke(String action, JSONObject payload, JSONObject senderIdentity) { logger.info(String.format("provider processing action %s, payload=%s", action, payload.toString())); JSONObject obj = new JSONObject(); obj.put("value", x.incrementAndGet()); @@ -84,7 +84,7 @@ public JSONObject invoke(String action, JSONObject payload) { }); provider.register("incrementBy", new ChannelAction() { @Override - public JSONObject invoke(String action, JSONObject payload) { + public JSONObject invoke(String action, JSONObject payload, JSONObject senderIdentity) { logger.info(String.format("provider processing action %s, payload=%s", action, payload.toString())); int delta = payload.getInt("delta"); JSONObject obj = new JSONObject(); @@ -100,13 +100,13 @@ public JSONObject invoke(String action, JSONObject payload) { * Create a channel client that invokes "getValue", "increment" and "incrementBy n" actions */ public void createChannelClient() { - desktopConnection.getChannel(CHANNEL_NAME).connect(CHANNEL_NAME + "Client", new AsyncCallback() { + desktopConnection.getChannel(CHANNEL_NAME).connect(new AsyncCallback() { @Override public void onSuccess(ChannelClient client) { // register a channel event client.register("event", new ChannelAction() { @Override - public JSONObject invoke(String action, JSONObject payload) { + public JSONObject invoke(String action, JSONObject payload, JSONObject senderIdentity) { logger.info("channel event {}", action); return null; } diff --git a/src/main/java/com/openfin/desktop/demo/FDC3Example.java b/src/main/java/com/openfin/desktop/demo/FDC3Example.java index 38d853c..8487517 100644 --- a/src/main/java/com/openfin/desktop/demo/FDC3Example.java +++ b/src/main/java/com/openfin/desktop/demo/FDC3Example.java @@ -166,8 +166,8 @@ protected JScrollPane layoutOutputPanel() { void launchOpenfin() throws DesktopException, DesktopIOException, IOException, InterruptedException { RuntimeConfiguration config = new RuntimeConfiguration(); -// config.setRuntimeVersion("stable"); - config.setRuntimeVersion("10.66.41.18"); + config.setRuntimeVersion("alpha"); +// config.setRuntimeVersion("10.66.41.18"); config.setAdditionalRuntimeArguments("--v=1 "); // serviceConfig = new JSONArray(); // JSONObject layout = new JSONObject(); @@ -182,7 +182,7 @@ void launchOpenfin() throws DesktopException, DesktopIOException, IOException, I @Override public void onReady() { this.fdc3Client = FDC3Client.getInstance(this.desktopConnection); - this.fdc3Client.connect("JavaFDC3Demo", new AckListener() { + this.fdc3Client.connect(new AckListener() { @Override public void onSuccess(Ack ack) { btnLaunchRed.setEnabled(true); diff --git a/src/main/java/com/openfin/desktop/demo/FxLayoutFrame.java b/src/main/java/com/openfin/desktop/demo/FxLayoutFrame.java index 99aaa16..d2a67b6 100644 --- a/src/main/java/com/openfin/desktop/demo/FxLayoutFrame.java +++ b/src/main/java/com/openfin/desktop/demo/FxLayoutFrame.java @@ -58,7 +58,7 @@ public void run() { @Override public void onSuccess(Ack ack) { ExternalWindowObserver observer = (ExternalWindowObserver) ack.getSource(); - observer.getDesktopConnection().getChannel(LayoutServiceChannelName).connect(LayoutServiceChannelName, + observer.getDesktopConnection().getChannel(LayoutServiceChannelName).connect( new AsyncCallback() { @Override public void onSuccess(ChannelClient client) { diff --git a/src/main/java/com/openfin/desktop/demo/LaunchManifestDemo.java b/src/main/java/com/openfin/desktop/demo/LaunchManifestDemo.java index 88de4cd..38161b1 100644 --- a/src/main/java/com/openfin/desktop/demo/LaunchManifestDemo.java +++ b/src/main/java/com/openfin/desktop/demo/LaunchManifestDemo.java @@ -176,7 +176,7 @@ private void createExternalWindowObserver() { @Override public void onSuccess(Ack ack) { ExternalWindowObserver observer = (ExternalWindowObserver) ack.getSource(); - observer.getDesktopConnection().getChannel(LayoutServiceChannelName).connect(LayoutServiceChannelName, + observer.getDesktopConnection().getChannel(LayoutServiceChannelName).connect( new AsyncCallback() { @Override public void onSuccess(ChannelClient client) { @@ -184,7 +184,7 @@ public void onSuccess(ChannelClient client) { client.register("event", new ChannelAction() { @Override - public JSONObject invoke(String action, JSONObject payload) { + public JSONObject invoke(String action, JSONObject payload, JSONObject senderIdentity) { System.out.printf("channel event " + action); return null; } diff --git a/src/main/java/com/openfin/desktop/demo/LayoutFrame.java b/src/main/java/com/openfin/desktop/demo/LayoutFrame.java index 14ea901..1a0f096 100644 --- a/src/main/java/com/openfin/desktop/demo/LayoutFrame.java +++ b/src/main/java/com/openfin/desktop/demo/LayoutFrame.java @@ -113,7 +113,7 @@ public void actionPerformed(ActionEvent e) { @Override public void onSuccess(Ack ack) { ExternalWindowObserver observer = (ExternalWindowObserver) ack.getSource(); - observer.getDesktopConnection().getChannel(LayoutServiceChannelName).connect(LayoutServiceChannelName, + observer.getDesktopConnection().getChannel(LayoutServiceChannelName).connect( new AsyncCallback() { @Override public void onSuccess(ChannelClient client) { @@ -130,7 +130,7 @@ public void actionPerformed(ActionEvent e) { client.register("event", new ChannelAction() { @Override - public JSONObject invoke(String action, JSONObject payload) { + public JSONObject invoke(String action, JSONObject payload, JSONObject senderIdentity) { System.out.printf("channel event " + action); return null; } diff --git a/src/main/java/com/openfin/desktop/demo/LayoutServiceDemo.java b/src/main/java/com/openfin/desktop/demo/LayoutServiceDemo.java index 6461c86..b22ac8a 100644 --- a/src/main/java/com/openfin/desktop/demo/LayoutServiceDemo.java +++ b/src/main/java/com/openfin/desktop/demo/LayoutServiceDemo.java @@ -159,7 +159,7 @@ void launchOpenfin() throws DesktopException, DesktopIOException, IOException, I if (rvm != null) { config.setLaunchRVMPath(rvm); } - config.setRuntimeVersion("stable"); + config.setRuntimeVersion("alpha"); config.setAdditionalRuntimeArguments("--v=1 "); serviceConfig = new JSONArray(); JSONObject layout = new JSONObject(); diff --git a/src/test/java/com/openfin/desktop/ChannelTest.java b/src/test/java/com/openfin/desktop/ChannelTest.java index f96a490..22cb8a5 100644 --- a/src/test/java/com/openfin/desktop/ChannelTest.java +++ b/src/test/java/com/openfin/desktop/ChannelTest.java @@ -73,12 +73,11 @@ public void createChannelClient() throws Exception { desktopConnection.getChannel(channelName).create(new AsyncCallback() { @Override public void onSuccess(ChannelProvider provider) { - desktopConnection.getChannel(channelName).connect(channelName, new AsyncCallback() { + desktopConnection.getChannel(channelName).connect(new AsyncCallback() { @Override public void onSuccess(ChannelClient result) { latch.countDown(); } - }); } }); @@ -87,6 +86,66 @@ public void onSuccess(ChannelClient result) { assertEquals(0, latch.getCount()); } + + @Ignore + @Test + public void multipleChannelClients() throws Exception { + CountDownLatch latch1 = new CountDownLatch(1); + CountDownLatch latch2 = new CountDownLatch(1); + final String channelName = "createMultipleChannelClientTest"; + final String clientActionName = "clientAction"; + final String providerActionName = "providerAction"; + desktopConnection.getChannel(channelName).create(new AsyncCallback() { + @Override + public void onSuccess(ChannelProvider provider) { + + provider.register(providerActionName, new ChannelAction() { + + @Override + public JSONObject invoke(String action, JSONObject payload, JSONObject senderIdentity) { + return null; + } + }); + + //first channel client + desktopConnection.getChannel(channelName).connect(new AsyncCallback() { + @Override + public void onSuccess(ChannelClient client) { + client.dispatch(providerActionName, new JSONObject(), null); + + client.register(clientActionName, new ChannelAction() { + @Override + public JSONObject invoke(String action, JSONObject payload, JSONObject senderIdentity) { + latch1.countDown(); + return null; + } + }); + } + }); + //second channel client + desktopConnection.getChannel(channelName).connect(new AsyncCallback() { + @Override + public void onSuccess(ChannelClient client) { + client.register(clientActionName, new ChannelAction() { + @Override + public JSONObject invoke(String action, JSONObject payload, JSONObject senderIdentity) { + latch2.countDown(); + return null; + } + }); + + provider.publish(clientActionName, new JSONObject(), null); + } + }); + } + }); + + latch1.await(10, TimeUnit.SECONDS); + latch2.await(10, TimeUnit.SECONDS); + + assertEquals(0, latch1.getCount()); + assertEquals(0, latch2.getCount()); + } @Test public void registerAction() throws Exception { @@ -97,7 +156,7 @@ public void registerAction() throws Exception { public void onSuccess(ChannelProvider provider) { provider.register("currentTime", new ChannelAction() { @Override - public JSONObject invoke(String action, JSONObject payload) { + public JSONObject invoke(String action, JSONObject payload, JSONObject senderIdentity) { return payload.put("currentTime", java.lang.System.currentTimeMillis()); } }); @@ -123,13 +182,13 @@ public void invokeProviderAction() throws Exception { public void onSuccess(ChannelProvider provider) { provider.register(actionName, new ChannelAction() { @Override - public JSONObject invoke(String action, JSONObject payload) { + public JSONObject invoke(String action, JSONObject payload, JSONObject senderIdentity) { int currentValue = payload.getInt("value"); return payload.put("value", currentValue + 1); } }); - desktopConnection.getChannel(channelName).connect(channelName, new AsyncCallback() { + desktopConnection.getChannel(channelName).connect(new AsyncCallback() { @Override public void onSuccess(ChannelClient client) { @@ -158,48 +217,75 @@ public void onError(Ack ack) { assertEquals(0, latch.getCount()); assertEquals(initValue + 1, resultValue.get()); } - + @Test - public void publishToClient() throws Exception { - final String channelName = "publishToClientTest"; - final String actionName = "message"; - final String actionMessage = "actionMessage"; + public void invokeClientAction() throws Exception { + final String channelName = "invokeClientActionTest"; + final String providerActionName = "invokeClientAction"; + final String clientActionName = "clientAction"; CountDownLatch latch = new CountDownLatch(1); desktopConnection.getChannel(channelName).create(new AsyncCallback() { @Override public void onSuccess(ChannelProvider provider) { - desktopConnection.getChannel(channelName).addChannelListener(new ChannelListener() { + provider.register(providerActionName, new ChannelAction() { @Override - public void onChannelConnect(ConnectionEvent connectionEvent) { - // once the channel is connected, invoke publish method - JSONObject payload = new JSONObject(); - payload.put("message", actionMessage); - provider.publish(actionName, payload, null); + public JSONObject invoke(String action, JSONObject payload, JSONObject senderIdentity) { + provider.dispatch(senderIdentity, clientActionName, new JSONObject(), null); + return null; } + }); + desktopConnection.getChannel(channelName).connect(new AsyncCallback() { @Override - public void onChannelDisconnect(ConnectionEvent connectionEvent) { + public void onSuccess(ChannelClient client) { + client.register(clientActionName, new ChannelAction() { + @Override + public JSONObject invoke(String action, JSONObject payload, JSONObject senderIdentity) { + latch.countDown(); + return null; + } + }); + client.dispatch(providerActionName, new JSONObject(), null); } }); + } + }); - desktopConnection.getChannel(channelName).connect(channelName, new AsyncCallback() { + latch.await(10, TimeUnit.SECONDS); + + assertEquals(0, latch.getCount()); + } + + @Test + public void publishToClient() throws Exception { + final String channelName = "publishToClientTest"; + final String actionName = "message"; + final String actionMessage = "actionMessage"; + CountDownLatch latch = new CountDownLatch(1); + desktopConnection.getChannel(channelName).create(new AsyncCallback() { + @Override + public void onSuccess(ChannelProvider provider) { + desktopConnection.getChannel(channelName).connect(new AsyncCallback() { @Override public void onSuccess(ChannelClient client) { client.register(actionName, new ChannelAction() { @Override - public JSONObject invoke(String action, JSONObject payload) { + public JSONObject invoke(String action, JSONObject payload, JSONObject senderIdentity) { if (actionName.equals(action) && actionMessage.equals(payload.getString("message"))) { latch.countDown(); } return null; } }); + + JSONObject payload = new JSONObject(); + payload.put("message", actionMessage); + provider.publish(actionName, payload, null); } - }); } }); @@ -229,7 +315,7 @@ public void onChannelDisconnect(ConnectionEvent connectionEvent) { } }); - desktopConnection.getChannel(channelName).connect(channelName, new AsyncCallback() { + desktopConnection.getChannel(channelName).connect(new AsyncCallback() { @Override public void onSuccess(ChannelClient client) { client.disconnect(null); @@ -269,13 +355,13 @@ public JSONObject invoke(String action, JSONObject payload, JSONObject senderId) provider.register(actionName, new ChannelAction() { @Override - public JSONObject invoke(String action, JSONObject payload) { + public JSONObject invoke(String action, JSONObject payload, JSONObject senderIdentity) { int currentValue = payload.getInt("value"); return payload.put("value", currentValue + 1); } }); - desktopConnection.getChannel(channelName).connect(channelName, new AsyncCallback() { + desktopConnection.getChannel(channelName).connect(new AsyncCallback() { @Override public void onSuccess(ChannelClient client) {