Skip to content

Commit

Permalink
enable batch script manager in ZMQ proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
nxi committed Sep 18, 2024
1 parent ff8d659 commit e8e6e7b
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*******************************************************************************/
package au.gov.ansto.bragg.nbi.ui.internal;

import org.eclipse.ui.IFolderLayout;
import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.IPerspectiveFactory;

Expand All @@ -23,6 +24,7 @@ public class ControlExperimentPerspective implements IPerspectiveFactory {
public static final String ID_VIEW_ACTIVITY_MONITOR = "au.gov.ansto.bragg.nbi.ui.SicsRealtimeDataView";

public void createInitialLayout(final IPageLayout factory) {

factory.addShowViewShortcut(CONTROL_BATCH_RUNNER_VIEW_ID);
factory.addShowViewShortcut(CONTROL_TERMINAL_VIEW_ID);
factory.addShowViewShortcut(PROJECT_EXPLORER_VIEW_ID);
Expand All @@ -47,28 +49,40 @@ public void createInitialLayout(final IPageLayout factory) {
// bottomLeft.addView(PROJECT_EXPLORER_VIEW_ID);
factory.addStandaloneView(PROJECT_EXPLORER_VIEW_ID, false, IPageLayout.LEFT, 0.33f, CONTROL_TERMINAL_VIEW_ID);

factory.addStandaloneView(ID_VIEW_ACTIVITY_MONITOR, false, IPageLayout.RIGHT, 0.50f, CONTROL_TERMINAL_VIEW_ID);

// IFolderLayout right =
// factory.createFolder(
// "right",
// IPageLayout.RIGHT,
// 0.50f,
// factory.getEditorArea());
// right.addView(CONTROL_BATCH_RUNNER_VIEW_ID);
factory.addStandaloneView(CONTROL_BATCH_RUNNER_VIEW_ID, false, IPageLayout.RIGHT, 0.4f, factory.getEditorArea());

IFolderLayout top2 = factory.createFolder(
"top2", //NON-NLS-1
IPageLayout.RIGHT,
0.50f,
factory.getEditorArea());
top2.addView(CONTROL_BATCH_RUNNER_VIEW_ID);
top2.addView(CONTROL_TABLE_VIEW_ID);
// factory.addStandaloneView(CONTROL_TABLE_VIEW_ID, false, IPageLayout.RIGHT, 0.7f, factory.getEditorArea());

factory.addStandaloneView(CONTROL_TABLE_VIEW_ID, false, IPageLayout.RIGHT, 0.4f, factory.getEditorArea());
// factory.addStandaloneView(CONTROL_BATCH_RUNNER_VIEW_ID, false, IPageLayout.RIGHT, 0.33f, factory.getEditorArea());

factory.addStandaloneView(ID_VIEW_ACTIVITY_MONITOR, false, IPageLayout.RIGHT, 0.50f, CONTROL_TERMINAL_VIEW_ID);

factory.setEditorAreaVisible(false);
factory.getViewLayout(CONTROL_TERMINAL_VIEW_ID).setCloseable(false);
factory.getViewLayout(CONTROL_TERMINAL_VIEW_ID).setMoveable(false);
factory.getViewLayout(CONTROL_BATCH_RUNNER_VIEW_ID).setCloseable(false);
factory.getViewLayout(CONTROL_BATCH_RUNNER_VIEW_ID).setMoveable(false);
factory.getViewLayout(CONTROL_TABLE_VIEW_ID).setCloseable(false);
factory.getViewLayout(CONTROL_TABLE_VIEW_ID).setMoveable(false);
// factory.getViewLayout("bottomLeft").setMoveable(false);
// factory.getViewLayout("bottomLeft").setCloseable(false);
// factory.getViewLayout("right").setMoveable(false);
// factory.getViewLayout("right").setCloseable(false);

factory.setFixed(true);
factory.setEditorAreaVisible(true);

// factory.setFixed(true);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public BatchStatus getStatus() {
}

private synchronized void setBatchStatus(final BatchStatus status) {
System.err.println("status = " + status);
this.status = status;
for (IBatchListener listener : batchListeners) {
listener.statusChanged(status);
Expand Down Expand Up @@ -212,20 +213,26 @@ public void fireBatchEvent(String type, String value) {
listener.scriptChanged(value);
}
} else if (type.equals(PropertyConstants.PROP_BATCH_RANGE)) {
System.err.println("fire event range=" + value);
for (IBatchListener listener : batchListeners) {
listener.lineExecuted(Integer.valueOf(value));;
// listener.lineExecuted(Integer.valueOf(value));;
listener.rangeExecuted(value);
}
}
else if (type.equals(PropertyConstants.PROP_BATCH_TEXT)) {
for (IBatchListener listener : batchListeners) {
listener.scriptChanged(value);;
}
} else if (type.equals(PropertyConstants.PROP_BATCH_FINISH)) {
for (IBatchListener listener : batchListeners) {
// listener.lineExecuted(Integer.valueOf(value));;
listener.stop();
}
}
}

@Override
public void parseState(String stateName, String stateValue) {
logger.warn("parse batch: " + stateName + " " + stateValue);
if (stateName.equalsIgnoreCase(BatchStatus.START_STATE)) {
setBatchName(stateValue);
setBatchStatus(BatchStatus.EXECUTING);
Expand All @@ -250,6 +257,7 @@ public String getBatchName() {

private void setBatchName(final String batchName) {
this.batchId = String.valueOf(System.currentTimeMillis());
System.err.println("batch name = " + batchName);
this.batchName = batchName;
try {
sicsProxy.asyncRun("exe print " + batchName, new SicsCallbackAdapter() {
Expand All @@ -271,6 +279,7 @@ public void receiveFinish(final ISicsReplyData data) {

private void setBatchText(String text) {
batchText = text;
System.err.println("batch text = " + batchText);
fireBatchEvent(PropertyConstants.PROP_BATCH_TEXT, text);
getBatchRange();
}
Expand Down Expand Up @@ -367,6 +376,7 @@ public String getBatchRangeText() {
*/
private void setBatchRangeText(String batchRangeText) {
this.batchRangeText = batchRangeText;
fireBatchEvent(PropertyConstants.PROP_BATCH_TEXT, batchRangeText);
System.err.println("batch range = " + batchRangeText);
fireBatchEvent(PropertyConstants.PROP_BATCH_RANGE, batchRangeText);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public interface IBatchListener {

void charExecuted(int start, int end);

void rangeExecuted(String rangeText);

void lineExecuted(int line);

void lineExecutionError(int line);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public class BatchManager extends AbstractModelObject implements IBatchManager {

private SicsMessageAdapter messageListener;

private ISicsProxyListener proxyListener;

// SICS batch buffer manager callback
private ISicsCallback exeInterestCallback;

Expand Down Expand Up @@ -108,27 +110,27 @@ public void queueChanged() {
batchQueue.addQueueEventListener(queueEventListener);

// Handles proxy connect and disconnect events
// proxyListener = new SicsProxyListenerAdapter() {
//
// @Override
// public void interrupt(boolean isInterrupted) {
// // Batch is interrupt with level 3 or above
//// setBatchStatus(BatchManagerStatus.IDLE);
// // Pause for the rest of queue
// setAutoRun(false);
// }
//
// @Override
// public void disconnect() {
// handleSicsDisconnect();
// }
//
// @Override
// public void connect() {
// handleSicsConnect();
// }
// };
// sicsProxy.addProxyListener(proxyListener);
proxyListener = new SicsProxyListenerAdapter() {

@Override
public void interrupt(boolean isInterrupted) {
// Batch is interrupt with level 3 or above
// setBatchStatus(BatchManagerStatus.IDLE);
// Pause for the rest of queue
setAutoRun(false);
}

@Override
public void disconnect() {
handleSicsDisconnect();
}

@Override
public void connect() {
handleSicsConnect();
}
};
sicsProxy.addProxyListener(proxyListener);
batchControl = sicsProxy.getBatchControl();

batchListener = new IBatchListener() {
Expand All @@ -154,6 +156,11 @@ public void scriptChanged(String scriptName) {
fireBatchChangeEvent(scriptName);
}

@Override
public void rangeExecuted(String rangeText) {
fireBatchRangeEvent(rangeText);
}

@Override
public void lineExecutionError(int line) {
// TODO Auto-generated method stub
Expand Down Expand Up @@ -287,7 +294,7 @@ private void updateTimeEstimation() {
}
}

// protected void handleSicsConnect() {
protected void handleSicsConnect() {
// setBatchStatus(BatchManagerStatus.IDLE);
// try {
// asyncSend("exe info", new SicsCallbackAdapter() {
Expand All @@ -308,21 +315,21 @@ private void updateTimeEstimation() {
//
// } catch (Exception e) {
// }
//
// // Schedule queue
// scheduler.schedule();
// }

// Schedule queue
scheduler.schedule();
}

// protected void handleSicsDisconnect() {
// if (exeInterestCallback != null) {
// exeInterestCallback.setCallbackCompleted(true);
// exeInterestCallback = null;
// }
// // Set manager to disconnected state
protected void handleSicsDisconnect() {
if (exeInterestCallback != null) {
exeInterestCallback.setCallbackCompleted(true);
exeInterestCallback = null;
}
// Set manager to disconnected state
// setBatchStatus(BatchManagerStatus.DISCONNECTED);
// // Unschedule queue
// scheduler.cancel();
// }
// Unschedule queue
scheduler.cancel();
}

public boolean isAutoRun() {
return autoRun;
Expand Down Expand Up @@ -593,7 +600,13 @@ private void fireBatchChangeEvent(final String bufferName) {
listener.scriptChanged(bufferName);
}
}


private void fireBatchRangeEvent(final String range) {
for (IBatchManagerListener listener : batchManagerListeners) {
listener.rangeChanged(range);
}
}

private void handleException(String err) {
synchronized (batchControl.getStatus()) {
// this.status = BatchManagerStatus.ERROR;
Expand Down Expand Up @@ -684,8 +697,9 @@ public static IBatchManager getBatchScriptManager(ISicsProxy sicsProxy) {

public void setMessageListener(SicsMessageAdapter messageListener) {
this.messageListener = messageListener;
sicsProxy.addMessageListener(messageListener);
if (messageListener != null) {
sicsProxy.addMessageListener(messageListener);
}
}


}
Loading

0 comments on commit e8e6e7b

Please sign in to comment.