1, cluster background introduction
1.1 Term Defining Service Software is the S moiety of the B / S or C / S structure, is a service software system for serving B or C.
Serve hardware refers to hardware, such as a PC, and a PC server.
Service entity refers to service software and service hardware.
The client refers to the software or hardware that accepts the service entity service.
1.2 Two major key features clusters are a set of collaborative work-working services to provide a service platform than a single service entity more scalability and usability. At the client, a cluster is like a service entity, but in fact, the cluster consists of a set of service entities. Compared with a single service entity, the cluster provides the following two key features:
Scalability - The performance of the cluster is not limited to a single service entity, and new service entities can be dynamically added to the cluster, thereby enhancing the performance of the cluster. High availability - cluster redundancy by service entity makes clients to easily encounter Out of Service warnings. In the cluster, the same service can be provided by multiple service entities. If a service entity fails, another service entity will take over the failed service entity. The cluster is provided from an error-enhanced function to another service entity to enhance the availability of the application.
1.3 Two major capabilities In order to have scalability and high availability, the cluster must have the following two major capabilities:
Load balancing - load balancing the task is balanced to computational and network resources in the cluster environment. Error recovery - For some reason, the resource of the execution of a task has failed, and the resource of the same task in another service entity will then complete the task. This kind of resource transparent continued completion task is incorrectly recovered by the resource transparent in another entity.
Load balancing and error recovery requires that there is a resource that performs the same task in each service entity, and for the various resources of the same task, the information view (information context) required to perform the task must be the same.
1.4 Two major technologies have the following two major technologies:
The cluster address - cluster consists of multiple service entities, and the cluster client obtains the functionality of each service entity within the cluster by accessing the cluster address of the cluster. Has a single cluster address (also called a single image) is a basic feature of the cluster. The setting of the maintenance cluster address is called a load balancer. The load balancer is responsible for managing the addition and exit of each service entity, and the externally responsible for the conversion of the cluster address to the internal service entity address. Some load balancers achieve real load balancing algorithms, and some support only the transformation of the task. Only the load balancer of the task-converted is suitable for supporting the Active-Standby cluster environment, where only one service entity is working in the cluster, when the service entity is working, the load balancer turns the later task to another service entity. Internal communication - In order to work together, implement load balancing and error recovery, the cluster must be communicated between each entity, such as load balancer, the service entity heartbeat test information, and the service entity task performs context information. Communication.
With the same cluster address enables the client to access the computing service provided by the cluster, the internal address of each service entity is hidden under a cluster address, so that the computing service requested by the customer can be distributed between the various service entities. Internal communication is the basis for the normal operation of the cluster, which makes the cluster have the ability to balance load and error recovery.
2 cluster configuration
From the above figure, it is known that a cluster is formed by the service entity 1, the service entity 2, and the load balancer. Service Entity 1 and Services 2 participate in service support work for clients, balanced loaders to maintain a single image of the cluster. This communication network is generally used by the interior communication network. The load balancer detects the heartbeat information of each service entity through the internal communication network, and the service entity completes the propagation of task resources through the internal communication network. It can be seen that the configuration cluster is mainly composed of two parts: configured service entities and configuring load balancers. This article uses Tomcat 4.12, Apache 2.0.43 Configure cluster environments. The deployment diagram of related software is as follows: Service entity 1/2, the load balancer can be deployed on different machines, or on the same machine, this article is the same machine.
2.1 Preparing Software
Tomcat is open source servlet / jsp server, download location http://jakarta.apache.org/; apache 2.0.43 is an open source WWW server, download location http://www.apache.org/dist/httpd/binaries/; JavaGroups is a communication protocol that implements communication between cluster service entities. Downloads: http://www.javagroups.com/; Tomcat session replication library, based on JavaGroups communication protocol, complete the cluster service entity task execution context copy, download address : http://www.filip.net/tomcat/tomcat-javagroups.jar JK2 module, JK is an alternative to MOD_JSERV, which is a Tomcat-Apache plugin, handling communication between Tomcat and Apache, acting as a load in the cluster configuration. The role of equalizer. JK2 is a new product in accordance with the Apache 2.x series, download address: http://jakarta.apache.org/builds/jakarta-tomcat-connectors/jk2/release/v2.0.2/bin/.
2.2 Configuring a load balancer Configuring a load balancer under Apache is three steps, note that each modify httpd.conf and worker2.properties will not forget to restart Apache.
The first step, the installation and debug Apache load balancer JK2 module is a plugin for the Apache WWW service, so configuring a load balancer to install Apache first. This article downloads Windows version 2.0.43, executes setup.exe and answer some simple questions to complete the Apache task. It is worth noting that after installing and launching apache, if apache does not respond to the http: // localhost / address, you have to modify the index.html.xx file under the HTDOCS directory under the Apache installation path, such as change index.html.en. INDEX.html. In the second step, install the JK2 to change the downloaded mod_jk2-2.0.43.dll into mod_jk2.dll to place the Apache's modules directory, modify the apache's httpd.conf, that is, insert MOD_JK2 in loadModule Foo_Module Modules / Mod_foo.so Module loading information:
# EXample:
# Loadingmodule foo_module modules / mod_foo.so
#
LoadModule JK2_Module Modules / MOD_JK2.DLL
In the third step, configure the configuration of JK2JK2 in a configuration file, the file name is workers2.properties, and the apache's httpd.conf is placed in the same directory. The following is the content of this file:
# # Only At Beginnin. in Production UNComment It Out
[Logger.Apache2]
Level = Debug
#SHM must be equipped
[SHM]
File = d: / program files / apache group / apache2 / logs / shm.file
SIZE = 1048576
# 第一 第一 的 t 地址 地址
# Example Socket Channel, Override Port and Host.
[channel.socket: Tomcat1]
Port = 11009
Host = 127.0.0.1
# Defining the first worker pointing to the first Tomcat
# Define the worker
[AJP13: Tomcat1]
Channel = CHANNEL. Socket: Tomcat1
# 第二 第二 t 得 地址 地址
# Example Socket Channel, Override Port and Host.
[channel.socket: Tomcat2]
Port = 12009
Host = 10.1.36.123
# Defining the second worker pointing to the second Tomcat
# Define the worker
[AJP13: Tomcat2]
Channel = CHANNEL. Socket: Tomcat2
# Define the load balancer so that it contains two workers
[lb: lb1]
Worker = ajp13: Tomcat2
Worker = ajp13: Tomcat1
# Specify the load balancer to complete a single address map, so that the URI where the Apache service points to ROOT on the two Tomcat
# Uri mapping
[URI: / *]
Group = lb: lb1
#
For the load balancing configuration of the JK2 module, see the relevant site, it is worth mentioning that JK2 load balancing also supports excellent functions such as weight assignment.
2.3 Configuring Tomcat The two service entities belonging to a cluster requires the same identity, so we can install and configure the first Tomcat, then copy the second Tomcat, and finally configure the second Tomcat.
2.3.1 Installing the first Tomcat Install Tomcat is very simple, this article is no longer described. We assume that the first Tomcat's installation path is D: / Tomcat1.
Copy Tomcat-JavaGroups.jar and JavaGroups.jar to D: / Tomcat1 / Server / LIB path.
2.3.2 Configuring the first Tomcat
2.3.2.1 Configuring JK2
The JK2 Connector default port in Tomcat is 8009. In order to run two Tomcat on a machine, modify D: /TOMCAT1/conf/jk2.properties, set the port of JK2 Connector to 11009, the entire file content is as follows:
# channelsocket.port = 11009
#
2.3.2.2 Modify Server.conf
First, in order to run two Tomcat on a machine, modify the Tomcat stop instruction of Server.conf:
Then open the JK2 AJP Connector, close other Connector, below is the JK2 AJP 1.3, which has changed its port to 11009:
Port = "11009" MINPROCESSORS = "5" maxprocessors = "75" Enablelookups = "True" redirectport = "8443" Acceptcount = "10" debug = "0" connectionTIMEOUT = "20000" Useurivalidationhack = "false" ProtocolHandlerclassName = "org.apache.jk.server.jkcoyotehandler" /> Then configure the context of WebApp (such as Examples) that requires the cluster support, add the following manager: ClassName = "org.apache.catalina.session.inmemoryReplicationManager" Protocolstack = "udp (mcast_addr = 228.1.2.3; mcast_port = 45566; ip_ttl = 32): ping (timeout = 3000; Num_initial_members = 6): FD (Timeout = 5000): verify_suspect (timeout = 1500): Pbcast.stable (design_avg_gossip = 10000): pbcast.nakack (gc_lag = 10; Retransmit_timeout = 3000): Unicast (timeout = 5000; min_wait_time = 2000): Merge2: frag: pbcast.gms (join_timeout = 5000; join_retry_timeout = 2000; SHUN = false; print_local_addr = false) "> Manager> Note that the value of Protocolstack must be written within one line. 2.3.3 Configuring the second Tomcat Let's copy the first Tomcat that has been equipped to form a second Tomcat, assume that the path is D: / Tomcat2. 2.3.3.1 Configuring JK2 Modify d: /tomcat2/conf/jk2.properties, set the port 12009 of JK2 Connector, the entire file content is as follows: # Channelsocket.port = 12009 # 2.3.3.2 Modify Server.conf With the first Tomcat configuration, we only need to modify the Tomcat stop instruction of Server.conf: Then set the JK2 AJP Connector port 12009. 2.4 Run Test Start Apache, Tomcat1 and Tomcat2. 2.4.1 Test load balancing We first prepare two files, the first file is Test.jsp, copy to the first Tomcat root web application Directory is d: / tomcat1 / webapps / root:
<% = Request.getSession (). getId ()%>
body>
html>
The second file is also Test.jsp, copy to the second Tomcat root web application directory is d: / tomcat2 / webapps / root:
<% = Request.getSession (). getId ()%>
body>
html>
The input address from different browsers http: //localhost/test.jsp will see different colors, indicating that the JK2 module in Apache has played a load balancing.
2.4.2 Test error recovery
Access URL: http: // localhost / example / servlet / sessionExample can get an example of session, we use it to test the cluster's error recovery capabilities.
The test steps are as follows:
Close Tomcat1 and Tomcat2; Start Tomcat1 Enter the property name Tomcat1 and property value tomcat1 and property value Tomcat1 in the browser. The returned page shows the Tomcat1 attributes just entered in the session; launch Tomcat2; after a while (wait for Tomcat2 and Tomcat1 communication and copy Information) Close Tomcat1; Enter the property name tomcat2 and attribute value Tomcat2 in the browser, return, the return page displays the Tomcat2 property you just entered in the session, and the previously entered Tomcat1 attribute; start Tomcat1; after a while (wait after a while Tomcat2 and Tomcat1 communication and copy information) Close Tomcat2; Enter the property name Tomcat11 and property value tomcat11 and property value tomcat11 in the browser. The return page displays the Tomcat11 attributes just entered in the session, as well as previously entered Tomcat1 and Tomcat2 properties; ... ...
2.4.3 Method for testing multi-optical transmission
If the run test fails, you can use the following JavaGroup method to test the multi-purpose transfer property of the machine:
Start multi-purpose receiver:
Java org.javagroups.tests.mcastreceivertest -mcast_addr 224.10.10.10 -port 5555
Start multicast transmitter:
Java Org.javagroups.tests.mcastsendertest -MCast_addr 224.10.10.10 -port 5555
This way you enter content in the Mcastsendertest window, you should see the results in McAstreceiverWindow. If you can't see the result, add -ttl 32 in the Mcastsendertest running parameter. If you can't still, you can modify the number of addresses and try again (pay attention to avoid the multi-purpose address for the system); if you can't do it, you will ask the network management Let's!
2.4.4 Modifications to Tomcat-JavaGroups
The removettribute method of the org.apache.catalina.session.ReplicatedSession class in tomcat-javaGroups.jar will cause the Stackoverflow error. Please modify it according to the code below:
Public void Removettribute (String Name, Boolean Notify, Boolean JGnotify) {
Super.RemoveAttribute (name);
IF (jgnotify)
{
SessionMessage MSG =
New sessionMessage (Notify? sessionMestage.evt_attribute_removed_wnotify: sessionMESSAGE.EVT_ATTRIBUTE_REMOVED_WONOTIFY,
NULL,
GetId (),
Name,
NULL,
NULL);
SendMessage (MSG);
}
}
Public Void Removettribute (String Name, Boolean Notify) {
REMOVEATTRIBUTE (Name, Notify, True);
}
3 JetSpeed Cluster We now know how to configure, even a cluster environment, next this article analyzed the status quo of JetSpeed cluster, mainly including Repository and session data; in order to make the analysis, the cluster is analyzed before analyzing JetSpeed Demand and Rundata objects. Readers can use cluster environments to verify and debug the cluster function of JetSpeed. 3.1 Cluster requirements
The "Memory Session Replication" describes the key points for supporting the cluster application, and now summarizes the matters that should be paid to the application system development:
The object saved in the session must implement a java.io.Serializable interface; get the object from the session to reset the properties in the session with the session.setttribute method, because only SetAttribute can cause session replication. Java VM does not support the serialization of class variables, so pay attention to Failover can't rely on class variables; ensure that the configuration of each service entity is exactly the same; ensuring that the SESSION state is something, temporary file, class variable, etc. that make the current task status, make error recovery It is difficult to implement, and behavior may be impressed; save the status of the current request grade using request.settribute (), reducing the number of communication between service entities. Try not to save large objects in the session, improve communication performance between service entities.
3.2 Rundata object
The Rundata object concept comes from Turbine, the type of Rundata object in JetSpeed is DefaultJetSpeedRundata, which extends the DefaultTurBinerundata class in Turbine. The JetSpeed system receives the URL request of the user browser, performs calculation and information processing, and finally returns the code in the entire process of the browser HTTP code stream to access the same Rundata object. So the Rundata object is a mechanism for sharing information in each code module in the JetSpeed system.
3.3 JetSpeed RepositoryRepository generally refers to a software system to start, run a persistent environment, including launching repository and running repository. Start repository to determine the parameters of the system startup, the system does not change it when the system is running, if these parameters are changed, the software system must restart; run the repository refers to the parameters of the software system business operation, these parameters can be managed by the user or management The staff change when the system is online. The current trend is: Try to minimize the startup repository, and expand Run REPOSTINTORY; modifications to Repository can best use administrative frameworks, such as SNMP and JMX. JetSpeed's repository is mainly implemented in XREG, PSML, and Properties files.
XREG is a registry of JetSpeed, used to register the definition of original resources such as portlet, control, controller, skin, mediatype, to implement it into file form in JetSpeed, various types have their own registry file; PSML is a portal Structure marker language is referred to as the original resource in the XREG forms a definition of a portal view. When the user uses a desktop browser to access the JetSpeed system, the system locates a PSML document according to the user's URL, and then explains this document to form HTML. The code stream returns to the browser, the browser exhibits this code stream to form a windowing portal view. JetSpeed includes two implementations of PSML databases and files; Properties defines important services and parameters of JetSpeed, and currently only file implementations.
JetSpeed Start repository mainly in the Properties file, run the repository in XREG and PSML. The implementation of the file form greatly hinders the capabilities and performance of the JetSpeed support cluster, because now very few application server clusters can run on a file system, if repository needs to change during runtime, you must synchronize the files on multiple service entities. This is a quite trouble. If Repository supports database implementation form, JetSpeed can make full use of the database's storage and synchronization mechanism to achieve the same repository service in multiple JetSpeed. So I want JetSpeed to support the cluster, with better performance, and the repository's database is a non-negligible task. The cluster configuration supporting the database is shown below:
This figure shows a single image of the JetSpeed cluster configuration in the database cluster environment. The database load balancer implements a single image of the database cluster. Example There is a single cluster IP of MultiPool DataSource in WebLogic Server, SQL Server-based Windows 2000 cluster's single cluster IP, Oracle RAC support Thin JDBC Driver for multiple connection addresses.
3.4 JetSpeed SESSION Data Support Cluster must make each of the service entities are the same for the execution environment of a task, and for JetSpeed is for each URL request, the session data can be copied on each JetSpeed. These session are identified by the same sessionID, which may come from the browser's cookies or URL. Let's first use a VelocityPortlet to display what data saved in the session in JetSpeed, this portlet's registration name is sessionportlet.
3.4.1 sessionportlet
Sessionportlet is a VelocityPortlet, and its class name can be a CustomizerVELOTLET or VelocityPortlet, in general, there is no need to develop a new portlet class. The tutorials on how to develop deployment portlets can be found in the reference section, now we are registered, control assistants, portlet templates and running to tell this portlet.
3.4.1.1 Register
SessionPortlets are used to display current session data. It is registered in XREG:
Parent = "CustomizerVelocity" Application = "False">
Meta-Info>
Cachedonname = "true" cachedonvalue = "true" /> portlet-entry> 3.4.1.2 Control Assistant Action Portlets.SessionAction is the control assistant of the VelocityPortlet template portlet, before the Velocity interpretation mode: Public class sessionaction extends VelocityPortletAction { Protected Void Buildnormalcontext (VelocityPortlet portlet, Context context, Rundata Rundata) { Map map = new hashmap (); Enumeration enumeration = rundata.getations (). GetAttributeNames (); While (enumeration.hasmoreElements ()) { Object key = (object) enumeration.nextelement (); Object value = (object) Rundata.getSession (). GetAttribute (key.tostring ()); Map.Put (key, value); } Context.put ("sessions", map); } } As can be seen from the code above, this control assistant sets a MAP data structure that saves session data in the template model (M) environment in MVC. 3.4.1.3 Portlet template The temoduate file of the sessionportlet is session.vm (v) in MVC, the contents of this file are as follows:
#foreach ($ Key in $ sessions.keyset ())
#end
ul>
3.4.1.4 Custom PSML and Run sessionportlet
After logging in to the JetSpeed system with admin / jetspeed or turbine / turbine account / password, you can find the sessionportlet in the Velocity.legend portlet classification, add the sessionportlet displayed after you join your PSML (you can click more Other URLs, try to put JetSpeed more data in the session):
As you can see from the SESSION snapshot, JetSpeed session data is mainly divided into two categories: BaseJetSpeeduser and JetSpeedHTTPSTATEMANAGERSERVICE $ StateEntry, let's take a look at these two classes. 3.4.2 BasejetSpeeduser
We can see the basejetspeeduser from "Session Data Class Data (Part)" implements the serializable interface. In addition, this class and its parent class code can be learned that members of this class also implements the Serializable interface. So you can start this class is a cluster.
DefaultTurBinerundata implements this type of SESSION data operation interface:
Save the User object to the session, this method is called by TurbineAuthentication after logging in, before logging in to the DOPERFORM DOPERFORM of JetSpeedSessionValidator, which will call the setuser method of DEFAULTTURBINERUNDATA:
Public void save ()
{
Session.putValue (user.session_key, (object) user;
}
Public void setuser (user user)
{
THIS.USER = User;
}
Get User object data from the session, this method is called by the DOPERFORM of JetSpeedSessionValidator:
Public void populate ()
{
User = getUserFromSession ();
IF (user! = null)
{
User.setlastaccessdate ();
User.incrementAccessCounter ();
User.incrementAccessCounterForsession ();
}
}
Public user getUserFromSession ()
{
Return GetUserFromSession (session);
}
Public Static User GetUserFromSession (httpsession session)
{
Try
{
Return (user) session.getValue (user.session_key);
}
Catch (ClassCastException E)
{
Return NULL;
}
}
Delete user data in the session, there is no local call:
Public Boolean RemoveUserFromSession ()
{
Return RemoveUserFromSession (session);
}
Public Static Boolean RemoveUserFromSession (httpsession session)
{
Try
{
Session.removevalue (user.session_key);
}
Catch (Exception E)
{
Return False;
}
Return True;
}
3.4.2.1 User Login
Jetspeed home user input user name and password, then click login (login) button, you can activate JLoginUser.doPerfom-> TurbineAuthentication.login-> DefaultTurbineRundata.save-> JetspeedSessionValidator.doPerform-> DefaultTurbineRundata.populate series of steps.
If the value of the configuration item automatic.logon.enable in the Properties configuration is true, jloginuser.doperfom also sets browser cookies: username and logincookie. UserName is a username successfully logged in, and LogIncookie is a random value that is saved to the user database. When the user accesses the first page of JetSpeed, JetSpeedSessionValidator.doperform Checks the current user in the Rundata object. If there is no logging in and the value of Automatic.logon.enable is true, it will get UserName and Logincookie from cookies, and then find users from the user database. LogIncookie, if they call the following code to set the user data of Rundata:
Data.setuser (user);
User.SethasLoggedin (New Boolean (TRUE);
User.UpdateLastLogin ();
Data.save ();
As for different users, the portlet displayed in the home page is determined by the method of calling JetSpeedTool in the default Screen template (with a PSML positioning algorithm).
3.4.2.2 Displays the homepage of anonymous users after the session expires
When the session expires, Turbine.Doget first creates a new session, then activation JetSpeedSessionValidator.doperform-> jetspeedsecurity.GetAnonymoususeuser-> defaultTurbinerundata.save series steps.
JetSpeedSessionValidator.doperform sets the default Screen template.
3.4.2.3 Users log out
When the user logs in, click the logout button in the upper right corner of the JetSpeed system to activate the jlogout.doperform-> turbineauthentication.getanonymoususeuser-> DefaultTurBinerundata.save series steps.
TurbineAuthentication.Getanonymoususer obtains user data from the database (User.anonymous item in the Properties configuration).
If the value of the configuration item Automatic.logon.enable in the Properties configuration, Jlogout.Doperform also deletes the browser and current Request's cookies: username and logincookie, preventing the later JetSpeedSessionValidator from being automatically logged in with previous user data. Jlogout.doperform finally sets the Data default Screen template.
3.4.3 JetSpeedhttpStateManagerService $ STATEENTRY
We can see that StateEntry does not implement the serializable interface. Putting it in the properties of the session is not a cluster. The Serializable interface is just a flag interface, which does not have any functions and data members,
In order to make it cluster, first, StateEntry must first enable the Serializable interface.
DefaultJetSpeedRundata has the following session data operation interfaces for the STATEENTRY type:
User session interface, get sessionState to save user session data. This sessionState saved session data is "org.apache.jetspeed.services.StateManager.jetspeedHttpStateManager" sessionid as Key. Public sessionState getUsersessionState ()
{
StateManagerService Service = (StateManagerService) TurbineServices
. GetInstance (). getService (stateManagerService.Service_name);
IF (service == null) Return NULL;
Return Service.getSessionState (GetSession (). getId ());
}
Request's session interface, get the sessionState that saves the current REQUEST SESSION data. This sessionState saved session data is "org.apache.jetspeed.services.stateManager.jetspeedhttpStateManagerSpeedHttpStateManagerSpeedHttpStateManagerSpeedHttpStateManagerSpeed" (PagesessionID consisting of sessionid and profileid) .
Public sessionState getPageSessionState ()
{
StateManagerService Service = (StateManagerService) TurbineServices
. GetInstance (). getService (stateManagerService.Service_name);
IF (service == null) Return NULL;
Return Service.getSessionState (GetpageSessionID ());
}
Portlet's session interface, get sessionState for saving portlet session data. This sessionState saved session data is "org.apache.jetspeed.services.stateManager.jetspeedhttpStateManager" PageSessionID portletID as Key.
Public sessionState getPortletSessionState (String ID)
{
// Get The StateManagerService
StateManagerService Service = (StateManagerService) TurbineServices
. GetInstance (). getService (stateManagerService.Service_name);
IF (service == null) Return NULL;
String pageinstanceId = getpagesessionID ();
Return Service.getSessionState (PageInstanceID ID);
}
3.4.3.1 Class diagram
BaseStateManagerService has a type of MAP member variable m_httpsessions, with the Thread object as KEY, HTTPSession object is a value. The key of the attribute of the httpsession object is the keystry object of the STATEENTRY Type of the front DEFAULTJETSPEEDRUNDATA. The value of the property is the StateEntry object. The member variable of the StateEntry object M_Key saves the key of the operation interface, the member variable M_map is a MAP object, and the Name parameter of the SetAttribute method we have to say is the value of the value. 3.4.3.2 Initialization
The following sequence diagram is a brief map, which is mainly used to explain the mapping of the member variable of BaseStateManagerService M_httpSESSIONS to be populated and cleared.
Turbine is a servlet, its Doget method is the entry of the JetSpeed system.
Filling Turbine request JetspeedRunDataService generating RunData objects, JetspeedRunDataService call HttpServiceRequest of the getSession (true) method to get the corresponding httpSession objects with the current request (to true as parameters, the getSession returns a new httpSession objects in the current session is invalid, otherwise it returns to a previous request the httpSession objects), JetspeedRunDataService then calls the JetspeedHttpStateManagerService setCurrentContext (httpSession Object) method, this method is based on current Thread key, the parameter value to fill the httpSession object member variable of m_httpSessions BaseStateManagerService. Clear doGet method fills the m_httpSessions, and made after a lot of things, just before the exit called JetspeedRunDataService putRunData (data) method, which then calls the clearCurrentContext JetspeedHttpStateManagerService () method to delete BaseStateManagerService member variable m_httpSessions is key to the current Thread Map items. The figure below shows the M_HTTPSESSIONS object after initial memory status snapshot, which reflects the map relationship of the Thread-> HttpSession reserved by the M_HTTPSESSSIONS object.
3.4.3.3 Property operation
Once the DEFAULTJETSPEEDRUNDATA acquires sessionState through the Session Operating Interface, other members of the sessionState object operate in the operating status properties. These two methods are:
Public void setttribute (string name, object value);
Public void Removettribute (String Name);
After obtaining the sessionState object from the Rundata object, the JetSpeed code can call the properties method of this object.
the setAttribute (name, value) probably steps are: (1) main steps: 1.1sessionState objects use their key, in conjunction with the parameter name, value of the call JetspeedHttpStateManagerService the setAttribute (key, name, value) method; 1.1.1JetspeedHttpStateManagerService calls itself GetState (key) method Gets the m_map variable saved in the StateEntry object saved in the current thread session with the help of the parameter key, which is composed of 1.1.1.1-1.1.1.4; 1.1.2 After obtaining the m_map variable of the StateEntry object, JetSpeedHttpStateManagerService then Process the attribute values corresponding to the previous parameter Name in m_map, and then set the new value of the attribute value corresponding to the parameter NAME to be the parameter value. (2) Candidating steps: 1.1.1A If there is no corresponding stateEntry object in the session, you will join one to a session. the getAttribute (name) is probably steps: (1) main steps: 2.1sessionState objects use their key, calling name JetspeedHttpStateManagerService binding parameters of the getAttribute (key, name) method; 2.1.1JetspeedHttpStateManagerService call your own getState (key) method With the help of the parameter key, get the m_map variable saved in the StateEntry object in the current thread session; 2.1.2 After obtaining the m_map variable of the stateEntry object, JetSpeedHttpStateManagerService then invokes the Get (Name) method of the M_Map object to obtain the attribute value. The picture below reflects the key-> stateEntry object that these methods are executed after the HttpSession object, and the mapping relationship of the Name-> Value of the StateEntry object.
3.5 Modifying advice
(1) Realize the repository in the form of a database. Based on the previous cluster requirements, the Repository database must be used to make the resource view of each JetSpeed under the cluster.
(2) stateentry. According to the first cluster demand first, StateEntry must enable the Serializable interface. At present, StateEntry is an internal class. In order to make JVM's Serializer facilities to create a StateEntry object smoothly, it is best to make it public.
(3) SetAttribute To reset the session attribute. According to the first cluster requirements, the SETATTRIBUTE of the Session object is a primer that causes replication. We must call the SetAttribute method for calling the session object after changing the session property, reset the session attribute, as shown below.
Although the code in JetSpeed is as follows:
Change the SetAttribute method for JetSpeedhttpStateManagerService.
Modifications in this mode in this mode.
Controllers.multicolumnControlleraction; portlets.customizsetAction; controller.rowcolumnControlleraction; Note Sequence of the value in StateEntry.
4 Summary Can tell this way, the current JetSpeed does not consider the operation of the cluster environment when designing and implementation, the analysis of this article highlights the main crux of the JetSpeed support cluster, but not necessarily improved, even incorrect places, another major The content is the data analyzing JetSpeed to save data in the Session object. I hope this article will help you deepen the understanding of the cluster and help you "Keep Clustering In Mind" when designing and developing software systems. Reference
Memory session replication describes the principle of the Session replication of the cluster. Apache 2.x Tomcat 4.x describes how to use the JK configuration cluster load balancing. The documents of JK and JK2 tell the corresponding configuration details. BEA WebLogic 8.1 describes cluster configuration and implementation of J2EE applications. The tutorial tells you how to write the JetSpeed portlet. "Java Pitfalls Chinese" ITEM 23 describes the detailed process of serialization of Java objects. When using JavaGroup, try to avoid a multicast address.
About the author Name: Gong Yongsheng Email: gongys@lenovo.com address (AddR): Lenovo, No.7, Kondow Road, Shangdi Information Industry Base, Haidian District, Beijing: 100085 Phone (TEL): 010-62986638-5749 Mobile (Mobile): 13910304330 Fax (FAX): 010-62975824