在 Java v3 Bloomberg API 中启动 bbcomm

发布于 2024-08-14 09:11:56 字数 123 浏览 7 评论 0原文

当我使用 Java Bloomber V3 API 时,它通常可以工作。但是,有时,尤其是重新启动后,bbcomm.exe 不会在后台运行。我可以通过运行 blp.exe 手动启动它,但我想知道是否有办法通过 API 来执行此操作?

When I use the Java Bloomber V3 API it usually works. However, sometimes, especially after a reboot, bbcomm.exe is not running in the background. I can start it manually by running blp.exe, but I wondered if there was a way of doing this via the API?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

最初的梦 2024-08-21 09:11:56

与服务台交谈后,发现在 64 位 Windows 上,在 64 位 JVM 下运行的 bbcomm 不会自动启动。这在 32 位 Java 下不会发生 - 在 32 位 bbcomm 下自动运行。

所以我的解决方案要么等待彭博社解决问题(现在我明白了),要么检查这个具体案例。

检查具体情况:

  • 是否在 64 位 Windows 下运行(系统属性 os.arch
  • 以及是否在 64 位 JVM 下运行(系统属性 java.vm.name
  • 然后尝试启动会话
  • 如果失败,则假设 bbcomm.exe 未运行。尝试使用 Runtime.exec() 运行 bbcomm.exe

我还没有测试过上面的内容。它可能与 Bloomberg 在 64 位虚拟机上遇到的问题完全相同。

After talking to the help desk, it turns out that on 64 bit Windows, running under a 64bit JVM bbcomm is not automatically started. This does not happen under 32bit Java - under 32 bit bbcomm automatically runs.

So my solutions are either to wait for the problem to be fixed by Bloomberg (now I understand it) or to check this specific case.

To check the specific case:

  • if running under a 64 bit windows (System property os.arch)
  • and if running under a 64bit JVM (System property java.vm.name)
  • then try and start a session
  • If this fails, assume bbcomm.exe is not running. Try to run bbcomm.exe using Runtime.exec()

I haven't tested the above yet. It may have exactly the same issues as Bloomberg have with 64bit VMs.

や莫失莫忘 2024-08-21 09:11:56

在使用帮助帮助一段时间后,似乎当您使用 Excel API 或运行 API 演示时,bbcomm 就会启动。但从 Java API 调用时它不会自动启动。启动它的可能方法是:

  • 在注册表中添加一个条目以在启动时自动启动 bbcomm:在 HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run 中添加一个名为 bbcomm 的字符串值code> 的值为 C:\blp\API\bbcomm.exe - 但这会打开一个保持可见的命令窗口,因此并不是一个真正的选项(如果关闭该窗口,它会终止 bbcomm 进程)
  • 创建一个批处理文件 START /MIN C:\blp\API\bbcomm.exe 并将注册表中的条目替换为该条目(未经测试),以静默方式调用 bbcomm
  • 从您的 java 代码中手动启动 bbcomm建议。作为参考,我在下面发布了我正在使用的代码。
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);
    }
}

After spending some time with Help Help, it seems that bbcomm gets started either when you use the Excel API or run the API demo. But it does not get started automatically when called from the Java API. Possible ways to start it are:

  • adding an entry in the registry to automatically start bbcomm on startup: in HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run add a String value called bbcomm with value C:\blp\API\bbcomm.exe - but that opens a command window which remains visible, so not really an option (and if you close that window it terminates the bbcomm process)
  • create a batch file START /MIN C:\blp\API\bbcomm.exe and replace the entry in the registry with that (not tested) to call bbcomm silently
  • manually launch bbcomm from your java code as already suggested. As a reference, I post below the code that I'm using.
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);
    }
}
浅紫色的梦幻 2024-08-21 09:11:56

如果有人需要帮助从代码隐藏控制台窗口检查/启动 bbcomm.exe 进程,此代码段是用 C# 编写的;我希望你能轻松地将它翻译成Java。

void Main()
{
    var processes = Process.GetProcessesByName("bbcomm");
    if (processes.Any())
    {
        Console.WriteLine(processes.First().ProcessName + " already running");
        return;
    }

    var exePath = @"C:\blp\DAPI\bbcomm.exe";
    var processStart = new ProcessStartInfo(exePath);
    processStart.UseShellExecute = false;
    processStart.CreateNoWindow = true;
    processStart.RedirectStandardError = true;
    processStart.RedirectStandardOutput = true;
    processStart.RedirectStandardInput = true;  
    var process = Process.Start(processStart);
    Console.WriteLine(process.ProcessName + " started");
}

In case someone needs help checking/starting bbcomm.exe process from the code hiding console window, this snippet is written in C#; I hope you can easily translate it to Java.

void Main()
{
    var processes = Process.GetProcessesByName("bbcomm");
    if (processes.Any())
    {
        Console.WriteLine(processes.First().ProcessName + " already running");
        return;
    }

    var exePath = @"C:\blp\DAPI\bbcomm.exe";
    var processStart = new ProcessStartInfo(exePath);
    processStart.UseShellExecute = false;
    processStart.CreateNoWindow = true;
    processStart.RedirectStandardError = true;
    processStart.RedirectStandardOutput = true;
    processStart.RedirectStandardInput = true;  
    var process = Process.Start(processStart);
    Console.WriteLine(process.ProcessName + " started");
}
人生百味 2024-08-21 09:11:56

bbcomm.exe 由 V3 API 自动启动。

bbcomm.exe is automatically started by the V3 API.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文