Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'examples/com.windriver.tcf.examples.daytime/src/com/windriver/tcf/examples/daytime/DaytimeServiceProxy.java')
-rw-r--r--examples/com.windriver.tcf.examples.daytime/src/com/windriver/tcf/examples/daytime/DaytimeServiceProxy.java63
1 files changed, 63 insertions, 0 deletions
diff --git a/examples/com.windriver.tcf.examples.daytime/src/com/windriver/tcf/examples/daytime/DaytimeServiceProxy.java b/examples/com.windriver.tcf.examples.daytime/src/com/windriver/tcf/examples/daytime/DaytimeServiceProxy.java
new file mode 100644
index 000000000..2bf385471
--- /dev/null
+++ b/examples/com.windriver.tcf.examples.daytime/src/com/windriver/tcf/examples/daytime/DaytimeServiceProxy.java
@@ -0,0 +1,63 @@
+package com.windriver.tcf.examples.daytime;
+
+import com.windriver.tcf.api.core.Command;
+import com.windriver.tcf.api.protocol.IChannel;
+import com.windriver.tcf.api.protocol.IToken;
+import com.windriver.tcf.api.protocol.Protocol;
+
+public class DaytimeServiceProxy implements IDaytimeService {
+
+ private final IChannel channel;
+
+ DaytimeServiceProxy(IChannel channel) {
+ this.channel = channel;
+ }
+
+ /**
+ * Return service name, as it appears on the wire - a TCF name of the service.
+ */
+ public String getName() {
+ return NAME;
+ }
+
+ /**
+ * The method translates arguments to JSON string and sends the command message
+ * to remote server. When response arrives, it is translated from JSON to
+ * Java object, which are used to call call-back object.
+ *
+ * The translation (marshaling) is done by using utility class Command.
+ */
+ public IToken getTimeOfDay(String tz, final DoneGetTimeOfDay done) {
+ return new Command(channel, this, "getTimeOfDay", new Object[]{ tz }) {
+ @Override
+ public void done(Exception error, Object[] args) {
+ String str = null;
+ if (error == null) {
+ assert args.length == 3;
+ error = toError(args[0], args[1]);
+ str = (String)args[2];
+ }
+ done.doneGetTimeOfDay(token, error, str);
+ }
+ }.token;
+ }
+
+ static {
+ /*
+ * Make Daytime Service proxy available to all potential clients by creating
+ * the proxy object every time a TCF communication channel is opened.
+ * Note: extension point "com.windriver.tcf.api.startup" is used to load this class
+ * at TCF startup time, so proxy factory is properly activated even if nobody
+ * import directly from this plugin.
+ */
+ Protocol.addChannelOpenListener(new Protocol.ChannelOpenListener() {
+
+ public void onChannelOpen(IChannel channel) {
+ // Check if remote server provides Daytime service
+ if (channel.getRemoteService(IDaytimeService.NAME) == null) return;
+ // Create service proxy
+ channel.setServiceProxy(IDaytimeService.class, new DaytimeServiceProxy(channel));
+ }
+ });
+ }
+}

Back to the top