VisClient/org/hfbk/vis/ServerManager.java

Go to the documentation of this file.
00001 package org.hfbk.vis;
00002 
00003 import java.util.HashMap;
00004 
00005 import org.dronus.graph.Graph;
00006 import org.hfbk.util.Updater;
00007 import org.hfbk.vis.source.Source;
00008 
00021 public class ServerManager extends Thread{
00022                 
00023         HashMap<String,Graph> nodes=new HashMap<String,Graph>();
00024         
00028         HashMap<String, Source> fetchers=new HashMap<String, Source>();
00029         
00036         String getServer(){
00037                 String[] servers=Prefs.current.baseURLs.split(";");
00038                 
00039                 if (servers.length==0) return "";
00040                 
00041                 System.out.println("Checking servers: "+Prefs.current.baseURLs);
00042 
00043                 //start simultaneous fetches for a server 
00044                 for(String s: servers){
00045                         Source source=Source.getSource(s+"graph.php?action=getgraph&source=server");
00046                         source.setPriority(Thread.MAX_PRIORITY);
00047                         fetchers.put(s,source);                 
00048                 }
00049                 
00050                 String server=null;             
00051                 
00052                 try {
00053                         Thread.sleep(Prefs.current.servertimeout);
00054                 } catch (InterruptedException e) {}
00055                 
00056                 //test servers in order
00057                 for (String s: servers){
00058                         Source sources=fetchers.get(s);
00059                         if (sources!=null && sources.finished){
00060                                 server=s;
00061                                 break;
00062                         }
00063                 }
00064                 
00065                 if (server==null){ 
00066                         System.out.println("Unable to find ANY Vis Server! Please check your internet connection");
00067                         server="http://";
00068                 }
00069                 
00070                 return server;
00071         }
00072         
00073         public void run() {
00074                 Prefs.current.baseURL=getServer();
00075                 System.out.println("Using Server " + Prefs.current.baseURL);
00076                 if (Prefs.current.update) Updater.update();
00077         }
00078 }

Generated on Tue Apr 7 17:57:20 2009 for visclient by  doxygen 1.5.1