Skip to content

Commit

Permalink
Merge pull request #128 from gyorokpeter/parallelQuery
Browse files Browse the repository at this point in the history
add option to allow executing queries in parallel
  • Loading branch information
gyorokpeter authored Jun 27, 2022
2 parents 0035fb3 + bfff5ca commit 55bbf7f
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 8 deletions.
20 changes: 15 additions & 5 deletions src/main/kx/c.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class c {
int j;
int J;
boolean a;
private volatile boolean cancelled;
int rxBufferSize;
private String encoding = "UTF-8";

Expand Down Expand Up @@ -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);
Expand All @@ -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;
}

}
1 change: 1 addition & 0 deletions src/main/studio/kdb/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 8 additions & 1 deletion src/main/studio/ui/SettingsDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -109,6 +110,10 @@ public boolean isFileWatcherEnabled() {
return chBoxFileWatcher.isSelected();
}

public boolean isAllowParallelQuery() {
return chBoxAllowParallelQuery.isSelected();
}

public boolean isAnimateBracketMatching() {
return chBoxRTSAAnimateBracketMatching.isSelected();
}
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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)
);

Expand Down
6 changes: 4 additions & 2 deletions src/main/studio/ui/StudioPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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());

Expand Down
5 changes: 5 additions & 0 deletions src/main/studio/ui/action/QueryExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -158,6 +159,10 @@ protected QueryResult doInBackground() {
return result;
}

public void cancelQuery() {
c.cancel();
}

@Override
protected void done() {
if (pm != null) {
Expand Down

0 comments on commit 55bbf7f

Please sign in to comment.