java - Get more than One value and display it -
i checking 'n' number of servers every minute, if servers down mail triggered user server name down. issue facing if more 1 server down getting 1 server name down. how name of servers down.
obj = dataaccess.getservers(); //getting status , links of servers mailserver sender = new mailserver(from,password); list<string> downserver = new arraylist(); (map<string, string> objs : obj) { //iterating each server serverstatus = objs.get("status"); if (serverstatus.equals("down")) { servername = objs.get("name"); statusserver=objs.get("status"); } downserver.add(servername); if(!(servername.equals(null))){ sender.sendmail("server status",downserver.get(i),from,to) }
without checking reasonability of code or trying improve anything, code should little more following (at least) come close trying:
servers = dataaccess.getservers(); mailserver sender = new mailserver(from,password); list<string> downservers = new arraylist(); (map<string, string> server : servers) { serverstatus = server.get("status"); servername = server.get("name"); if (serverstatus.equals("down") && servername != null) { downservers.add(servername); } } stringbuilder sb = new stringbuilder(); string sep = ""; (server : downservers) { sb.append(sep).append(server); sep = ", "; } sender.sendmail("server status", sb.tostring(), from, to);
or short 1 iteration:
mailserver sender = new mailserver(from,password); stringbuilder sb = new stringbuilder(); string sep = ""; (map<string, string> server : dataaccess.getservers()) { string servername = server.get("name"); if (server.get("status").equals("down") && servername != null) { sb.append(sep).append(servername); sep = ", "; } } sender.sendmail("server status", sb.tostring(), from, to);
Comments
Post a Comment