Search in sources :

Example 1 with IChannelConfig

use of org.eclipse.ecf.datashare.IChannelConfig in project ecf by eclipse.

the class DsClient2 method createChannel.

protected IChannel createChannel(IContainer container) throws ECFException {
    // Get IChannelContainerAdapter adapter
    IChannelContainerAdapter channelContainer = (IChannelContainerAdapter) container.getAdapter(IChannelContainerAdapter.class);
    // Check it's valid, throw if not
    if (channelContainer == null)
        throw new NullPointerException("cannot get channel container adapter");
    // Create channel ID with fixed name 'channel2'
    final ID channelID = IDFactory.getDefault().createID(channelContainer.getChannelNamespace(), "channel2");
    // Setup listener so then when channelmessageevents are received that
    // they present in UI
    final IChannelListener channelListener = new IChannelListener() {

        public void handleChannelEvent(final IChannelEvent event) {
            if (event instanceof IChannelMessageEvent) {
                IChannelMessageEvent msg = (IChannelMessageEvent) event;
                showMessageInUI(new String(msg.getData()));
            } else
                System.out.println("got channel event " + event);
        }
    };
    // Create channel config information
    IChannelConfig config = new BaseChannelConfig(channelID, channelListener, new HashMap());
    // Create and return new channel
    return channelContainer.createChannel(config);
}
Also used : IChannelConfig(org.eclipse.ecf.datashare.IChannelConfig) IChannelListener(org.eclipse.ecf.datashare.IChannelListener) IChannelEvent(org.eclipse.ecf.datashare.events.IChannelEvent) BaseChannelConfig(org.eclipse.ecf.datashare.BaseChannelConfig) HashMap(java.util.HashMap) IChannelContainerAdapter(org.eclipse.ecf.datashare.IChannelContainerAdapter) ID(org.eclipse.ecf.core.identity.ID) IChannelMessageEvent(org.eclipse.ecf.datashare.events.IChannelMessageEvent)

Aggregations

HashMap (java.util.HashMap)1 ID (org.eclipse.ecf.core.identity.ID)1 BaseChannelConfig (org.eclipse.ecf.datashare.BaseChannelConfig)1 IChannelConfig (org.eclipse.ecf.datashare.IChannelConfig)1 IChannelContainerAdapter (org.eclipse.ecf.datashare.IChannelContainerAdapter)1 IChannelListener (org.eclipse.ecf.datashare.IChannelListener)1 IChannelEvent (org.eclipse.ecf.datashare.events.IChannelEvent)1 IChannelMessageEvent (org.eclipse.ecf.datashare.events.IChannelMessageEvent)1