Coherence的架构参考

在极端压力之下,有时候代理节点会忙于处理请求而不响应其他的心跳,同步,导致其他节点传输的报文没有回应,而被认为是离开集群,从而影响业务。

写了一段代码,能让进程在监听到有节点离开时关闭节点,同时通过命令自动重起,实现恢复功能。

其中有几个要点问题解决如下:

1.Coherence Server可能是多台机器,这样任何proxy离开都会发送消息到监听程序,监听程序需要判断是否是本地进程才能操作。

2.如果通过ip来判断,java在获取本地ip时更多时候是一个list列表,所以程序中通过hostname进行判断

3.hostname和ip的映射,因为只涉及2台coherence server,所以直接把这种关系固定在程序中,当然也可以放到数据库,coherence或者文件。

4.通过proxy离开的消息能够获取processid,但通过pid如何可以获取proxy监听的端口,这里是通过

netstat -nap |grep "+processid +" | grep tcp | grep "+ ip+ ":9"的操作,也就是约定监听在以9开头的端口,然后把特定的行取出来后再进行解析。

5.获取port后再根据port和程序的映射关系去运行相关的启动命令。

6.测试可以分开测试,比如先是获取进程号的测试,然后再进行有进程号后如何kill和重新启动的测试. main下面好多都是调试的脚本。

代码如下:

package coherencetest;

import com.tangosol.net.CacheFactory;
import com.tangosol.net.MemberEvent;
import com.tangosol.net.MemberListener;
import com.tangosol.net.NamedCache;
import com.tangosol.util.MapEvent;
import com.tangosol.util.MapListener;

import java.io.InputStreamReader;

import java.io.LineNumberReader;

import java.net.InetAddress;

import java.util.ArrayList;
import java.util.List;

class ProxyListenerNotification implements MemberListener {
static String IP1 = "192.168.0.150";
String ip;

public void memberJoined (MemberEvent e) {
System.out.println("====== Member Join ");
}
public void memberLeaving(MemberEvent e) {}
public void memberLeft(MemberEvent e) {
System.out.println("************ Member Left");
System.out.println("====================");
// System.out.println(e.toString());

System.out.println(e.getMember());

String processId = e.getMember().getProcessName();
String totalstring = e.getMember().getAddress().getHostName();
String localhostname ="";

try {

InetAddress addr = InetAddress.getLocalHost();
localhostname=addr.getHostName().toString();

System.out.println("=============*======="+ip);
} catch (Exception e1) {
System.out.println(e1.getMessage());
}

if (totalstring.indexOf(localhostname) != 0) {
if (localhostname == "ocp") {
ip=IP1;
}

String shStr;
String port = getPort(Integer.parseInt(processId),ip);

if ( port =="9099") {
shStr = "/home/oracle/Middleware/coherence/bin/proxy-cache.sh";
} else {
shStr = "/home/oracle/Middleware/coherence/bin/proxy-cache1.sh";
}
Process process;

String killStr = "kill -9 "+processId;

try {

process = Runtime.getRuntime().exec(killStr);
System.out.println("kill successful");

process = Runtime.getRuntime().exec(new String[]{"/bin/sh","-c",shStr},null,null);

} catch(Exception e1) {
System.out.println(e1.getMessage());
}

}
}

public String getPort(int processid,String ip) {

Process process;
String line="";
try {
String shStr = "netstat -nap |grep "+processid +" | grep tcp | grep "+ ip+ ":9";
System.out.println(shStr);
process = Runtime.getRuntime().exec(new String[]{"/bin/sh","-c",shStr},null,null);
InputStreamReader ir = new InputStreamReader(process.getInputStream());
LineNumberReader input = new LineNumberReader(ir);
process.waitFor();
line = input.readLine();
/*while ((line = input.readLine()) != null){
strList.add(line);
}*/
}catch (Exception e) {
System.out.println(e.getMessage());
}

int index=line.indexOf(":9");
String port = line.substring(index+1, index+5);
System.out.println(" port ="+port);
return port;
}

}

public class ProxyListener {

public static void main(String[] args) {
try {
NamedCache cache = CacheFactory.getCache("POFSample");
/*
cache.addMapListener(new MapListener() {

public void entryUpdated(MapEvent arg0) {
System.out.println(arg0);
}

public void entryInserted(MapEvent arg0) {
System.out.println(arg0);

}
public void entryDeleted(MapEvent arg0) {
System.out.println(arg0);
}});
*/

String processId = "6458";
String localhostname ="";

try {

InetAddress addr = InetAddress.getLocalHost();
localhostname=addr.getHostName().toString();

System.out.println("=============*======="+localhostname);
} catch (Exception e1) {
System.out.println(e1.getMessage());
}

String ip = "192.168.0.150";

String shStr;

ProxyListenerNotification pl = new ProxyListenerNotification();
String port = pl.getPort(Integer.parseInt(processId),ip);

//cache.getCacheService().addMemberListener(new ProxyListenerNotification());

if ( port.equals("9099")) {
System.out.println("1");
shStr = "/home/oracle/Middleware/coherence/bin/proxy-cache.sh";
} else {
System.out.println("2");
shStr = "/home/oracle/Middleware/coherence/bin/proxy-cache1.sh";
}
Process process;

String killStr = "kill -9 "+processId;

try {
process = Runtime.getRuntime().exec(killStr);
System.out.println("kill successful");

process = Runtime.getRuntime().exec(new String[]{"/bin/sh","-c",shStr},null,null);
} catch(Exception e1) {
System.out.println(e1.getMessage());
}

while(true){
// Thread.sleep(100000);
}
} catch (Exception e) {
System.out.println(e);
}
}
}

Coherence代理节点在离开集群时的恢复的更多相关文章

  1. 监控Coherence成员的加入和离开集群事件

    对server事件的监控主要是实现MemberListener类,对Cache事件的监控主要通过MapListener 参考代码 package coherencetest; import com.t ...

  2. 沉淀,再出发——手把手教你使用VirtualBox搭建含有三个虚拟节点的Hadoop集群

    手把手教你使用VirtualBox搭建含有三个虚拟节点的Hadoop集群 一.准备,再出发 在项目启动之前,让我们看一下前面所做的工作.首先我们掌握了一些Linux的基本命令和重要的文件,其次我们学会 ...

  3. Apache shiro集群实现 (八) web集群时session同步的3种方法

    Apache shiro集群实现 (一) shiro入门介绍 Apache shiro集群实现 (二) shiro 的INI配置 Apache shiro集群实现 (三)shiro身份认证(Shiro ...

  4. 为什么PPIO要设计支付代理节点?

    PPIO是我和姚欣发起的去中心化存储项目(https://pp.io),这是为开发者提供的存储和分发网络平台,使得比云存储更廉价,更高速,更隐私.   我在设计PPIO的时候,设计了一个商业角色——支 ...

  5. Spark程序提交到Yarn集群时所遇异常

    Exception 1:当我们将任务提交给Spark Yarn集群时,大多会出现以下异常,如下: 14/08/09 11:45:32 WARN component.AbstractLifeCycle: ...

  6. 构建hadoop集群时遇到的问题

    在构建hadoop集群时,出现过主节点中的namenode或datanode启动不成功的问题.在日志文件中往往会显示namenode和datanode中clusterID不相同的问题,这个问题往往都是 ...

  7. redis 创建集群时 出现的错误解决方式

    1. 创建集群时报以下错误 (1)错误1 ./redis-trib.rb create --replicas 1 XXXXXX:5301 XXXXXX:5302 XXXXXX:5303 XXXXXX: ...

  8. Kibana安装(图文详解)(多节点的ELK集群安装在一个节点就好)

    对于Kibana ,我们知道,是Elasticsearch/Logstash/Kibana的必不可少成员. 前提: Elasticsearch-2.4.3的下载(图文详解) Elasticsearch ...

  9. PXC 避免加入集群时发生SST

    环境 现有集群节点: 192.168.99.210:3101 新加入节点: 192.168.99.211:3101 通过xtrabackup备份还原实例,并通过同步方式追数据: 已有节点情况: roo ...

随机推荐

  1. 用 letsencrypt 生成 SSL 证书

    letsencrypt 生成 SSL 证书 事先配置好访问域名解析 在nginx 对应虚拟主机添加一个验证区域: 配置 nginx server { listen 80; ... location ~ ...

  2. 最短路算法详解(Dijkstra,Floyd)

    最短路径 在一个无权的图中,若从一个顶点到另一个顶点存在着一条路径,则称该路径长度为该路径上所经过的边的数目,它等于该路径上的顶点数减1.由于从一个顶点到另一个顶点可能存在着多条路径,每条路径上所经过 ...

  3. 视频图像处理基础知识5(RGB与Ycbcr相互转换公式 )【转】

    转自:http://blog.csdn.net/Times_poem/article/details/51471438 版权声明:本文为博主原创文章,未经博主允许不得转载. 需求说明:视频处理算法基本 ...

  4. Makefile之大型工程项目子目录Makefile的一种通用写法【转】

    转自:http://www.cnblogs.com/skyofbitbit/p/3680753.html 管理Linux环境下的C/C++大型项目,如果有一个智能的Build System会起到事半功 ...

  5. (二十八)fopen与读写的标识r,r+,rb+,rt+,w+.....

    fopen与读写的标识r,r+,rb+,rt+,w+..... 函数简介 函数功能: 打开一个文件 函数原型:FILE * fopen(const char * path,const char * m ...

  6. phpstudy2014没有mysqldumpslow.pl及其在性能优化的作用

    mysqldumpslow.pl的作用是监控mysql的性能瓶颈的 1)在phpstudy2014中没有这个mysqldumpslow.pl所以需要去下载一个然后放置于mysql/bin的文件夹中,由 ...

  7. DRF的限流功能

    限流,可以对接口访问的频次进行限制,以减轻服务器压力. 全局配置 在settings.py上添加 REST_FRAMEWORK = { 'DEFAULT_THROTTLE_CLASSES': ( 'r ...

  8. hdu 3768(spfa+暴力)

    Shopping Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  9. poj1860(Bellman—fold)

    题目连接:http://poj.org/problem?id=1860 Description Several currency exchange points are working in our ...

  10. 6、Django实战第6天:用户登录

    今天开始,我们需要来写后台逻辑了.... 后台逻辑代码都是编写在views.py文件里面,今天要完成的登录功能,因此来编辑users.views.py 这里我们根据请求方法来判断分为2种情况,网页默认 ...