Search in sources :

Example 11 with IChannelListener

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

the class NIODatashareTest method testChannelConnectEvent.

public void testChannelConnectEvent() throws Exception {
    final ID[] eventIds = new ID[2];
    channelA = createChannel(channelContainerA, new IChannelListener() {

        public void handleChannelEvent(IChannelEvent e) {
            if (e instanceof IChannelConnectEvent) {
                IChannelConnectEvent event = (IChannelConnectEvent) e;
                eventIds[0] = event.getChannelID();
                eventIds[1] = event.getTargetID();
            }
        }
    });
    containerA.connect(null, null);
    assertEquals(channelA.getID(), eventIds[0]);
    assertEquals(containerA.getConnectedID(), eventIds[1]);
}
Also used : IChannelListener(org.eclipse.ecf.datashare.IChannelListener) IChannelEvent(org.eclipse.ecf.datashare.events.IChannelEvent) IChannelConnectEvent(org.eclipse.ecf.datashare.events.IChannelConnectEvent) ID(org.eclipse.ecf.core.identity.ID)

Example 12 with IChannelListener

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

the class NIODatashareTest method testOneWaySend16k.

public void testOneWaySend16k() 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 = new byte[16384];
    for (int i = 0; i < expected.length; i++) {
        expected[i] = (byte) (i % 128);
    }
    channelA.sendMessage(containerB.getConnectedID(), expected);
    channelContainerB.enqueue(new InetSocketAddress(LOCALHOST, targetPort));
    waitForCompletion(10000);
    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 13 with IChannelListener

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

the class DsClient1 method createChannel.

protected IChannel createChannel(IContainer container) throws ECFException {
    IChannelContainerAdapter channelContainer = (IChannelContainerAdapter) container.getAdapter(IChannelContainerAdapter.class);
    if (channelContainer == null)
        throw new NullPointerException("cannot get channel container adapter");
    ID channelID = IDFactory.getDefault().createID(channelContainer.getChannelNamespace(), "channel1");
    IChannelListener channelListener = new IChannelListener() {

        public void handleChannelEvent(IChannelEvent event) {
            System.out.println("handleChannelEvent(" + event + ")");
        }
    };
    return channelContainer.createChannel(channelID, channelListener, new HashMap());
}
Also used : IChannelListener(org.eclipse.ecf.datashare.IChannelListener) IChannelEvent(org.eclipse.ecf.datashare.events.IChannelEvent) HashMap(java.util.HashMap) IChannelContainerAdapter(org.eclipse.ecf.datashare.IChannelContainerAdapter) ID(org.eclipse.ecf.core.identity.ID)

Example 14 with IChannelListener

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

the class NIOChannel method setListener.

public IChannelListener setListener(IChannelListener listener) {
    IChannelListener previous = this.listener;
    this.listener = listener;
    return previous;
}
Also used : IChannelListener(org.eclipse.ecf.datashare.IChannelListener)

Example 15 with IChannelListener

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

the class AbstractDatashareApplication method createChannel.

protected void createChannel() throws ECFException {
    // Get datashare adapter from new container
    datashareAdapter = (IChannelContainerAdapter) container.getAdapter(IChannelContainerAdapter.class);
    // Create channel listener for channel to be created
    IChannelListener channelListener = createChannelListener();
    // Create a channel with given channel listener
    testChannel = datashareAdapter.createChannel(IDFactory.getDefault().createStringID(Activator.class.getName()), channelListener, null);
}
Also used : IChannelListener(org.eclipse.ecf.datashare.IChannelListener)

Aggregations

IChannelListener (org.eclipse.ecf.datashare.IChannelListener)16 IChannelEvent (org.eclipse.ecf.datashare.events.IChannelEvent)12 IChannelMessageEvent (org.eclipse.ecf.datashare.events.IChannelMessageEvent)8 ID (org.eclipse.ecf.core.identity.ID)7 HashMap (java.util.HashMap)5 InetSocketAddress (java.net.InetSocketAddress)3 IChannelContainerAdapter (org.eclipse.ecf.datashare.IChannelContainerAdapter)3 StringID (org.eclipse.ecf.core.identity.StringID)2 ISharedObject (org.eclipse.ecf.core.sharedobject.ISharedObject)2 SharedObjectCreateException (org.eclipse.ecf.core.sharedobject.SharedObjectCreateException)2 IMergeableChannel (org.eclipse.ecf.datashare.mergeable.IMergeableChannel)2 File (java.io.File)1 IOException (java.io.IOException)1 Constructor (java.lang.reflect.Constructor)1 List (java.util.List)1 Map (java.util.Map)1 ContainerTypeDescription (org.eclipse.ecf.core.ContainerTypeDescription)1 IDCreateException (org.eclipse.ecf.core.identity.IDCreateException)1 SharedObjectDescription (org.eclipse.ecf.core.sharedobject.SharedObjectDescription)1 SharedObjectTypeDescription (org.eclipse.ecf.core.sharedobject.SharedObjectTypeDescription)1