谢谢您的建议答案。但是,我认为我已经使用以下配置解决了此问题。希望任何人对此配置提供任何反馈。
我的方法:
1)使用spring配置建立实例。2)使用带有Web过滤器配置的最低配置的hazelcast.xml文件增强实例。请注意,mulitcast和tcp-
ip连接器为假。
web.xml:
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"><!-- The definition of the Root Spring Container shared by all Servlets and Filters --> <context-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/spring/servlet-context.xml, /WEB-INF/spring/root-context.xml, .... /WEB-INF/spring/hazelcastContext.xml </param-value> </context-param><listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener>....<filter> <filter-name>hazelcast-filter</filter-name> <filter-class>com.hazelcast.web.WebFilter</filter-class> <!-- Name of the distributed map storing your web session objects --> <init-param> <param-name>map-name</param-name> <param-value>my-sessions</param-value> </init-param> <!-- How is your load-balancer configured? stick-session means all requests of a session is routed to the node where the session is first created. This is excellent for performance. If sticky-session is set to false, when a session is updated on a node, entry for this session on all other nodes is invalidated. You have to know how your load-balancer is configured before setting this parameter. Default is true. --> <init-param> <param-name>sticky-session</param-name> <param-value>true</param-value> </init-param> <!-- Name of session id cookie --> <init-param> <param-name>cookie-name</param-name> <param-value>hazelcast.sessionId</param-value> </init-param> <!-- Domain of session id cookie. Default is based on incoming request. --> <init-param> <param-name>cookie-domain</param-name> <param-value>.mycompany.com</param-value> </init-param> <!-- Should cookie only be sent using a secure protocol? Default is false. --> <init-param> <param-name>cookie-secure</param-name> <param-value>false</param-value> </init-param> <!-- Should Httponly attribute be set on cookie ? Default is false. --> <init-param> <param-name>cookie-http-only</param-name> <param-value>false</param-value> </init-param> <!-- Are you debugging? Default is false. --> <init-param> <param-name>debug</param-name> <param-value>true</param-value> </init-param> <!-- Configuration xml location; * as servlet resource OR * as classpath resource OR * as URL Default is one of hazelcast-default.xml or hazelcast.xml in classpath. --> <init-param> <param-name>config-location</param-name> <param-value>/WEB-INF/classes/hazelcast.xml</param-value> </init-param> <!-- Do you want to use an existing HazelcastInstance? Default is null. -->`enter pre here` <init-param> <param-name>instance-name</param-name> <param-value>myapp</param-value> </init-param> <!-- Do you want to connect as a client to an existing cluster? Default is false. --> <init-param> <param-name>use-client</param-name> <param-value>false</param-value> </init-param> <!-- Client configuration location; * as servlet resource OR * as classpath resource OR * as URL Default is null. --> <init-param> <param-name>client-config-location</param-name> <param-value>/WEB-INF/classes/hazelcast-client.properties</param-value> </init-param> <!-- Do you want to shutdown HazelcastInstance during web application undeploy process? Default is true. --> <init-param> <param-name>shutdown-on-destroy</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>hazelcast-filter</filter-name> <url-pattern>/*</url-pattern> <dispatcher>FORWARD</dispatcher> <dispatcher>INCLUDE</dispatcher> <dispatcher>REQUEST</dispatcher> </filter-mapping>...</web-app>
hazelcast.xml(从jar文件中的hazelcast.xml复制)…
<hazelcast xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-2.4.xsd"xmlns="http://www.hazelcast.com/schema/config"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">...<network> <port auto-increment="true">5701</port> <outbound-ports> <!-- Allowed port range when connecting to other nodes. 0 or * means use system provided port. --> <ports>0</ports> </outbound-ports> <join> <multicast enabled="false"> <multicast-group>224.2.2.3</multicast-group> <multicast-port>54327</multicast-port> </multicast> <tcp-ip enabled="false"> <interface>127.0.0.1</interface> </tcp-ip> ... </join> ...</network>...</hazelcast>
弹簧配置…
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:hz="http://www.hazelcast.com/schema/spring" xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.hazelcast.com/schema/springhttp://www.hazelcast.com/schema/spring/hazelcast-spring-2.4.xsd"><bean id="hazelcast" /><!-- Hazelcast Instance configuration --><hz:hazelcast id="myapp"> <hz:config> <!-- Hazelcast Instance Name --> <hz:instance-name>${hz.instance.name}</hz:instance-name> <!-- Hazelcast Group Name and Password --> <hz:group name="${hz.group.name}" password="${hz.group.password}" /> <!-- Hazelcast Management Center URL --> <hz:management-center enabled="${hz.management.center.enabled}" url="${hz.management.center.url}" /> <!-- Hazelcast Tcp based network configuration --> <hz:network port="${hz.network.port}" port-auto-increment="${hz.network.port.auto.increment}"> <hz:join> <hz:multicast enabled="${hz.multicast.enabled}" multicast-group="224.2.2.3" multicast-port="54327" /> <hz:tcp-ip enabled="${hz.tcp.ip.enabled}"> <hz:members>${hz.members}</hz:members> </hz:tcp-ip> </hz:join> </hz:network> <!-- Hazelcast Distributed Map configuration --> <hz:map name="map" backup-count="${hz.map.backup.count}" max-size="${hz.map.max.size}" eviction-percentage="${hz.map.eviction.percentage}" read-backup-data="${hz.map.read.backup.data}" eviction-policy="${hz.map.eviction.policy}" merge-policy="${hz.map.merge.policy}" /> </hz:config></hz:hazelcast>属性文件…。
#-- Hazelcast properties.hz.instance.name = myapphz.group.name = CERThz.group.password = certhz.management.center.enabled = truehz.management.center.url = http://127.0.0.1:8080/mancenterhz.network.port = 5701hz.network.port.auto.increment = truehz.multicast.enabled = truehz.tcp.ip.enabled = falsehz.members = 127.0.0.1hz.executor.service.core.pool.size = 2hz.executor.service.max.pool.size = 30hz.executor.service.keep.alive.seconds = 30hz.map.backup.count=2hz.map.max.size=0hz.map.eviction.percentage=30hz.map.read.backup.data=truehz.map.cache.value=truehz.map.eviction.policy=NONEhz.map.merge.policy=hz.ADD_NEW_ENTRY
根Context.xml
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:hz="http://www.hazelcast.com/schema/spring" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd http://www.hazelcast.com/schema/spring http://www.hazelcast.com/schema/spring/hazelcast-spring-2.4.xsd">... <bean id="propertyConfigurer" > <property name="locations"> <list> <jee:jndi-lookup jndi-name="java:comp/env/config_file" /> </list> </property> </bean>...</beans>
Tomcat配置…
<Host appbase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">... <Context docbase="myapp" path="/myapp" reloadable="true" source="org.eclipse.jst.j2ee.server:pwc-ws"> <Environment description="" name="config_file" override="false" type="java.lang.String" value="file:c:/path/to/config/myapp.properties" /> </Context>...</Host>
Tomcat输出(注意:这是两个节点hazelcast组的重新启动方案。在这种情况下,节点1重新启动。节点2的输出显示节点1从该组中删除,然后返回到该组)。
组CERT的节点1
Nov 19, 2013 4:27:56 PM com.hazelcast.impl.AddressPickerINFO: Prefer IPv4 stack is true.Nov 19, 2013 4:27:56 PM com.hazelcast.impl.AddressPickerINFO: Picked Address[10.23.43.13]:5701, using socket ServerSocket[addr=/0:0:0:0:0:0:0:0,localport=5701], bind any local is trueNov 19, 2013 4:27:57 PM com.hazelcast.systemINFO: [10.23.43.13]:5701 [CERT] Hazelcast Community Edition 2.4 (20121017) starting at Address[10.23.43.13]:5701Nov 19, 2013 4:27:57 PM com.hazelcast.systemINFO: [10.23.43.13]:5701 [CERT] Copyright (C) 2008-2012 Hazelcast.comNov 19, 2013 4:27:57 PM com.hazelcast.impl.LifecycleServiceImplINFO: [10.23.43.13]:5701 [CERT] Address[10.23.43.13]:5701 is STARTINGNov 19, 2013 4:27:57 PM com.hazelcast.impl.NodeINFO: [10.23.43.13]:5701 [CERT] ** setting master address to Address[10.23.43.14]:5701Nov 19, 2013 4:27:57 PM com.hazelcast.impl.MulticastJoinerINFO: [10.23.43.13]:5701 [CERT] Connecting to master node: Address[10.23.43.14]:5701Nov 19, 2013 4:27:57 PM com.hazelcast.nio.ConnectionManagerINFO: [10.23.43.13]:5701 [CERT] 54106 accepted socket connection from /10.23.43.14:5701Nov 19, 2013 4:27:57 PM com.hazelcast.impl.NodeINFO: [10.23.43.13]:5701 [CERT] ** setting master address to Address[10.23.43.14]:5701Nov 19, 2013 4:27:57 PM com.hazelcast.impl.NodeINFO: [10.23.43.13]:5701 [CERT] ** setting master address to Address[10.23.43.14]:5701Nov 19, 2013 4:27:58 PM com.hazelcast.impl.NodeINFO: [10.23.43.13]:5701 [CERT] ** setting master address to Address[10.23.43.14]:5701Nov 19, 2013 4:27:58 PM com.hazelcast.impl.NodeINFO: [10.23.43.13]:5701 [CERT] ** setting master address to Address[10.23.43.14]:5701Nov 19, 2013 4:27:59 PM com.hazelcast.impl.NodeINFO: [10.23.43.13]:5701 [CERT] ** setting master address to Address[10.23.43.14]:5701Nov 19, 2013 4:27:59 PM com.hazelcast.impl.NodeINFO: [10.23.43.13]:5701 [CERT] ** setting master address to Address[10.23.43.14]:5701Nov 19, 2013 4:28:00 PM com.hazelcast.impl.NodeINFO: [10.23.43.13]:5701 [CERT] ** setting master address to Address[10.23.43.14]:5701Nov 19, 2013 4:28:00 PM com.hazelcast.impl.NodeINFO: [10.23.43.13]:5701 [CERT] ** setting master address to Address[10.23.43.14]:5701Nov 19, 2013 4:28:01 PM com.hazelcast.impl.NodeINFO: [10.23.43.13]:5701 [CERT] ** setting master address to Address[10.23.43.14]:5701Nov 19, 2013 4:28:01 PM com.hazelcast.impl.NodeINFO: [10.23.43.13]:5701 [CERT] ** setting master address to Address[10.23.43.14]:5701Nov 19, 2013 4:28:02 PM com.hazelcast.impl.NodeINFO: [10.23.43.13]:5701 [CERT] ** setting master address to Address[10.23.43.14]:5701Nov 19, 2013 4:28:02 PM com.hazelcast.impl.NodeINFO: [10.23.43.13]:5701 [CERT] ** setting master address to Address[10.23.43.14]:5701Nov 19, 2013 4:28:02 PM com.hazelcast.cluster.ClusterManagerINFO: [10.23.43.13]:5701 [CERT]Members [2] { Member [10.23.43.14]:5701 Member [10.23.43.13]:5701 this}Nov 19, 2013 4:28:04 PM com.hazelcast.impl.LifecycleServiceImplINFO: [10.23.43.13]:5701 [CERT] Address[10.23.43.13]:5701 is STARTEDNov 19, 2013 4:28:04 PM com.hazelcast.impl.management.ManagementCenterServiceINFO: [10.23.43.13]:5701 [CERT] Hazelcast will connect to Management Center on address: http://localhost:8080/mancenter/Nov 19, 2013 4:28:04 PM com.hazelcast.config.UrlXmlConfigINFO: Configuring Hazelcast from 'jndi:/localhost/pwc-ui/WEB-INF/classes/hazelcast.xml'.Nov 19, 2013 4:28:04 PM com.hazelcast.web.WebFilterINFO: sticky:true, debug: true, shutdown-on-destroy: true, map-name: my-sessionsNov 19, 2013 4:28:05 PM org.apache.catalina.startup.HostConfig deployDescriptor组CERT的节点2(注意放置并重新添加)
Nov 19, 2013 4:27:11 PM com.hazelcast.nio.ConnectionINFO: [10.23.43.14]:5701 [CERT] Connection [Address[10.23.43.13]:5701] lost. Reason: java.io.IOException[Connection reset by peer]Nov 19, 2013 4:27:11 PM com.hazelcast.nio.ReadHandlerWARNING: [10.23.43.14]:5701 [CERT] hz.pwc.IO.thread-1 Closing socket to endpoint Address[10.23.43.13]:5701, Cause:java.io.IOException: Connection reset by peerNov 19, 2013 4:27:12 PM com.hazelcast.nio.SocketConnectorINFO: [10.23.43.14]:5701 [CERT] Could not connect to: /10.23.43.13:5701. Reason: ConnectException[Connection refused]Nov 19, 2013 4:27:13 PM com.hazelcast.nio.SocketConnectorINFO: [10.23.43.14]:5701 [CERT] Could not connect to: /10.23.43.13:5701. Reason: ConnectException[Connection refused]Nov 19, 2013 4:27:14 PM com.hazelcast.nio.SocketConnectorINFO: [10.23.43.14]:5701 [CERT] Could not connect to: /10.23.43.13:5701. Reason: ConnectException[Connection refused]Nov 19, 2013 4:27:14 PM com.hazelcast.nio.ConnectionMonitorWARNING: [10.23.43.14]:5701 [CERT] Removing connection to endpoint Address[10.23.43.13]:5701 Cause => java.net.ConnectException {Connection refused}, Error-Count: 5Nov 19, 2013 4:27:14 PM com.hazelcast.cluster.ClusterManagerINFO: [10.23.43.14]:5701 [CERT] Removing Address Address[10.23.43.13]:5701Nov 19, 2013 4:27:14 PM com.hazelcast.impl.PartitionManagerINFO: [10.23.43.14]:5701 [CERT] Starting to send partition replica diffs...trueNov 19, 2013 4:27:14 PM com.hazelcast.cluster.ClusterManagerINFO: [10.23.43.14]:5701 [CERT]Members [1] { Member [10.23.43.14]:5701 this}Nov 19, 2013 4:27:18 PM com.hazelcast.impl.PartitionManagerINFO: [10.23.43.14]:5701 [CERT] Total 0 partition replica diffs have been processed.Nov 19, 2013 4:27:18 PM com.hazelcast.impl.PartitionManagerINFO: [10.23.43.14]:5701 [CERT] Re-partitioning cluster data... Immediate-Tasks: 0, Scheduled-Tasks: 0Nov 19, 2013 4:27:57 PM com.hazelcast.nio.SocketAcceptorINFO: [10.23.43.14]:5701 [CERT] 5701 is accepting socket connection from /10.23.43.13:54106Nov 19, 2013 4:27:57 PM com.hazelcast.nio.ConnectionManagerINFO: [10.23.43.14]:5701 [CERT] 5701 accepted socket connection from /10.23.43.13:54106Nov 19, 2013 4:27:57 PM com.hazelcast.web.WebFilterINFO: Created new session with id: HZ650FDF62693F45A99AC0C30BBD8840B0Nov 19, 2013 4:27:57 PM com.hazelcast.web.WebFilterINFO: 195 is sessions.size and originalSessions.size: 195Nov 19, 2013 4:27:57 PM com.hazelcast.web.WebFilterINFO: PUTTING SESSION HZ650FDF62693F45A99AC0C30BBD8840B0Nov 19, 2013 4:28:02 PM com.hazelcast.cluster.ClusterManagerINFO: [10.23.43.14]:5701 [CERT]Members [2] { Member [10.23.43.14]:5701 this Member [10.23.43.13]:5701}Nov 19, 2013 4:28:02 PM com.hazelcast.impl.PartitionManagerINFO: [10.23.43.14]:5701 [CERT] Re-partitioning cluster data... Immediate-Tasks: 271, Scheduled-Tasks: 0Nov 19, 2013 4:28:24 PM com.hazelcast.web.WebFilterINFO: Created new session with id: HZAD50E5F483CC448C9FA7CB66D65848BBNov 19, 2013 4:28:24 PM com.hazelcast.web.WebFilterINFO: 196 is sessions.size and originalSessions.size: 196Nov 19, 2013 4:28:24 PM com.hazelcast.web.WebFilterINFO: PUTTING SESSION HZAD50E5F483CC448C9FA7CB66D65848BBNov 19, 2013 4:28:24 PM com.hazelcast.web.WebFilterINFO: Request is instance of RequestWrapper! Continue...Nov 19, 2013 4:28:24 PM com.hazelcast.web.WebFilterINFO: Request is instance of RequestWrapper! Continue...Nov 19, 2013 4:28:24 PM com.hazelcast.web.WebFilterINFO: Request is instance of RequestWrapper! Continue...Nov 19, 2013 4:28:24 PM com.hazelcast.web.WebFilterINFO: Request is instance of RequestWrapper! Continue...Nov 19, 2013 4:28:50 PM com.hazelcast.web.WebFilterINFO: Created new session with id: HZC9553A4C330044CA8A0C20549EE23BF0Nov 19, 2013 4:28:50 PM com.hazelcast.web.WebFilterINFO: 197 is sessions.size and originalSessions.size: 197Nov 19, 2013 4:28:50 PM com.hazelcast.web.WebFilterINFO: PUTTING SESSION HZC9553A4C330044CA8A0C20549EE23BF0Nov 19, 2013 4:28:50 PM com.hazelcast.web.WebFilterINFO: Request is instance of RequestWrapper! Continue...Nov 19, 2013 4:28:50 PM com.hazelcast.web.WebFilterINFO: Request is instance of RequestWrapper! Continue...Nov 19, 2013 4:28:50 PM com.hazelcast.web.WebFilterINFO: Request is instance of RequestWrapper! Continue...Nov 19, 2013 4:28:50 PM com.hazelcast.web.WebFilterINFO: Request is instance of RequestWrapper! Continue...10069.275: [GC [PSYoungGen: 693173K->3458K(695488K)] 877908K->188718K(2093632K), 0.0224650 secs] [Times: user=0.04 sys=0.00, real=0.02 secs]Nov 19, 2013 4:29:18 PM com.hazelcast.web.WebFilterINFO: Created new session with id: HZE46365454C2C45F98A7947AC40E404BBNov 19, 2013 4:29:18 PM com.hazelcast.web.WebFilterINFO: 198 is sessions.size and originalSessions.size: 198Nov 19, 2013 4:29:18 PM com.hazelcast.web.WebFilterINFO: PUTTING SESSION HZE46365454C2C45F98A7947AC40E404BB


