1 | throw 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) { console.out(JSON.stringify(evt)); });
|
---|
42 | * ...
|
---|
43 | * handle2.close();
|
---|
44 | * handle1.close();
|
---|
45 | */
|
---|
46 | function 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) { console.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 returned. If the timeout
|
---|
94 | * is 'null', waiting will never 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 distributed through
|
---|
102 | * the service SERVER/SERVICE_DESC. If an event has no
|
---|
103 | * description or access to the data by name is not important,
|
---|
104 | * requireNamed can 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 the received data to an event object has failed
|
---|
110 | *
|
---|
111 | * @returns {Event}
|
---|
112 | * A valid event is returned, undefined in the case waiting for an
|
---|
113 | * event has timed out and exceptions are supressed by a negative
|
---|
114 | * timeout.
|
---|
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 | }
|
---|