Examples of ItsNatTimerHandle


Examples of org.itsnat.core.event.ItsNatTimerHandle

                        EventListener listener = new EventListener()
                        {
                            public void handleEvent(Event evt)
                            {
                                ItsNatTimerEvent timerEvt = (ItsNatTimerEvent)evt;
                                ItsNatTimerHandle handle = timerEvt.getItsNatTimerHandle();
                                long firstTime = handle.getFirstTime();
                                if ((new Date().getTime() - firstTime) > 30*60*1000) // 30 minutes
                                {
                                    handle.cancel();
                                    clientOwner.addCodeToSend("The timer for updating the client has finished");
                                }
                            }
                        };
                        ItsNatTimer timer = clientOwner.createItsNatTimer();
View Full Code Here

Examples of org.itsnat.core.event.ItsNatTimerHandle

    }

    public void handleEvent(Event evt)
    {
         ItsNatTimerEvent timerEvt = (ItsNatTimerEvent)evt;
         ItsNatTimerHandle handle = timerEvt.getItsNatTimerHandle();
         long lastNonTimerEvent = parent.getLastNonTimerEvent();
         if ((new Date().getTime() - lastNonTimerEvent) > 2*60*1000) // to avoid never ending pages
             handle.cancel();
    }
View Full Code Here

Examples of org.itsnat.core.event.ItsNatTimerHandle

        EventListener listener = new EventListener()
        {
            public void handleEvent(Event evt)
            {
                ItsNatTimerEvent timerEvt = (ItsNatTimerEvent)evt;
                ItsNatTimerHandle handle = timerEvt.getItsNatTimerHandle();
                long firstTime = handle.getFirstTime();
                if ((new Date().getTime() - firstTime) > 10000) // to avoid never ending ticks
                {
                    handle.cancel();
                    log("Scheduled task canceled, id: " + handle.hashCode());
                }
                else log("Tick, id: " + handle.hashCode() + " next execution: " + new Date(handle.scheduledExecutionTime()));
            }
        };
        ItsNatTimerHandle handle = timer.schedule(null,listener,1000,2000);

        log("Scheduled task started, id: " + handle.hashCode() + " first time: " + new Date(handle.getFirstTime()) + " period: " + handle.getPeriod());
    }
View Full Code Here

Examples of org.itsnat.core.event.ItsNatTimerHandle

        EventListener listener = new EventListener()
        {
            public void handleEvent(Event evt)
            {
                ItsNatTimerEvent timerEvt = (ItsNatTimerEvent)evt;
                ItsNatTimerHandle handle = timerEvt.getItsNatTimerHandle();
                long firstTime = handle.getFirstTime();
                if ((new Date().getTime() - firstTime) > 10000) // to avoid never ending ticks
                {
                    handle.cancel();
                    System.out.println("Timer canceled");
                }
                else System.out.println("Tick, next execution: " + new Date(handle.scheduledExecutionTime()));
            }
        };

        ItsNatTimer timer = clientDoc.createItsNatTimer();
        ItsNatTimerHandle handle = timer.schedule(null,listener,1000,2000);

        System.out.println("Scheduled task started, first time: " + new Date(handle.getFirstTime()) + " period: " + handle.getPeriod());
    }
View Full Code Here

Examples of org.itsnat.core.event.ItsNatTimerHandle

        ItsNatTimer timer = clientDoc.createItsNatTimer();
        EventListener timerListener = new EventListener() {
            public void handleEvent(Event evt) { }   // Nothing to do, this timer just update the client with the current state of progressElem
        };
        this.currentTimerHnd = timer.schedule(null,timerListener,0,1000);
        final ItsNatTimerHandle timerHnd = currentTimerHnd;

        if (currentIframeUpload != null) currentIframeUpload.dispose();
        this.currentIframeUpload = iframe.getHTMLIFrameFileUpload(clientDoc,input.getHTMLInputElement());

        final HTMLIFrameFileUpload iframeUpload = currentIframeUpload;
        ItsNatServletRequestListener listener = new ItsNatServletRequestListener()
        {
            public void processRequest(ItsNatServletRequest request, ItsNatServletResponse response)
            {
                FileUploadRequest fileUpReq = iframeUpload.processFileUploadRequest(request, response);

                try
                {
                    ServletResponse servRes = response.getServletResponse();
                    Writer out = servRes.getWriter();
                    out.write("<html><head /><body>");
                    out.write("<p>Content Type: \"" + fileUpReq.getContentType() + "\"</p>");
                    out.write("<p>Field Name: \"" + fileUpReq.getFieldName() + "\"</p>");
                    out.write("<p>File Name: \"" + fileUpReq.getFileName() + "\"</p>");
                    out.write("<p>File Size: " + fileUpReq.getFileSize() + "</p>");
                    if (fileUpReq.getFileSize() > 4*1024*1024)
                        out.write("<h2>TOO LARGE FILE</h2>");
                    out.write("</body></html>");

                    long fileSize = fileUpReq.getFileSize();
                    if ((fileSize == 0)||(fileSize > 4*1024*1024)) return;

                    byte[] buffer = new byte[10*1024];
                    InputStream fileUp = fileUpReq.getFileUploadInputStream();
                    long count = 0;
                    int read = 0;
                    do
                    {
                        if (iframeUpload.isDisposed())
                            return;

                        try { Thread.sleep(50); }catch(InterruptedException ex){ }
                        count += read;
                        updateProgression((count * 100) / fileSize);
                        read = fileUp.read(buffer);
                    }
                    while (read != -1);
                }
                catch(IOException ex)
                {
                    throw new RuntimeException(ex);
                }
                finally
                {
                    ItsNatDocument itsNatDoc = getItsNatDocument();
                    synchronized(itsNatDoc)
                    {
                        timerHnd.cancel();
                    }
                }
            }
        };
        iframeUpload.addItsNatServletRequestListener(listener);
View Full Code Here

Examples of org.itsnat.core.event.ItsNatTimerHandle

            outText("OK timer started "); // Para que se vea

            boolean fixedRate = checkBoxElem.getChecked();

            ItsNatTimerHandle timerHandle;
            if (!fixedRate)
                timerHandle = timerMgr.schedule(null,this,3000,2000);
            else
                timerHandle = timerMgr.scheduleAtFixedRate(null,this,3000,200);
            timerHandleList.add(timerHandle);
        }
        else if (currentTarget == removeTimerElem)
        {
            ItsNatTimerHandle timerHandle = getFirstTimerHandle();
            if (timerHandle != null)
            {
                boolean res = timerHandle.cancel();
                if (res)
                    outText("OK timer canceled "); // Para que se vea
                removeFirstTimerHandle();
            }
        }
        else
        {
            ItsNatTimerEvent timerEvt = (ItsNatTimerEvent)evt;
            ItsNatTimerHandle handle = timerEvt.getItsNatTimerHandle();
            long firstTime = handle.getFirstTime();
            if ((new Date().getTime() - firstTime) > 10000) // to avoid never ending ticks
            {
                handle.cancel();
                outText("Timer canceled (timeout)");
            }
            else
            {
                long delay = System.currentTimeMillis() - timerEvt.getItsNatTimerHandle().scheduledExecutionTime();
                long period = handle.getPeriod();
                // El delay es para ver lo que ha tardado en procesarse el evento respecto al instante previsto
                // En el caso de fixedRate el periodo de test es peque�o pero la t�cnica permite "acelerar"
                // el delay podr� superar el periodo alguna vez pero se recuperar� (si no es demasiado peque�o)
                String msg = "OK timer, delay: " + delay + " ";
                if (delay >= period) // el retraso choca el instante siguiente evento
View Full Code Here

Examples of org.itsnat.core.event.ItsNatTimerHandle

        ClientDocument clientDoc = ((ItsNatEvent)evt).getClientDocument();
        ItsNatTimer timer = clientDoc.createItsNatTimer();
        EventListener timerListener = new EventListener() {
            public void handleEvent(Event evt) { }   // Nothing to do, this timer just update the client with the current state of progressElem
        };
        final ItsNatTimerHandle timerHnd = timer.schedule(null,timerListener,0,1000);

        final HTMLIFrameFileUpload iframeUpload = iframe.getHTMLIFrameFileUpload(clientDoc,input.getHTMLInputElement());

        ItsNatServletRequestListener listener = new ItsNatServletRequestListener()
        {
            public void processRequest(ItsNatServletRequest request, ItsNatServletResponse response)
            {
                FileUploadRequest fileUpReq = iframeUpload.processFileUploadRequest(request, response);

                try
                {
                    ServletResponse servRes = response.getServletResponse();
                    Writer out = servRes.getWriter();
                    out.write("<html><head /><body>");
                    out.write("<p>Content Type: \"" + fileUpReq.getContentType() + "\"</p>");
                    out.write("<p>Field Name: \"" + fileUpReq.getFieldName() + "\"</p>");
                    out.write("<p>File Name: \"" + fileUpReq.getFileName() + "\"</p>");
                    out.write("<p>File Size: " + fileUpReq.getFileSize() + "</p>");
                    out.write("</body></html>");

                    long fileSize = fileUpReq.getFileSize();
                    if (fileSize == 0) return;

                    byte[] buffer = new byte[10*1024];
                    InputStream fileUp = fileUpReq.getFileUploadInputStream();
                    long count = 0;
                    int read = 0;
                    do
                    {
                        if (iframeUpload.isDisposed())
                            return;

                        try { Thread.sleep(50); }catch(InterruptedException ex){ }
                        count += read;

                        long per = (count * 100) / fileSize;
                        synchronized(itsNatDoc)
                        {
                            Text text = (Text)progressElem.getFirstChild();
                            text.setData(String.valueOf(per));
                        }

                        read = fileUp.read(buffer);
                    }
                    while (read != -1);
                }
                catch(IOException ex)
                {
                    throw new RuntimeException(ex);
                }
                finally
                {
                    synchronized(itsNatDoc)
                    {
                        timerHnd.cancel();
                    }
                }
            }
        };
        iframeUpload.addItsNatServletRequestListener(listener);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.