@Override public Object get(ScriptSession scriptSession, String name) { return scriptSession.getAttribute(name); }
public boolean match(ScriptSession session) { return !user.getUserId().equals(session.getAttribute("userId")) && currentSession.getPage().equals(session.getPage()) && host.equals(session.getAttribute("host")); } },
@SuppressWarnings("unchecked") public <T> String saveCallback(Callback<T> callback, Class<T> type) { String key = createUniqueId(); for (ScriptSession session : callback.getScriptSessions()) { // Save the callback itself Map<String, Callback<T>> callbackMap = (Map<String, Callback<T>>) session.getAttribute(KEY_CALLBACK); callbackMap.put(key, callback); session.setAttribute(KEY_CALLBACK, callbackMap); // And save the type of the callback Map<String, Class<T>> typeMap = (Map<String, Class<T>>) session.getAttribute(KEY_TYPE); typeMap.put(key, type); session.setAttribute(KEY_TYPE, typeMap); } return key; }
/** * Stop notifications of against a subscription id * @param subscriptionId The ID to pass back to link to client side data * @return true iff someone was unsubscribed */ @SuppressWarnings("unchecked") public boolean unsubscribe(String subscriptionId) { WebContext webContext = WebContextFactory.get(); Hub hub = HubFactory.get(); ScriptSession session = webContext.getScriptSession(); Map<String, BrowserMessageListener> subscriptions = (Map<String, BrowserMessageListener>) session.getAttribute(ATTRIBUTE_SUBSCRIPTIONS); BrowserMessageListener subscription = subscriptions.get(subscriptionId); return hub.unsubscribe(subscription.topic, subscription); }
/** * Internal method to find or create a StoreProvider for a given user. */ @Override protected StoreProvider<T> getStoreProvider() { ScriptSession session = WebContextFactory.get().getScriptSession(); @SuppressWarnings("unchecked") StoreProvider<T> storeProvider = (StoreProvider<T>) session.getAttribute(attributeName); if (storeProvider == null) { storeProvider = factory.create(session); session.setAttribute(attributeName, storeProvider); } return storeProvider; }
object = webcx.getScriptSession().getAttribute(name);
/** * Ensure that the clients know about server publishes * @param topic The topic being subscribed to * @param subscriptionId The ID to pass back to link to client side data */ @SuppressWarnings("unchecked") public void subscribe(String topic, String subscriptionId) { WebContext webContext = WebContextFactory.get(); Hub hub = HubFactory.get(); final ScriptSession session = webContext.getScriptSession(); // Create a subscription block BrowserMessageListener subscription = new BrowserMessageListener(session, topic, subscriptionId); Map<String, BrowserMessageListener> subscriptions = (Map<String, BrowserMessageListener>) session.getAttribute(ATTRIBUTE_SUBSCRIPTIONS); if (subscriptions == null) { subscriptions = new HashMap<String, BrowserMessageListener>(); } subscriptions.put(subscriptionId, subscription); session.setAttribute(ATTRIBUTE_SUBSCRIPTIONS, subscriptions); hub.subscribe(subscription.topic, subscription); }
public Object doFilter(Object obj, Method method, Object[] params, AjaxFilterChain chain) throws Exception { ScriptSession session = WebContextFactory.get().getScriptSession(); Long lastAccess = (Long) session.getAttribute(ATTRIBUTE_LAST_ACTION); // Free pass in if you've not done anything so far. if (lastAccess != null) { long now = System.currentTimeMillis(); if (now > lastAccess + actionTimeoutMillis) { session.addScript(new ScriptBuffer(onTimeout)); session.invalidate(); throw new DwrConvertedException("Your session has timed out"); } } Object reply = chain.doFilter(obj, method, params); session.setAttribute(ATTRIBUTE_LAST_ACTION, System.currentTimeMillis()); return reply; }
ConverterManager converterManager = webContext.getContainer().getBean(ConverterManager.class); Map<String, Class<T>> typeMap = (Map<String, Class<T>>) session.getAttribute(KEY_TYPE); Class<T> type = typeMap.remove(key); session.removeAttribute(KEY_TYPE); Object callbackData = converterManager.convertInbound(type, iv, property); Map<String, Callback<T>> callbackMap = (Map<String, Callback<T>>) session.getAttribute(KEY_TYPE); Callback<T> callback = callbackMap.remove(key); session.removeAttribute(KEY_TYPE);