Search in sources :

Example 1 with ClientServerCacheLifecycleListener

use of org.apache.geode.modules.session.catalina.ClientServerCacheLifecycleListener in project geode by apache.

the class Tomcat8SessionsClientServerDUnitTest method setupServer.

// Set up the servers we need
public void setupServer(DeltaSessionManager manager) throws Exception {
    Host host = Host.getHost(0);
    vm0 = host.getVM(1);
    String hostName = vm0.getHost().getHostName();
    int cacheServerPort = vm0.invoke(() -> {
        Properties props = new Properties();
        CacheFactory cf = new CacheFactory(props);
        Cache cache = cf.create();
        CacheServer server = cache.addCacheServer();
        server.start();
        return server.getPort();
    });
    port = AvailablePortHelper.getRandomAvailableTCPPort();
    server = new EmbeddedTomcat8("/test", port, "JVM-1");
    ClientServerCacheLifecycleListener listener = new ClientServerCacheLifecycleListener();
    listener.setProperty(MCAST_PORT, "0");
    listener.setProperty(LOG_LEVEL, "config");
    server.addLifecycleListener(listener);
    sessionManager = manager;
    sessionManager.setEnableCommitValve(true);
    server.getRootContext().setManager(sessionManager);
    servlet = server.addServlet("/test/*", "default", CommandServlet.class.getName());
    server.startContainer();
    PoolFactory pf = PoolManager.createFactory();
    pf.addServer(hostName, cacheServerPort);
    pf.create("Pool Connecting to Cache Server");
    /*
     * Can only retrieve the region once the container has started up (and the cache has started
     * too).
     */
    region = sessionManager.getSessionCache().getSessionRegion();
    sessionManager.getTheContext().setSessionTimeout(30);
}
Also used : PoolFactory(org.apache.geode.cache.client.PoolFactory) ClientServerCacheLifecycleListener(org.apache.geode.modules.session.catalina.ClientServerCacheLifecycleListener) CacheServer(org.apache.geode.cache.server.CacheServer) Host(org.apache.geode.test.dunit.Host) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) CacheFactory(org.apache.geode.cache.CacheFactory) Cache(org.apache.geode.cache.Cache)

Aggregations

Properties (java.util.Properties)1 Cache (org.apache.geode.cache.Cache)1 CacheFactory (org.apache.geode.cache.CacheFactory)1 PoolFactory (org.apache.geode.cache.client.PoolFactory)1 CacheServer (org.apache.geode.cache.server.CacheServer)1 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)1 ClientServerCacheLifecycleListener (org.apache.geode.modules.session.catalina.ClientServerCacheLifecycleListener)1 Host (org.apache.geode.test.dunit.Host)1