Package org.apache.cometd.bayeux

Examples of org.apache.cometd.bayeux.Channel


                Stock[] stocks = new Stock[] {
                        new Stock("GOOG", 435.43),
                        new Stock("YHOO", 27.88),
                        new Stock("SPRG", 1015.55), };
                for (Stock s : stocks) {
                    Channel ch = b.getChannel("/stock/"+s.getSymbol(), true);
                    ch.subscribe(c);
                   
                }
                Random r = new Random(System.currentTimeMillis());
                while (run) {
                    for (int j = 0; j < 1; j++) {
                        int i = r.nextInt() % 3;
                        if (i < 0)
                            i = i * (-1);
                        Stock stock = stocks[i];
                        double change = r.nextDouble();
                        boolean plus = r.nextBoolean();
                        if (plus) {
                            stock.setValue(stock.getValue() + change);
                        } else {
                            stock.setValue(stock.getValue() - change);
                        }
                        Channel ch = b.getChannel("/stock/"+stock.getSymbol(), true);
                        Message m = b.newMessage(c);
                        m.put("stock", stock.toString());
                        m.put("symbol", stock.getSymbol());
                        m.put("price", stock.getValueAsString());
                        m.put("change", stock.getLastChangeAsString());
                        ch.publish(m);
                        System.out.println("Stock: "+stock.getSymbol()+" Price: "+stock.getValueAsString()+" Change: "+stock.getLastChangeAsString());
                    }
                    Thread.sleep(850);
                }
            } catch (InterruptedException ix) {
View Full Code Here


    public void attributeAdded(ServletContextAttributeEvent scae) {
        if (scae.getName().equals(Bayeux.DOJOX_COMETD_BAYEUX)) {
            System.out.println("Starting echo chat client!");
            b = (Bayeux)scae.getValue();
            c = b.newClient("echochat-",this);
            Channel ch = b.getChannel("/chat/demo",true);
            ch.subscribe(c);
            tt.start();
        }
    }
View Full Code Here

       
        public void run() {
            while (alive) {
                try {
                    sleep(5000);
                    Channel ch = b.getChannel("/chat/demo",false);
                    if (ch.getSubscribers().size()<=1) {
                        continue;
                    }
                    Message m = b.newMessage(c);
                    m.put("user","echochatserver");
                    m.put("chat","Time is:"+new java.sql.Date(System.currentTimeMillis()).toLocaleString());
                    m.put("join",false);
                    ch.publish(m);
                }catch (InterruptedException ignore) {
                    Thread.currentThread().interrupted();
                }catch (Exception x) {
                    x.printStackTrace();
                }
View Full Code Here

    public void destroy() {
        throw new UnsupportedOperationException("TomcatBayeux.destroy() not yet implemented");
    }

    public Channel getChannel(String channelId, boolean create) {
        Channel result = channels.get(channelId);
        if (result==null && create) {
            result = new ChannelImpl(channelId);
            channels.put(channelId,result);
        }
        return result;
View Full Code Here

    public void destroy() {
        throw new UnsupportedOperationException("TomcatBayeux.destroy() not yet implemented");
    }

    public Channel getChannel(String channelId, boolean create) {
        Channel result = channels.get(channelId);
        if (result==null && create) {
            result = new ChannelImpl(channelId);
            channels.put(channelId,result);
        }
        return result;
View Full Code Here

    public void attributeAdded(ServletContextAttributeEvent scae) {
        if (scae.getName().equals(Bayeux.DOJOX_COMETD_BAYEUX)) {
            System.out.println("Starting echo chat client!");
            b = (Bayeux)scae.getValue();
            c = b.newClient("echochat-",this);
            Channel ch = b.getChannel("/chat/demo",true);
            ch.subscribe(c);
            tt.start();
        }
    }
View Full Code Here

        public void run() {
            while (alive) {
                try {
                    sleep(5000);
                    Channel ch = b.getChannel("/chat/demo",false);
                    if (ch.getSubscribers().size()<=1) {
                        continue;
                    }
                    Message m = b.newMessage(c);
                    m.put("user","echochatserver");
                    m.put("chat","Time is:"+new java.sql.Date(System.currentTimeMillis()).toLocaleString());
                    m.put("join",false);
                    ch.publish(m);
                }catch (InterruptedException ignore) {
                    Thread.currentThread().interrupted();
                }catch (Exception x) {
                    x.printStackTrace();
                }
View Full Code Here

                Stock[] stocks = new Stock[] {
                        new Stock("GOOG", 435.43),
                        new Stock("YHOO", 27.88),
                        new Stock("ASF", 1015.55), };
                for (Stock s : stocks) {
                    Channel ch = b.getChannel("/stock/"+s.getSymbol(), true);
                    ch.subscribe(c);

                }
                Random r = new Random(System.currentTimeMillis());
                while (run) {
                    for (int j = 0; j < 1; j++) {
                        int i = r.nextInt() % 3;
                        if (i < 0)
                            i = i * (-1);
                        Stock stock = stocks[i];
                        double change = r.nextDouble();
                        boolean plus = r.nextBoolean();
                        if (plus) {
                            stock.setValue(stock.getValue() + change);
                        } else {
                            stock.setValue(stock.getValue() - change);
                        }
                        Channel ch = b.getChannel("/stock/"+stock.getSymbol(), true);
                        Message m = b.newMessage(c);
                        m.put("stock", stock.toString());
                        m.put("symbol", stock.getSymbol());
                        m.put("price", stock.getValueAsString());
                        m.put("change", stock.getLastChangeAsString());
                        ch.publish(m);
                        System.out.println("Bayeux Stock: "+stock.getSymbol()+" Price: "+stock.getValueAsString()+" Change: "+stock.getLastChangeAsString());
                    }
                    Thread.sleep(850);
                }
            } catch (InterruptedException ix) {
View Full Code Here

TOP

Related Classes of org.apache.cometd.bayeux.Channel

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.