private void disconnect(PrologInterface pif) { PrologSocketConsoleModel model = models.get(pif); if (model == null) { return; } model.disconnect(); }
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(); }