Summary of the invention
To the efficiency that above-described data read, the present invention provides a kind of distributed caching synchro system and method.
The technical scheme that the present invention solves the problems of the technologies described above is following: the synchronous method of a kind of distributed system buffer memory, and it may further comprise the steps:
Step 1: desired data in every station server database is carried out buffer memory;
Step 2: when a station server is data cached when changing, the data with change in this server are assembled into packet;
Step 3: this server is given other servers with packet delivery;
Step 4: other servers receive said packet, packet are changed into the data of said change again;
Step 5: other servers carry out buffer memory with the data of said change.
Further, step 1 comprises following substep:
Step 1.1: the territory that on every station server, is configured in internal memory, store, promptly will carry out the data in buffer database data and be divided into value object by demand, add class name with the bag name of value object and form the unique territory in the buffer memory;
Step 1.2: the record in the database is read, and it is configured to entity class, and the entity class of the corresponding one-tenth of each bar record in the database;
Step 1.3: entity class is deposited in the territory with the key-value pair mode of Map, and wherein Key is a major key, and the Value value is corresponding entity class.
Further, every station server has disposed Listener (Listener has been that (Servlet is a kind of java application of server end to Servlet, has the characteristic that is independent of platform and agreement, can generate the dynamic Web page in the step 2.) monitor, it can monitor the request of client, the operation of service end etc.), when a station server is data cached when changing, Listener simultaneously dispense request to other servers.
Further, server becomes the data conversion of change through reflex mechanism the packet of Map structure in the step 2.
Further, step 3 is passed through the xmlrpc mode for this server, gives other servers with packet delivery.
A kind of distributed system buffer memory synchro system, it comprises multiple servers, said every station server comprises:
Buffer unit carries out buffer memory with desired data in the database;
Monitoring unit is monitored as the request of other servers of receiving terminal or as the operation of the server of transmitting terminal;
Conversion unit with the data cached packet that changes into of change in the server, or changes into packet the data of change;
Transmission unit, with said data packet transmission to other servers.
Further, it also comprises the emergent cache interface that loads, and when certain station server during when machine, said emergent loading cache interface reloads data cached, guarantees simultaneously and the proper communication of other servers.
The invention has the beneficial effects as follows:
1. reduce the database access times, one time reading database deposits buffer memory in, can accept to visit many times, accepts database resource.
2. the speed that reads buffer memory is much higher than and reads file and database, improves reading speed greatly.
3. distributed support can make large-scale high concurrent system adopt buffer memory to become possibility.
Embodiment
Below in conjunction with accompanying drawing principle of the present invention and characteristic are described, institute gives an actual example and only is used to explain the present invention, is not to be used to limit scope of the present invention.
As shown in Figure 1, the synchronous method of a kind of distributed system buffer memory, it may further comprise the steps:
Step 1: desired data in every station server database is carried out buffer memory;
Step 2: when a station server is data cached when changing, the data with change in this server are assembled into packet;
Step 3: this server is given other servers with packet delivery;
Step 4: other servers receive said packet, packet are changed into the data of said change again;
Step 5: other servers carry out buffer memory with the data of said change.
Step 1 comprises following substep:
Step 1.1: the territory that on every station server, is configured in internal memory, store, promptly will carry out the data in buffer database data and be divided into value object by demand, add class name with the bag name of value object and form the unique territory in the buffer memory;
Step 1.2: the record in the database is read, and it is configured to entity class, and the entity class of the corresponding one-tenth of each bar record in the database;
Step 1.3: entity class is deposited in the territory with the key-value pair mode of Map, and wherein Key is a major key, and the Value value is corresponding entity class.
Step 2 has disposed Listener for every station server; When a station server is data cached when changing; Listener dispense request simultaneously arrives other servers; And this server becomes the data conversion of change through reflex mechanism (reflex mechanism, a kind of ability of itself state or behavior can be visited, detects and revised to the program that mainly is meant) packet of Map (Map is with the object of the key value of being mapped to) structure.
Step 3 for this server through xmlrpc (xmlrpc is to use the http agreement as the rpc of host-host protocol mechanism, uses the mode transmission command and the data of xml text) mode, give other servers with packet delivery.
As shown in Figure 2, a kind of distributed system buffer memory synchro system, it comprises multiple servers 1, said every station server 1 comprises:
Buffer unit 3 carries out buffer memory with desired data in the database;
Monitoring unit 6 is monitored as the request of other servers of receiving terminal or as the operation of the server of transmitting terminal;
Conversion unit 4 with the data cached packet that changes into of change in the server, or changes into packet the data of change;
Transmission unit 2, with said data packet transmission to other servers.
It also comprises the emergent cache interface 5 that loads, and when certain station server during when machine, said emergent loading cache interface 5 reloads data cached, guarantees simultaneously and the proper communication of other servers.Can revise all data cached stationary problems.More can guarantee the accuracy of data.
Every station server 1 can be done transmitting terminal and receiving terminal.The security and stability of the system that this mode is just strengthened greatly is promptly when certain server occurs when problems such as machines.Do not influence the normal operation of other servers 1.
Adopt the program of java language specific as follows:
1. be to utilize the realization of reflex mechanism below with object (entity class) and the mutual commentaries on classics of Map:
/*
* with Map type of converting to
*/
public?static?void?map2Object(Object?obj,?Map?map)
throws?IllegalArgumentException,?IllegalAccessException?{
Field[]?fields?=?obj.getClass().getDeclaredFields();
for?(int?j?=?0;?j?<?fields.length;?j++)?{
Fields [j] .setAccessible (true); // this variable variable that scope check is provided with in class that do not conduct interviews is set private can be be
fields[j].set(obj,?map.get(fields[j].getName()));
}
}
/*
* convert class to Map
*/
public?static?void?object2Map(Object?obj,?Map?map)
throws?IllegalArgumentException,?IllegalAccessException?{
Field[]?fields?=?obj.getClass().getDeclaredFields();
for?(int?j?=?0;?j?<?fields.length;?j++)?{
Fields [j] .setAccessible (true); // this variable variable that scope check is provided with in class that do not conduct interviews is set private can be be
map.put(fields[j].getName(),?fields[j].get(obj));
}
}
/*
Obtain instance according to class name
*/
public?static?Object?getClassByName(String?className)?throws?Exception
{
Class?c;
Object?o;
c?=?Class.forName(className);
o?=?(c.getClassLoader().loadClass(className)).newInstance();
return?o;
}
2. be the realization that the transmitting terminal traversal is sent data below:
/*
The inlet traversal sends to each member in the cluster.
*/
public?boolean?distributData(List?list,String?className){
boolean?flag?=?true;
try{
=null && isDistribute.equals (" on ")) { // distributed caching switch.
convertDataforRpc(list,className);
for?(int?i?=?0;?i?<?host.length;?i++)?{
logger.info(host[i]?+?":"?+?port[i]?+?"/"?+?server[i]+?"?are?in?updata.....");
if?(!sendData(host[i],?port[i],?server[i],dataList))?{
logger.error("IndexServerError?error:"+?host[i]+?":"+?port[i]+?"/"+?server[i]+?"?faild?!");
flag?=?false;
}
}
}
}catch(Exception?e){
logger.error("error:?in?PromptDistributer.distributData()",e);
return?false;
}
return?flag;
}
It below 3 the realization of accepting data
/*
Accepting rpc passes the packet of coming and resolves synchronization caching sava again
*/
public?Boolean?receiveUpdateData(List?rpcData)?{
try?{
String?className?=?(String)rpcData.get(0);
logger.info("******seccess?received?bossDataDistrabutData***classname="+className);
Map?rpcDataMap?=?new?HashMap();
List?rpcRelultList?=?new?ArrayList();
// renewal buffer memory
SychronizedBossInfo?se?=?new?SychronizedBossInfo();
//**************************
Object?o?=?DistrabutTool.getClassByName(className);
For (int i=1; I < rpcData.size (); I++) />/ since 1.0 for being className
o?=?DistrabutTool.getClassByName(className);
rpcDataMap?=?(HashMap)?rpcData.get(i);
DistrabutTool.map2Object(o,rpcDataMap);
rpcRelultList.add(o);;
}
//**************************
If (className.equals (" com.sitech.kms.ehcache.pojo.UserInfo ")) { // user
se.updataUserByCach(rpcRelultList);
Else if (className.equals (" com.sitech.kms.ehcache.pojo.Dept ")) { // department
se.updataDeptByCach(rpcRelultList);
Else if (className.equals (" com.sitech.kms.ehcache.pojo.UserRole ")) { // user role
se.updataUserRoleByCach(rpcRelultList);
Else if (className.equals (" com.sitech.kms.ehcache.pojo.RoleMenu ")) { // role menu
se.updataRoleMenuByCach(rpcRelultList);
Else if (className.equals (" com.sitech.kms.ehcache.pojo.RoleModule ")) { // role function module
se.updataRoleModuleByCach(rpcRelultList);
}
}?catch?(Exception?e)?{
e.printStackTrace();
logger.error("IndexServerError?in?PromptDistributReceiver.receiveUpdateData",e);
return?new?Boolean("false")?;
}
return?new?Boolean("true");
}
In the industry during data of Query Database, all be directly to inquire about basically now with the sql statement.Each inquiry all can be to database build-up of pressure and resource consumption.Adopting behind the present invention can one time behind the reading database, unlimited accepting request.And what the present invention read is internal storage data, so speed is fast more a lot of than reading database.
Be applicable to fewer updating form data.Generally to use table (comprising update (legacy data in the updating form), insert (insertion), delete (deletion) etc.) in fewer execution write (data are write in the opened file) operation
The present invention has set forth through depositing numerous types of data in buffer memory.To improve the efficient to the data visit, one cutting system of efficiency when being applicable to data access.
The above is merely preferred embodiment of the present invention, and is in order to restriction the present invention, not all within spirit of the present invention and principle, any modification of being done, is equal to replacement, improvement etc., all should be included within protection scope of the present invention.