Java Bloomber V3 APIを使用すると、通常は機能します。ただし、特に再起動後、bbcomm.exeがバックグラウンドで実行されない場合があります。blp.exeを実行して手動で起動できますが、APIを介してこれを行う方法があるかどうか疑問に思いました。
私はまだヘルプを待っています-ヘルプ...
ヘルプデスクに相談したところ、64ビットWindowsでは、64ビットJVMbbcommでの実行が自動的に開始されないことがわかりました。これは、32ビットJavaでは発生しません。32ビット未満のbbcommは自動的に実行されます。
したがって、私の解決策は、問題がBloombergによって修正されるのを待つか(今では理解しています)、この特定のケースを確認することです。
特定のケースを確認するには:
os.arch)java.vm.name)bbcomm.exeが実行されていないと想定します。bbcomm.exeを使用して実行してみてくださいRuntime.exec()上記はまだテストしていません。ブルームバーグが64ビットVMで抱えている問題とまったく同じ問題が発生する可能性があります。
ヘルプヘルプでしばらく時間を過ごした後、Excel APIを使用するか、APIデモを実行すると、bbcommが開始されたようです。ただし、JavaAPIから呼び出されても自動的には開始されません。それを開始するための可能な方法は次のとおりです。
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run呼び出される文字列値を追加bbcommしますC:\blp\API\bbcomm.exe-しかし、それは表示されたままのコマンドウィンドウを開くので、実際にはオプションではありません(そして、そのウィンドウを閉じると、bbcommプロセスが終了します)START /MIN C:\blp\API\bbcomm.exeを作成し、レジストリ内のエントリをそのエントリ(テストされていない)に置き換えて、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);
}
}
私はこれが古い投稿であることを知っていますが、誰かがコード非表示のコンソールウィンドウから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");
}
bbcomm.exeは、V3APIによって自動的に開始されます。