use of org.eclipse.winery.repository.rest.resources.apiData.RefinementElementApiData in project winery by eclipse.
the class RefinementWebSocket method onMessage.
@Override
@OnMessage
public void onMessage(String message, Session session) throws IOException {
RefinementWebSocketApiData data = JacksonProvider.mapper.readValue(message, RefinementWebSocketApiData.class);
switch(data.task) {
case START:
if (!running) {
Thread thread = new Thread(() -> {
RefinementElementApiData element = new RefinementElementApiData();
element.serviceTemplateContainingRefinements = refinement.refineServiceTemplate(new ServiceTemplateId(data.serviceTemplate));
try {
this.sendAsync(element);
this.session.close();
this.session = null;
} catch (JsonProcessingException e) {
LOGGER.error("Error while sending refinement result", e);
} catch (IOException e) {
LOGGER.error("Error while closing the session", e);
}
running = false;
});
this.running = true;
thread.start();
}
break;
case REFINE_WITH:
this.future.complete(data.refineWith);
break;
case STOP:
this.future.complete(-1);
this.sendAsync(new RefinementElementApiData(null, this.refinementServiceTemplate, null));
this.onClose(this.session);
break;
}
}
use of org.eclipse.winery.repository.rest.resources.apiData.RefinementElementApiData in project winery by eclipse.
the class RefinementWebSocket method chooseRefinement.
@Override
public RefinementCandidate chooseRefinement(List<RefinementCandidate> candidates, ServiceTemplateId refinementServiceTemplate, TTopologyTemplate topology) {
this.refinementServiceTemplate = refinementServiceTemplate;
try {
this.future = new CompletableFuture<>();
RefinementElementApiData element = new RefinementElementApiData(candidates, refinementServiceTemplate, topology);
this.sendAsync(element);
int id = future.get();
if (id >= 0) {
return candidates.stream().filter(candidate -> candidate.getId() == id).findFirst().orElseThrow(NotFoundException::new);
}
} catch (InterruptedException | ExecutionException e) {
LOGGER.error("Error while retrieving ");
} catch (JsonProcessingException e) {
LOGGER.error("Error while creating JSON request", e);
}
return null;
}
Aggregations