er的hash发生变化(对比当前cluster的hash和proxy传递过来的hash),则将cluster member的信息通知给proxy,这个通知也是通过http header来实现,不同的是header名为:X_WEBLOGIC_CLUSTER_LIST及X_WEBLOGIC_CLUSTER_HASH,如下:
ServletResponseImpl.java
1 /*package*/ final void writeHeaders() throws IOException {
2
3 HttpServer httper = getHttpServer();
4 if (httper != null) {
5 boolean isPlugin = false;
6 ServerMBean serverMBean = ManagementService.getRuntimeAccess(
7 WebAppConfigManager.KERNEL_ID).getServer();
8 if (serverMBean.getCluster() != null &&
9 request.getHeader(X_WEBLOGIC_REQUEST_CLUSTERINFO) != null) {
10
11 String hash = request.getHeader(X_WEBLOGIC_CLUSTER_HASH);
12 String oldHash = hash == null ? "" : hash;
//MemberControllerImpl is a singlton instance and it''s hash is changed when cluster changs
13 String currentHash = MembershipControllerImpl.getInstance().getHash();
14 String passedHash = headers.getHeader(X_WEBLOGIC_CLUSTER_HASH);
15 if (currentHash != null && !currentHash.equals(oldHash)) {
16 String[] servers =
17 MembershipControllerImpl.getInstance().getClusterList(
18 request.getConnection().getChannel());
19
20 headers.setHeader(X_WEBLOGIC_CLUSTER_HASH, currentHash);
21 headers.setHeader(X_WEBLOGIC_CLUSTER_LIST, sb.toString());//sb presents servers list string
22 }
23 }
24 }
25 }
3:proxy端,
回到proxy端,proxy读取managed server的response,将response写回到客户端。在读取response的时候,它同时会解析inter header的信息。如果发现DynamicServerList为true,而且response的header中包含 X_WEBLOGIC_CLUSTER_LIST、X_WEBLOGIC_CLUSTER_HASH等信息,它会据此更新request info,如下:
HttpClusterServlet.java
1 public void addResponseHeaders(HttpServletResponse response, String name, String value, Object o) {
2 RequestInfo ri = (RequestInfo) o;
3 if (ri.needToUpdateDynamicList() &&
4 name.equals(ServletResponseImpl.X_WEBLOGIC_CLUSTER_LIST)) {
5 ri.setDynamicList(value);
6 return;
7 }
8 if (ri.needToUpdateDynamicList() &&
9 name.equals(ServletResponseImpl.X_WEBLOGIC_CLUSTER_HASH)) {
10 ri.setDynamicHash(value);
11 return;
12 }
13
14 }
而requestInfo是一个请求范围的变量,更新它其实无法更新到proxy中的server list。server list的更新发生在一个request结束的时候,就HttpServletRequest.service()的finally块中。在 finally块中,检查requestInfo中的dynamicServerList存在,如果存在则说明后端cluster发生了变化(否则 managed server不会发送X |