Fourinone学习笔记-集群管理

集群管理

 

集群管理部分增加了一些类,扩展了fourinone的功能。
使得集群管理中的集群管理者,host:port是可以在config.xml中配置的,而不是像demo那样需要硬编码。


增加一个类GroupConfigContext.java,从ConfigContext继承,增加一个函数
package com.fourinone;

public class GroupConfigContext extends ConfigContext {
 public static String[][] getGroupConfig()
 {
 //从配置文件里面读取Group/servers配置
  String servers = getConfig("Group","SERVERS",null);
  return getServerFromStr(servers);
 }
}
 
/*
增加类GroupBeanContext.java 从BeanContext继承, 增加一个函数getGroupPark
*/
package com.fourinone;

public class GroupBeanContext extends BeanContext {
 public static ParkLocal getGroupPark(){
  String[][] parkcfg = GroupConfigContext.getGroupConfig();
  return getPark(parkcfg[0][0], Integer.parseInt(parkcfg[0][1]), parkcfg);//input serverconfiglist string[][]
 }
 
}
/*
  修改GroupManager
  从配置文件里面读取Group/servers配置
 
*/ 
import com.fourinone.BeanContext;
import com.fourinone.GroupConfigContext;

public class GroupManager
{
 public static void main(String[] args)
 {
//  String[][] master = new String[][]{{"localhost","1888"},{"localhost","1889"}};
//  String[][] slave = new String[][]{{"localhost","1889"},{"localhost","1888"}};

  String[][] parkcfg = GroupConfigContext.getGroupConfig();
  String[][] master = new String[][]{{parkcfg[0][0],parkcfg[0][1]},{parkcfg[1][0],parkcfg[1][1]}};
  String[][] slave = new String[][]{{parkcfg[1][0],parkcfg[1][1]},{parkcfg[0][0],parkcfg[0][1]}};

//  startPark(parkcfg[0][0], Integer.parseInt(parkcfg[0][1]), parkcfg);

  String[][] server = null;
  if(args[0].equalsIgnoreCase("M"))
   server = master;
  else if(args[0].equalsIgnoreCase("S"))
   server = slave;
  
  BeanContext.startPark(server[0][0],Integer.parseInt(server[0][1]), server);
 }
}

/*
  修改GroupServer.java
  从配置文件里面读取Group/servers配置
*/ 
import java.util.List;

import com.fourinone.AuthPolicy;
import com.fourinone.GroupBeanContext;
import com.fourinone.ObjectBean;
import com.fourinone.ParkLocal;

public class GroupServer
{
 public static void main(String[] args)
 {
  ParkLocal pl = GroupBeanContext.getGroupPark();//BeanContext.getPark();
  pl.create("group", args[0], args[0], AuthPolicy.OP_ALL, true);
  
  List<ObjectBean> oldls = null;
  while(true){
   List<ObjectBean> newls = pl.getLastest("group", oldls);
   if(newls!=null){
    System.out.println("Group:"+newls);
    oldls = newls;
   }
  }
 }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值