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. exec,eval

    一.什么是Exec语句 假如我们一串字符串里面有Python代码,这个时候,普通情况是会把这串代码作为字符串来输出的,而不会执行这段代码.如果此时,我们想执行这串字符串里面的python代码,使用Ex ...

  2. RabbitMQ消息队列(二): 工作队列

    1. 工作队列: 对于资源密集型任务,我们等待其处理完成在很多情况下是不现实的,比如无法在http的短暂请求窗口中处理大量耗时任务, 为了达到主线程无需等待,任务异步执行的要求,我们可以将任务加入任务 ...

  3. Python3安装cx_Oracle连接oracle数据库实操总结

    弄清版本,最重要!!! 首先安装配置时,必须把握一个点,就是版本一致!包括:系统版本,python版本,oracle客户端的版本,cx_Oracle的版本,然后安装配置就容易了! 如果已经安装Pyth ...

  4. Selenium IDE安装和检查获取的控件路径技巧

    来源:http://www.jianshu.com/p/0ea2dc83549f 从学习Selenium 开始,都是自己写脚本,后来得知有个插件Selenium IDE可以录制脚本,也懒得用了,觉得自 ...

  5. mybatis插入值的时候返回对象的主键值

    mapping文件: <insert id="insert" parameterType="com.vimtech.bms.business.riskproject ...

  6. go语言中的json

    结构体类型转化为json格式 package main import ( "encoding/json" "fmt" ) //如果要转化成json格式,那么成员 ...

  7. [ Python - 10 ] 练习:批量管理主机工具

    需求: 主机分组 登录后显示主机分组,选择分组后查看主机列表 可批量执行命令.发送文件,结果实时返回 主机用户名密码可以不同 流程图: 说明: ## 需求: 主机分组 登录后显示主机分组,选择分组后查 ...

  8. python通过多进程实行多任务

    #原创,转载请联系 在开始之前,我们要知道什么是进程.道理很简单,你平时电脑打开QQ客户端,就是一个进程.再打开一个QQ客户端,又是一个进程.那么,在python中如何用一篇代码就可以开启几个进程呢? ...

  9. 移动APP 支付宝快捷支付开发流程

    [代码] [Java]代码 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 ...

  10. linux下IPTABLES配置详解 (防火墙命令)

    linux下IPTABLES配置详解 -A RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport 24000 -j ACCEPT ...