2009-12-10 7 views
5

Cuando uso la API de Java Bloomber V3 generalmente funciona. Sin embargo, a veces, especialmente después de un reinicio, bbcomm.exe no se ejecuta en segundo plano. Puedo iniciarlo manualmente ejecutando blp.exe, pero me pregunté si habría alguna forma de hacerlo a través de la API.Iniciar bbcomm en Java v3 Bloomberg API

Todavía estoy esperando en Ayuda-Ayuda ...

Respuesta

4

Después de hablar con la mesa de ayuda, resulta que en Windows de 64 bits, la ejecución bajo una bbcomm JVM de 64 bits no se inicia automáticamente. Esto no sucede en Java de 32 bits: bajo 32 bit, bbcomm se ejecuta automáticamente.

Así que mis soluciones deben o bien esperar a que Bloomberg resuelva el problema (ahora lo entiendo) o verificar este caso específico.

Para comprobar el caso específico:

  • si se ejecuta en una ventana de 64 bits (propiedad Sistema os.arch)
  • y si se ejecuta en una JVM de 64 bits (propiedad Sistema java.vm.name)
  • continuación, tratar de inicio una sesión
  • Si esto falla, suponga que bbcomm.exe no se está ejecutando. Intente ejecutar bbcomm.exe utilizando Runtime.exec()

Todavía no he probado el contenido anterior. Puede tener exactamente los mismos problemas que Bloomberg con máquinas virtuales de 64 bits.

+0

Lo he intentado y funciona. –

-2

bbcomm.exe se inicia automáticamente por el API V3.

+0

En realidad, es a veces, pero a veces no lo es. Agregaré una respuesta con mi resolución final –

+0

Debe informar el problema. La biblioteca del cliente API ya hace exactamente lo que estás tratando de hacer.Si no se puede conectar al bbcomm, intenta iniciarlo. Si eso no funciona en algunos casos, debe informarlo a Bloomberg si aún no lo ha hecho. –

+1

Terminé haciendo lo que sugerí en mi respuesta. No puedo molestarme en pasar por el dolor de pasar por el servicio de asistencia de BB para buscar a alguien que sepa de lo que están hablando. Si trabajas para Bloomberg no dudes en informarme o envíame un mensaje privado –

0

Tenemos el mismo problema en una máquina con Windows 7 de 64 bits, que utiliza .NET API. El bbcomm.exe no se inicia automáticamente, y la única solución alternativa es iniciar la aplicación "Bloomberg API DEMO" ...

3

Después de pasar algo de tiempo con Ayuda Ayuda, parece que bbcomm se inicia cuando usa el Excel API o ejecuta la demostración de la API. Pero no se inicia automáticamente cuando se llama desde la API de Java. Las posibles formas de iniciar la misma son:

  • añadiendo una entrada en el registro para iniciarse automáticamente bbcomm en el arranque: en HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run añadir un valor de cadena llamado bbcomm con valor C:\blp\API\bbcomm.exe - pero que abre una ventana de comandos, que permanece visible, por lo que no realmente una opción (y si se cierra esa ventana se termina el proceso bbcomm)
  • crear un archivo por lotes START /MIN C:\blp\API\bbcomm.exe y sustituir la entrada en el registro con el que (no probado) para llamar bbcomm silencio
  • manualmente lanzar bbcomm de su java código como ya se sugirió. Como referencia, publico debajo del código que estoy 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); 
    } 
} 
Cuestiones relacionadas