import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import xsf.data.*;
/**
-
SSH工具类
-
@author
-
2013-4-7
*/
public class TestGetData {
public static void main(String args[]){
}
public static Map getXml(String url){
Map<String, String> hashMap = new HashMap<>();
//创建解析器
SAXReader saxreader = new SAXReader();
//读取文档
Document doc = null;
try {
doc = saxreader.read(new File(url));
} catch (DocumentException e) {
e.printStackTrace();
}
//获取根
Element root = doc.getRootElement();
//获取子节点
List list = root.elements();
for (Element element : list) {
String name = element.getName();
if(“System”.equals(name)){
Element dbConnection = element.element(“DataBase”).element(“DBConnection”);
String removeAbandoned = dbConnection.attributeValue(“removeAbandoned”);
hashMap.put(“removeAbandoned”,removeAbandoned != “” && removeAbandoned != null ? removeAbandoned : “”);
String removeAbandonedTimeout = dbConnection.attributeValue(“removeAbandonedTimeout”);
hashMap.put(“removeAbandonedTimeout”,removeAbandonedTimeout != “” && removeAbandonedTimeout != null ? removeAbandonedTimeout : “”);
String logAbandoned = dbConnection.attributeValue(“logAbandoned”);
hashMap.put(“logAbandoned”,logAbandoned != “” && logAbandoned != null ? logAbandoned : “”);
}
if(“Service”.equals(name)){
Element connector = element.element(“Connector”);
hashMap.put(“port”,connector.attributeValue(“port”));
hashMap.put(“protocol”,connector.attributeValue(“protocol”));
hashMap.put(“maxThreads”,connector.attributeValue(“maxThreads”));
hashMap.put(“connectionTimeout”,connector.attributeValue(“connectionTimeout”));
}
if(“ConnectionSettings”.equals(name)){
List settings = element.elements(“Settings”);
for (Element setting : settings) {
String attributeValue = setting.attributeValue(“Id”);
if(“XUGUConnection”.equals(attributeValue)){
List elements = setting.elements(“Add”);
for (Element attr : elements) {
List attributes = attr.attributes();
DefaultAttribute value = (DefaultAttribute) attributes.get(0);
String valueValue = value.getValue();
DefaultAttribute data = (DefaultAttribute) attributes.get(1);
String dataValue = data.getValue();
if(“removeAbandoned”.equals(valueValue)){
hashMap.put(“removeAbandoned”,dataValue);
}
if(“removeAbandonedTimeout”.equals(valueValue)){
hashMap.put(“removeAbandonedTimeout”,dataValue);
}
if(“logAbandoned”.equals(valueValue)){
hashMap.put(“logAbandoned”,dataValue);
}
}
}
}
}
}
return hashMap;
}
//
//
// static ThreadPoolTaskExecutor threadPoolTaskExecutor;
//
// static {
// threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
// threadPoolTaskExecutor.setCorePoolSize(5);
// threadPoolTaskExecutor.setMaxPoolSize(10);
// threadPoolTaskExecutor.setQueueCapacity(100);
// threadPoolTaskExecutor.initialize();
// }
//
// /**
// * 获取数据
// */
// public static List
// List
// if(!“Linux”.equals(OSinfo.getOSname())){
// final CountDownLatch latch = new CountDownLatch(5);
// threadPoolTaskExecutor.submit(new Runnable() {
// @Override
// public void run() {
// TestGetData.getJVM();
// latch.countDown();
// }
// });
// threadPoolTaskExecutor.submit(new Runnable() {
// @Override
// public void run() {
// Map linux = TestGetData.getOpenFiles(“192.168.134.100”, “root”, “root”, 22, “ulimit -a”);
// list.add(linux);
// latch.countDown();
// }
// });
// threadPoolTaskExecutor.submit(new Runnable() {
// @Override
// public void run() {
// Map mysql = TestGetData.getMysql(“192.168.134.100”, “root”, “root”, 22, “cat /etc/my.cnf”);
// list.add(mysql);
// latch.countDown();
// }
// });
// threadPoolTaskExecutor.submit(new Runnable() {
// @Override
// public void run() {
// Map redis = TestGetData.getRedis(“192.168.134.100”, “root”, “root”, 22, “cat redis.conf”, “/usr/local/redis/bin/redis-cli info clients”);
// list.add(redis);
// latch.countDown();
// }
// });
// threadPoolTaskExecutor.submit(new Runnable() {
// @Override
// public void run() {
Map tomcat = TestGetData.getXml(“G:\Tomcat\PersonalTomcat\OrdinaryTomcat\apache-tomcat-9.0.27\conf\server.xml”);
list.add(tomcat);
// latch.countDown();
// }
// });
// }
// return list;
// }
//
//
//
// /**
// * 远程 执行命令并返回结果调用过程 是同步的(执行完23才会返回)
// * @param host 主机名
// * @param user 用户名
// * @param psw 密码
// * @param port 端口
// * @param command 命令
// * @return
// */
// public static Map exec(String host,String user,String psw,int port,String command){
// String result=“”;
// Session session =null;
// ChannelExec openChannel =null;
// Map<String, String> map = new HashMap<>();
// try {
// JSch jsch=new JSch();
// session = jsch.getSession(user, host, port);
// java.util.Properties config = new java.util.Properties();
// config.put(“StrictHostKeyChecking”, “no”);
// session.setConfig(config);
// session.setPassword(psw);
// session.connect();
// openChannel = (ChannelExec) session.openChannel(“exec”);
// openChannel.setCommand(command);
// openChannel.connect();
// InputStream in = openChannel.getInputStream();
// BufferedReader reader = new BufferedReader(new InputStreamReader(in));
// String buf = null;
// while ((buf = reader.readLine()) != null) {
// String data = new String(buf.getBytes(“UTF-8”),“UTF-8”);
// result+= data +“\r\n”;
// if(buf.contains(“open files”)){
// map.put(“openFiles”,data);
// }
// if(buf.contains(“soft nofile”)){
// map.put(“softNofile”,data);
// }
// if(buf.contains(“hard nofile”)){
// map.put(“hardNofile”,data);
// }
// if(buf.contains(“max_connections”)){
// map.put(“maxConnections”,data);
// }
// if(buf.contains(“innodb_buffer_pool_size”)){
// map.put(“innodbBufferPoolSize”,data);
// }
// if(buf.contains(“timeout”)){
// map.put(“timeout”,data);
// }
// if(buf.contains(“connected_clients”)){
// map.put(“connectedClients”,data);
// }
// }
// } catch (JSchException | IOException e) {
// result+=e.getMessage();
// }finally{
// if(openChannel!=null&&!openChannel.isClosed()){
// openChannel.disconnect();
// }
// if(session!=null&&session.isConnected()){
// session.disconnect();
// }
// }
// map.put(“all”,result);
// return map;
// }
//
// public static void getJVM(){
最全的Linux教程,Linux从入门到精通
======================
-
linux从入门到精通(第2版)
-
Linux系统移植
-
Linux驱动开发入门与实战
-
LINUX 系统移植 第2版
-
Linux开源网络全栈详解 从DPDK到OpenFlow
第一份《Linux从入门到精通》466页
====================
内容简介
====
本书是获得了很多读者好评的Linux经典畅销书**《Linux从入门到精通》的第2版**。本书第1版出版后曾经多次印刷,并被51CTO读书频道评为“最受读者喜爱的原创IT技术图书奖”。本书第﹖版以最新的Ubuntu 12.04为版本,循序渐进地向读者介绍了Linux 的基础应用、系统管理、网络应用、娱乐和办公、程序开发、服务器配置、系统安全等。本书附带1张光盘,内容为本书配套多媒体教学视频。另外,本书还为读者提供了大量的Linux学习资料和Ubuntu安装镜像文件,供读者免费下载。
本书适合广大Linux初中级用户、开源软件爱好者和大专院校的学生阅读,同时也非常适合准备从事Linux平台开发的各类人员。
需要《Linux入门到精通》、《linux系统移植》、《Linux驱动开发入门实战》、《Linux开源网络全栈》电子书籍及教程的工程师朋友们劳烦您转发+评论