public String toString() { String ret = "\n"; while (true) { if (amazon == null) try { amazon = JCS.getInstance("Instances"); } catch (CacheException e) { e.printStackTrace(); continue; } synchronized (AmazonService.class) { for (Object key : amazon.getGroupKeys("Instances")) { Instance i = (Instance) amazon.getFromGroup(key, "Instances"); if (i == null) continue; ret += (i.getInstanceId() + " " + i.getImageId() + " " + i.getImageId() + " " + i.getArchitecture() + " " + i.getPrivateDnsName() + " " + i.getState().getName()) + "\n"; } for (Object key : amazon.getGroupKeys("AMIs")) { Image r = (Image) amazon.getFromGroup(key, "AMIs"); ; if (r == null) continue; ret += (r.getImageId() + " " + r.getDescription() + " " + r.getState()) + "\n"; } } if (ret.length() > 10) break; else { try { Thread.sleep(1000 * 5); } catch (InterruptedException e) { e.printStackTrace(); } continue; } } return ret; }
public List<Instance> getInstances() { List<Instance> list = new ArrayList<Instance>(); if (amazon == null) try { amazon = JCS.getInstance("Instances"); } catch (CacheException e) { e.printStackTrace(); return list; } synchronized (AmazonService.class) { for (Object key : amazon.getGroupKeys("Instances")) { Instance i = (Instance) amazon.getFromGroup(key, "Instances"); if (i == null) continue; list.add(i); } } return list; }