use of org.eclipse.ecf.datashare.IChannelListener in project ecf by eclipse.
the class ChannelTest method getIChannelListener.
protected IChannelListener getIChannelListener(final ID containerid) throws Exception {
return new IChannelListener() {
public void handleChannelEvent(IChannelEvent event) {
if (event instanceof IChannelMessageEvent) {
IChannelMessageEvent cme = (IChannelMessageEvent) event;
System.out.println("receivercontainerid=" + containerid + "; fromcontainerid=" + cme.getFromContainerID() + "; channelid=" + cme.getChannelID());
System.out.println(" event=" + event);
System.out.println(" message=" + new String(cme.getData()));
}
}
};
}
use of org.eclipse.ecf.datashare.IChannelListener in project ecf by eclipse.
the class NIODatashareTest method testOneWaySend.
public void testOneWaySend() throws Exception {
final byte[][] actual = new byte[1][];
channelA = createChannel(channelContainerA);
int targetPort = channelA.getPort();
channelB = createChannel(channelContainerB, new IChannelListener() {
public void handleChannelEvent(IChannelEvent event) {
if (event instanceof IChannelMessageEvent) {
actual[0] = ((IChannelMessageEvent) event).getData();
synchronized (waitObject) {
waitObject.notify();
}
}
}
});
byte[] expected = { 1, 2, 3 };
channelA.sendMessage(containerB.getConnectedID(), expected);
channelContainerB.enqueue(new InetSocketAddress(LOCALHOST, targetPort));
waitForCompletion(5000);
assertEquals(expected, actual[0]);
}
use of org.eclipse.ecf.datashare.IChannelListener in project ecf by eclipse.
the class NIODatashareTest method testChannelDisconnectEvent.
public void testChannelDisconnectEvent() throws Exception {
final ID[] eventIds = new ID[2];
channelA = createChannel(channelContainerA, new IChannelListener() {
public void handleChannelEvent(IChannelEvent e) {
if (e instanceof IChannelDisconnectEvent) {
IChannelDisconnectEvent event = (IChannelDisconnectEvent) e;
eventIds[0] = event.getChannelID();
eventIds[1] = event.getTargetID();
}
}
});
containerA.disconnect();
assertEquals(channelA.getID(), eventIds[0]);
// technically, getConnectedID() should return null when a container has
// disconnected, but anyway...
assertEquals(containerA.getConnectedID(), eventIds[1]);
}
use of org.eclipse.ecf.datashare.IChannelListener 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);
}
use of org.eclipse.ecf.datashare.IChannelListener in project ecf by eclipse.
the class ScribbleClient method createChannel.
protected void createChannel() throws ECFException {
// Get IChannelContainerAdapter adapter
IChannelContainerAdapter channelContainer = (IChannelContainerAdapter) container.getAdapter(IChannelContainerAdapter.class);
// Create channel ID with fixed name 'channel2'
final ID channelID = IDFactory.getDefault().createID(channelContainer.getChannelNamespace(), CHANNEL_ID);
// 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;
scribbleView.handleDrawLine(msg.getData());
}
}
};
// Create new channel
IChannel channel = channelContainer.createChannel(channelID, channelListener, new HashMap());
// Set the view to use the given channel (for sending)
scribbleView.setChannel(channel);
}
Aggregations