diff --git a/src/features/CacheRequest/index.html b/src/features/CacheRequest/index.html new file mode 100644 index 0000000..e7b951d --- /dev/null +++ b/src/features/CacheRequest/index.html @@ -0,0 +1,280 @@ + + + + Solclientjs: SolCache Request + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
+ +

Solclientjs Samples > SolCache Request

+
+
+
+ + SolCache - Signed Out - + +
+
+ + +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Cache Cluster Name +
+ +
+
Max Message Age +
+ +
+
Max Message Count +
+ +
+
Request Timeout +
+ +
+
+ + +
Cache Topic +
+ + + +
+
Live Data Action +
+ +
+
+ +
+ + +
Cache Reply + +
+
+
+ + + + + +
+ + Show Console + + +
+
+ +
+

Copyright 2009-2016 Solace Corporation. All rights reserved.

+ +
Permission is hereby granted, free of charge, to any person obtaining a copy of + this software and associated documentation files (the "Software"), to use and + copy the Software, and to permit persons to whom the Software is furnished to + do so, subject to the following conditions:
+
The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. +
+
+ UNLESS STATED ELSEWHERE BETWEEN YOU AND SOLACE CORPORATION, THE SOFTWARE IS + PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING + BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +
+ http://www.SolaceSystems.com
+
+ + + +
+
+
+
+ +
+
+
+
+ +
+ Nickname: + +
+ +
+ + Appliance url: + +
+ +
+ User + name: + +
+ +
+ + Message VPN: + +
+ +
+ + Password: + +
+ +
+
+ + + + + + + + diff --git a/src/features/CacheRequest/sol-cache-ui.js b/src/features/CacheRequest/sol-cache-ui.js new file mode 100644 index 0000000..0b0138c --- /dev/null +++ b/src/features/CacheRequest/sol-cache-ui.js @@ -0,0 +1,312 @@ +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// Solace Corporation Messaging API for JavaScript +// Copyright 2010-2016 Solace Corporation. All rights reserved. // +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to use +// and copy the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// UNLESS STATED ELSEWHERE BETWEEN YOU AND SOLACE CORPORATION, THE SOFTWARE +// IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR +// A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR +// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// +// http://www.solace.com +// +//////////////////////// User Interface /////////////////////////////////////////////////////////////////////////////// + +// The following line is for processing by JSLint. +/*global jQuery:true, $:true, solace:true, window:true */ + +$(function() { + // Tabs + $('#tabs').tabs(); + // Dialog + $('#dialog').dialog({ + autoOpen: false, + width: 300, + buttons: { + "Ok": function() { + $(this).dialog("close"); + solace.sample.onLogin(); + }, + "Cancel": function() { + $(this).dialog("close"); + } + } + }); + // Dialog Link + $('#dialog_link').click(function() { + $('#dialog').dialog('open'); + return false; + }); + //hover states on the static widgets + $('#dialog_link, ul#icons li').hover( + function() { + $(this).addClass('ui-state-hover'); + }, + function() { + $(this).removeClass('ui-state-hover'); + } + ); + // Button + $("button.solbutton").button(); + $("#LoginButton").button({ + text: true, + icons: { + primary: "ui-icon-check" + } + }); + $("#LogoutButton").button({ + text: true, + icons: { + primary: "ui-icon-closethick" + } + }); + $("#ClearButton").button({ + text: true, + width: 100, + icons: { + primary: "ui-icon-trash" + } + }); + $('#ClearResponseButton').button({ + text: true, + width: 200, + icons: { + primary: "ui-icon-trash" + } + }); + +}); + +var solace = solace || {}; +solace.sample = solace.sample || {}; + +(function() { + var ns = this; + + this.utils_appendToConsole = function(message) { + ns.utils_appendLineToTextArea("output_console", message, true); + }; + + this.utils_showConsole = function() { + var visible = ns.utils_isChecked("input_show_console"); + ns.utils_setVisibility("output_console", visible); + ns.utils_setVisibility("ClearButton", visible); + }; + + this.utils_clearConsole = function() { + ns.utils_clearTextArea("output_console"); + }; + + this.utils_getUrl = function() { + return ns.utils_getField("input_session_url"); + }; + + this.utils_getUserName = function() { + return ns.utils_getField("input_session_username"); + }; + + this.utils_getVPN = function() { + return ns.utils_getField("input_session_vpn"); + }; + + this.utils_getPassword = function() { + return ns.utils_getField("input_session_password"); + }; + + this.utils_getNickName = function() { + return ns.utils_getField("input_session_nickname"); + }; + + this.utils_getCacheClusterName = function() { + return ns.utils_getField("input_clusterName"); + }; + + this.utils_getMaxMessageAge = function() { + return parseInt(ns.utils_getField("input_maxAge")); + }; + + this.utils_getMaxMessageCount = function() { + return parseInt(ns.utils_getField("input_maxMessages")); + }; + + this.utils_getRequestTimeout = function() { + return parseInt(ns.utils_getField("input_requestTimeout")); + }; + + this.utils_getSubscribe = function() { + return ns.utils_isChecked("input_subscribe"); + }; + + this.utils_getTopicName = function() { + return ns.utils_getField("input_cacheTopic"); + }; + + this.utils_getLiveDataAction = function() { + return parseInt(ns.utils_getField("input_liveDataAction")); + }; + + this.utils_clearCacheReply = function() { + ns.utils_clearTextArea("cache_reply"); + }; + + this.utils_Button_Login_setState = function(state) { + ns.utils_control_setButtonState("LoginButton", state); + }; + + this.utils_Button_Logout_setState = function(state) { + ns.utils_control_setButtonState("LogoutButton", state); + }; + + this.utils_Button_ConnectCache_setState = function(state) { + ns.utils_control_setButtonState("CacheConnect", state); + }; + + this.utils_Button_DisconnectCache_setState = function(state) { + ns.utils_control_setButtonState("CacheDisconnect", state); + }; + + this.utils_Button_CacheRequest_setState = function(state) { + ns.utils_control_setButtonState("CacheRequest", state); + }; + + this.utils_CacheParameters_setState = function(state) { + var selector = '#input_clusterName, #input_maxAge, #input_maxMessages, #input_requestTimeout'; + if (state) { + $(selector).removeAttr('disabled'); + } else { + $(selector).attr('disabled', 'disabled'); + } + }; + + this.utils_RequestParameters_setState = function(state) { + var selector = '#input_cacheTopic, #input_subscribe, #input_liveDataAction'; + if (state) { + $(selector).removeAttr('disabled'); + } else { + $(selector).attr('disabled', 'disabled'); + } + }; + + this.utils_addContent = function(msg) { + ns.utils_appendLineToTextArea("cache_reply", msg, false); + }; + + this.signal_loggedIn = function() { + ns.utils_Button_Login_setState(false); + ns.utils_Button_Logout_setState(true); + ns.utils_Button_ConnectCache_setState(true); + ns.utils_Button_DisconnectCache_setState(false); + ns.utils_Button_CacheRequest_setState(false); + ns.utils_CacheParameters_setState(true); + ns.utils_RequestParameters_setState(false); + $('#nickname').html("SolCache - Signed In"); + }; + + this.signal_loggedOut = function() { + ns.utils_clearCacheReply(); + ns.utils_Button_Login_setState(true); + ns.utils_Button_Logout_setState(false); + ns.utils_Button_ConnectCache_setState(false); + ns.utils_Button_DisconnectCache_setState(false); + ns.utils_Button_CacheRequest_setState(false); + ns.utils_CacheParameters_setState(false); + ns.utils_RequestParameters_setState(false); + $('#nickname').html("SolCache - Signed Out"); + }; + + this.signal_loggingIn = function() { + ns.utils_clearCacheReply(); + ns.utils_Button_Login_setState(false); + ns.utils_Button_Logout_setState(false); + ns.utils_Button_ConnectCache_setState(false); + ns.utils_Button_DisconnectCache_setState(false); + ns.utils_Button_CacheRequest_setState(false); + ns.utils_CacheParameters_setState(false); + ns.utils_RequestParameters_setState(false); + }; + + this.signal_cacheSessionCreated = function() { + ns.utils_clearCacheReply(); + ns.utils_Button_Login_setState(false); + ns.utils_Button_Logout_setState(true); + ns.utils_Button_ConnectCache_setState(false); + ns.utils_Button_DisconnectCache_setState(true); + ns.utils_Button_CacheRequest_setState(true); + ns.utils_CacheParameters_setState(false); + ns.utils_RequestParameters_setState(true); + }; + + this.signal_cacheSessionDisposed = function() { + ns.utils_clearCacheReply(); + ns.utils_Button_Login_setState(false); + ns.utils_Button_Logout_setState(true); + ns.utils_Button_ConnectCache_setState(true); + ns.utils_Button_DisconnectCache_setState(false); + ns.utils_Button_CacheRequest_setState(false); + ns.utils_CacheParameters_setState(true); + ns.utils_RequestParameters_setState(false); + }; + +}.apply(solace.sample)); + +/** + * jquery initialize page function + */ +$(document).ready(function() { + var path = document.URL; + var prefix = ''; + var index1 = path.indexOf('//'); + var index2 = -1; + if (index1 > 0) { + index2 = path.indexOf('/', index1 + 2); + if (index2 > 0) { + prefix = path.substring(0, index2); + } + } + + var DEFAULT_APPLIANCE_URL = prefix + '/solace/smf'; + var DEFAULT_USER_NAME = 'default'; + var DEFAULT_MSG_VPN = 'default'; + var DEFAULT_NICKNAME = "John"; + var DEFAULT_CLUSTER = "v1.d1"; + var DEFAULT_MAX_AGE = "0"; + var DEFAULT_MAX_COUNT = "1000"; + var DEFAULT_TIMEOUT = "10000"; + var DEFAULT_TOPIC = "sanity/0000/0000/0000/0000"; + + solace.sample.signal_loggedOut(); + solace.sample.utils_setChecked('input_show_console', true); + solace.sample.utils_setVisibility('output_console', true); + solace.sample.utils_setVisibility('ClearButton', true); + solace.sample.utils_setText('output_console',''); + $('body').layout({ applyDefaultStyles: true }); + + solace.sample.utils_setText('input_session_url',DEFAULT_APPLIANCE_URL); + solace.sample.utils_setText('input_session_username',DEFAULT_USER_NAME); + solace.sample.utils_setText('input_session_vpn',DEFAULT_MSG_VPN); + solace.sample.utils_setText('input_session_nickname',DEFAULT_NICKNAME); + solace.sample.utils_setText('input_clusterName', DEFAULT_CLUSTER); + solace.sample.utils_setText('input_maxAge', DEFAULT_MAX_AGE); + solace.sample.utils_setText('input_maxMessages', DEFAULT_MAX_COUNT); + solace.sample.utils_setText('input_requestTimeout', DEFAULT_TIMEOUT); + solace.sample.utils_setText('input_cacheTopic', DEFAULT_TOPIC); + + +}); + +$(window).unload(function() { + solace.sample.cleanup(); +}); + + diff --git a/src/features/CacheRequest/sol-cache.js b/src/features/CacheRequest/sol-cache.js new file mode 100644 index 0000000..2a547c9 --- /dev/null +++ b/src/features/CacheRequest/sol-cache.js @@ -0,0 +1,307 @@ +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// Solace Corporation Messaging API for JavaScript +// Copyright 2009-2016 Solace Corporation. All rights reserved. // +// Permission is hereby granted, free of charge, to any person obtaining a copy of +// this software and associated documentation files (the "Software"), to use and +// copy the Software, and to permit persons to whom the Software is furnished to +// do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// UNLESS STATED ELSEWHERE BETWEEN YOU AND SOLACE CORPORATION, THE SOFTWARE IS +// PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +// BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// +// http://www.solace.com +// +// * SolCache * +// +// This sample demonstrates use of SolCache: creating a cache session, sending cache requests, +// and receiving replies. +// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +// The following line is for processing by JSLint. +/*global jQuery:true, $:true, solace:true, window:true */ + +var solace = solace || {}; +solace.sample = solace.sample || {}; + +(function() { + + var OPERATION_TIMEOUT = 30000; + + var ns = this; + /** + * Data members in the global scope + */ + var mySessionProperties = null; + var mySession = null; + var myNickName = null; + + var sessionEventCb; // forward declaration + var messageEventCb; // forward declaration + var cacheRequestCb; // forward declaration + + var requestID = 0; + var messageCount = 0; + var receivingCacheMessages = false; + + var cacheSession; + + /** + * Invoked when the Ok button is clicked on the login dialog. This method will trigger the creation and connect() + * operation on the session. When successfully connected, handle_sessionConnected() is invoked + */ + this.onLogin = function() { + // Set UI state for login in progress + ns.signal_loggingIn(); + + // log to console + var msg = "Creating Session: [ url='" + ns.utils_getUrl() + "', " + + "user='" + ns.utils_getUserName() + ", vpn='" + ns.utils_getVPN() + "']"; + ns.utils_appendToConsole(msg); + // create the session + try { + // Create Session + mySessionProperties = new solace.SessionProperties(); + mySessionProperties.connectTimeoutInMsecs = OPERATION_TIMEOUT; + mySessionProperties.readTimeoutInMsecs = OPERATION_TIMEOUT; + mySessionProperties.keepAliveIntervalsLimit = 10; + mySessionProperties.userName = ns.utils_getUserName(); + mySessionProperties.vpnName = ns.utils_getVPN(); + mySessionProperties.password = ns.utils_getPassword(); + mySessionProperties.url = ns.utils_getUrl(); + myNickName = mySessionProperties.clientName = ns.utils_getNickName(); + + mySession = solace.SolclientFactory.createSession( + mySessionProperties, + new solace.MessageRxCBInfo( + function(session, message) { + messageEventCb(session, message); + }, + this + ), + new solace.SessionEventCBInfo( + function(session, event) { + sessionEventCb(session, event); + }, + this + ) + ); + ns.utils_appendToConsole("Session was successfully created."); + // Connect it + mySession.connect(); + + } catch (error) { + ns.utils_appendToConsole("Could not login"); + ns.utils_appendToConsole(error.toString()); + if (mySession !== null) { + mySession.dispose(); + mySession = null; + } + ns.signal_loggedOut(); + } + }; + + this.onCacheCreate = function() { + var cacheSessionProperties = new solace.CacheSessionProperties( + ns.utils_getCacheClusterName(), + ns.utils_getMaxMessageAge(), + ns.utils_getMaxMessageCount(), + ns.utils_getRequestTimeout() + ); + + try { + cacheSession = mySession.createCacheSession(cacheSessionProperties); + ns.utils_appendToConsole("Created a cache session: " + cacheSession); + ns.signal_cacheSessionCreated(); + } catch (e) { + ns.utils_appendToConsole("Could not create a cache session: " + e); + } + }; + + this.onCacheDispose = function() { + try { + cacheSession.dispose(); + ns.utils_appendToConsole("Cache session disposed: " + cacheSession); + ns.signal_cacheSessionDisposed(); + } catch (e) { + ns.utils_appendToConsole("Could not dispose cache session: " + e); + } + }; + + this.onCacheRequest = function() { + try { + messageCount = 0; + receivingCacheMessages = false; + var topic = solace.SolclientFactory.createTopic(ns.utils_getTopicName()); + cacheSession.sendCacheRequest( + requestID, + topic, + ns.utils_getSubscribe(), + ns.utils_getLiveDataAction(), + new solace.CacheCBInfo( + cacheRequestCb, + { + data: requestID++ + } + ) + ); + } catch (e) { + ns.utils_appendToConsole("Could not send cache request: " + e); + } + }; + + /** + * Invoked when the user logs out + */ + this.onLogout = function() { + ns.cleanup(); + ns.signal_loggedOut(); + }; + + /** + * Invoked when "Show Console" checkbox is clicked + */ + this.onShowConsole = function() { + ns.utils_showConsole(); + }; + + /** + * Invoked when Clear button is clicked + */ + this.onClearConsole = function() { + ns.utils_clearConsole(); + }; + + this.onClearCacheReply = function() { + ns.utils_clearCacheReply(); + }; + + /** + * The session was successfully connected, the next step is to add the 'rendez-vous' topic subscription + */ + this.handle_sessionConnected = function() { + ns.signal_loggedIn(); + }; + + /** + * General failure + * @param text + * @param updateContent + */ + this.handle_failure = function(text, updateContent) { + if (updateContent) { + ns.utils_addContent(text); + } + ns.utils_appendToConsole(text); + ns.cleanup(); + ns.signal_loggedOut(); + }; + + /** + * General cleanup + */ + this.cleanup = function() { + if (mySession !== null) { + mySession.dispose(); + mySession = null; + } + }; + +////////////////////// Callback functions ////////////////////////////////////////////////////////////////////////////// + + /** + * Session event callback + * @param session + * @param event + */ + sessionEventCb = function (session, event) { + ns.utils_appendToConsole(event.toString()); + if (event.sessionEventCode === solace.SessionEventCode.UP_NOTICE) { + ns.handle_sessionConnected(); + } else if (event.sessionEventCode === solace.SessionEventCode.SUBSCRIPTION_OK) { + ns.handle_subscriptionOperationSucceeded(); + } else if (event.sessionEventCode === solace.SessionEventCode.SUBSCRIPTION_ERROR) { + ns.handle_failure("Failed to add subscription", true); + } else if (event.sessionEventCode === solace.SessionEventCode.LOGIN_FAILURE) { + ns.handle_failure("Failed to login to appliance:" + event.infoStr, true); + } else if (event.sessionEventCode === solace.SessionEventCode.CONNECTING) { + ns.utils_appendToConsole("Connecting..."); + } else if (event.sessionEventCode === solace.SessionEventCode.DISCONNECTED) { + ns.handle_failure("Session is disconnected", false); + } else { + ns.handle_failure("Session failure!", false); + } + }; + + /** + * Direct message receive callback + * @param session + * @param message + */ + messageEventCb = function (session, message) { + try { + if (message.getCacheRequestId() === null) { + ns.utils_appendToConsole("Received message: " + JSON.stringify(message)); + } else { + var status; + switch (message.getCacheStatus()) { + case solace.MessageCacheStatus.LIVE: + status = "Live"; + break; + case solace.MessageCacheStatus.CACHED: + status = "Cached"; + break; + case solace.MessageCacheStatus.SUSPECT: + status = "Suspect"; + } + + if (!receivingCacheMessages) { + ns.utils_addContent("Receiving cache messages for request: " + message.getCacheRequestId() + " " + + "Status: " + status); + receivingCacheMessages = true; + } + messageCount++; + } + } catch (error) { + ns.utils_appendToConsole("Failed to send reply "); + ns.utils_appendToConsole(error.toString()); + } + }; + + + cacheRequestCb = function(requestID, cacheRequestResult, userObject) { + ns.utils_appendToConsole("Received cache request callback"); + var resultString = JSON.stringify(cacheRequestResult); + var userObjectString = JSON.stringify(userObject); + var key; + var returnCodeName; + var subcodeName; + for (key in solace.CacheReturnCode) { + if (cacheRequestResult.returnCode === solace.CacheReturnCode[key]) { + returnCodeName = key; + break; + } + } + for (key in solace.CacheReturnSubcode) { + if (cacheRequestResult.subcode === solace.CacheReturnSubcode[key]) { + subcodeName = key; + break; + } + } + ns.utils_addContent("Result for request " + requestID + ":\n" + + "Result: solace.CacheReturnCode." + returnCodeName + "\n" + + "Subcode: solace.CacheReturnSubcode." + subcodeName + "\n" + + "Contents: \n" + resultString + "\nUserObject: \n" + userObjectString + "\n" + + "Total cache messages received: " + messageCount + "\n"); + }; + +}.apply(solace.sample)); diff --git a/src/features/CacheRequest/working-rough-sample.html b/src/features/CacheRequest/working-rough-sample.html new file mode 100644 index 0000000..f4b3ef7 --- /dev/null +++ b/src/features/CacheRequest/working-rough-sample.html @@ -0,0 +1,134 @@ + + + + + + + + + + + + + + + + + +

hi

+ + +