diff --git a/src/main/kx/c.java b/src/main/kx/c.java index 9d69440d..d2f99ffb 100755 --- a/src/main/kx/c.java +++ b/src/main/kx/c.java @@ -36,6 +36,7 @@ public class c { int j; int J; boolean a; + private volatile boolean cancelled; int rxBufferSize; private String encoding = "UTF-8"; @@ -636,17 +637,21 @@ private void u() { public synchronized K.KBase k(K.KBase x, ProgressCallback progress) throws K4Exception, IOException { try { - + cancelled = false; if (isClosed()) connect(true); try { w(1, x); inputStream.readFully(b = new byte[8]); } catch (IOException e) { close(); - // may be the socket was closed on the server side? - connect(true); - w(1, x); - inputStream.readFully(b = new byte[8]); + if (!cancelled) { + // maybe the socket was closed on the server side? + connect(true); + w(1, x); + inputStream.readFully(b = new byte[8]); + } else { + return null; + } } return k(progress); @@ -659,4 +664,9 @@ public synchronized K.KBase k(K.KBase x, ProgressCallback progress) throws K4Exc public K.KBase k(K.KBase x) throws K4Exception, IOException { return k(x, null); } + + public void cancel() { + cancelled = true; + } + } diff --git a/src/main/studio/kdb/Config.java b/src/main/studio/kdb/Config.java index 5d71b6c3..4f2cc744 100755 --- a/src/main/studio/kdb/Config.java +++ b/src/main/studio/kdb/Config.java @@ -44,6 +44,7 @@ public enum ThemeEntry { CHARVECTOR, EOLCOMMENT, IDENTIFIER, OPERATOR, BOOLEAN, public static final String AUTO_SAVE = configDefault("isAutoSave", ConfigType.BOOLEAN, false); public static final String SAVE_ON_EXIT = configDefault("isSaveOnExit", ConfigType.BOOLEAN, true); public static final String FILE_WATCHER_ENABLED = configDefault("isFileWatcherEnabled", ConfigType.BOOLEAN, true); + public static final String ALLOW_PARALLEL_QUERY = configDefault("allowParallelQuery", ConfigType.BOOLEAN, false); public static final String SERVER_LIST_BOUNDS = configDefault("serverList", ConfigType.BOUNDS, new Dimension(ServerList.DEFAULT_WIDTH, ServerList.DEFAULT_HEIGHT)); public static final String CHART_BOUNDS = configDefault("chartBounds", ConfigType.BOUNDS, 0.5); public static final String CELL_RIGHT_PADDING = configDefault("cellRightPadding", ConfigType.DOUBLE, 0.5); diff --git a/src/main/studio/ui/SettingsDialog.java b/src/main/studio/ui/SettingsDialog.java index 691d81d4..8f3a0114 100644 --- a/src/main/studio/ui/SettingsDialog.java +++ b/src/main/studio/ui/SettingsDialog.java @@ -25,6 +25,7 @@ public class SettingsDialog extends EscapeDialog { private JCheckBox chBoxAutoSave; private JCheckBox chBoxSaveOnExit; private JCheckBox chBoxFileWatcher; + private JCheckBox chBoxAllowParallelQuery; private JCheckBox chBoxRTSAAnimateBracketMatching; private JCheckBox chBoxRTSAHighlightCurrentLine; private JCheckBox chBoxRTSAWordWrap; @@ -109,6 +110,10 @@ public boolean isFileWatcherEnabled() { return chBoxFileWatcher.isSelected(); } + public boolean isAllowParallelQuery() { + return chBoxAllowParallelQuery.isSelected(); + } + public boolean isAnimateBracketMatching() { return chBoxRTSAAnimateBracketMatching.isSelected(); } @@ -258,6 +263,8 @@ private void initComponents() { chBoxSaveOnExit.setSelected(Config.getInstance().getBoolean(Config.SAVE_ON_EXIT)); chBoxFileWatcher = new JCheckBox("File watcher (needs restart to take effect)"); chBoxFileWatcher.setSelected(Config.getInstance().getBoolean(Config.FILE_WATCHER_ENABLED)); + chBoxAllowParallelQuery = new JCheckBox("Allow parallel queries"); + chBoxAllowParallelQuery.setSelected(Config.getInstance().getBoolean(Config.ALLOW_PARALLEL_QUERY)); JLabel lblDefaultLineEnding = new JLabel ("Default line ending:"); comboBoxLineEnding = new JComboBox<>(LineEnding.values()); @@ -287,7 +294,7 @@ private void initComponents() { new GroupLayoutSimple.Stack() .addLineAndGlue(lblLookAndFeel, comboBoxLookAndFeel) .addLineAndGlue(chBoxShowServerCombo, chBoxAutoSave, chBoxSaveOnExit) - .addLineAndGlue(chBoxFileWatcher) + .addLineAndGlue(chBoxFileWatcher, chBoxAllowParallelQuery) .addLine(lblAuthMechanism, comboBoxAuthMechanism, lblUser, txtUser, lblPassword, txtPassword) ); diff --git a/src/main/studio/ui/StudioPanel.java b/src/main/studio/ui/StudioPanel.java index cbedd912..be986b38 100755 --- a/src/main/studio/ui/StudioPanel.java +++ b/src/main/studio/ui/StudioPanel.java @@ -224,8 +224,9 @@ public void refreshActionState() { boolean queryRunning = editor.getQueryExecutor().running(); stopAction.setEnabled(queryRunning); - executeAction.setEnabled(!queryRunning); - executeCurrentLineAction.setEnabled(!queryRunning); + boolean allowParallel = CONFIG.getBoolean(Config.ALLOW_PARALLEL_QUERY); + executeAction.setEnabled(allowParallel || !queryRunning); + executeCurrentLineAction.setEnabled(allowParallel || !queryRunning); refreshAction.setEnabled(lastQuery != null && !queryRunning); TabPanel tab = (TabPanel) tabbedPane.getSelectedComponent(); @@ -827,6 +828,7 @@ public static void settings() { CONFIG.setExecAllOption(dialog.getExecAllOption()); CONFIG.setBoolean(Config.SAVE_ON_EXIT, dialog.isSaveOnExit()); CONFIG.setBoolean(Config.FILE_WATCHER_ENABLED, dialog.isFileWatcherEnabled()); + CONFIG.setBoolean(Config.ALLOW_PARALLEL_QUERY, dialog.isAllowParallelQuery()); CONFIG.setBoolean(Config.AUTO_SAVE, dialog.isAutoSave()); CONFIG.setEnum(Config.DEFAULT_LINE_ENDING, dialog.getDefaultLineEnding()); diff --git a/src/main/studio/ui/action/QueryExecutor.java b/src/main/studio/ui/action/QueryExecutor.java index 8626fe2a..545dc6d0 100644 --- a/src/main/studio/ui/action/QueryExecutor.java +++ b/src/main/studio/ui/action/QueryExecutor.java @@ -44,6 +44,7 @@ public void execute(String query) { public void cancel() { if (worker == null) return; if (worker.isDone()) return; + worker.cancelQuery(); //avoid double-executing the query when cancelling worker.closeConnection(); worker.cancel(true); worker = null; @@ -158,6 +159,10 @@ protected QueryResult doInBackground() { return result; } + public void cancelQuery() { + c.cancel(); + } + @Override protected void done() { if (pm != null) {