private void startServer(PrologInterface pif, PrologSession session) { try { String queryString = bT( PDTConsolePredicates.PDT_START_CONSOLE_SERVER, "Port", Util.quoteAtom( PrologRuntimePlugin.getDefault().getPrologInterfaceRegistry().getKey(pif))); Debug.info("starting console server using: " + queryString); Map<String, ?> result = session.queryOnce(queryString); if (result == null) { Debug.info("starting server failed, which may mean that it is actualy running already."); result = session.queryOnce(bT(PDTConsolePredicates.PDT_CURRENT_CONSOLE_SERVER, "Port")); if (result == null) { throw new RuntimeException("No Server running."); } } int port = Integer.parseInt((String) result.get("Port")); Debug.debug("A server thread seems to be listinging at port " + port); } catch (Throwable e) { Debug.report(e); throw new RuntimeException(e); } }
private void ensureConnection(final PrologInterface pif, PrologSocketConsoleModel model) throws PrologInterfaceException { if (model.isConnected()) { return; } PrologSession session = pif.getSession(PrologInterface.NONE); // FileSearchPathConfigurator.configureFileSearchPath(PrologRuntimeUIPlugin.getDefault() // .getLibraryManager(), session, // new String[] { PDTConsole.PL_LIBRARY }); Map<String, ?> result = null; try { // result = session.queryOnce( "consult(lib_pdt_console_pl(loader))."); result = session.queryOnce( bT( PDTConsolePredicates.PDT_START_CONSOLE_SERVER, "Port", Util.quoteAtom( PrologRuntimePlugin.getDefault().getPrologInterfaceRegistry().getKey(pif)))); if (result == null) { startServer(pif, session); result = session.queryOnce(bT(PDTConsolePredicates.PDT_CURRENT_CONSOLE_SERVER, "Port")); } if (result == null) { throw new RuntimeException("could not install console server"); } } catch (Exception e) { Debug.info(e.toString()); } finally { if (session != null) { session.dispose(); } } int port = Integer.parseInt(result.get("Port").toString()); model.setPort(port); model.connect(); }