IContainer container = null;
IChannel channel = null;
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);
}