2013-10-13 32 views
0

我試圖使用到clusterize http會話配置Hazelcast-WM hazelcast-WM 3.0hazelcast彈簧3.0春天3.2.2servlet的API 3.0如何使用系統屬性和春季

的web.xml

<listener> 
    <listener-class>com.company.PropertiesListener</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>false</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> 
    <!-- 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>false</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>hazelcast-context.xml</param-value> 
    </init-param> 
    <!-- Do you want to use an existing HazelcastInstance? Default is null. --> 
    <init-param> 
     <param-name>instance-name</param-name> 
     <param-value>hz.session.instance</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> 

<listener> 
    <listener-class>com.hazelcast.web.SessionListener</listener-class> 
</listener> 

hazelcast-context.xml中

<hz:hazelcast id="hz.session.cluster" depends-on="hazelcast.properties"> 
    <hz:config> 
     <hz:instance-name>hz.session.instance</hz:instance-name> 
     <hz:group name="${cluster.name:my-sessions}" password="${cluster.password:mypass}" /> 
     <hz:properties> 
      <hz:property name="hazelcast.logging.type">slf4j</hz:property> 
      <hz:property name="hazelcast.version.check.enabled">false</hz:property> 
      <hz:property name="hazelcast.jmx">true</hz:property> 
     </hz:properties> 
     <hz:network port="${cluster.network.port:5701}" 
      public-address="${cluster.member.address:127.0.0.1}" 
      port-auto-increment="${cluster.network.port-auto-increment:true}"> 
      <hz:join> 
       <hz:multicast enabled="${cluster.network.multicast.enabled:false}" 
        multicast-group="${cluster.network.multicast.group:224.2.2.3}" 
        multicast-port="${cluster.network.multicast.port:54327}" /> 
       <hz:tcp-ip enabled="${cluster.network.tcpip:true}"> 
        <hz:members>${cluster.members:127.0.0.1}</hz:members> 
       </hz:tcp-ip> 
      </hz:join> 
     </hz:network> 
    </hz:config> 
</hz:hazelcast> 

PropertiesListener設置System.properties:cluster.members,cluster.member.address等,這取決於在正在運行的機器上。

如果我使用應用程序的Spring上下文創建hazelcast情況下,它的偉大工程:

@Configuration 
@ImportResource("classpath:hazelcast-context.xml") 
public class HazelcastConfig { 

} 

的偉大工程! Hazelcast實例綁定到正確的網絡接口。 。

但問題是,當我使用網頁過濾(以前,我刪除了HazelcastConfig類,所以不能創建

Hazelcast例如兩次這些都是出現在日誌中的消息:

Oct 13, 2013 9:09:28 PM com.hazelcast.config.UrlXmlConfig 
INFO: Configuring Hazelcast from 'file:/home/neuquino/springsource/vfabric-tc-server-developer-2.9.2.RELEASE/my-app/wtpwebapps/my-app-web/WEB-INF/classes/hazelcast-context.xml'. 
Oct 13, 2013 9:09:28 PM com.hazelcast.config.XmlConfigBuilder 
WARNING: Could not find a value for property 'cluster.name:my-sessions' on node: null 
Oct 13, 2013 9:09:28 PM com.hazelcast.config.XmlConfigBuilder 
WARNING: Could not find a value for property 'cluster.password:mypass' on node: null 
Oct 13, 2013 9:09:28 PM com.hazelcast.config.XmlConfigBuilder 
WARNING: Could not find a value for property 'cluster.network.port:5701' on node: null 
Oct 13, 2013 9:09:28 PM com.hazelcast.config.XmlConfigBuilder 
WARNING: Could not find a value for property 'cluster.network.port-auto-increment:true' on node: null 
Oct 13, 2013 9:09:28 PM com.hazelcast.config.XmlConfigBuilder 
WARNING: Could not find a value for property 'cluster.member.address:127.0.0.1' on node: null 
Oct 13, 2013 9:09:28 PM com.hazelcast.config.XmlConfigBuilder 
WARNING: Could not find a value for property 'cluster.network.multicast.enabled:false' on node: null 
Oct 13, 2013 9:09:28 PM com.hazelcast.config.XmlConfigBuilder 
WARNING: Could not find a value for property 'cluster.network.multicast.group:224.2.2.3' on node: null 
Oct 13, 2013 9:09:28 PM com.hazelcast.config.XmlConfigBuilder 
WARNING: Could not find a value for property 'cluster.network.multicast.port:54327' on node: null 
Oct 13, 2013 9:09:28 PM com.hazelcast.config.XmlConfigBuilder 
WARNING: Could not find a value for property 'cluster.network.tcpip:true' on node: null 
Oct 13, 2013 9:09:28 PM com.hazelcast.config.XmlConfigBuilder 
WARNING: Could not find a value for property 'cluster.members:127.0.0.1' on node: null 
Oct 13, 2013 9:09:29 PM com.hazelcast.instance.DefaultAddressPicker 
INFO: Prefer IPv4 stack is true. 
Oct 13, 2013 9:09:29 PM com.hazelcast.instance.DefaultAddressPicker 
INFO: Picked Address[10.8.254.133]:5701, using socket ServerSocket[addr=/0:0:0:0:0:0:0:0,localport=5701], bind any local is true 
Oct 13, 2013 9:09:29 PM com.hazelcast.system 
INFO: [10.8.254.133]:5701 [dev] Hazelcast Community Edition 3.0.2 (20130906) starting at Address[10.8.254.133]:5701 
Oct 13, 2013 9:09:29 PM com.hazelcast.system 
INFO: [10.8.254.133]:5701 [dev] Copyright (C) 2008-2013 Hazelcast.com 
Oct 13, 2013 9:09:29 PM com.hazelcast.instance.Node 
INFO: [10.8.254.133]:5701 [dev] Creating MulticastJoiner 
Oct 13, 2013 9:09:29 PM com.hazelcast.core.LifecycleService 
INFO: [10.8.254.133]:5701 [dev] Address[10.8.254.133]:5701 is STARTING 
Oct 13, 2013 9:09:34 PM com.hazelcast.cluster.MulticastJoiner 
INFO: [10.8.254.133]:5701 [dev] 


Members [1] { 
    Member [10.8.254.133]:5701 this 
} 

Oct 13, 2013 9:09:34 PM com.hazelcast.core.LifecycleService 
INFO: [10.8.254.133]:5701 [dev] Address[10.8.254.133]:5701 is STARTED 

正確IP應該是11.1.0.133($ {cluster.member.address}的值),Hazelcast正在選擇我的PC的網絡接口之一,但不使用$ {cluster.member.address}的值。使用WebFilter和系統屬性?

在此先感謝!

回答

0

您可以嘗試自己讀取屬性並修改從XML創建的Config實例,或者您可以自己創建Config實例。 XmlConfigBuilder應該爲你做詭計。也許我會添加一種將創建後監聽器註冊到Spring模塊的方法。