国产chinesehdxxxx野外,国产av无码专区亚洲av琪琪,播放男人添女人下边视频,成人国产精品一区二区免费看,chinese丰满人妻videos

8.6.權(quán)限緩存同步刷新

2023-07-03 17:27 更新
從BDF2-2.0.1開始,我們在BDF2-WEBSERVICE模塊當(dāng)中添加了利用Webservice來同步集群環(huán)境下各個(gè)節(jié)點(diǎn)權(quán)限緩存信息的功能,利用這個(gè)功能,在集群環(huán)境下使用BDF2就不需要再配置諸如TerracottaServer之類的緩存服務(wù)器。利用Webservice來同步緩存,本質(zhì)上,緩存還是集群中各個(gè)節(jié)點(diǎn)應(yīng)用自已處理,相比使用緩存服務(wù)器效率要高出很多(緩存服務(wù)器本質(zhì)是利用網(wǎng)絡(luò)將各個(gè)節(jié)點(diǎn)緩存信息同步到緩存服務(wù)器當(dāng)中再進(jìn)行二次分發(fā),對(duì)網(wǎng)絡(luò)及服務(wù)器內(nèi)存消耗過大),但因?yàn)榭梢詫?shí)現(xiàn)緩存的同步,所以同樣可以達(dá)到只有配置了Terracotta Server才能達(dá)到的功能。
需要特別指出的是,這里利用Webservice來同步緩存,實(shí)際上是將業(yè)務(wù)方法調(diào)用攔截功能與調(diào)用SpringBean中特定方法的Webservice結(jié)合而實(shí)現(xiàn)。要使用這一功能,我們需要配置下面兩個(gè)屬性:
屬性名類型默認(rèn)值描述
bdf2.syncCacheremoteServerUrlsString
用于指定在當(dāng)前應(yīng)用當(dāng)中用戶手工觸發(fā)權(quán)限模塊當(dāng)中刷新緩存操作時(shí),需要調(diào)用哪些其它節(jié)點(diǎn)應(yīng)用的Webservice來同步刷新權(quán)限緩存,比如:
bdf2.syncCacheremoteServerUrls=http://www.bstek.com:82/bdf2-demo/,http://www.bstek.com:81/bdf2-demo/可以看到上面配置了兩個(gè)URL,中間使用逗號(hào)分隔,這樣當(dāng)前應(yīng)用在刷新權(quán)限緩存時(shí)就是更新這兩個(gè)URL上對(duì)應(yīng)的權(quán)限緩存信息,可以看到這個(gè)URL在定義時(shí)要包含我們應(yīng)用的ContextPath,比如這里的bdf2-demo。除了可以在dorado-home目錄下的configure.properties當(dāng)中配置bdf2.syncCacheremoteServerUrls這個(gè)屬性值以外,我們還可以將其配置成JVM變量,JVM變量名就是bdf2.syncCacheremoteServerUrls。
bdf2.syncCacheRemoteServerUsernamePasswordString調(diào)用目標(biāo)節(jié)點(diǎn)應(yīng)用Webservice時(shí)需要的驗(yàn)證的用戶名密碼信息,它們中間用逗號(hào)分隔(username,password,順序不能顛倒),同時(shí)這個(gè)屬性值除了可以在dorado-home目錄下的configure.properties當(dāng)中外,還可以配置到我們應(yīng)用所在JVM變量當(dāng)中,變量名就叫bdf2.syncCacheRemoteServerUsernamePassword。
如果在使用的時(shí)候我們沒有配置這兩個(gè)屬性值,那么系統(tǒng)將不會(huì)在戶手工觸發(fā)權(quán)限模塊當(dāng)中刷新緩存操作時(shí)刷新其它節(jié)點(diǎn)的緩存信息。同時(shí),要使這個(gè)功能運(yùn)轉(zhuǎn)正常,我們還需要正確配置bdf2.globalMethodIntercetporBeanNamesPattern屬性值(該屬性作用參見業(yè)務(wù)方法調(diào)用攔截功能中相關(guān)介紹),保證該屬性值中包含*Maintain,否則系統(tǒng)將無法攔截用戶手工執(zhí)行的刷新緩存操作。

實(shí)際上,利用類似的方法,我們還可以根據(jù)業(yè)務(wù)的需要實(shí)現(xiàn)集群環(huán)境下其它信息的同步,具體實(shí)現(xiàn)方法,與我們這里的權(quán)限緩存同步基本相同,下面的代碼當(dāng)中,列出了我們實(shí)現(xiàn)緩存同步操作的具體源代碼,大家要實(shí)現(xiàn)其它操作可以模仿這種寫法:
實(shí)現(xiàn)權(quán)限緩存同步類的源碼
package com.bstek.bdf2.webservice.sync.cache;
import java.lang.reflect.Method;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.InitializingBean;
import com.bstek.bdf2.core.aop.IMethodInterceptor;
import com.bstek.bdf2.core.business.IUser;
import com.bstek.bdf2.core.context.ContextHolder;
import com.bstek.bdf2.webservice.client.WebServiceClient;
import com.bstek.bdf2.webservice.jaxb.IWebservice;
import com.bstek.bdf2.webservice.rpc.data.DataRequest;
import com.bstek.bdf2.webservice.rpc.data.DataResponse;
/**
 * @author Jacky.gao
 * @since 2013年7月12日
 */
public class SyncRefreshSecurityCache implements IMethodInterceptor,InitializingBean{
 private static final String C1="com.bstek.bdf2.core.view.role.component.RoleComponentMaintain";
 private static final String C2="com.bstek.bdf2.core.view.role.RoleMaintain";
 private static final String C3="com.bstek.bdf2.core.view.role.url.RoleUrlMaintain";
 private static final String C4="com.bstek.bdf2.authoritydelegation.view.role.url.RoleUrlMaintain";
 private static final String M1="refreshUrlSecurityMetadata";
 private static final String M2="refreshAllSecurityMetadata";
 private static final String M3="refreshComponentSecurityMetadata";
 private String remoteServerUrls;
 private String remoteServerUsernamePassword;
 private String username;
 private String password;
 public boolean support(Class<?> objectClass, Method method) {
 if(objectClass==null)return false;
 if(ContextHolder.getRequest()==null)return false;
 Object
loginWay=ContextHolder.getHttpSession().getAttribute(ContextHolder.USER_LOGIN_WAY_KEY);
 if(loginWay!=null && loginWay.equals(IWebservice.WS_LOGIN_WAY.toString()))return false;
 if(StringUtils.isEmpty(remoteServerUrls))return false;
 String className=objectClass.getName();
 if(className.equals(C1) || className.equals(C2) || className.equals(C3) || className.equals(C4)){
 String methodName=method.getName();
 if(methodName.equals(M1) || methodName.equals(M2) || methodName.equals(M3)){
 return true;
 }
 }
 return false;
 }
 public void doBefore(Class<?> objectClass, Method method, Object[] arguments)
 throws Exception {
 //do nothing
 }
 public void doAfter(Class<?> objectClass, Method method,Object[] arguments, Object returnValue)
throws Exception {
 DataRequest req=new DataRequest();
 req.setBeanId("bdf2.roleMaintain");
 req.setMethodName(method.getName());
 String suffix="dorado/webservice/SpringBeanRPC";
 if(StringUtils.isEmpty(remoteServerUsernamePassword)){
 IUser user=ContextHolder.getLoginUser();
 this.username=user.getUsername();
 this.password=user.getPassword();
 }
 for(String url:remoteServerUrls.split(",")){
 if(url.endsWith("/")){
 url=url+suffix;
 }else{
 url=url+"/"+suffix; 
 }
 WebServiceClient client=new WebServiceClient(url);
 client.setUsernameToken(username, password, true);
 client.setMarshallerClasses(new Class<?>[]{DataRequest.class,DataResponse.class});
 DataResponse res=(DataResponse)client.sendAndReceive(req);
 if(!res.isSuccessful()){
 throw new RuntimeException(res.getReturnValue());
 }
 }
 }
 public void afterPropertiesSet() throws Exception {
 if(StringUtils.isEmpty(remoteServerUsernamePassword)){
 
remoteServerUsernamePassword=System.getProperty("bdf2.syncCacheRemoteServerUsernamePasswo
rd");
 }
 if(StringUtils.isNotEmpty(remoteServerUsernamePassword)){
 String[] account=remoteServerUsernamePassword.split(",");
 if(account.length!=2){
 throw new IllegalArgumentException("Username and password must be separated by commas");
 }
 this.username=account[0];
 this.password=account[1];
 }
 if(StringUtils.isEmpty(remoteServerUrls)){
 remoteServerUrls=System.getProperty("bdf2.syncCacheremoteServerUrls");
 }
 }
 public void setRemoteServerUrls(String remoteServerUrls) {
 this.remoteServerUrls = remoteServerUrls;
 }
 public void setRemoteServerUsernamePassword(String remoteServerUsernamePassword) {
 this.remoteServerUsernamePassword = remoteServerUsernamePassword;
 }
}
類編寫完成,不要忘記配置到Spring環(huán)境當(dāng)中。

以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)