protected Gravity getGravity() { return GravityManager.getGravity(servletContext); }
public void onReload(ServletContext context, GraniteConfig config) { parseConfig(config.getGravityConfig()); GravityManager.reconfigure(context, this); }
return; Gravity gravity = GravityManager.getGravity(servletContextEvent.getServletContext()); try { if (gravity == null) gravity = GravityManager.start(servletContextEvent.getServletContext());
public static void init(ServletConfig config) throws ServletException { GravityManager.start(config); }
/** * Parse gravity configuration (granite-config.xml), start gravity by using the specified factory and put it * in ServletContext. If Gravity is already started, returns the previous instance from the servlet context. * <br><br> * This method is intended to be used in {@link HttpServlet#init(ServletConfig)} methods only and * synchronizes on the current ServletContext instance. * * @param servletConfig the servlet config passed in HttpServlet.init(ServletConfig config) method. * @return a newly created and started Gravity instance or previously started one. * @throws ServletException if something goes wrong (GravityFactory not found, Gravity.start() error, etc.) */ public static Gravity start(ServletConfig servletConfig) throws ServletException { return start(servletConfig.getServletContext()); }
public static long getLongPollingTimeout(ServletContext context) { return GravityManager.getGravity(context).getGravityConfig().getLongPollingTimeoutMillis(); }
/** * Reconfigure gravity with the new supplied configuration (after reloading granite-config.xml). * <br><br> * Only these configuration options are taken into account when reconfiguring Gravity: * <ul> * <li>channelIdleTimeoutMillis</li> * <li>longPollingTimeout</li> * <li>retryOnError</li> * <li>maxMessagesQueuedPerChannel</li> * <li>corePoolSize</li> * <li>maximumPoolSize</li> * <li>keepAliveTimeMillis</li> * </ul> * * @param context the ServletContext where the gravity instance is registered. * @param gravityConfig the new (reloaded) GravityConfig. */ public static void reconfigure(ServletContext context, GravityConfig gravityConfig) { synchronized (context) { Gravity gravity = getGravity(context); gravity.reconfigure(gravityConfig, ServletGraniteConfig.getConfig(context)); } }
@Override protected Gravity getGravity() { if (gravity != null) return gravity; ServletContext servletContext = null; if (!servletContextInstance.isUnsatisfied()) { // Use ServletContext exposed with @Default qualifier (by Apache DeltaSpike Servlet for example) servletContext = servletContextInstance.select(DEFAULT_LITERAL).get(); } if (servletContext == null) { // If not found, lookup in GraniteContext GraniteContext graniteContext = GraniteContext.getCurrentInstance(); if (graniteContext != null && graniteContext instanceof ServletGraniteContext) servletContext = ((ServletGraniteContext)graniteContext).getServletContext(); } return servletContext != null ? GravityManager.getGravity(servletContext) : null; }
@SuppressWarnings("deprecation") @Override public void init(ServletConfig config) throws ServletException { super.init(config); GravityServletUtil.init(config); GravityInternal gravity = (GravityInternal)GravityManager.getGravity(getServletContext()); String mapping = null; String servletName = null; for (ServletRegistration sr : getServletContext().getServletRegistrations().values()) { if (!sr.getClassName().equals(getClass().getName())) continue; servletName = sr.getName(); mapping = sr.getMappings().iterator().next(); } app = new GlassFishWebSocketApplication(getServletContext(), gravity, mapping, servletName); try { WebSocketEngine.getEngine().register(getServletContext().getContextPath(), mapping, app); } catch (NoSuchMethodError e) { // Deprecated since Grizzly 1.5.? WebSocketEngine.getEngine().register(app); } }
@Override protected void doTimeout(RequestResponseKey key) throws IOException, ServletException { GravityInternal gravity = (GravityInternal)GravityManager.getGravity(getServletContext()); WebLogicChannelFactory channelFactory = new WebLogicChannelFactory(gravity); CommandMessage amf3Request = GravityServletUtil.getConnectMessage(key.getRequest()); String channelId = (String)amf3Request.getClientId(); WebLogicChannel channel = gravity.getChannel(channelFactory, channelId); channel.setRequestResponseKey(null); } }
@Override public void configure(WebSocketServletFactory factory) { Gravity gravity = GravityManager.getGravity(getServletContext()); factory.getPolicy().setIdleTimeout(gravity.getGravityConfig().getChannelIdleTimeoutMillis()); factory.setCreator(new JettyWebSocketCreator(getServletContext())); } }
return null; GravityInternal gravity = (GravityInternal)GravityManager.getGravity(servletContext); JettyWebSocketChannelFactory channelFactory = new JettyWebSocketChannelFactory(gravity);
DistributedData gdd = distributedDataFactory.getInstance(); if (gdd != null) { this.gravity = GravityManager.getGravity(((ServletGraniteContext)graniteContext).getServletContext()); gravity = GravityManager.getGravity(((ServletGraniteContext)graniteContext).getServletContext());
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { GravityInternal gravity = (GravityInternal)GravityManager.getGravity(getServletContext()); GAEChannelFactory channelFactory = new GAEChannelFactory(gravity);
@Override protected StreamInbound createWebSocketInbound(String protocol, HttpServletRequest request) { GravityInternal gravity = (GravityInternal)GravityManager.getGravity(getServletContext()); TomcatWebSocketChannelFactory channelFactory = new TomcatWebSocketChannelFactory(gravity);
HttpServletResponse response = event.getHttpServletResponse(); GravityInternal gravity = (GravityInternal)GravityManager.getGravity(getServletContext()); JBossWebChannelFactory channelFactory = new JBossWebChannelFactory(gravity);
HttpServletResponse response = event.getHttpServletResponse(); GravityInternal gravity = (GravityInternal)GravityManager.getGravity(getServletContext()); TomcatChannelFactory channelFactory = new TomcatChannelFactory(gravity);
GravityInternal gravity = (GravityInternal)GravityManager.getGravity(getServletContext()); ContinuationChannelFactory channelFactory = new ContinuationChannelFactory(gravity);
@Override public boolean handleError(CometEvent event) throws IOException { if (EventUtil.isErrorButNotTimeout(event)) log.warn("Got an error event: %s", EventUtil.toString(event)); try { HttpServletRequest request = event.getHttpServletRequest(); Message connect = getConnectMessage(request); if (connect != null) { // This should be a timeout. GravityInternal gravity = (GravityInternal)GravityManager.getGravity(getServletContext()); TomcatChannelFactory channelFactory = new TomcatChannelFactory(gravity); String channelId = (String)connect.getClientId(); TomcatChannel channel = gravity.getChannel(channelFactory, channelId); // Cancel channel's execution (timeout or other errors). if (channel != null) channel.setCometEvent(null); } } catch (Exception e) { log.error(e, "Error while processing event: %s", EventUtil.toString(event)); } return true; // Close http event. } }
throw new ServletException("Gravity Servlet3 implementation doesn't support dispatch(...) mode"); GravityInternal gravity = (GravityInternal)GravityManager.getGravity(getServletContext()); AsyncChannelFactory channelFactory = new AsyncChannelFactory(gravity);