データベース接続、ipポート番号接続ステータスの検証


server1=10.10.10.91:9001
server3=10.10.10.91:8080
server2=10.10.10.60:8080
server4=10.10.10.82:9001

 
public class GetCfg {

	public  List getAllValues(){
	    Properties pro = new Properties();
		try {
			pro.load(this.getClass().getClassLoader().getResourceAsStream("conf.properties"));
		} catch (IOException e1) {
		   e1.printStackTrace();
		}
		List list=new ArrayList();
		Enumeration e = pro.elements();
		while(e.hasMoreElements()){
			String s=(String) e.nextElement();
			list.add(s);
		}
		pro.clear();
		return list;
  }
	
}

 
public class CntvCheckConnection extends ControllerBase {
	
	private final static Logger logger = Logger.getLogger(CntvCheckConnection.class);

	 /**
     *  
     */
    public static void cntvCheckConnection_index() {
    	String check=" !"+"<br/><br/>";
    	EntityManagerFactory ef=null;
    	try{
    	   ef=Persistence.createEntityManagerFactory("sqlserver");
    	}catch(Exception e){
    		e.printStackTrace();
    		logger.info(e.getMessage());
    		check=" !"+"<br/>";
    		
    	}finally{
    		ef.close();
    	}
    	String checktemp=checkip();
    	String s1="<div style='font-size:16px'>";
    	String s2="</div>";
    	check=s1+check+checktemp+s2;
    	renderHtml(check);
    }
    
    public static String checkip(){
    	GetCfg gc=new GetCfg();
    	List s=gc.getAllValues();
    	StringBuffer checktemp=new StringBuffer();
		for(int i=0;i<s.size();i++){
			String temp=(String) s.get(i);
			String [] cc=temp.split(":");
		    String host=cc[0];
		    int port=Integer.valueOf(cc[1]);
		    String msg=bindPort(host,port);
		    System.out.println(host+":"+port);
		    
		    checktemp.append(host+":");
		    checktemp.append(port+"&nbsp;&nbsp;&nbsp;");
		    checktemp.append(msg+"    ");
		    checktemp.append("<br/>"); 
		}
		return checktemp.toString();
    }
    
	public static String bindPort(String host, int port) {
		String isBind=" ";
		Socket client = null;
		try{
		    client = new Socket(host, port);
		    client.close();
		}catch(Exception e){
		    isBind=" ";
		}

		return isBind;
	}
}