Package org.itsnat.core

Examples of org.itsnat.core.CometNotifier


                    {
                        Thread.sleep(2000);
                    }
                    catch(InterruptedException ex) { }

                    CometNotifier notifier = CometNotifierTreeNode.this.notifier;
                    if ((notifier != null) && !notifier.isStopped())
                    {
                        synchronized(itsNatDoc)
                        {
                            log("Tick"); // Access/modifies the document
                        }
                        notifier.notifyClient();
                    }
                    t2 = System.currentTimeMillis();
                }
                while( !endBgTask && ((t2 - t1) < 1*60*1000) ); // Max 1 minute

                if (notifier != null) notifier.stop();

                synchronized(itsNatDoc)
                {
                    log("Background server task finished");
                }
View Full Code Here


                    outText("OK Comet Event " + evt.getType() + " ");
                }
            };
            comet.addEventListener(listener);

            final CometNotifier comet = this.comet;
            Thread task = new Thread()
            {
                public void run()
                {
                    long t1 = System.currentTimeMillis();
                    long t2 = t1;
                    long timeout = 10*1000;
                    while((t2 - t1) < timeout)
                    {
                        try
                        {
                            Thread.sleep(2000);
                        }
                        catch(InterruptedException ex) { }

                        synchronized(itsNatDoc)
                        {
                            outText("OK End Comet Task ");
                        }

                        if (comet.isStopped()) // por ejemplo cuando salgamos de la p�gina
                            break;                       

                        comet.notifyClient(); // No es necesario sincronizar con el documento pero no pasar�a nada
                       
                        t2 = System.currentTimeMillis();
                    }

                    comet.stop(); // Si ya est� parado no hace nada
                    outText("Stop Notifier (thread) ");

                    synchronized(itsNatDoc)
                    {
                        if ((t2 - t1) >= timeout)
                            outText("End Thread (timeout) ");
                        else
                            outText("End Thread (notifier stopped) ");
                    }
                }
            };

            task.start();

            outText("Created Notifier ");
        }
        else
        {
            comet.stop();
            outText("Stop Notifier (manual) ");
        }
    }
View Full Code Here

    public void COMET_NOTIFIER()
    {
    final ItsNatDocument itsNatDoc = null;

    final CometNotifier notifier = itsNatDoc.getClientDocumentOwner().createCometNotifier();
    EventListener listener = new EventListener()
    {
        public void handleEvent(Event evt)
        {
            itsNatDoc.addCodeToSend("alert('Tick From Event');");
        }
    };
    notifier.addEventListener(listener);

    Thread backgroundThr = new Thread()
    {
        public void run()
        {
            System.out.println("Background server task started");
            long t1 = System.currentTimeMillis();
            long t2 = t1;
            do
            {
                try
                {
                    Thread.sleep(2000);
                }
                catch(InterruptedException ex) { }

                if (!notifier.isStopped())
                {
                    synchronized(itsNatDoc)
                    {
                        itsNatDoc.addCodeToSend("alert('Tick From Thread');");
                    }
                    notifier.notifyClient();
                }
                t2 = System.currentTimeMillis();
            }
            while( (t2 - t1) < 10*60*1000 ); // Max 10 minutes

            notifier.stop();

            System.out.println("Background server task finished");
        }
    };

View Full Code Here

TOP

Related Classes of org.itsnat.core.CometNotifier

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.