source: trunk/FACT++/scripts/doc/Subscription.js@ 14675

Last change on this file since 14675 was 14675, checked in by tbretz, 12 years ago
Made sure that nobody tried to start a docu script.
File size: 4.4 KB
Line 
1throw new Error("Description for built in functions. Must not be included!");
2/**
3 * @fileOverview
4 * Documentation of a DIM service Subscription
5 */
6
7/**
8 * @class
9 *
10 * Subscription to a DIM service.
11 *
12 * This class represents the subscription to a DIM service. Received
13 * events are first copied to an even queue internally, to avoid
14 * any processing blocking the DIM thread (which could block the
15 * whole network as a result). Then the events are processed.
16 * If a callback is installed, the processing will take place in
17 * another JavaScript thread. Physically it will run synchronously
18 * with the other JavaScript threads. However, the processing blocks
19 * event processing. Consequetly, processing should on average be
20 * faster than the frequency with which events arrive to ensure they
21 * will not fill up the memory and possible reactions to there
22 * contents will happen within a reasonable time and not delayed
23 * too much.
24 *
25 * @param {String} service
26 * Name of the DIM service to which a subscription should be made.
27 * Usully of the form SERVER/SUBSCRIPTION.
28 *
29 * @param {Function} [callback]
30 * An optional function which is set as 'onchange' property.
31 * This can avoid to loose th first event after the subscription
32 * before the callback is set by the 'onchange' property (which
33 * is very unlikely).
34 *
35 * @throws
36 * <li>If number or type of arguments is wrong
37 * <li>If an open subscription to the same service already exists.
38 *
39 * @example
40 * var handle1 = new Subscription("MAGIC_WEATHER/DATA");
41 * var handle2 = new Subscription("TNG_WEATHER/DATA", function(evt) { dim.out(JSON.stringify(evt)); });
42 * ...
43 * handle2.close();
44 * handle1.close();
45 */
46function Subscription(service, callback)
47{
48 /**
49 *
50 * The name of the service subscribed to.
51 *
52 * @constant
53 * @type String
54 *
55 */
56 this.name = service;
57
58 /**
59 *
60 * Boolean value which is set to false if the Subscription was closed.
61 *
62 * @type Boolean
63 *
64 */
65 this.isOpen = false;
66
67 /**
68 *
69 * Callback in case of event reception.
70 *
71 * To install a callback in case a new event of this Subscription
72 * was received, set this property to a function. The argument
73 * provided to the function is identical with the object returned
74 * by Subscription.get(). For the code executed, the same rules apply
75 * than for a thread created with Thread.
76 *
77 * @type Function
78 *
79 * @example
80 * handle.onchange = function(event) { dim.out(JSON.stringify(event); };
81 *
82 */
83 this.onchange = callback;
84
85 /**
86 *
87 * Returns the last received event of this subscription.
88 *
89 * @param {Integer} [timeout=0]
90 * A timeout in millisecond to wait for an event to arrive.
91 * This timeout only applied if no event has been received yet
92 * after a new Subscription has been created. If an event
93 * is already available, the event is received. If the timeout
94 * is 'null', waiting will nevr timeout until an event was received.
95 * If the timeout is less than zero, no exception will be thrown,
96 * but 'undefined' returned in case of timeout. The corresponding
97 * timeout is then Math.abs(timeout).
98 *
99 * @param {Boolean} [requireNamed=true]
100 * Usually an event is only considered complete, if also the
101 * corresponding decription is available distcibuted through
102 * the service SERVER/SERVICE_DESC. If an event has no
103 * subscription or it is not important, requireNamed can
104 * be set to false.
105 *
106 * @throws
107 * <li> If number or type of arguments is wrong
108 * <li> After a timeout, if the timeout value was greater or equal zero
109 * <li> If conversion of th received data to an event object has failed
110 *
111 * @returns {Event}
112 * If the thread was still known, true is returned, false
113 * otherwise. If the thread terminated already, false is
114 * returned.
115 *
116 */
117 this.get = function() { /* [native code] */ }
118
119 /**
120 *
121 * Unsubscribe from an existing subscription. Note that all open
122 * subscription produce network traffic and should be omitted if
123 * not needed.
124 *
125 * @returns {Boolean}
126 * true if the subscription was still open, false if it was
127 * already closed.
128 *
129 */
130 this.close() = function() { /* [native code] */ }
131}
Note: See TracBrowser for help on using the repository browser.