知识库--DistributedManager 集群 (50)

来源:互联网 发布:xps分析软件下载 编辑:程序博客网 时间:2024/05/21 12:39

DistributedManager **Tomcat4中的集群环境–昙花一现**zk

A subclass of PersistentManagerBase, DistributedManager is used in a clustered environment with two or more nodes. A node represents a Tomcat deployment. Nodes in a cluster can exist in different machines or the same machine. In a clustered environment, each node must use an instance of DistributedManager as its Manager to support session replication, which is the main responsibility of DistributedManager.

For the replication purpose, DistributeManager sends notification to other nodes whenever a session object is created or destroyed. In addition, a node must be able to receive notification from other nodes as well. This way, an HTTP request can be served by any node in the cluster.

For sending and receiving notification to and from other instances of DistributedManager in other nodes, Catalina provides classes in the org.apache.catalina.cluster package. Among others, the ClusterSender class is used for sending notifications to other nodes and the ClusterReceiver class for receiving notifications from other nodes.

The createSession method of DistrbutedManager must create a session object to be stored in the current instance and use a ClusterSender instance to send notification to other nodes.

    public Session createSession(){        Session session = super.createSession();        ObjectOutputStream oos = null;        ByteArrayOutputStream bos = null;        ByteArrayInputStream bis = null;        try{            bos = new ByteArrayOutputStream();            oos = new ObjectOutputStream(new BufferedOutputStream(bos));            ((StandardSession)session).writeObjectData(oos);            oos.close();            byte[] obs = bos.toByteArray();            clusterSender.send(obs);//send            if(debug > 0)                log("Replicating Session:"+session.getId());        }catch(IOException e){            log();        }        return(session);    }
0 0
原创粉丝点击