/* *
, *监听饲养员集群中某个饲养员实例是否宕机
,
* @author管理员,*
, */
公共类ZookeeperServiceStatusTest {
私有静态最终字符串主机=?92.168.0.128”;
私有静态最终整数端口=2182;
@Test
公共空间serverStatus()抛出IOException {
插座袜子=零;
BufferedReader读者=零;
字符串cmd=暗匚弧?
尝试{
袜子=新的套接字(主机、端口);
OutputStream outstream=sock.getOutputStream ();
//通过管理员的身份命令获取服务器的状态
outstream.write (cmd.getBytes ());
outstream.flush ();
sock.shutdownOutput ();
读者=new BufferedReader(新InputStreamReader (sock.getInputStream ())),
字符串行;
, ((=reader.readLine行())!=null) {
//如果(行)。“模式:”indexOf () !=1) {
//System.out.println(线。replaceAll(“模式:”、“”).trim ());
//}
System.out.println(线);
}
}捕捉(异常e) {
system . out。println(“饲养员地址:“+主机+”:“+ +港”连接失败”+“味精:”+ ExceptionUtils.getStackTrace (e));
}最后{
如果(袜子!=null) {
sock.close ();}
如果(读者!=null) {
reader.close ();}
}
}
}