# sprint-1 renaming in ignite-web
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/5aba0234 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/5aba0234 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/5aba0234 Branch: refs/heads/sprint-1 Commit: 5aba02348f125b9e737a7e89594c3bbfc51d5c55 Parents: c8a0289 Author: sboikov <sboi...@gridgain.com> Authored: Fri Feb 13 10:44:14 2015 +0300 Committer: sboikov <sboi...@gridgain.com> Committed: Fri Feb 13 10:45:55 2015 +0300 ---------------------------------------------------------------------- .../core/src/test/webapp/META-INF/gg-config.xml | 349 -------------- .../webapp/META-INF/ignite-webapp-config.xml | 349 ++++++++++++++ modules/core/src/test/webapp/WEB-INF/web.xml | 6 +- .../ignite/cache/websession/GridWebSession.java | 286 ------------ .../cache/websession/GridWebSessionFilter.java | 466 ------------------- .../websession/GridWebSessionListener.java | 196 -------- .../cache/websession/IgniteWebSession.java | 286 ++++++++++++ .../websession/IgniteWebSessionFilter.java | 466 +++++++++++++++++++ .../websession/IgniteWebSessionListener.java | 196 ++++++++ .../internal/websession/WebSessionSelfTest.java | 8 +- .../websession/WebSessionServerStart.java | 2 +- .../internal/websession/WebSessionTest.java | 2 +- 12 files changed, 1306 insertions(+), 1306 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5aba0234/modules/core/src/test/webapp/META-INF/gg-config.xml ---------------------------------------------------------------------- diff --git a/modules/core/src/test/webapp/META-INF/gg-config.xml b/modules/core/src/test/webapp/META-INF/gg-config.xml deleted file mode 100644 index a254173..0000000 --- a/modules/core/src/test/webapp/META-INF/gg-config.xml +++ /dev/null @@ -1,349 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<!-- - Licensed to the Apache Software Foundation (ASF) under one or more - contributor license agreements. See the NOTICE file distributed with - this work for additional information regarding copyright ownership. - The ASF licenses this file to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---> - -<!-- - Ignite Spring configuration file to startup grid cache. - - When starting a standalone Ignite node, you need to execute the following command: - {IGNITE_HOME}/bin/ignite.{bat|sh} examples/config/spring-cache.xml - - When starting Ignite from Java IDE, pass path to this file into Ignition: - Ignition.start("examples/config/spring-cache.xml"); ---> -<beans xmlns="http://www.springframework.org/schema/beans" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns:util="http://www.springframework.org/schema/util" - xsi:schemaLocation=" - http://www.springframework.org/schema/beans - http://www.springframework.org/schema/beans/spring-beans.xsd - http://www.springframework.org/schema/util - http://www.springframework.org/schema/util/spring-util.xsd"> - <!-- - Configuration below demonstrates how to setup caches within grid nodes. - --> - <bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration"> - <property name="deploymentMode" value="SHARED"/> - - <!-- - For better performance set this property to false in case - peer deployment is not used. - Default value is false. - --> - <property name="peerClassLoadingEnabled" value="true"/> - - <!-- - Configure optimized marshaller. - --> - <property name="marshaller"> - <bean class="org.apache.ignite.marshaller.optimized.OptimizedMarshaller"> - <!-- - For better performance set this property to true in case - all marshalled classes implement java.io.Serializable. - Default value is true. - - Note, that it is recommended to implement java.io.Externalizable - instead of java.io.Serializable for smaller network footprint - and even better performance. - --> - <property name="requireSerializable" value="false"/> - </bean> - </property> - - <!-- Set to local host address just for examples. --> - <property name="localHost" value="127.0.0.1"/> - - <!-- Configure REST TCP server address. --> - <property name="connectorConfiguration"> - <bean class="org.apache.ignite.configuration.ConnectorConfiguration"> - <property name="host" value="127.0.0.1"/> - </bean> - </property> - - <!-- - Enable cache events. - --> - <property name="includeEventTypes"> - <util:constant static-field="org.apache.ignite.events.EventType.EVTS_CACHE"/> - </property> - - <property name="cacheConfiguration"> - <!-- - Specify list of cache configurations here. Any property from - CacheConfiguration interface can be configured here. - Note that absolutely all configuration properties are optional. - --> - <list> - <!-- - Partitioned cache example configuration (Atomic mode). - --> - <bean class="org.apache.ignite.configuration.CacheConfiguration"> - <property name="name" value="partitioned"/> - - <property name="cacheMode" value="PARTITIONED"/> - - <!-- Only atomic updates will be supported. --> - <property name="atomicityMode" value="ATOMIC"/> - - <!-- Enable primary sync write mode. --> - <property name="writeSynchronizationMode" value="PRIMARY_SYNC"/> - - <!-- Disable near cache in atomic mode. --> - <property name="distributionMode" value="PARTITIONED_ONLY"/> - - <!-- Initial cache size. --> - <property name="startSize" value="1500000"/> - - <!-- - For better performance set this property to false in case - cache queries are not used. - Default value is false. - --> - <property name="queryIndexEnabled" value="true"/> - - <!-- Allow to index primitive values. --> - <property name="queryConfiguration"> - <bean class="org.apache.ignite.cache.query.CacheQueryConfiguration"> - <!-- Index primitives. --> - <property name="indexPrimitiveKey" value="true"/> - </bean> - </property> - - <!-- - This shows how to configure number of backups. The below configuration - sets the number of backups to 1 (which is default). - --> - <property name="backups" value="1"/> - - <!-- Set synchronous preloading (default is asynchronous). --> - <property name="preloadMode" value="SYNC"/> - </bean> - - <!-- - Partitioned cache example configuration (Transactional mode). - --> - <bean class="org.apache.ignite.configuration.CacheConfiguration"> - <property name="name" value="partitioned_tx"/> - - <property name="cacheMode" value="PARTITIONED"/> - - <!-- Transactional updates supported. --> - <property name="atomicityMode" value="TRANSACTIONAL"/> - - <!-- Enable near cache to cache recently accessed data. --> - <property name="distributionMode" value="NEAR_PARTITIONED"/> - - <!-- Initial cache size. --> - <property name="startSize" value="1500000"/> - - <!-- - Setting this value will cause local node to wait for remote commits. - However, it's important to set it this way in the examples as we assert on - conditions that usually assume full completion of transactions on all nodes. - --> - <property name="writeSynchronizationMode" value="FULL_SYNC"/> - - <!-- - For better performance set this property to false in case - cache queries are not used. - Default value is false. - --> - <property name="queryIndexEnabled" value="true"/> - - <!-- Allow to index primitive values. --> - <property name="queryConfiguration"> - <bean class="org.apache.ignite.cache.query.CacheQueryConfiguration"> - <!-- Index primitives. --> - <property name="indexPrimitiveKey" value="true"/> - </bean> - </property> - - <!-- - This shows how to configure number of backups. The below configuration - sets the number of backups to 1 (which is default). - --> - <property name="backups" value="1"/> - - <!-- Set synchronous preloading (default is asynchronous). --> - <property name="preloadMode" value="SYNC"/> - </bean> - - <!-- - Replicated cache example configuration. - --> - <bean class="org.apache.ignite.configuration.CacheConfiguration"> - <property name="name" value="replicated"/> - - <!-- - Setting this value will cause local node to wait for remote commits. - However, it's important to set it this way in the examples as we assert on - conditions that usually assume full completion of transactions on all nodes. - --> - <property name="writeSynchronizationMode" value="FULL_SYNC"/> - - <!-- REPLICATED cache mode. --> - <property name="cacheMode" value="REPLICATED"/> - - <!-- Set synchronous preloading (default is asynchronous). --> - <property name="preloadMode" value="SYNC"/> - - <!-- Initial cache size. --> - <property name="startSize" value="150000"/> - - <!-- - For better performance set this property to false in case - cache queries are not used. - Default value is false. - --> - <property name="queryIndexEnabled" value="true"/> - - <!-- Allow to index primitive values. --> - <property name="queryConfiguration"> - <bean class="org.apache.ignite.cache.query.CacheQueryConfiguration"> - <!-- Index primitives. --> - <property name="indexPrimitiveKey" value="true"/> - </bean> - </property> - </bean> - - <!-- - Local cache example configuration. - --> - <bean class="org.apache.ignite.configuration.CacheConfiguration"> - <!-- Cache name is 'local'. --> - <property name="name" value="local"/> - - <!-- LOCAL cache mode. --> - <property name="cacheMode" value="LOCAL"/> - - <!-- Initial cache size. --> - <property name="startSize" value="150000"/> - - <!-- - For better performance set this property to false in case - cache queries are not used. - Default value is false. - --> - <property name="queryIndexEnabled" value="true"/> - - <!-- Allow to index primitive values. --> - <property name="queryConfiguration"> - <bean class="org.apache.ignite.cache.query.CacheQueryConfiguration"> - <!-- Index primitives. --> - <property name="indexPrimitiveKey" value="true"/> - </bean> - </property> - </bean> - </list> - </property> - - <!-- - Uncomment this to provide TCP discovery SPI (Amazon EC2). - --> - <!-- - <property name="discoverySpi"> - <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi"> - <property name="ipFinder"> - <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.s3.TcpDiscoveryS3IpFinder"> - <property name="awsCredentials"> - <bean class="com.amazonaws.auth.BasicAWSCredentials"> - <constructor-arg value="YOUR_ACCESS_KEY_ID" /> - <constructor-arg value="YOUR_SECRET_ACCESS_KEY" /> - </bean> - </property> - <property name="bucketName" value="YOUR_BUCKET_NAME_IP_FINDER"/> - </bean> - </property> - <property name="heartbeatFrequency" value="2000"/> - </bean> - </property> - --> - - <!-- - Uncomment this to provide TCP discovery SPI (Local network). - - If path to shared file system is not explicitly provided, - then only local nodes will be able to discover each other. - --> - <!-- - <property name="discoverySpi"> - <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi"> - <property name="ipFinder"> - <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.sharedfs.TcpDiscoverySharedFsIpFinder"> - <property name="path" value="work/disco/tcp"/> - </bean> - </property> - </bean> - </property> - --> - - <!-- - TCP discovery SPI configuration with predefined addresses. - Use the addresses list to provide IP addresses of initial nodes in the grid - (at least one address must be provided). - - Note: - ===== - If running in distributed environment, you should change IP addresses to the actual IP addresses - of the servers on your network. Not all addresses need to be specified, only the addresses - of one or more servers which will always be started first. - --> - <property name="discoverySpi"> - <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi"> - <property name="ipFinder"> - <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder"> - <property name="addresses"> - <list> - <!-- - List all IP/port configurations that potentially - can be started first in examples. We are assuming - grid of size 10 or less. - --> - <value>127.0.0.1:47500</value> - <value>127.0.0.1:47501</value> - <value>127.0.0.1:47502</value> - <value>127.0.0.1:47503</value> - <value>127.0.0.1:47504</value> - <value>127.0.0.1:47505</value> - <value>127.0.0.1:47506</value> - <value>127.0.0.1:47507</value> - <value>127.0.0.1:47508</value> - <value>127.0.0.1:47509</value> - </list> - </property> - </bean> - <!-- - Uncomment this to provide IP finder using multicast for nodes discovery. - In addition to addresses received via multicast this finder can work with pre-configured - list of addresses. - --> - <!-- - <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder"> - <property name="addresses"> - <list> - <value>host1:port1</value> - <value>host2:port2</value> - </list> - </property> - </bean> - --> - </property> - </bean> - </property> - </bean> -</beans> http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5aba0234/modules/core/src/test/webapp/META-INF/ignite-webapp-config.xml ---------------------------------------------------------------------- diff --git a/modules/core/src/test/webapp/META-INF/ignite-webapp-config.xml b/modules/core/src/test/webapp/META-INF/ignite-webapp-config.xml new file mode 100644 index 0000000..a254173 --- /dev/null +++ b/modules/core/src/test/webapp/META-INF/ignite-webapp-config.xml @@ -0,0 +1,349 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<!-- + Ignite Spring configuration file to startup grid cache. + + When starting a standalone Ignite node, you need to execute the following command: + {IGNITE_HOME}/bin/ignite.{bat|sh} examples/config/spring-cache.xml + + When starting Ignite from Java IDE, pass path to this file into Ignition: + Ignition.start("examples/config/spring-cache.xml"); +--> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:util="http://www.springframework.org/schema/util" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans + http://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/util + http://www.springframework.org/schema/util/spring-util.xsd"> + <!-- + Configuration below demonstrates how to setup caches within grid nodes. + --> + <bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration"> + <property name="deploymentMode" value="SHARED"/> + + <!-- + For better performance set this property to false in case + peer deployment is not used. + Default value is false. + --> + <property name="peerClassLoadingEnabled" value="true"/> + + <!-- + Configure optimized marshaller. + --> + <property name="marshaller"> + <bean class="org.apache.ignite.marshaller.optimized.OptimizedMarshaller"> + <!-- + For better performance set this property to true in case + all marshalled classes implement java.io.Serializable. + Default value is true. + + Note, that it is recommended to implement java.io.Externalizable + instead of java.io.Serializable for smaller network footprint + and even better performance. + --> + <property name="requireSerializable" value="false"/> + </bean> + </property> + + <!-- Set to local host address just for examples. --> + <property name="localHost" value="127.0.0.1"/> + + <!-- Configure REST TCP server address. --> + <property name="connectorConfiguration"> + <bean class="org.apache.ignite.configuration.ConnectorConfiguration"> + <property name="host" value="127.0.0.1"/> + </bean> + </property> + + <!-- + Enable cache events. + --> + <property name="includeEventTypes"> + <util:constant static-field="org.apache.ignite.events.EventType.EVTS_CACHE"/> + </property> + + <property name="cacheConfiguration"> + <!-- + Specify list of cache configurations here. Any property from + CacheConfiguration interface can be configured here. + Note that absolutely all configuration properties are optional. + --> + <list> + <!-- + Partitioned cache example configuration (Atomic mode). + --> + <bean class="org.apache.ignite.configuration.CacheConfiguration"> + <property name="name" value="partitioned"/> + + <property name="cacheMode" value="PARTITIONED"/> + + <!-- Only atomic updates will be supported. --> + <property name="atomicityMode" value="ATOMIC"/> + + <!-- Enable primary sync write mode. --> + <property name="writeSynchronizationMode" value="PRIMARY_SYNC"/> + + <!-- Disable near cache in atomic mode. --> + <property name="distributionMode" value="PARTITIONED_ONLY"/> + + <!-- Initial cache size. --> + <property name="startSize" value="1500000"/> + + <!-- + For better performance set this property to false in case + cache queries are not used. + Default value is false. + --> + <property name="queryIndexEnabled" value="true"/> + + <!-- Allow to index primitive values. --> + <property name="queryConfiguration"> + <bean class="org.apache.ignite.cache.query.CacheQueryConfiguration"> + <!-- Index primitives. --> + <property name="indexPrimitiveKey" value="true"/> + </bean> + </property> + + <!-- + This shows how to configure number of backups. The below configuration + sets the number of backups to 1 (which is default). + --> + <property name="backups" value="1"/> + + <!-- Set synchronous preloading (default is asynchronous). --> + <property name="preloadMode" value="SYNC"/> + </bean> + + <!-- + Partitioned cache example configuration (Transactional mode). + --> + <bean class="org.apache.ignite.configuration.CacheConfiguration"> + <property name="name" value="partitioned_tx"/> + + <property name="cacheMode" value="PARTITIONED"/> + + <!-- Transactional updates supported. --> + <property name="atomicityMode" value="TRANSACTIONAL"/> + + <!-- Enable near cache to cache recently accessed data. --> + <property name="distributionMode" value="NEAR_PARTITIONED"/> + + <!-- Initial cache size. --> + <property name="startSize" value="1500000"/> + + <!-- + Setting this value will cause local node to wait for remote commits. + However, it's important to set it this way in the examples as we assert on + conditions that usually assume full completion of transactions on all nodes. + --> + <property name="writeSynchronizationMode" value="FULL_SYNC"/> + + <!-- + For better performance set this property to false in case + cache queries are not used. + Default value is false. + --> + <property name="queryIndexEnabled" value="true"/> + + <!-- Allow to index primitive values. --> + <property name="queryConfiguration"> + <bean class="org.apache.ignite.cache.query.CacheQueryConfiguration"> + <!-- Index primitives. --> + <property name="indexPrimitiveKey" value="true"/> + </bean> + </property> + + <!-- + This shows how to configure number of backups. The below configuration + sets the number of backups to 1 (which is default). + --> + <property name="backups" value="1"/> + + <!-- Set synchronous preloading (default is asynchronous). --> + <property name="preloadMode" value="SYNC"/> + </bean> + + <!-- + Replicated cache example configuration. + --> + <bean class="org.apache.ignite.configuration.CacheConfiguration"> + <property name="name" value="replicated"/> + + <!-- + Setting this value will cause local node to wait for remote commits. + However, it's important to set it this way in the examples as we assert on + conditions that usually assume full completion of transactions on all nodes. + --> + <property name="writeSynchronizationMode" value="FULL_SYNC"/> + + <!-- REPLICATED cache mode. --> + <property name="cacheMode" value="REPLICATED"/> + + <!-- Set synchronous preloading (default is asynchronous). --> + <property name="preloadMode" value="SYNC"/> + + <!-- Initial cache size. --> + <property name="startSize" value="150000"/> + + <!-- + For better performance set this property to false in case + cache queries are not used. + Default value is false. + --> + <property name="queryIndexEnabled" value="true"/> + + <!-- Allow to index primitive values. --> + <property name="queryConfiguration"> + <bean class="org.apache.ignite.cache.query.CacheQueryConfiguration"> + <!-- Index primitives. --> + <property name="indexPrimitiveKey" value="true"/> + </bean> + </property> + </bean> + + <!-- + Local cache example configuration. + --> + <bean class="org.apache.ignite.configuration.CacheConfiguration"> + <!-- Cache name is 'local'. --> + <property name="name" value="local"/> + + <!-- LOCAL cache mode. --> + <property name="cacheMode" value="LOCAL"/> + + <!-- Initial cache size. --> + <property name="startSize" value="150000"/> + + <!-- + For better performance set this property to false in case + cache queries are not used. + Default value is false. + --> + <property name="queryIndexEnabled" value="true"/> + + <!-- Allow to index primitive values. --> + <property name="queryConfiguration"> + <bean class="org.apache.ignite.cache.query.CacheQueryConfiguration"> + <!-- Index primitives. --> + <property name="indexPrimitiveKey" value="true"/> + </bean> + </property> + </bean> + </list> + </property> + + <!-- + Uncomment this to provide TCP discovery SPI (Amazon EC2). + --> + <!-- + <property name="discoverySpi"> + <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi"> + <property name="ipFinder"> + <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.s3.TcpDiscoveryS3IpFinder"> + <property name="awsCredentials"> + <bean class="com.amazonaws.auth.BasicAWSCredentials"> + <constructor-arg value="YOUR_ACCESS_KEY_ID" /> + <constructor-arg value="YOUR_SECRET_ACCESS_KEY" /> + </bean> + </property> + <property name="bucketName" value="YOUR_BUCKET_NAME_IP_FINDER"/> + </bean> + </property> + <property name="heartbeatFrequency" value="2000"/> + </bean> + </property> + --> + + <!-- + Uncomment this to provide TCP discovery SPI (Local network). + + If path to shared file system is not explicitly provided, + then only local nodes will be able to discover each other. + --> + <!-- + <property name="discoverySpi"> + <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi"> + <property name="ipFinder"> + <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.sharedfs.TcpDiscoverySharedFsIpFinder"> + <property name="path" value="work/disco/tcp"/> + </bean> + </property> + </bean> + </property> + --> + + <!-- + TCP discovery SPI configuration with predefined addresses. + Use the addresses list to provide IP addresses of initial nodes in the grid + (at least one address must be provided). + + Note: + ===== + If running in distributed environment, you should change IP addresses to the actual IP addresses + of the servers on your network. Not all addresses need to be specified, only the addresses + of one or more servers which will always be started first. + --> + <property name="discoverySpi"> + <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi"> + <property name="ipFinder"> + <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder"> + <property name="addresses"> + <list> + <!-- + List all IP/port configurations that potentially + can be started first in examples. We are assuming + grid of size 10 or less. + --> + <value>127.0.0.1:47500</value> + <value>127.0.0.1:47501</value> + <value>127.0.0.1:47502</value> + <value>127.0.0.1:47503</value> + <value>127.0.0.1:47504</value> + <value>127.0.0.1:47505</value> + <value>127.0.0.1:47506</value> + <value>127.0.0.1:47507</value> + <value>127.0.0.1:47508</value> + <value>127.0.0.1:47509</value> + </list> + </property> + </bean> + <!-- + Uncomment this to provide IP finder using multicast for nodes discovery. + In addition to addresses received via multicast this finder can work with pre-configured + list of addresses. + --> + <!-- + <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder"> + <property name="addresses"> + <list> + <value>host1:port1</value> + <value>host2:port2</value> + </list> + </property> + </bean> + --> + </property> + </bean> + </property> + </bean> +</beans> http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5aba0234/modules/core/src/test/webapp/WEB-INF/web.xml ---------------------------------------------------------------------- diff --git a/modules/core/src/test/webapp/WEB-INF/web.xml b/modules/core/src/test/webapp/WEB-INF/web.xml index 595c6aa..2710e6e 100644 --- a/modules/core/src/test/webapp/WEB-INF/web.xml +++ b/modules/core/src/test/webapp/WEB-INF/web.xml @@ -30,12 +30,12 @@ <!-- Declare filter for web sessions caching. --> <filter> - <filter-name>GridWebSessionsFilter</filter-name> - <filter-class>org.apache.ignite.cache.websession.GridWebSessionFilter</filter-class> + <filter-name>IgniteWebSessionsFilter</filter-name> + <filter-class>org.apache.ignite.cache.websession.IgniteWebSessionFilter</filter-class> </filter> <filter-mapping> - <filter-name>GridWebSessionsFilter</filter-name> + <filter-name>IgniteWebSessionsFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app> http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5aba0234/modules/web/src/main/java/org/apache/ignite/cache/websession/GridWebSession.java ---------------------------------------------------------------------- diff --git a/modules/web/src/main/java/org/apache/ignite/cache/websession/GridWebSession.java b/modules/web/src/main/java/org/apache/ignite/cache/websession/GridWebSession.java deleted file mode 100644 index b9079f1..0000000 --- a/modules/web/src/main/java/org/apache/ignite/cache/websession/GridWebSession.java +++ /dev/null @@ -1,286 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.cache.websession; - -import org.apache.ignite.internal.util.tostring.*; -import org.apache.ignite.internal.util.typedef.*; -import org.apache.ignite.internal.util.typedef.internal.*; -import org.jetbrains.annotations.*; - -import javax.servlet.*; -import javax.servlet.http.*; -import java.io.*; -import java.util.*; - -/** - * Session implementation. - */ -@SuppressWarnings({"deprecation", "NonSerializableObjectBoundToHttpSession"}) -class GridWebSession implements HttpSession, Externalizable { - /** */ - private static final long serialVersionUID = 0L; - - /** Empty session context. */ - private static final HttpSessionContext EMPTY_SES_CTX = new HttpSessionContext() { - @Nullable @Override public HttpSession getSession(String id) { - return null; - } - - @Override public Enumeration<String> getIds() { - return Collections.enumeration(Collections.<String>emptyList()); - } - }; - - /** Session ID. */ - private String id; - - /** Creation time. */ - private long createTime; - - /** Last access time. */ - private long accessTime; - - /** Maximum inactive interval. */ - private int maxInactiveInterval; - - /** Attributes. */ - @GridToStringInclude - private Map<String, Object> attrs; - - /** Servlet context. */ - @GridToStringExclude - private transient ServletContext ctx; - - /** Listener. */ - @GridToStringExclude - private transient GridWebSessionListener lsnr; - - /** New session flag. */ - private transient boolean isNew; - - /** Updates list. */ - private transient Collection<T2<String, Object>> updates; - - /** - * Required by {@link Externalizable}. - */ - public GridWebSession() { - // No-op. - } - - /** - * @param ses Session. - */ - GridWebSession(HttpSession ses) { - assert ses != null; - - id = ses.getId(); - createTime = ses.getCreationTime(); - accessTime = ses.getLastAccessedTime(); - maxInactiveInterval = ses.getMaxInactiveInterval(); - isNew = ses.isNew(); - - attrs = new HashMap<>(); - - Enumeration<String> names = ses.getAttributeNames(); - - while (names.hasMoreElements()) { - String name = names.nextElement(); - - attrs.put(name, ses.getAttribute(name)); - } - } - - /** - * @param ses Session. - * @param isNew Is new flag. - */ - GridWebSession(HttpSession ses, boolean isNew) { - this(ses); - - this.isNew = isNew; - } - - /** - * @param accessTime Last access time. - */ - void accessTime(long accessTime) { - this.accessTime = accessTime; - } - - /** - * @param ctx Servlet context. - */ - public void servletContext(ServletContext ctx) { - assert ctx != null; - - this.ctx = ctx; - } - - /** - * @param lsnr Listener. - */ - public void listener(GridWebSessionListener lsnr) { - assert lsnr != null; - - this.lsnr = lsnr; - } - - /** - * Resets updates list. - */ - public void resetUpdates() { - updates = new LinkedList<>(); - } - - /** - * @return Updates list. - */ - public Collection<T2<String, Object>> updates() { - Collection<T2<String, Object>> updates0 = updates; - - updates = null; - - return updates0; - } - - /** {@inheritDoc} */ - @Override public String getId() { - return id; - } - - /** {@inheritDoc} */ - @Override public ServletContext getServletContext() { - return ctx; - } - - /** {@inheritDoc} */ - @Override public long getCreationTime() { - return createTime; - } - - /** {@inheritDoc} */ - @Override public long getLastAccessedTime() { - return accessTime; - } - - /** {@inheritDoc} */ - @Override public int getMaxInactiveInterval() { - return maxInactiveInterval; - } - - /** {@inheritDoc} */ - @Override public void setMaxInactiveInterval(int interval) { - maxInactiveInterval = interval; - } - - /** {@inheritDoc} */ - @Override public Object getAttribute(String name) { - return attrs.get(name); - } - - /** {@inheritDoc} */ - @Override public Object getValue(String name) { - return attrs.get(name); - } - - /** {@inheritDoc} */ - @Override public Enumeration<String> getAttributeNames() { - return Collections.enumeration(attrs.keySet()); - } - - /** {@inheritDoc} */ - @Override public String[] getValueNames() { - return attrs.keySet().toArray(new String[attrs.size()]); - } - - /** {@inheritDoc} */ - @Override public void setAttribute(String name, Object val) { - attrs.put(name, val); - - if (updates != null) - updates.add(new T2<>(name, val)); - } - - /** {@inheritDoc} */ - @Override public void putValue(String name, Object val) { - setAttribute(name, val); - } - - /** {@inheritDoc} */ - @Override public void removeAttribute(String name) { - attrs.remove(name); - - if (updates != null) - updates.add(new T2<>(name, null)); - } - - /** {@inheritDoc} */ - @Override public void removeValue(String name) { - removeAttribute(name); - } - - /** {@inheritDoc} */ - @Override public void invalidate() { - attrs.clear(); - - updates = null; - - lsnr.destroySession(id); - } - - /** - * @param isNew New session flag. - */ - void setNew(boolean isNew) { - this.isNew = isNew; - } - - /** {@inheritDoc} */ - @Override public boolean isNew() { - return isNew; - } - - /** {@inheritDoc} */ - @Override public HttpSessionContext getSessionContext() { - return EMPTY_SES_CTX; - } - - /** {@inheritDoc} */ - @Override public void writeExternal(ObjectOutput out) throws IOException { - U.writeString(out, id); - out.writeLong(createTime); - out.writeLong(accessTime); - out.writeInt(maxInactiveInterval); - U.writeMap(out, attrs); - } - - /** {@inheritDoc} */ - @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { - id = U.readString(in); - createTime = in.readLong(); - accessTime = in.readLong(); - maxInactiveInterval = in.readInt(); - attrs = U.readMap(in); - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(GridWebSession.class, this); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5aba0234/modules/web/src/main/java/org/apache/ignite/cache/websession/GridWebSessionFilter.java ---------------------------------------------------------------------- diff --git a/modules/web/src/main/java/org/apache/ignite/cache/websession/GridWebSessionFilter.java b/modules/web/src/main/java/org/apache/ignite/cache/websession/GridWebSessionFilter.java deleted file mode 100644 index 298fccb..0000000 --- a/modules/web/src/main/java/org/apache/ignite/cache/websession/GridWebSessionFilter.java +++ /dev/null @@ -1,466 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.cache.websession; - -import org.apache.ignite.*; -import org.apache.ignite.cache.*; -import org.apache.ignite.configuration.*; -import org.apache.ignite.internal.util.typedef.*; -import org.apache.ignite.internal.util.typedef.internal.*; -import org.apache.ignite.lang.*; -import org.apache.ignite.transactions.*; - -import javax.cache.*; -import javax.cache.expiry.*; -import javax.servlet.*; -import javax.servlet.http.*; -import java.io.*; -import java.util.*; - -import static java.util.concurrent.TimeUnit.*; -import static org.apache.ignite.cache.CacheAtomicityMode.*; -import static org.apache.ignite.cache.CacheMode.*; -import static org.apache.ignite.cache.CacheWriteSynchronizationMode.*; -import static org.apache.ignite.transactions.IgniteTxConcurrency.*; -import static org.apache.ignite.transactions.IgniteTxIsolation.*; - -/** - * Filter for web sessions caching. - * <p> - * This is a request filter, that you need to specify in your {@code web.xml} along - * with {@link org.apache.ignite.startup.servlet.IgniteServletContextListenerStartup} to enable web sessions caching: - * <pre name="code" class="xml"> - * <listener> - * <listener-class>org.apache.ignite.startup.servlet.IgniteServletContextListenerStartup</listener-class> - * </listener> - * - * <filter> - * <filter-name>GridWebSessionFilter</filter-name> - * <filter-class>org.apache.ignite.cache.websession.GridWebSessionFilter</filter-class> - * </filter> - * - * <!-- You can also specify a custom URL pattern. --> - * <filter-mapping> - * <filter-name>GridWebSessionsFilter</filter-name> - * <url-pattern>/*</url-pattern> - * </filter-mapping> - * </pre> - * It is also possible to specify a servlet name in a filter mapping, and a servlet URL pattern will - * be used in this case: - * <pre name="code" class="xml"> - * <filter> - * <filter-name>GridWebSessionFilter</filter-name> - * <filter-class>org.apache.ignite.cache.websession.GridWebSessionFilter</filter-class> - * </filter> - * - * <filter-mapping> - * <filter-name>GridWebSessionFilter</filter-name> - * <servlet-name>YourServletName</servlet-name> - * </filter-mapping> - * </pre> - * The filter has the following optional configuration parameters: - * <table class="doctable"> - * <tr> - * <th>Name</th> - * <th>Description</th> - * <th>Default</th> - * </tr> - * <tr> - * <td>IgniteWebSessionsGridName</td> - * <td>Name of the grid that contains cache for web session storage.</td> - * <td>{@code null} (default grid)</td> - * </tr> - * <tr> - * <td>IgniteWebSessionsCacheName</td> - * <td>Name of the cache for web session storage.</td> - * <td>{@code null} (default cache)</td> - * </tr> - * <tr> - * <td>IgniteWebSessionsMaximumRetriesOnFail</td> - * <td> - * Valid for {@code ATOMIC} caches only. Maximum number of retries for session updates in case - * node leaves topology and update fails. If retry is enabled, - * some updates can be applied more than once, otherwise some - * updates can be lost. - * <p> - * To disable retries, set this parameter to {@code 0}. - * </td> - * <td>{@code 3}</td> - * </tr> - * </table> - * These parameters are taken from either filter init parameter list or - * servlet context parameters. You can specify filter init parameters as follows: - * <pre name="code" class="xml"> - * <filter> - * <filter-name>GridWebSessionFilter</filter-name> - * <filter-class>org.apache.ignite.cache.websession.GridWebSessionFilter</filter-class> - * <init-param> - * <param-name>IgniteWebSessionsGridName</param-name> - * <param-value>WebGrid</param-value> - * </init-param> - * <init-param> - * <param-name>IgniteWebSessionsCacheName</param-name> - * <param-value>WebCache</param-value> - * </init-param> - * - * <!-- Valid for ATOMIC caches only. --> - * <init-param> - * <param-name>IgniteWebSessionsMaximumRetriesOnFail</param-name> - * <param-value>10</param-value> - * </init-param> - * </filter> - * </pre> - * <b>Note:</b> filter init parameter has a priority over servlet context - * parameter; if you specify both, the servlet context parameter will be ignored. - * <h1 class="header">Web sessions caching and concurrent requests</h1> - * If your web application can accept concurrent request for one session, - * consider using {@link org.apache.ignite.cache.CacheAtomicityMode#TRANSACTIONAL} cache - * instead of {@link org.apache.ignite.cache.CacheAtomicityMode#ATOMIC}. In this case each request - * be processed inside pessimistic transaction which will guarantee that all - * updates will be applied in correct order. This is important, for example, - * if you get some attribute from the session, update its value and set new - * value back to the session. In case of {@link org.apache.ignite.cache.CacheAtomicityMode#ATOMIC} - * cache concurrent requests can get equal value, but {@link org.apache.ignite.cache.CacheAtomicityMode#TRANSACTIONAL} - * cache will always process such updates one after another. - */ -public class GridWebSessionFilter implements Filter { - /** Web sessions caching grid name parameter name. */ - public static final String WEB_SES_NAME_PARAM = "IgniteWebSessionsGridName"; - - /** Web sessions caching cache name parameter name. */ - public static final String WEB_SES_CACHE_NAME_PARAM = "IgniteWebSessionsCacheName"; - - /** Web sessions caching retry on fail parameter name (valid for ATOMIC */ - public static final String WEB_SES_MAX_RETRIES_ON_FAIL_NAME_PARAM = "IgniteWebSessionsMaximumRetriesOnFail"; - - /** Default retry on fail flag value. */ - public static final int DFLT_MAX_RETRIES_ON_FAIL = 3; - - /** Cache. */ - private IgniteCache<String, GridWebSession> cache; - - /** Transactions. */ - private IgniteTransactions txs; - - /** Listener. */ - private GridWebSessionListener lsnr; - - /** Logger. */ - private IgniteLogger log; - - /** Servlet context. */ - private ServletContext ctx; - - /** Session ID transformer. */ - private IgniteClosure<String, String> sesIdTransformer; - - /** Transactions enabled flag. */ - private boolean txEnabled; - - /** {@inheritDoc} */ - @Override public void init(FilterConfig cfg) throws ServletException { - ctx = cfg.getServletContext(); - - String gridName = U.firstNotNull( - cfg.getInitParameter(WEB_SES_NAME_PARAM), - ctx.getInitParameter(WEB_SES_NAME_PARAM)); - - String cacheName = U.firstNotNull( - cfg.getInitParameter(WEB_SES_CACHE_NAME_PARAM), - ctx.getInitParameter(WEB_SES_CACHE_NAME_PARAM)); - - String retriesStr = U.firstNotNull( - cfg.getInitParameter(WEB_SES_MAX_RETRIES_ON_FAIL_NAME_PARAM), - ctx.getInitParameter(WEB_SES_MAX_RETRIES_ON_FAIL_NAME_PARAM)); - - int retries; - - try { - retries = retriesStr != null ? Integer.parseInt(retriesStr) : DFLT_MAX_RETRIES_ON_FAIL; - } - catch (NumberFormatException e) { - throw new IgniteException("Maximum number of retries parameter is invalid: " + retriesStr, e); - } - - Ignite webSesIgnite = G.ignite(gridName); - - if (webSesIgnite == null) - throw new IgniteException("Grid for web sessions caching is not started (is it configured?): " + - gridName); - - txs = webSesIgnite.transactions(); - - log = webSesIgnite.log(); - - if (webSesIgnite == null) - throw new IgniteException("Grid for web sessions caching is not started (is it configured?): " + - gridName); - - cache = webSesIgnite.jcache(cacheName); - - if (cache == null) - throw new IgniteException("Cache for web sessions is not started (is it configured?): " + cacheName); - - CacheConfiguration cacheCfg = cache.getConfiguration(CacheConfiguration.class); - - if (cacheCfg.getWriteSynchronizationMode() == FULL_ASYNC) - throw new IgniteException("Cache for web sessions cannot be in FULL_ASYNC mode: " + cacheName); - - if (!cacheCfg.isEagerTtl()) - throw new IgniteException("Cache for web sessions cannot operate with lazy TTL. " + - "Consider setting eagerTtl to true for cache: " + cacheName); - - if (cacheCfg.getCacheMode() == LOCAL) - U.quietAndWarn(webSesIgnite.log(), "Using LOCAL cache for web sessions caching " + - "(this is only OK in test mode): " + cacheName); - - if (cacheCfg.getCacheMode() == PARTITIONED && cacheCfg.getAtomicityMode() != ATOMIC) - U.quietAndWarn(webSesIgnite.log(), "Using " + cacheCfg.getAtomicityMode() + " atomicity for web sessions " + - "caching (switch to ATOMIC mode for better performance)"); - - if (log.isInfoEnabled()) - log.info("Started web sessions caching [gridName=" + gridName + ", cacheName=" + cacheName + - ", maxRetriesOnFail=" + retries + ']'); - - txEnabled = cacheCfg.getAtomicityMode() == TRANSACTIONAL; - - lsnr = new GridWebSessionListener(webSesIgnite, cache, retries); - - String srvInfo = ctx.getServerInfo(); - - // Special case for WebLogic, which appends timestamps to session - // IDs upon session creation (the created session ID looks like: - // pdpTSTcCcG6CVM8BTZWzxjTB1lh3w7zFbYVvwBb4bJGjrBx3TMPl!-508312620!1385045122601). - if (srvInfo != null && srvInfo.contains("WebLogic")) { - sesIdTransformer = new C1<String, String>() { - @Override public String apply(String s) { - // Find first exclamation mark. - int idx = s.indexOf('!'); - - // Return original string if not found. - if (idx < 0 || idx == s.length() - 1) - return s; - - // Find second exclamation mark. - idx = s.indexOf('!', idx + 1); - - // Return original string if not found. - if (idx < 0) - return s; - - // Return the session ID without timestamp. - return s.substring(0, idx); - } - }; - } - } - - /** {@inheritDoc} */ - @Override public void destroy() { - // No-op. - } - - /** {@inheritDoc} */ - @Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) - throws IOException, ServletException { - assert ctx != null; - - if (req instanceof HttpServletRequest) { - HttpServletRequest httpReq = (HttpServletRequest)req; - - String sesId = null; - - try { - if (txEnabled) { - try (IgniteTx tx = txs.txStart(PESSIMISTIC, REPEATABLE_READ)) { - sesId = doFilter0(httpReq, res, chain); - - tx.commit(); - } - } - else - sesId = doFilter0(httpReq, res, chain); - } - catch (Exception e) { - U.error(log, "Failed to update web session: " + sesId, e); - } - } - else - chain.doFilter(req, res); - } - - /** - * @param httpReq Request. - * @param res Response. - * @param chain Filter chain. - * @return Session ID. - * @throws IOException In case of I/O error. - * @throws ServletException In case oif servlet error. - * @throws CacheException In case of other error. - */ - private String doFilter0(HttpServletRequest httpReq, ServletResponse res, FilterChain chain) throws IOException, - ServletException, CacheException { - GridWebSession cached; - - String sesId = httpReq.getRequestedSessionId(); - - if (sesId != null) { - cached = cache.get(sesId); - - if (cached != null) { - if (log.isDebugEnabled()) - log.debug("Using cached session for ID: " + sesId); - - if (cached.isNew()) - cached = new GridWebSession(cached, false); - } - else { - if (log.isDebugEnabled()) - log.debug("Cached session was invalidated and doesn't exist: " + sesId); - - HttpSession ses = httpReq.getSession(false); - - if (ses != null) { - try { - ses.invalidate(); - } - catch (IllegalStateException ignore) { - // Session was already invalidated. - } - } - - cached = createSession(httpReq); - } - } - else { - cached = createSession(httpReq); - - sesId = cached.getId(); - } - - assert cached != null; - - cached.servletContext(ctx); - cached.listener(lsnr); - cached.resetUpdates(); - - httpReq = new RequestWrapper(httpReq, cached); - - chain.doFilter(httpReq, res); - - HttpSession ses = httpReq.getSession(false); - - if (ses != null && ses instanceof GridWebSession) { - Collection<T2<String, Object>> updates = ((GridWebSession)ses).updates(); - - if (updates != null) - lsnr.updateAttributes(ses.getId(), updates, ses.getMaxInactiveInterval()); - } - - return sesId; - } - - /** - * @param httpReq HTTP request. - * @return Cached session. - */ - @SuppressWarnings("unchecked") - private GridWebSession createSession(HttpServletRequest httpReq) { - HttpSession ses = httpReq.getSession(true); - - String sesId = sesIdTransformer != null ? sesIdTransformer.apply(ses.getId()) : ses.getId(); - - if (log.isDebugEnabled()) - log.debug("Session created: " + sesId); - - GridWebSession cached = new GridWebSession(ses, true); - - try { - while (true) { - try { - IgniteCache<String, GridWebSession> cache0; - - if (cached.getMaxInactiveInterval() > 0) { - long ttl = cached.getMaxInactiveInterval() * 1000; - - ExpiryPolicy plc = new ModifiedExpiryPolicy(new Duration(MILLISECONDS, ttl)); - - cache0 = cache.withExpiryPolicy(plc); - } - else - cache0 = cache; - - GridWebSession old = cache0.getAndPutIfAbsent(sesId, cached); - - if (old != null) { - cached = old; - - if (cached.isNew()) - cached = new GridWebSession(cached, false); - } - - break; - } - catch (CachePartialUpdateException e) { - if (log.isDebugEnabled()) - log.debug(e.getMessage()); - } - } - } - catch (CacheException e) { - throw new IgniteException("Failed to save session: " + sesId, e); - } - - return cached; - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(GridWebSessionFilter.class, this); - } - - /** - * Request wrapper. - */ - private static class RequestWrapper extends HttpServletRequestWrapper { - /** Session. */ - private final GridWebSession ses; - - /** - * @param req Request. - * @param ses Session. - */ - private RequestWrapper(HttpServletRequest req, GridWebSession ses) { - super(req); - - assert ses != null; - - this.ses = ses; - } - - /** {@inheritDoc} */ - @Override public HttpSession getSession(boolean create) { - return ses; - } - - /** {@inheritDoc} */ - @Override public HttpSession getSession() { - return ses; - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5aba0234/modules/web/src/main/java/org/apache/ignite/cache/websession/GridWebSessionListener.java ---------------------------------------------------------------------- diff --git a/modules/web/src/main/java/org/apache/ignite/cache/websession/GridWebSessionListener.java b/modules/web/src/main/java/org/apache/ignite/cache/websession/GridWebSessionListener.java deleted file mode 100644 index 32db814..0000000 --- a/modules/web/src/main/java/org/apache/ignite/cache/websession/GridWebSessionListener.java +++ /dev/null @@ -1,196 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.cache.websession; - -import org.apache.ignite.*; -import org.apache.ignite.cache.*; -import org.apache.ignite.internal.*; -import org.apache.ignite.internal.util.typedef.*; -import org.apache.ignite.internal.util.typedef.internal.*; - -import javax.cache.*; -import javax.cache.expiry.*; -import javax.cache.processor.*; -import java.io.*; -import java.util.*; - -import static java.util.concurrent.TimeUnit.*; - -/** - * Session listener for web sessions caching. - */ -class GridWebSessionListener { - /** */ - private static final long RETRY_DELAY = 1; - - /** Cache. */ - private final IgniteCache<String, GridWebSession> cache; - - /** Maximum retries. */ - private final int retries; - - /** Logger. */ - private final IgniteLogger log; - - /** - * @param ignite Grid. - * @param cache Cache. - * @param retries Maximum retries. - */ - GridWebSessionListener(Ignite ignite, IgniteCache<String, GridWebSession> cache, int retries) { - assert ignite != null; - assert cache != null; - - this.cache = cache; - this.retries = retries > 0 ? retries : 1; - - log = ignite.log(); - } - - /** - * @param sesId Session ID. - */ - public void destroySession(String sesId) { - assert sesId != null; - - try { - if (cache.remove(sesId) && log.isDebugEnabled()) - log.debug("Session destroyed: " + sesId); - } - catch (CacheException e) { - U.error(log, "Failed to remove session: " + sesId, e); - } - } - - /** - * @param sesId Session ID. - * @param updates Updates list. - * @param maxInactiveInterval Max session inactive interval. - */ - @SuppressWarnings("unchecked") - public void updateAttributes(String sesId, Collection<T2<String, Object>> updates, int maxInactiveInterval) { - assert sesId != null; - assert updates != null; - - if (log.isDebugEnabled()) - log.debug("Session attributes updated [id=" + sesId + ", updates=" + updates + ']'); - - try { - for (int i = 0; i < retries; i++) { - try { - IgniteCache<String, GridWebSession> cache0; - - if (maxInactiveInterval > 0) { - long ttl = maxInactiveInterval * 1000; - - ExpiryPolicy plc = new ModifiedExpiryPolicy(new Duration(MILLISECONDS, ttl)); - - cache0 = cache.withExpiryPolicy(plc); - } - else - cache0 = cache; - - cache0.invoke(sesId, new AttributesProcessor(updates)); - - break; - } - catch (CachePartialUpdateException ignored) { - if (i == retries - 1) { - U.warn(log, "Failed to apply updates for session (maximum number of retries exceeded) [sesId=" + - sesId + ", retries=" + retries + ']'); - } - else { - U.warn(log, "Failed to apply updates for session (will retry): " + sesId); - - U.sleep(RETRY_DELAY); - } - } - } - } - catch (CacheException | IgniteInterruptedCheckedException e) { - U.error(log, "Failed to update session attributes [id=" + sesId + ']', e); - } - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(GridWebSessionListener.class, this); - } - - /** - * Multiple attributes update transformer. - */ - private static class AttributesProcessor implements EntryProcessor<String, GridWebSession, Void>, Externalizable { - /** */ - private static final long serialVersionUID = 0L; - - /** Updates list. */ - private Collection<T2<String, Object>> updates; - - /** - * Required by {@link Externalizable}. - */ - public AttributesProcessor() { - // No-op. - } - - /** - * @param updates Updates list. - */ - AttributesProcessor(Collection<T2<String, Object>> updates) { - assert updates != null; - - this.updates = updates; - } - - /** {@inheritDoc} */ - @Override public Void process(MutableEntry<String, GridWebSession> entry, Object... args) { - if (!entry.exists()) - return null; - - GridWebSession ses = new GridWebSession(entry.getValue()); - - for (T2<String, Object> update : updates) { - String name = update.get1(); - - assert name != null; - - Object val = update.get2(); - - if (val != null) - ses.setAttribute(name, val); - else - ses.removeAttribute(name); - } - - entry.setValue(ses); - - return null; - } - - /** {@inheritDoc} */ - @Override public void writeExternal(ObjectOutput out) throws IOException { - U.writeCollection(out, updates); - } - - /** {@inheritDoc} */ - @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { - updates = U.readCollection(in); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5aba0234/modules/web/src/main/java/org/apache/ignite/cache/websession/IgniteWebSession.java ---------------------------------------------------------------------- diff --git a/modules/web/src/main/java/org/apache/ignite/cache/websession/IgniteWebSession.java b/modules/web/src/main/java/org/apache/ignite/cache/websession/IgniteWebSession.java new file mode 100644 index 0000000..70c4e27 --- /dev/null +++ b/modules/web/src/main/java/org/apache/ignite/cache/websession/IgniteWebSession.java @@ -0,0 +1,286 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.cache.websession; + +import org.apache.ignite.internal.util.tostring.*; +import org.apache.ignite.internal.util.typedef.*; +import org.apache.ignite.internal.util.typedef.internal.*; +import org.jetbrains.annotations.*; + +import javax.servlet.*; +import javax.servlet.http.*; +import java.io.*; +import java.util.*; + +/** + * Session implementation. + */ +@SuppressWarnings({"deprecation", "NonSerializableObjectBoundToHttpSession"}) +class IgniteWebSession implements HttpSession, Externalizable { + /** */ + private static final long serialVersionUID = 0L; + + /** Empty session context. */ + private static final HttpSessionContext EMPTY_SES_CTX = new HttpSessionContext() { + @Nullable @Override public HttpSession getSession(String id) { + return null; + } + + @Override public Enumeration<String> getIds() { + return Collections.enumeration(Collections.<String>emptyList()); + } + }; + + /** Session ID. */ + private String id; + + /** Creation time. */ + private long createTime; + + /** Last access time. */ + private long accessTime; + + /** Maximum inactive interval. */ + private int maxInactiveInterval; + + /** Attributes. */ + @GridToStringInclude + private Map<String, Object> attrs; + + /** Servlet context. */ + @GridToStringExclude + private transient ServletContext ctx; + + /** Listener. */ + @GridToStringExclude + private transient IgniteWebSessionListener lsnr; + + /** New session flag. */ + private transient boolean isNew; + + /** Updates list. */ + private transient Collection<T2<String, Object>> updates; + + /** + * Required by {@link Externalizable}. + */ + public IgniteWebSession() { + // No-op. + } + + /** + * @param ses Session. + */ + IgniteWebSession(HttpSession ses) { + assert ses != null; + + id = ses.getId(); + createTime = ses.getCreationTime(); + accessTime = ses.getLastAccessedTime(); + maxInactiveInterval = ses.getMaxInactiveInterval(); + isNew = ses.isNew(); + + attrs = new HashMap<>(); + + Enumeration<String> names = ses.getAttributeNames(); + + while (names.hasMoreElements()) { + String name = names.nextElement(); + + attrs.put(name, ses.getAttribute(name)); + } + } + + /** + * @param ses Session. + * @param isNew Is new flag. + */ + IgniteWebSession(HttpSession ses, boolean isNew) { + this(ses); + + this.isNew = isNew; + } + + /** + * @param accessTime Last access time. + */ + void accessTime(long accessTime) { + this.accessTime = accessTime; + } + + /** + * @param ctx Servlet context. + */ + public void servletContext(ServletContext ctx) { + assert ctx != null; + + this.ctx = ctx; + } + + /** + * @param lsnr Listener. + */ + public void listener(IgniteWebSessionListener lsnr) { + assert lsnr != null; + + this.lsnr = lsnr; + } + + /** + * Resets updates list. + */ + public void resetUpdates() { + updates = new LinkedList<>(); + } + + /** + * @return Updates list. + */ + public Collection<T2<String, Object>> updates() { + Collection<T2<String, Object>> updates0 = updates; + + updates = null; + + return updates0; + } + + /** {@inheritDoc} */ + @Override public String getId() { + return id; + } + + /** {@inheritDoc} */ + @Override public ServletContext getServletContext() { + return ctx; + } + + /** {@inheritDoc} */ + @Override public long getCreationTime() { + return createTime; + } + + /** {@inheritDoc} */ + @Override public long getLastAccessedTime() { + return accessTime; + } + + /** {@inheritDoc} */ + @Override public int getMaxInactiveInterval() { + return maxInactiveInterval; + } + + /** {@inheritDoc} */ + @Override public void setMaxInactiveInterval(int interval) { + maxInactiveInterval = interval; + } + + /** {@inheritDoc} */ + @Override public Object getAttribute(String name) { + return attrs.get(name); + } + + /** {@inheritDoc} */ + @Override public Object getValue(String name) { + return attrs.get(name); + } + + /** {@inheritDoc} */ + @Override public Enumeration<String> getAttributeNames() { + return Collections.enumeration(attrs.keySet()); + } + + /** {@inheritDoc} */ + @Override public String[] getValueNames() { + return attrs.keySet().toArray(new String[attrs.size()]); + } + + /** {@inheritDoc} */ + @Override public void setAttribute(String name, Object val) { + attrs.put(name, val); + + if (updates != null) + updates.add(new T2<>(name, val)); + } + + /** {@inheritDoc} */ + @Override public void putValue(String name, Object val) { + setAttribute(name, val); + } + + /** {@inheritDoc} */ + @Override public void removeAttribute(String name) { + attrs.remove(name); + + if (updates != null) + updates.add(new T2<>(name, null)); + } + + /** {@inheritDoc} */ + @Override public void removeValue(String name) { + removeAttribute(name); + } + + /** {@inheritDoc} */ + @Override public void invalidate() { + attrs.clear(); + + updates = null; + + lsnr.destroySession(id); + } + + /** + * @param isNew New session flag. + */ + void setNew(boolean isNew) { + this.isNew = isNew; + } + + /** {@inheritDoc} */ + @Override public boolean isNew() { + return isNew; + } + + /** {@inheritDoc} */ + @Override public HttpSessionContext getSessionContext() { + return EMPTY_SES_CTX; + } + + /** {@inheritDoc} */ + @Override public void writeExternal(ObjectOutput out) throws IOException { + U.writeString(out, id); + out.writeLong(createTime); + out.writeLong(accessTime); + out.writeInt(maxInactiveInterval); + U.writeMap(out, attrs); + } + + /** {@inheritDoc} */ + @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + id = U.readString(in); + createTime = in.readLong(); + accessTime = in.readLong(); + maxInactiveInterval = in.readInt(); + attrs = U.readMap(in); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(IgniteWebSession.class, this); + } +}