本文整理汇总了Java中com.hazelcast.web.WebFilter类的典型用法代码示例。如果您正苦于以下问题:Java WebFilter类的具体用法?Java WebFilter怎么用?Java WebFilter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WebFilter类属于com.hazelcast.web包,在下文中一共展示了WebFilter类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildJettyServer
import com.hazelcast.web.WebFilter; //导入依赖的package包/类
private static Server buildJettyServer(int serverPort)
throws Exception {
Server server = new Server();
SelectChannelConnector connector = new SelectChannelConnector();
connector.setPort(serverPort);
connector.setAcceptQueueSize(100);
connector.setThreadPool(new QueuedThreadPool(5));
server.addConnector(connector);
ContextHandlerCollection contexts = new ContextHandlerCollection();
server.setHandler(contexts);
server.setGracefulShutdown(1000);
server.setStopAtShutdown(true);
ServletContextHandler handler = new ServletContextHandler(contexts, "/", ServletContextHandler.SESSIONS);
handler.addEventListener(new SessionListener());
handler.addServlet(TestServlet.class, "/");
handler.setLogger(null);
FilterHolder filterHolder = new FilterHolder(WebFilter.class);
filterHolder.setInitParameter("sticky-session", "false");
filterHolder.setInitParameter("map-name", "default");
filterHolder.setInitParameter("instance-name", "client");
filterHolder.setInitParameter("shutdown-on-destroy", "true");
filterHolder.setInitParameter("use-client", "true");
filterHolder.setInitParameter("deferred-write", "false");
handler.addFilter(filterHolder, "/*", EnumSet.of(DispatcherType.REQUEST));
server.start();
return server;
}
示例2: initClusteredHttpSessionFilter
import com.hazelcast.web.WebFilter; //导入依赖的package包/类
/**
* Initializes the Clustered Http Session filter
*/
private void initClusteredHttpSessionFilter(ServletContext servletContext, EnumSet<DispatcherType> disps) {
log.debug("Registering Clustered Http Session Filter");
disps = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ASYNC, DispatcherType.INCLUDE);
servletContext.addListener(new SessionListener());
WebFilter webFilter = new WebFilter() {
@Override
protected HazelcastInstance getInstance(Properties properties) throws ServletException {
return CacheConfiguration.getHazelcastInstance();
}
};
final FilterRegistration.Dynamic hazelcastWebFilter = servletContext.addFilter("hazelcastWebFilter", webFilter);
Map<String, String> parameters = new HashMap<>();
// Name of the distributed map storing your web session objects
parameters.put("map-name", "clustered-http-sessions");
// How is your load-balancer configured?
// Setting "sticky-session" to "true" means all requests of a session
// are routed to the node where the session is first created.
// This is excellent for performance.
// If "sticky-session" is set to "false", then when a session is updated
// on a node, entries for this session on all other nodes are invalidated.
// You have to know how your load-balancer is configured before
// setting this parameter. Default is true.
parameters.put("sticky-session", "false");
// Name of session id cookie
parameters.put("cookie-name", "hazelcast.sessionId");
// Are you debugging? Default is false.
if (env.acceptsProfiles(Constants.SPRING_PROFILE_PRODUCTION)) {
parameters.put("debug", "false");
} else {
parameters.put("debug", "true");
}
// Do you want to shutdown HazelcastInstance during
// web application undeploy process?
// Default is true.
parameters.put("shutdown-on-destroy", "true");
hazelcastWebFilter.setInitParameters(parameters);
hazelcastWebFilter.addMappingForUrlPatterns(disps, false, "/*");
hazelcastWebFilter.setAsyncSupported(true);
}