Merge branch 'master' of ssh://gerrit.onlab.us:29418/onos-next
Showing
12 changed files
with
214 additions
and
27 deletions
1 | package org.onlab.onos.store.service; | 1 | package org.onlab.onos.store.service; |
2 | 2 | ||
3 | +import com.google.common.base.MoreObjects; | ||
4 | + | ||
3 | /** | 5 | /** |
4 | * Database read request. | 6 | * Database read request. |
5 | */ | 7 | */ |
... | @@ -31,6 +33,9 @@ public class ReadRequest { | ... | @@ -31,6 +33,9 @@ public class ReadRequest { |
31 | 33 | ||
32 | @Override | 34 | @Override |
33 | public String toString() { | 35 | public String toString() { |
34 | - return "ReadRequest [tableName=" + tableName + ", key=" + key + "]"; | 36 | + return MoreObjects.toStringHelper(getClass()) |
37 | + .add("tableName", tableName) | ||
38 | + .add("key", key) | ||
39 | + .toString(); | ||
35 | } | 40 | } |
36 | } | 41 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
1 | package org.onlab.onos.store.service; | 1 | package org.onlab.onos.store.service; |
2 | 2 | ||
3 | +import com.google.common.base.MoreObjects; | ||
4 | + | ||
3 | 5 | ||
4 | /** | 6 | /** |
5 | * Database read result. | 7 | * Database read result. |
... | @@ -18,7 +20,7 @@ public class ReadResult { | ... | @@ -18,7 +20,7 @@ public class ReadResult { |
18 | 20 | ||
19 | /** | 21 | /** |
20 | * Returns database table name. | 22 | * Returns database table name. |
21 | - * @return table name. | 23 | + * @return table name |
22 | */ | 24 | */ |
23 | public String tableName() { | 25 | public String tableName() { |
24 | return tableName; | 26 | return tableName; |
... | @@ -26,7 +28,7 @@ public class ReadResult { | ... | @@ -26,7 +28,7 @@ public class ReadResult { |
26 | 28 | ||
27 | /** | 29 | /** |
28 | * Returns database table key. | 30 | * Returns database table key. |
29 | - * @return key. | 31 | + * @return key |
30 | */ | 32 | */ |
31 | public String key() { | 33 | public String key() { |
32 | return key; | 34 | return key; |
... | @@ -39,4 +41,13 @@ public class ReadResult { | ... | @@ -39,4 +41,13 @@ public class ReadResult { |
39 | public VersionedValue value() { | 41 | public VersionedValue value() { |
40 | return value; | 42 | return value; |
41 | } | 43 | } |
44 | + | ||
45 | + @Override | ||
46 | + public String toString() { | ||
47 | + return MoreObjects.toStringHelper(getClass()) | ||
48 | + .add("tableName", tableName) | ||
49 | + .add("key", key) | ||
50 | + .add("value", value) | ||
51 | + .toString(); | ||
52 | + } | ||
42 | } | 53 | } | ... | ... |
... | @@ -2,6 +2,8 @@ package org.onlab.onos.store.service; | ... | @@ -2,6 +2,8 @@ package org.onlab.onos.store.service; |
2 | 2 | ||
3 | import java.util.Arrays; | 3 | import java.util.Arrays; |
4 | 4 | ||
5 | +import com.google.common.base.MoreObjects; | ||
6 | + | ||
5 | /** | 7 | /** |
6 | * Wrapper object that holds the object (as byte array) and its version. | 8 | * Wrapper object that holds the object (as byte array) and its version. |
7 | */ | 9 | */ |
... | @@ -38,7 +40,9 @@ public class VersionedValue { | ... | @@ -38,7 +40,9 @@ public class VersionedValue { |
38 | 40 | ||
39 | @Override | 41 | @Override |
40 | public String toString() { | 42 | public String toString() { |
41 | - return "VersionedValue [value=" + Arrays.toString(value) + ", version=" | 43 | + return MoreObjects.toStringHelper(getClass()) |
42 | - + version + "]"; | 44 | + .add("version", version) |
45 | + .add("value", Arrays.toString(value)) | ||
46 | + .toString(); | ||
43 | } | 47 | } |
44 | } | 48 | } | ... | ... |
... | @@ -4,6 +4,8 @@ import static com.google.common.base.Preconditions.checkArgument; | ... | @@ -4,6 +4,8 @@ import static com.google.common.base.Preconditions.checkArgument; |
4 | 4 | ||
5 | import java.util.Objects; | 5 | import java.util.Objects; |
6 | 6 | ||
7 | +import com.google.common.base.MoreObjects; | ||
8 | + | ||
7 | /** | 9 | /** |
8 | * Database write request. | 10 | * Database write request. |
9 | */ | 11 | */ |
... | @@ -67,10 +69,13 @@ public class WriteRequest { | ... | @@ -67,10 +69,13 @@ public class WriteRequest { |
67 | 69 | ||
68 | @Override | 70 | @Override |
69 | public String toString() { | 71 | public String toString() { |
70 | - return "WriteRequest [tableName=" + tableName + ", key=" + key | 72 | + return MoreObjects.toStringHelper(getClass()) |
71 | - + ", newValue=" + newValue | 73 | + .add("tableName", tableName) |
72 | - + ", previousVersion=" + previousVersion | 74 | + .add("key", key) |
73 | - + ", oldValue=" + oldValue; | 75 | + .add("newValue", newValue) |
76 | + .add("previousVersion", previousVersion) | ||
77 | + .add("oldValue", oldValue) | ||
78 | + .toString(); | ||
74 | } | 79 | } |
75 | 80 | ||
76 | @Override | 81 | @Override | ... | ... |
1 | package org.onlab.onos.store.service; | 1 | package org.onlab.onos.store.service; |
2 | 2 | ||
3 | +import com.google.common.base.MoreObjects; | ||
4 | + | ||
3 | 5 | ||
4 | /** | 6 | /** |
5 | * Database write result. | 7 | * Database write result. |
... | @@ -27,4 +29,13 @@ public class WriteResult { | ... | @@ -27,4 +29,13 @@ public class WriteResult { |
27 | public VersionedValue previousValue() { | 29 | public VersionedValue previousValue() { |
28 | return previousValue; | 30 | return previousValue; |
29 | } | 31 | } |
32 | + | ||
33 | + @Override | ||
34 | + public String toString() { | ||
35 | + return MoreObjects.toStringHelper(getClass()) | ||
36 | + .add("tableName", tableName) | ||
37 | + .add("key", key) | ||
38 | + .add("previousValue", previousValue) | ||
39 | + .toString(); | ||
40 | + } | ||
30 | } | 41 | } | ... | ... |
... | @@ -69,10 +69,10 @@ public class ClusterMessagingProtocol implements Protocol<TcpMember> { | ... | @@ -69,10 +69,10 @@ public class ClusterMessagingProtocol implements Protocol<TcpMember> { |
69 | private final Logger log = getLogger(getClass()); | 69 | private final Logger log = getLogger(getClass()); |
70 | 70 | ||
71 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 71 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
72 | - ClusterService clusterService; | 72 | + protected ClusterService clusterService; |
73 | 73 | ||
74 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 74 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
75 | - ClusterCommunicationService clusterCommunicator; | 75 | + protected ClusterCommunicationService clusterCommunicator; |
76 | 76 | ||
77 | public static final MessageSubject COPYCAT_PING = | 77 | public static final MessageSubject COPYCAT_PING = |
78 | new MessageSubject("copycat-raft-consensus-ping"); | 78 | new MessageSubject("copycat-raft-consensus-ping"); | ... | ... |
... | @@ -49,10 +49,10 @@ public class DatabaseManager implements DatabaseService, DatabaseAdminService { | ... | @@ -49,10 +49,10 @@ public class DatabaseManager implements DatabaseService, DatabaseAdminService { |
49 | private final Logger log = getLogger(getClass()); | 49 | private final Logger log = getLogger(getClass()); |
50 | 50 | ||
51 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 51 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
52 | - ClusterService clusterService; | 52 | + protected ClusterService clusterService; |
53 | 53 | ||
54 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 54 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
55 | - ClusterMessagingProtocol copycatMessagingProtocol; | 55 | + protected ClusterMessagingProtocol copycatMessagingProtocol; |
56 | 56 | ||
57 | public static final String LOG_FILE_PREFIX = "onos-copy-cat-log"; | 57 | public static final String LOG_FILE_PREFIX = "onos-copy-cat-log"; |
58 | 58 | ... | ... |
... | @@ -82,7 +82,7 @@ public class LinkDiscovery implements TimerTask { | ... | @@ -82,7 +82,7 @@ public class LinkDiscovery implements TimerTask { |
82 | private final PacketService pktService; | 82 | private final PacketService pktService; |
83 | private final MastershipService mastershipService; | 83 | private final MastershipService mastershipService; |
84 | private Timeout timeout; | 84 | private Timeout timeout; |
85 | - private boolean isStopped; | 85 | + private volatile boolean isStopped; |
86 | 86 | ||
87 | /** | 87 | /** |
88 | * Instantiates discovery manager for the given physical switch. Creates a | 88 | * Instantiates discovery manager for the given physical switch. Creates a |
... | @@ -243,8 +243,10 @@ public class LinkDiscovery implements TimerTask { | ... | @@ -243,8 +243,10 @@ public class LinkDiscovery implements TimerTask { |
243 | public void run(final Timeout t) { | 243 | public void run(final Timeout t) { |
244 | boolean isMaster = mastershipService.getLocalRole(device.id()) == MASTER; | 244 | boolean isMaster = mastershipService.getLocalRole(device.id()) == MASTER; |
245 | if (!isMaster) { | 245 | if (!isMaster) { |
246 | - // reschedule timer | 246 | + if (!isStopped()) { |
247 | - timeout = Timer.getTimer().newTimeout(this, this.probeRate, MILLISECONDS); | 247 | + // reschedule timer |
248 | + timeout = Timer.getTimer().newTimeout(this, this.probeRate, MILLISECONDS); | ||
249 | + } | ||
248 | return; | 250 | return; |
249 | } | 251 | } |
250 | 252 | ||
... | @@ -280,16 +282,18 @@ public class LinkDiscovery implements TimerTask { | ... | @@ -280,16 +282,18 @@ public class LinkDiscovery implements TimerTask { |
280 | } | 282 | } |
281 | } | 283 | } |
282 | 284 | ||
283 | - // reschedule timer | 285 | + if (!isStopped()) { |
284 | - timeout = Timer.getTimer().newTimeout(this, this.probeRate, MILLISECONDS); | 286 | + // reschedule timer |
287 | + timeout = Timer.getTimer().newTimeout(this, this.probeRate, MILLISECONDS); | ||
288 | + } | ||
285 | } | 289 | } |
286 | 290 | ||
287 | - public void stop() { | 291 | + public synchronized void stop() { |
288 | timeout.cancel(); | 292 | timeout.cancel(); |
289 | isStopped = true; | 293 | isStopped = true; |
290 | } | 294 | } |
291 | 295 | ||
292 | - public void start() { | 296 | + public synchronized void start() { |
293 | if (isStopped) { | 297 | if (isStopped) { |
294 | timeout = Timer.getTimer().newTimeout(this, 0, MILLISECONDS); | 298 | timeout = Timer.getTimer().newTimeout(this, 0, MILLISECONDS); |
295 | isStopped = false; | 299 | isStopped = false; | ... | ... |
... | @@ -71,6 +71,7 @@ | ... | @@ -71,6 +71,7 @@ |
71 | var ONOS = $.onos({ | 71 | var ONOS = $.onos({ |
72 | comment: "configuration options", | 72 | comment: "configuration options", |
73 | startVid: 'topo', | 73 | startVid: 'topo', |
74 | +// startVid: 'sampleKeys', | ||
74 | trace: false | 75 | trace: false |
75 | }); | 76 | }); |
76 | </script> | 77 | </script> |
... | @@ -82,6 +83,7 @@ | ... | @@ -82,6 +83,7 @@ |
82 | <script src="sample2.js"></script> | 83 | <script src="sample2.js"></script> |
83 | <script src="sampleAlt2.js"></script> | 84 | <script src="sampleAlt2.js"></script> |
84 | <script src="sampleRadio.js"></script> | 85 | <script src="sampleRadio.js"></script> |
86 | + <script src="sampleKeys.js"></script> | ||
85 | 87 | ||
86 | <!-- Contributed (application) views injected here --> | 88 | <!-- Contributed (application) views injected here --> |
87 | <!-- TODO: replace with template marker and inject refs server-side --> | 89 | <!-- TODO: replace with template marker and inject refs server-side --> | ... | ... |
... | @@ -49,13 +49,40 @@ | ... | @@ -49,13 +49,40 @@ |
49 | ctx: '' | 49 | ctx: '' |
50 | }, | 50 | }, |
51 | built = false, | 51 | built = false, |
52 | - errorCount = 0; | 52 | + errorCount = 0, |
53 | + keyHandler = {}; | ||
53 | 54 | ||
54 | // DOM elements etc. | 55 | // DOM elements etc. |
55 | var $view, | 56 | var $view, |
56 | $mastRadio; | 57 | $mastRadio; |
57 | 58 | ||
58 | 59 | ||
60 | + function whatKey(code) { | ||
61 | + switch (code) { | ||
62 | + case 13: return 'enter'; | ||
63 | + case 16: return 'shift'; | ||
64 | + case 17: return 'ctrl'; | ||
65 | + case 18: return 'alt'; | ||
66 | + case 27: return 'esc'; | ||
67 | + case 32: return 'space'; | ||
68 | + case 37: return 'leftArrow'; | ||
69 | + case 38: return 'upArrow'; | ||
70 | + case 39: return 'rightArrow'; | ||
71 | + case 40: return 'downArrow'; | ||
72 | + case 91: return 'cmdLeft'; | ||
73 | + case 93: return 'cmdRight'; | ||
74 | + default: | ||
75 | + if ((code >= 48 && code <= 57) || | ||
76 | + (code >= 65 && code <= 90)) { | ||
77 | + return String.fromCharCode(code); | ||
78 | + } else if (code >= 112 && code <= 123) { | ||
79 | + return 'F' + (code - 111); | ||
80 | + } | ||
81 | + return '.'; | ||
82 | + } | ||
83 | + } | ||
84 | + | ||
85 | + | ||
59 | // .......................................................... | 86 | // .......................................................... |
60 | // Internal functions | 87 | // Internal functions |
61 | 88 | ||
... | @@ -206,9 +233,11 @@ | ... | @@ -206,9 +233,11 @@ |
206 | // the incoming view, then unload it... | 233 | // the incoming view, then unload it... |
207 | if (current.view && (current.view.vid !== view.vid)) { | 234 | if (current.view && (current.view.vid !== view.vid)) { |
208 | current.view.unload(); | 235 | current.view.unload(); |
209 | - // detach radio buttons, if they were there.. | ||
210 | - $('#mastRadio').children().detach(); | ||
211 | 236 | ||
237 | + // detach radio buttons, key handlers, etc. | ||
238 | + $('#mastRadio').children().detach(); | ||
239 | + keyHandler.fn = null; | ||
240 | + keyHandler.map = {}; | ||
212 | } | 241 | } |
213 | 242 | ||
214 | // cache new view and context | 243 | // cache new view and context |
... | @@ -283,6 +312,27 @@ | ... | @@ -283,6 +312,27 @@ |
283 | $mastRadio.node().appendChild(btnG.node()); | 312 | $mastRadio.node().appendChild(btnG.node()); |
284 | } | 313 | } |
285 | 314 | ||
315 | + function setKeyBindings(keyArg) { | ||
316 | + if ($.isFunction(keyArg)) { | ||
317 | + // set general key handler callback | ||
318 | + keyHandler.fn = keyArg; | ||
319 | + } else { | ||
320 | + // set specific key filter map | ||
321 | + keyHandler.map = keyArg; | ||
322 | + } | ||
323 | + } | ||
324 | + | ||
325 | + function keyIn() { | ||
326 | + var event = d3.event, | ||
327 | + keyCode = event.keyCode, | ||
328 | + key = whatKey(keyCode), | ||
329 | + cb = isF(keyHandler.map[key]) || isF(keyHandler.fn); | ||
330 | + | ||
331 | + if (cb) { | ||
332 | + cb(current.view.token(), key, keyCode, event); | ||
333 | + } | ||
334 | + } | ||
335 | + | ||
286 | function resize(e) { | 336 | function resize(e) { |
287 | d3.selectAll('.onosView').call(setViewDimensions); | 337 | d3.selectAll('.onosView').call(setViewDimensions); |
288 | // allow current view to react to resize event... | 338 | // allow current view to react to resize event... |
... | @@ -320,7 +370,6 @@ | ... | @@ -320,7 +370,6 @@ |
320 | this.radioButtons = null; // no radio buttons yet | 370 | this.radioButtons = null; // no radio buttons yet |
321 | this.ok = true; // valid view | 371 | this.ok = true; // valid view |
322 | } | 372 | } |
323 | - | ||
324 | } | 373 | } |
325 | 374 | ||
326 | function validateViewArgs(vid) { | 375 | function validateViewArgs(vid) { |
... | @@ -348,7 +397,8 @@ | ... | @@ -348,7 +397,8 @@ |
348 | width: this.width, | 397 | width: this.width, |
349 | height: this.height, | 398 | height: this.height, |
350 | uid: this.uid, | 399 | uid: this.uid, |
351 | - setRadio: this.setRadio | 400 | + setRadio: this.setRadio, |
401 | + setKeys: this.setKeys | ||
352 | } | 402 | } |
353 | }, | 403 | }, |
354 | 404 | ||
... | @@ -433,6 +483,10 @@ | ... | @@ -433,6 +483,10 @@ |
433 | setRadioButtons(this.vid, btnSet, cb); | 483 | setRadioButtons(this.vid, btnSet, cb); |
434 | }, | 484 | }, |
435 | 485 | ||
486 | + setKeys: function (keyArg) { | ||
487 | + setKeyBindings(keyArg); | ||
488 | + }, | ||
489 | + | ||
436 | uid: function (id) { | 490 | uid: function (id) { |
437 | return uid(this, id); | 491 | return uid(this, id); |
438 | } | 492 | } |
... | @@ -536,6 +590,8 @@ | ... | @@ -536,6 +590,8 @@ |
536 | $(window).on('hashchange', hash); | 590 | $(window).on('hashchange', hash); |
537 | $(window).on('resize', resize); | 591 | $(window).on('resize', resize); |
538 | 592 | ||
593 | + d3.select('body').on('keydown', keyIn); | ||
594 | + | ||
539 | // Invoke hashchange callback to navigate to content | 595 | // Invoke hashchange callback to navigate to content |
540 | // indicated by the window location hash. | 596 | // indicated by the window location hash. |
541 | hash(); | 597 | hash(); |
... | @@ -544,7 +600,6 @@ | ... | @@ -544,7 +600,6 @@ |
544 | reportBuildErrors(); | 600 | reportBuildErrors(); |
545 | } | 601 | } |
546 | 602 | ||
547 | - | ||
548 | // export the api and build-UI function | 603 | // export the api and build-UI function |
549 | return { | 604 | return { |
550 | ui: uiApi, | 605 | ui: uiApi, | ... | ... |
web/gui/src/main/webapp/sampleKeys.js
0 → 100644
1 | +/* | ||
2 | + * Copyright 2014 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | + | ||
17 | +/* | ||
18 | + Sample view to illustrate key bindings. | ||
19 | + | ||
20 | + @author Simon Hunt | ||
21 | + */ | ||
22 | + | ||
23 | +(function (onos) { | ||
24 | + 'use strict'; | ||
25 | + | ||
26 | + var keyDispatch = { | ||
27 | + Z: keyUndo, | ||
28 | + X: keyCut, | ||
29 | + C: keyCopy, | ||
30 | + V: keyPaste, | ||
31 | + space: keySpace | ||
32 | + }; | ||
33 | + | ||
34 | + function keyUndo(view) { | ||
35 | + note(view, 'Z = UNDO'); | ||
36 | + } | ||
37 | + | ||
38 | + function keyCut(view) { | ||
39 | + note(view, 'X = CUT'); | ||
40 | + } | ||
41 | + | ||
42 | + function keyCopy(view) { | ||
43 | + note(view, 'C = COPY'); | ||
44 | + } | ||
45 | + | ||
46 | + function keyPaste(view) { | ||
47 | + note(view, 'V = PASTE'); | ||
48 | + } | ||
49 | + | ||
50 | + function keySpace(view) { | ||
51 | + note(view, 'The SpaceBar'); | ||
52 | + } | ||
53 | + | ||
54 | + function note(view, msg) { | ||
55 | + view.$div.append('p') | ||
56 | + .text(msg) | ||
57 | + .style({ | ||
58 | + 'font-size': '10pt', | ||
59 | + color: 'darkorange', | ||
60 | + padding: '0 20px', | ||
61 | + margin: 0 | ||
62 | + }); | ||
63 | + } | ||
64 | + | ||
65 | + function keyCallback(view, key, keyCode, event) { | ||
66 | + note(view, 'Key = ' + key + ' KeyCode = ' + keyCode); | ||
67 | + } | ||
68 | + | ||
69 | + // Keys using a keyset to target specific keys only | ||
70 | + function load(view, ctx) { | ||
71 | + // this maps specific keys to specific functions (1) | ||
72 | + view.setKeys(keyDispatch); | ||
73 | + // whereas, this installs a general key handler function (2) | ||
74 | + view.setKeys(keyCallback); | ||
75 | + | ||
76 | + // Note that (1) takes precedence over (2) | ||
77 | + | ||
78 | + view.$div.append('p') | ||
79 | + .text('Press a key or two (try Z,X,C,V and others) ...') | ||
80 | + .style('padding', '2px 8px'); | ||
81 | + } | ||
82 | + | ||
83 | + // == register the view here, with links to lifecycle callbacks | ||
84 | + | ||
85 | + onos.ui.addView('sampleKeys', { | ||
86 | + reset: true, // empty the div on reset | ||
87 | + load: load | ||
88 | + }); | ||
89 | + | ||
90 | +}(ONOS)); |
-
Please register or login to post a comment