use of org.eclipse.scanning.api.event.scan.ScanBean in project gda-core by openGDA.
the class MScanSubmitterTest method willNotAllowStaticScanWithoutDetectors.
@Test
public void willNotAllowStaticScanWithoutDetectors() throws Exception {
// No Size, so default size=1
Object[] arr = { Scanpath.STATIC };
when(resolver.resolveScanClauses()).thenReturn(Arrays.asList(Arrays.asList(new ScanpathElementProcessor(Scanpath.STATIC))));
builder.buildAndSubmitBlockingScanRequest(arr);
verify(submitter).blockingSubmit(beanCaptor.capture());
verify(eventSubscriber).addListener(any(IScanListener.class));
ScanBean bean = beanCaptor.getValue();
assertThat(bean.getScanRequest().getCompoundModel(), is(equalTo(new CompoundModel(new StaticModel()))));
}
use of org.eclipse.scanning.api.event.scan.ScanBean in project gda-core by openGDA.
the class MScanSubmitterTest method createsCorrectProcessorListForPointScanWithShorthandSyntax.
@Test
public void createsCorrectProcessorListForPointScanWithShorthandSyntax() throws Exception {
Object[] arr = { scannable, anotherScannable, RegionShape.POINT, point.getX(), point.getY(), detectorRunnableDevice };
when(resolver.resolveScanClauses()).thenReturn(Arrays.asList(Arrays.asList(new ScannableElementProcessor(scannable), new ScannableElementProcessor(anotherScannable), new RegionShapeElementProcessor(RegionShape.POINT), new NumberElementProcessor(point.getX()), new NumberElementProcessor(point.getY()), new ScanpathElementProcessor(Scanpath.SINGLE_POINT), new NumberElementProcessor(point.getX()), new NumberElementProcessor(point.getY())), Arrays.asList(new IRunnableDeviceDetectorElementProcessor(detectorRunnableDevice))));
builder.buildAndSubmitBlockingScanRequest(arr);
List<IClauseElementProcessor> processors = captor.getValue();
assertThat(processors.size(), is(9));
assertThat(processors.get(0), instanceOf(ScannableElementProcessor.class));
assertThat(processors.get(0).getElement(), is(scannable));
assertThat(processors.get(1), instanceOf(ScannableElementProcessor.class));
assertThat(processors.get(1).getElement(), is(anotherScannable));
assertThat(processors.get(2), instanceOf(RegionShapeElementProcessor.class));
assertThat(processors.get(2).getElement(), is(RegionShape.POINT));
assertThat(processors.get(3), instanceOf(NumberElementProcessor.class));
assertThat(processors.get(3).getElement(), is(point.getX()));
assertThat(processors.get(4), instanceOf(NumberElementProcessor.class));
assertThat(processors.get(4).getElement(), is(point.getY()));
assertThat(processors.get(5), instanceOf(ScanpathElementProcessor.class));
assertThat(processors.get(5).getElement(), is(Scanpath.SINGLE_POINT));
assertThat(processors.get(6), instanceOf(NumberElementProcessor.class));
assertThat(processors.get(6).getElement(), is(point.getX()));
assertThat(processors.get(7), instanceOf(NumberElementProcessor.class));
assertThat(processors.get(7).getElement(), is(point.getY()));
assertThat(processors.get(8), instanceOf(IRunnableDeviceDetectorElementProcessor.class));
assertThat(processors.get(8).getElement(), is(detectorRunnableDevice));
verify(eventSubscriber).addListener(any(IScanListener.class));
verify(submitter).blockingSubmit(beanCaptor.capture());
ScanBean bean = beanCaptor.getValue();
assertThat(bean.getScanRequest().getCompoundModel(), is(equalTo(getCompoundModel(point, pointRoi))));
assertThat(bean.getScanRequest().getDetectors().values(), contains(detectorRunnableDevice.getModel()));
}
use of org.eclipse.scanning.api.event.scan.ScanBean in project gda-core by openGDA.
the class MScanSubmitter method submit.
/**
* Handle submission of the supplied ScanRequest and monitoring and reporting of the progress of the associated scan
*
* @param scanRequest The ScanRequest to be submitted
* @param block Whether the request should be submitted in blocking or non-blocking mode
* @throws Exception Any Exception arising from the submission operation
*/
public void submit(final ScanRequest scanRequest, final boolean block, final String name) throws Exception {
// validate the scan bean properly here or you get a nullpointer exception
final ScanBean bean = new ScanBean(scanRequest);
eventService.getEventConnectorService().marshal(bean);
final URI uri = new URI(LocalProperties.getActiveMQBrokerURI());
if (name != null && !name.isBlank()) {
bean.setName(name);
}
try (final ISubmitter<ScanBean> submitter = eventService.createSubmitter(uri, EventConstants.SUBMISSION_QUEUE);
final ISubscriber<IScanListener> subscriber = eventService.createSubscriber(uri, EventConstants.STATUS_TOPIC);
var queue = eventService.createJobQueueProxy(uri, EventConstants.SUBMISSION_QUEUE)) {
subscriber.addListener(new IScanListener() {
@Override
public void scanEventPerformed(ScanEvent evt) {
String message = evt.getBean().getMessage();
if (message != null) {
printToJython(Map.of(EMPTYSTRING, message));
}
}
@Override
public void scanStateChanged(ScanEvent evt) {
ScanBean bean = evt.getBean();
if ((bean.getStatus().equals(Status.PREPARING) || bean.getStatus().equals(Status.COMPLETE)) && bean.getFilePath() != null) {
printToJython(Map.of("Output file: ", bean.getFilePath()));
} else if (bean.getStatus().equals(Status.FAILED)) {
facade.print(bean.getMessage());
}
}
});
if (block) {
try {
submitter.blockingSubmit(bean);
} catch (InterruptedException e) {
queue.terminateJob(bean);
facade.print("Scan terminated");
Thread.currentThread().interrupt();
}
} else {
submitter.submit(bean);
}
}
}
use of org.eclipse.scanning.api.event.scan.ScanBean in project gda-core by openGDA.
the class QueuePreventingScanSubmitterTest method canSubmitImportantScanToEmptyQueue.
@Test
public void canSubmitImportantScanToEmptyQueue() throws Exception {
ScanBean scan = getTestScanBean();
scanSubmitter.submitImportantScan(scan);
verify(submitter).submit(scan);
}
use of org.eclipse.scanning.api.event.scan.ScanBean in project gda-core by openGDA.
the class QueuePreventingScanSubmitterTest method importantSubmissionAbortsRunningScan.
@Test
public void importantSubmissionAbortsRunningScan() throws Exception {
ScanBean runningScan = getTestScanBean();
runningScan.setStatus(Status.RUNNING);
runningAndCompleted.add(runningScan);
scanSubmitter.submitImportantScan(getTestScanBean());
verify(consumer).terminateJob(runningScan);
}
Aggregations