Search in sources :

Example 1 with IChannelMessageEvent

use of org.eclipse.ecf.datashare.events.IChannelMessageEvent 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()));
            }
        }
    };
}
Also used : IChannelListener(org.eclipse.ecf.datashare.IChannelListener) IChannelEvent(org.eclipse.ecf.datashare.events.IChannelEvent) IChannelMessageEvent(org.eclipse.ecf.datashare.events.IChannelMessageEvent)

Example 2 with IChannelMessageEvent

use of org.eclipse.ecf.datashare.events.IChannelMessageEvent 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]);
}
Also used : IChannelListener(org.eclipse.ecf.datashare.IChannelListener) IChannelEvent(org.eclipse.ecf.datashare.events.IChannelEvent) InetSocketAddress(java.net.InetSocketAddress) IChannelMessageEvent(org.eclipse.ecf.datashare.events.IChannelMessageEvent)

Example 3 with IChannelMessageEvent

use of org.eclipse.ecf.datashare.events.IChannelMessageEvent 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)

Example 4 with IChannelMessageEvent

use of org.eclipse.ecf.datashare.events.IChannelMessageEvent 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);
}
Also used : IChannelListener(org.eclipse.ecf.datashare.IChannelListener) IChannel(org.eclipse.ecf.datashare.IChannel) IChannelEvent(org.eclipse.ecf.datashare.events.IChannelEvent) HashMap(java.util.HashMap) IChannelContainerAdapter(org.eclipse.ecf.datashare.IChannelContainerAdapter) ID(org.eclipse.ecf.core.identity.ID) IChannelMessageEvent(org.eclipse.ecf.datashare.events.IChannelMessageEvent)

Example 5 with IChannelMessageEvent

use of org.eclipse.ecf.datashare.events.IChannelMessageEvent in project ecf by eclipse.

the class DatashareClientApplication method createChannelListener.

protected IChannelListener createChannelListener() {
    return new IChannelListener() {

        public void handleChannelEvent(IChannelEvent event) {
            if (event instanceof IChannelMessageEvent) {
                IChannelMessageEvent messageEvent = (IChannelMessageEvent) event;
                // print to system out
                System.out.println("Client received message from " + messageEvent.getFromContainerID().getName() + ": " + new String(messageEvent.getData()));
            }
        }
    };
}
Also used : IChannelListener(org.eclipse.ecf.datashare.IChannelListener) IChannelEvent(org.eclipse.ecf.datashare.events.IChannelEvent) IChannelMessageEvent(org.eclipse.ecf.datashare.events.IChannelMessageEvent)

Aggregations

IChannelMessageEvent (org.eclipse.ecf.datashare.events.IChannelMessageEvent)10 IChannelListener (org.eclipse.ecf.datashare.IChannelListener)8 IChannelEvent (org.eclipse.ecf.datashare.events.IChannelEvent)8 InetSocketAddress (java.net.InetSocketAddress)3 HashMap (java.util.HashMap)3 ID (org.eclipse.ecf.core.identity.ID)3 IChannelContainerAdapter (org.eclipse.ecf.datashare.IChannelContainerAdapter)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 BaseChannelConfig (org.eclipse.ecf.datashare.BaseChannelConfig)1 IChannel (org.eclipse.ecf.datashare.IChannel)1 IChannelConfig (org.eclipse.ecf.datashare.IChannelConfig)1 IInteractionContext (org.eclipse.mylyn.context.core.IInteractionContext)1 ITask (org.eclipse.mylyn.tasks.core.ITask)1 Shell (org.eclipse.swt.widgets.Shell)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1