2009-12-10 7 views
5

Quando utilizzo l'API Java Bloomber V3 di solito funziona. Tuttavia, a volte, soprattutto dopo un riavvio, bbcomm.exe non è in esecuzione in background. Posso avviarlo manualmente eseguendo blp.exe, ma mi chiedevo se esistesse un modo per farlo tramite l'API?Avvio di bbcomm in Java v3 API Bloomberg

sto ancora aspettando Aiuto-Aiuto ...

risposta

4

Dopo aver parlato con l'help desk, risulta che su 64 bit Windows, l'esecuzione di un BBcomm a 64 bit JVM non viene avviata automaticamente. Questo non avviene con Java a 32 bit: sotto a 32 bit viene eseguito automaticamente bbcomm.

Quindi le mie soluzioni sono di aspettare che il problema venga risolto da Bloomberg (ora lo capisco) o di verificare questo caso specifico.

Per controllare il caso specifico:

  • se in esecuzione con un Windows a 64 bit (proprietà del sistema os.arch)
  • e se in esecuzione con un JVM a 64 bit (proprietà del sistema java.vm.name)
  • poi cercare di avvio una sessione
  • Se ciò non riesce, supporre che bbcomm.exe non sia in esecuzione. Prova a eseguire bbcomm.exe utilizzando Runtime.exec()

Non ho ancora testato quanto sopra. Potrebbe avere esattamente gli stessi problemi di Bloomberg con le macchine virtuali a 64 bit.

+0

Ho provato questo, e funziona. –

-2

bbcomm.exe viene avviato automaticamente dal API V3.

+0

In realtà, a volte è, ma a volte non lo è. Aggiungerò una risposta con la mia risoluzione finale –

+0

Dovresti segnalare il problema. La libreria client API fa già esattamente ciò che stai cercando di fare.Se non riesce a connettersi a bbcomm, tenta di avviarlo. Se in alcuni casi non funziona, dovresti segnalarlo a bloomberg se non lo hai già fatto. –

+1

Ho finito per fare quello che ho suggerito nella mia risposta. Non posso essere preso la briga di passare attraverso il dolore di passare attraverso l'helpdesk BB per ottenere qualcuno che sa di cosa stanno parlando. Se lavori per bloomberg non esitare a segnalare, o inviami un messaggio privato –

0

Abbiamo lo stesso problema su un computer Windows 7 a 64 bit, utilizzando l'API .net. Bbcomm.exe non si avvia automaticamente e l'unica soluzione è avviare l'applicazione "Demo API Bloomberg" ...

3

Dopo aver trascorso un po 'di tempo con la Guida, sembra che bbcomm sia avviato quando si utilizza Excel API o esegui la demo dell'API. Ma non viene avviato automaticamente quando chiamato dall'API Java. Possibili modi per avviare esso sono:

  • aggiungendo una voce nel Registro di sistema per l'avvio automatico bbcomm all'avvio: in HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run Aggiungere un valore stringa denominato bbcomm con valore C:\blp\API\bbcomm.exe - ma che apre una finestra di comando che rimane visibile, quindi non davvero un'opzione (e se si chiude quella finestra si termina il processo bbcomm)
  • creare un file batch START /MIN C:\blp\API\bbcomm.exe e sostituire la voce nel registro di sistema con quella (non testato) per chiamare bbcomm silenziosamente
  • manualmente lanciare bbcomm dal java codice come già suggerito. Come riferimento, inserisco sotto il codice che sto usando.
private final static Logger logger = LoggerFactory.getLogger(BloombergUtils.class); 
private final static String BBCOMM_PROCESS = "bbcomm.exe"; 
private final static String BBCOMM_FOLDER = "C:/blp/API"; 

/** 
* 
* @return true if the bbcomm process is running 
*/ 
public static boolean isBloombergProcessRunning() { 
    return ShellUtils.isProcessRunning(BBCOMM_PROCESS); 
} 

/** 
* Starts the bbcomm process, which is required to connect to the Bloomberg data feed 
* @return true if bbcomm was started successfully, false otherwise 
*/ 
public static boolean startBloombergProcessIfNecessary() { 
    if (isBloombergProcessRunning()) { 
     logger.info(BBCOMM_PROCESS + " is started"); 
     return true; 
    } 

    Callable<Boolean> startBloombergProcess = getStartingCallable(); 
    return getResultWithTimeout(startBloombergProcess, 1, TimeUnit.SECONDS); 
} 

private static Callable<Boolean> getStartingCallable() { 
    return new Callable<Boolean>() { 
     @Override 
     public Boolean call() throws Exception { 
      logger.info("Starting " + BBCOMM_PROCESS + " manually"); 
      ProcessBuilder pb = new ProcessBuilder(BBCOMM_PROCESS); 
      pb.directory(new File(BBCOMM_FOLDER)); 
      pb.redirectErrorStream(true); 
      Process p = pb.start(); 
      BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); 
      String line; 
      while ((line = reader.readLine()) != null) { 
       if (line.toLowerCase().contains("started")) { 
        logger.info(BBCOMM_PROCESS + " is started"); 
        return true; 
       } 
      } 
      return false; 
     } 
    }; 

} 

private static boolean getResultWithTimeout(Callable<Boolean> startBloombergProcess, int timeout, TimeUnit timeUnit) { 
    ExecutorService executor = Executors.newSingleThreadExecutor(new ThreadFactory() { 

     @Override 
     public Thread newThread(Runnable r) { 
      Thread t = new Thread(r, "Bloomberg - bbcomm starter thread"); 
      t.setDaemon(true); 
      return t; 
     } 
    }); 
    Future<Boolean> future = executor.submit(startBloombergProcess); 

    try { 
     return future.get(timeout, timeUnit); 
    } catch (InterruptedException ignore) { 
     Thread.currentThread().interrupt(); 
     return false; 
    } catch (ExecutionException | TimeoutException e) { 
     logger.error("Could not start bbcomm", e); 
     return false; 
    } finally { 
     executor.shutdownNow(); 
     try { 
      if (!executor.awaitTermination(100, TimeUnit.MILLISECONDS)) { 
       logger.warn("bbcomm starter thread still running"); 
      } 
     } catch (InterruptedException ex) { 
      Thread.currentThread().interrupt(); 
     } 
    } 
} 

ShellUtils.java

public class ShellUtils { 

    private final static Logger logger = LoggerFactory.getLogger(ShellUtils.class); 

    /** 
    * @return a list of processes currently running 
    * @throws RuntimeException if the request sent to the OS to get the list of running processes fails 
    */ 
    public static List<String> getRunningProcesses() { 
     List<String> processes = new ArrayList<>(); 

     try { 
      Process p = Runtime.getRuntime().exec(System.getenv("windir") + "\\system32\\" + "tasklist.exe"); 
      BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); 
      String line; 
      int i = 0; 
      while ((line = input.readLine()) != null) { 
       if (!line.isEmpty()) { 
        String process = line.split(" ")[0]; 
        if (process.contains("exe")) { 
         processes.add(process); 
        } 
       } 
      } 
     } catch (IOException e) { 
      throw new RuntimeException("Could not retrieve the list of running processes from the OS"); 
     } 

     return processes; 
    } 

    /** 
    * 
    * @param processName the name of the process, for example "explorer.exe" 
    * @return true if the process is currently running 
    * @throws RuntimeException if the request sent to the OS to get the list of running processes fails 
    */ 
    public static boolean isProcessRunning(String processName) { 
     List<String> processes = getRunningProcesses(); 
     return processes.contains(processName); 
    } 
}