当我使用Java Bloomber V3 API它通常工作。但是,有时候,特别是在重新启动后,bbcomm.exe没有在后台运行。我可以通过运行blp.exe手动启动它,但我想知道是否有通过API这样做的呢?在Java开始bbcomm V3彭博API
我仍然在等待帮助,帮助...
当我使用Java Bloomber V3 API它通常工作。但是,有时候,特别是在重新启动后,bbcomm.exe没有在后台运行。我可以通过运行blp.exe手动启动它,但我想知道是否有通过API这样做的呢?在Java开始bbcomm V3彭博API
我仍然在等待帮助,帮助...
聊到服务台后,事实证明,在64位Windows,64位JVM bbcomm下运行不会自动启动。这在32位Java下不会发生 - 在32位bbcomm下自动运行。
所以我的解决方案,要么等待问题彭博是固定的(现在我理解它),或检查这种特殊情况下。
要检查的具体情况:
os.arch
)java.vm.name
)bbcomm.exe
没有运行。尝试运行bbcomm.exe
使用Runtime.exec()
我还没有测试过以上。它可能与Bloomberg对64位虚拟机的问题完全相同。
bbcomm.exe由V3 API自动启动。
实际上,它有时是,但有时并非如此。我将在最终决议中添加一个答案 – 2009-12-17 12:47:42
您应该报告问题。 API客户端库 已经完全符合您所要做的。如果它不能连接到bbcomm,它会尝试启动它。如果这在某些情况下不起作用,如果您还没有这样做,您应该将它报告给彭博社。 – 2009-12-17 17:32:30
我已经完成了我在我的回答中提出的建议。我不会因为经历BB帮助台的痛苦去找一个知道他们在说什么的人而烦恼。如果你为彭博社工作随时举报,或者私下给我发消息 – 2010-05-28 12:50:29
我们在使用.net API的Windows 7 64位机器上遇到同样的问题。 bbcomm.exe不会自动启动,唯一的解决方法是启动“Bloomberg API DEMO”应用程序...
花费了一些时间与帮助帮助后,似乎bbcomm开始或者当您使用Excel API或运行API演示。但是,从Java API调用它时不会自动启动。可能的方法来启动它是:
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);
}
}
我已经试过了,并且它可以工作。 – 2010-05-28 12:49:28