Package org.cometd.bayeux

Examples of org.cometd.bayeux.ChannelId


    }

    @Test
    public void testIsParent()
    {
        ChannelId foo = new ChannelId("/foo");
        ChannelId bar = new ChannelId("/bar");
        ChannelId foobar = new ChannelId("/foo/bar");
        ChannelId foobarbaz = new ChannelId("/foo/bar/baz");

        Assert.assertFalse(foo.isParentOf(foo));
        Assert.assertTrue(foo.isParentOf(foobar));
        Assert.assertFalse(foo.isParentOf(foobarbaz));
View Full Code Here


    }

    @Test
    public void testEquals()
    {
        ChannelId foobar0 = new ChannelId("/foo/bar");
        ChannelId foobar1 = new ChannelId("/foo/bar/");
        ChannelId foo = new ChannelId("/foo");
        ChannelId wild = new ChannelId("/foo/*");
        ChannelId deep = new ChannelId("/foo/**");

        Assert.assertTrue(foobar0.equals(foobar0));
        Assert.assertTrue(foobar0.equals(foobar1));

        Assert.assertFalse(foobar0.equals(foo));
View Full Code Here

    }

    @Test
    public void testMatches()
    {
        ChannelId foobar0 = new ChannelId("/foo/bar");
        ChannelId foobar1 = new ChannelId("/foo/bar");
        ChannelId foobarbaz = new ChannelId("/foo/bar/baz");
        ChannelId foo = new ChannelId("/foo");
        ChannelId wild = new ChannelId("/foo/*");
        ChannelId deep = new ChannelId("/foo/**");

        Assert.assertTrue(foobar0.matches(foobar0));
        Assert.assertTrue(foobar0.matches(foobar1));

        Assert.assertFalse(foo.matches(foobar0));
        Assert.assertTrue(wild.matches(foobar0));
        Assert.assertTrue(deep.matches(foobar0));

        Assert.assertFalse(foo.matches(foobarbaz));
        Assert.assertFalse(wild.matches(foobarbaz));
        Assert.assertTrue(deep.matches(foobarbaz));
    }
View Full Code Here

    }

    @Test
    public void testWilds()
    {
        ChannelId id = new ChannelId("/foo/bar/*");
        List<String> wilds = id.getWilds();
        Assert.assertEquals(0, wilds.size());

        id = new ChannelId("/foo");
        wilds = id.getWilds();
        Assert.assertEquals(2, wilds.size());
        Assert.assertEquals("/*", wilds.get(0));
        Assert.assertEquals("/**", wilds.get(1));

        id = new ChannelId("/foo/bar");
        wilds = id.getWilds();
        Assert.assertEquals(3, wilds.size());
        Assert.assertEquals("/foo/*", wilds.get(0));
        Assert.assertEquals("/foo/**", wilds.get(1));
        Assert.assertEquals("/**", wilds.get(2));

        id = new ChannelId("/foo/bar/bob");
        wilds = id.getWilds();
        Assert.assertEquals(4, wilds.size());
        Assert.assertEquals("/foo/bar/*", wilds.get(0));
        Assert.assertEquals("/foo/bar/**", wilds.get(1));
        Assert.assertEquals("/foo/**", wilds.get(2));
        Assert.assertEquals("/**", wilds.get(3));

        id = new ChannelId("/foo/{bar}");
        wilds = id.getWilds();
        Assert.assertEquals(3, wilds.size());
        Assert.assertEquals("/foo/*", wilds.get(0));
        Assert.assertEquals("/foo/**", wilds.get(1));
        Assert.assertEquals("/**", wilds.get(2));

        id = new ChannelId("/foo/{bar}/baz");
        wilds = id.getWilds();
        Assert.assertEquals(2, wilds.size());
        Assert.assertEquals("/foo/**", wilds.get(0));
        Assert.assertEquals("/**", wilds.get(1));
    }
View Full Code Here

    }

    @Test
    public void testRegularPart() throws Exception
    {
        Assert.assertEquals("/foo", new ChannelId("/foo/*").getRegularPart());
        Assert.assertEquals("/foo/bar", new ChannelId("/foo/bar/**").getRegularPart());
        Assert.assertEquals("/foo", new ChannelId("/foo/{p}").getRegularPart());
        Assert.assertEquals("/foo/bar", new ChannelId("/foo/bar/{p}").getRegularPart());
        Assert.assertEquals("/foo", new ChannelId("/foo/{p1}/{p2}").getRegularPart());
        Assert.assertNull(new ChannelId("/*").getRegularPart());
        Assert.assertNull(new ChannelId("/**").getRegularPart());
        Assert.assertNull(new ChannelId("/{p}").getRegularPart());
        Assert.assertNull(new ChannelId("/{p1}/{p2}").getRegularPart());
    }
View Full Code Here

    private void assertInvalid(String channel)
    {
        try
        {
            // Call depth() to ensure the ChannelId is resolved.
            new ChannelId(channel).depth();
            Assert.fail(channel);
        }
        catch (IllegalArgumentException x)
        {
            // Expected
View Full Code Here

        return (String)get(CHANNEL_FIELD);
    }

    public ChannelId getChannelId()
    {
        return new ChannelId(getChannel());
    }
View Full Code Here

                    checkSignaturesMatch(method, ListenerCallback.signature, paramNames);

                    String[] channels = listener.value();
                    for (String channel : channels)
                    {
                        ChannelId channelId = new ChannelId(channel);
                        if (channelId.isTemplate())
                        {
                            List<String> parameters = channelId.getParameters();
                            if (parameters.size() != paramNames.size())
                                throw new IllegalArgumentException("Wrong number of template parameters in annotation @" +
                                        Listener.class.getSimpleName() + " on method: " + method.getName() + "(...).");
                            if (!parameters.equals(paramNames))
                                throw new IllegalArgumentException("Wrong parameter names in annotation @" +
                                        Listener.class.getSimpleName() + " on method: " + method.getName() + "(...).");
                            channel = channelId.getRegularPart() + "/" + (parameters.size() < 2 ? ChannelId.WILD : ChannelId.DEEPWILD);
                        }

                        MarkedReference<ServerChannel> initializedChannel = bayeuxServer.createChannelIfAbsent(channel);
                        ListenerCallback listenerCallback = new ListenerCallback(localSession, bean, method, paramNames, channelId, channel, listener.receiveOwnPublishes());
                        initializedChannel.getReference().addListener(listenerCallback);
View Full Code Here

                        if (ChannelId.isMeta(channel))
                            throw new IllegalArgumentException("Annotation @" + Subscription.class.getSimpleName() +
                                    " on method '" + method.getName() + "' on class '" +
                                    method.getDeclaringClass().getName() + "' must specify a non meta channel");

                        ChannelId channelId = new ChannelId(channel);
                        if (channelId.isTemplate())
                        {
                            List<String> parameters = channelId.getParameters();
                            if (parameters.size() != paramNames.size())
                                throw new IllegalArgumentException("Wrong number of template parameters in annotation @" +
                                        Subscription.class.getSimpleName() + " on method: " + method.getName() + "(...).");
                            if (!parameters.equals(paramNames))
                                throw new IllegalArgumentException("Wrong parameter names in annotation @" +
                                        Subscription.class.getSimpleName() + " on method: " + method.getName() + "(...).");
                            channel = channelId.getRegularPart() + "/" + (parameters.size() < 2 ? ChannelId.WILD : ChannelId.DEEPWILD);
                        }

                        SubscriptionCallback subscriptionCallback = new SubscriptionCallback(localSession, bean, method, paramNames, channelId, channel);
                        localSession.getChannel(channel).subscribe(subscriptionCallback);
View Full Code Here

                    {
                        if (!target.startsWith("/"))
                            target = "/" + target;
                        String channel = Channel.SERVICE + target;

                        ChannelId channelId = new ChannelId(channel);
                        if (channelId.isWild())
                            throw new IllegalArgumentException("Annotation @" + RemoteCall.class.getSimpleName() +
                                    " on method: " + method.getName() + "(...) cannot specify wild channels.");

                        if (channelId.isTemplate())
                        {
                            List<String> parameters = channelId.getParameters();
                            if (parameters.size() != paramNames.size())
                                throw new IllegalArgumentException("Wrong number of template parameters in annotation @" +
                                        RemoteCall.class.getSimpleName() + " on method: " + method.getName() + "(...).");
                            if (!parameters.equals(paramNames))
                                throw new IllegalArgumentException("Wrong parameter names in annotation @" +
                                        RemoteCall.class.getSimpleName() + " on method: " + method.getName() + "(...).");
                            channel = channelId.getRegularPart() + "/" + (parameters.size() < 2 ? ChannelId.WILD : ChannelId.DEEPWILD);
                        }

                        MarkedReference<ServerChannel> initializedChannel = bayeuxServer.createChannelIfAbsent(channel);
                        RemoteCallCallback remoteCallCallback = new RemoteCallCallback(bayeuxServer, localSession, bean, method, paramNames, channelId, channel);
                        initializedChannel.getReference().addListener(remoteCallCallback);
View Full Code Here

TOP

Related Classes of org.cometd.bayeux.ChannelId

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.