use of org.eclipse.che.ide.debug.DebuggerDescriptor in project che by eclipse.
the class AbstractDebugger method addHandlers.
private void addHandlers(final MessageBusProvider messageBusProvider) {
eventBus.addHandler(WsAgentStateEvent.TYPE, new WsAgentStateHandler() {
@Override
public void onWsAgentStarted(WsAgentStateEvent event) {
messageBus = messageBusProvider.getMachineMessageBus();
if (!isConnected()) {
return;
}
Promise<DebugSessionDto> promise = service.getSessionInfo(debugSessionDto.getId());
promise.then(new Operation<DebugSessionDto>() {
@Override
public void apply(DebugSessionDto arg) throws OperationException {
debuggerManager.setActiveDebugger(AbstractDebugger.this);
setDebugSession(arg);
DebuggerInfo debuggerInfo = arg.getDebuggerInfo();
String info = debuggerInfo.getName() + " " + debuggerInfo.getVersion();
String address = debuggerInfo.getHost() + ":" + debuggerInfo.getPort();
DebuggerDescriptor debuggerDescriptor = new DebuggerDescriptor(info, address);
JsPromise<Void> promise = Promises.resolve(null);
for (DebuggerObserver observer : observers) {
observer.onDebuggerAttached(debuggerDescriptor, promise);
}
startCheckingEvents();
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
if (!isConnected()) {
invalidateDebugSession();
}
}
});
}
@Override
public void onWsAgentStopped(WsAgentStateEvent event) {
}
});
this.debuggerEventsHandler = new SubscriptionHandler<DebuggerEventDto>(new DebuggerEventUnmarshaller(dtoFactory)) {
@Override
public void onMessageReceived(DebuggerEventDto result) {
if (!isConnected()) {
return;
}
onEventListReceived(result);
}
@Override
public void onErrorReceived(Throwable exception) {
if (!isConnected()) {
return;
}
try {
messageBus.unsubscribe(eventChannel, this);
} catch (WebSocketException e) {
Log.error(AbstractDebugger.class, e);
}
if (exception instanceof ServerException) {
ServerException serverException = (ServerException) exception;
if (HTTPStatus.INTERNAL_ERROR == serverException.getHTTPStatus() && serverException.getMessage() != null && serverException.getMessage().contains("not found")) {
disconnect();
}
}
}
};
}
use of org.eclipse.che.ide.debug.DebuggerDescriptor in project che by eclipse.
the class AbstractDebugger method connect.
@Override
public Promise<Void> connect(Map<String, String> connectionProperties) {
if (isConnected()) {
return Promises.reject(JsPromiseError.create("Debugger already connected"));
}
Promise<DebugSessionDto> connect = service.connect(debuggerType, connectionProperties);
final DebuggerDescriptor debuggerDescriptor = toDescriptor(connectionProperties);
Promise<Void> promise = connect.then(new Function<DebugSessionDto, Void>() {
@Override
public Void apply(final DebugSessionDto arg) throws FunctionException {
DebuggerInfo debuggerInfo = arg.getDebuggerInfo();
debuggerDescriptor.setInfo(debuggerInfo.getName() + " " + debuggerInfo.getVersion());
setDebugSession(arg);
preserveDebuggerState();
startCheckingEvents();
startDebugger(arg);
return null;
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
Log.error(AbstractDebugger.class, arg.getMessage());
throw new OperationException(arg.getCause());
}
});
for (DebuggerObserver observer : observers) {
observer.onDebuggerAttached(debuggerDescriptor, promise);
}
return promise;
}
use of org.eclipse.che.ide.debug.DebuggerDescriptor in project che by eclipse.
the class DebuggerPresenterTest method testOnDebuggerAttached.
@Test
public void testOnDebuggerAttached() {
DebuggerDescriptor debuggerDescriptor = mock(DebuggerDescriptor.class);
final String address = "address";
doReturn(address).when(debuggerDescriptor).getAddress();
doReturn(promiseVoid).when(promiseVoid).then((Operation<Void>) any());
String title = "title";
doReturn(title).when(this.constant).debuggerConnectingTitle(address);
presenter.onDebuggerAttached(debuggerDescriptor, promiseVoid);
notificationManager.notify(eq(address), eq(PROGRESS), eq(FLOAT_MODE));
}
use of org.eclipse.che.ide.debug.DebuggerDescriptor in project che by eclipse.
the class DebuggerTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
super.setUp();
debuggerDescriptor = new DebuggerDescriptor(NAME + " " + VERSION, HOST + ":" + PORT);
doReturn(locationDto).when(dtoFactory).createDto(LocationDto.class);
doReturn(breakpointDto).when(dtoFactory).createDto(BreakpointDto.class);
doReturn(locationDto).when(breakpointDto).getLocation();
doReturn(messageBus).when(messageBusProvider).getMachineMessageBus();
doReturn(localStorage).when(localStorageProvider).get();
doReturn(DEBUG_INFO).when(localStorage).getItem(AbstractDebugger.LOCAL_STORAGE_DEBUGGER_SESSION_KEY);
doReturn(debugSessionDto).when(dtoFactory).createDtoFromJson(anyString(), eq(DebugSessionDto.class));
doReturn(Path.valueOf(PATH)).when(file).getLocation();
debugger = new TestDebugger(service, dtoFactory, localStorageProvider, messageBusProvider, eventBus, activeFileHandler, debuggerManager, notificationManager, "id");
doReturn(promiseInfo).when(service).getSessionInfo(SESSION_ID);
doReturn(promiseInfo).when(promiseInfo).then(any(Operation.class));
// setup messageBus
verify(eventBus).addHandler(eq(WsAgentStateEvent.TYPE), extServerStateHandlerCaptor.capture());
extServerStateHandlerCaptor.getValue().onWsAgentStarted(WsAgentStateEvent.createWsAgentStartedEvent());
debugger.addObserver(observer);
FileType fileType = mock(FileType.class);
doReturn("java").when(fileType).getExtension();
}
Aggregations