/* (non-Javadoc) * @see org.eclipse.tm.tcf.protocol.Protocol.ChannelOpenListener#onChannelOpen(org.eclipse.tm.tcf.protocol.IChannel) */ @Override public void onChannelOpen(IChannel channel) { Assert.isNotNull(channel); Assert.isTrue(Protocol.isDispatchThread()); // Trace the channel opening LogUtils.logMessageForChannel( channel, Messages.InternalChannelOpenListener_onChannelOpen_message, "debug/channels", this); //$NON-NLS-1$ // As the channel has just opened, there should be no channel listener, but better be safe and // check. IChannel.IChannelListener channelListener = channelListeners.remove(channel); if (channelListener != null) channel.removeChannelListener(channelListener); // Create a new channel listener instance channelListener = new InternalChannelListener(channel); // Add the channel listener to the global map setChannelListener(channel, channelListener); // Attach channel listener to the channel channel.addChannelListener(channelListener); // Fire the property change event for the channel Tcf.fireChannelStateChangeListeners(channel, IChannel.STATE_OPEN); }
protected void connectPeer() { final IChannel channel = fPeer.openChannel(); fChannel = channel; fFileSystem = null; channel.addChannelListener( new IChannelListener() { public void congestionLevel(int level) {} public void onChannelClosed(final Throwable error) { if (fChannel != channel) return; fChannel = null; if (fDisplay != null) { fDisplay.asyncExec( new Runnable() { public void run() { if (fRootInfo.children_pending) return; fRootInfo.children = null; fRootInfo.children_error = error; updateItems(fRootInfo); } }); } } public void onChannelOpened() { if (fChannel != channel) return; fFileSystem = fChannel.getRemoteService(IFileSystem.class); if (fFileSystem != null) { if (fFileToSelect != null && fFileToSelect.length() > 0) { final LinkedList<String> filePath = new LinkedList<String>(); filePath.addAll(Arrays.asList(fFileToSelect.split("[/\\\\]", -1))); if (fFileToSelect.charAt(0) == '/') { filePath.set(0, "/"); } fPathToSelect = filePath; fLastSelectedFileInfo = fRootInfo; } } if (fDisplay != null) { fDisplay.asyncExec( new Runnable() { public void run() { if (fRootInfo.children_pending) return; fRootInfo.children = null; fRootInfo.children_error = null; updateItems(fRootInfo); } }); } } }); }
/** * Closes the given channel and handle the given exception. * * @param channel The channel instance or <code>null</code>. * @param exception The exception to handle. Must be not <code>null</code>. */ protected void handleException(IChannel channel, Throwable exception) { Assert.isNotNull(exception); // Close the backend channel if (channel != null) { final IChannel finChannel = channel; if (Protocol.isDispatchThread()) { finChannel.close(); } else { Protocol.invokeAndWait( new Runnable() { @Override public void run() { finChannel.close(); } }); } } // Get the status handler IStatusHandler[] handler = StatusHandlerManager.getInstance().getHandler(getClass()); if (handler != null && handler.length > 0) { // If the exception is a core exception, we can pass on the status object to the handler IStatus status = null; if (exception instanceof CoreException) ((CoreException) exception).getStatus(); else { // Construct the status from the exception status = new Status( IStatus.ERROR, UIPlugin.getUniqueIdentifier(), 0, exception.getLocalizedMessage(), exception); } // Handle the status (Take the first status handler in the list) if (status != null) { IPropertiesContainer data = new PropertiesContainer(); data.setProperty(IStatusHandlerConstants.PROPERTY_TITLE, getStatusDialogTitle()); data.setProperty( IStatusHandlerConstants.PROPERTY_CONTEXT_HELP_ID, getStatusDialogContextHelpId()); data.setProperty( IStatusHandlerConstants.PROPERTY_DONT_ASK_AGAIN_ID, getStatusDialogDontAskAgainKey()); data.setProperty(IStatusHandlerConstants.PROPERTY_CALLER, this); handler[0].handleStatus(status, data, null); } } }
protected void disconnectPeer() { if (fChannel != null && fChannel.getState() != IChannel.STATE_CLOSED) { fChannel.close(); } }