Package java.util

Examples of java.util.Timer$Scheduler


        private final AtomicInteger receivedRequests = new AtomicInteger(0);
        private Timer timer;

        public void onInit() {
            timer = new Timer();
        }
View Full Code Here


        private final AtomicInteger receivedRequests = new AtomicInteger(0);
        private Timer timer;

        public void onInit() {
            timer = new Timer();
        }
View Full Code Here

 
    public static void main(String[] args) throws IOException {
       
        class ServerHandler implements IHttpRequestHandler {

            private final Timer timer = new Timer(false);
           
            public void onRequest(IHttpExchange exchange) throws IOException {
                String requestURI = exchange.getRequest().getRequestURI();
               
                if (requestURI.equals("/Events")) {
                    sendEventStream(exchange);
                   
                } else {
                    sendStaticContent(exchange, requestURI);
                }
            }
           
           
            private void sendStaticContent(IHttpExchange exchange, String uri) throws IOException {
                String page = "<html>\r\n " +
                              "  <head>\r\n" +
                              "     <script type='text/javascript'>\r\n" +
                              "        var source = new EventSource('Events');\r\n" +
                              "        source.onmessage = function (event) {\r\n" +
                              "          var ev = document.getElementById('events');\r\n" +
                              "          ev.innerHTML += \"data: \" + event.data;\r\n"+
                              "        };\r\n" +
                              "     </script>\r\n" +
                              "  </head>\r\n" +
                              "  <body>\r\n" +
                              "    Events:\r\n" +
                              "    <div id=\"events\"></div>\r\n" +
                              "  </body>\r\n" +
                              "</html>\r\n ";
               
                exchange.send(new HttpResponse(200, "text/html", page));
            }
           
           
            private void sendEventStream(final IHttpExchange exchange) throws IOException {

                // sending the response header
                final BodyDataSink sink = exchange.send(new HttpResponseHeader(200, "text/event-stream"));

               
                TimerTask tt = new TimerTask() {

                    private int id = Integer.parseInt(exchange.getRequest().getHeader("Last-Event-Id", "0"));
                   
                    public void run() {
                        try {
                            Event event = new Event(new Date().toString(), ++id);
                            sink.write(event.toString());
                        } catch (IOException ioe) {
                            cancel();
                            sink.destroy();
                        }
                    };
                };
               
                Event event = new Event();
                event.setRetryMillis(5 * 1000);
                sink.write(event.toString());
               
                timer.schedule(tt, 3000, 3000);
            }
        }

       
       
View Full Code Here

 
    public static void main(String[] args) throws IOException {
       
        class ServerHandler implements IHttpRequestHandler {

            private final Timer timer = new Timer(false);
           
            public void onRequest(IHttpExchange exchange) throws IOException {
                String requestURI = exchange.getRequest().getRequestURI();
               
                if (requestURI.equals("/ServerSentEventExample")) {
                    sendServerSendPage(exchange, requestURI);
                   
                } else if (requestURI.equals("/Events")) {
                    sendEventStream(exchange);
                   
                } else {
                    exchange.sendError(404);
                }
            }
           
           
            private void sendServerSendPage(IHttpExchange exchange, String uri) throws IOException {
                String page = "<html>\r\n " +
                              "  <head>\r\n" +
                              "     <script type='text/javascript'>\r\n" +
                              "        var source = new EventSource('Events');\r\n" +
                              "        source.onmessage = function (event) {\r\n" +
                              "          ev = document.getElementById('events');\r\n" +
                              "          ev.innerHTML += \"<br>[in] \" + event.data;\r\n"+
                              "        };\r\n" +
                              "     </script>\r\n" +
                              "  </head>\r\n" +
                              "  <body>\r\n" +
                              "    <div id=\"events\"></div>\r\n" +
                              "  </body>\r\n" +
                              "</html>\r\n ";
               
                exchange.send(new HttpResponse(200, "text/html", page));
            }
           

            private void sendEventStream(final IHttpExchange exchange) throws IOException {

                // get the last id string
                final String idString = exchange.getRequest().getHeader("Last-Event-Id", "0");

                // sending the response header
                final BodyDataSink sink = exchange.send(new HttpResponseHeader(200, "text/event-stream"));

                TimerTask tt = new TimerTask() {

                    private int id = Integer.parseInt(idString);
                   
                    public void run() {
                        try {
                            Event event = new Event(new Date().toString(), ++id);
                            sink.write(event.toString());
                        } catch (IOException ioe) {
                            cancel();
                            sink.destroy();
                        }
                    };
                };
               
                Event event = new Event();
                event.setRetryMillis(5 * 1000);
                event.setComment("time stream");
                sink.write(event.toString());
               
                timer.schedule(tt, 3000, 3000);
            }
        }

       
        HttpServer server = new HttpServer(8875, new ServerHandler());
View Full Code Here

        private final AtomicInteger receivedRequests = new AtomicInteger(0);
        private Timer timer;

        public void onInit() {
            timer = new Timer();
        }
View Full Code Here

      INSTANCE = new LinksPortlet();
      INSTANCE.setConfiguration(configuration);
      INSTANCE.refreshInterval = Long.parseLong((String)INSTANCE.getConfiguration().get("refreshSeconds")) * 1000;
      INSTANCE.contentLoader = new LinksPortletContentLoader();
      Tracing.createLoggerFor(LinksPortlet.class).info("Creating timer task for loading content.");
      Timer timer = new Timer();
      timer.schedule(INSTANCE.contentLoader, (new GregorianCalendar()).getTime(), INSTANCE.refreshInterval);
      INSTANCE.setTranslator(new PackageTranslator(Util.getPackageName(LinksPortlet.class), ureq.getLocale()));
      // override css class if configured
      String cssClass = (String)configuration.get("cssWrapperClass");
      if (cssClass != null) INSTANCE.setCssWrapperClass(cssClass);
    }
View Full Code Here

    @Override
    public Event pollDelayed(final int milli) {

        final SuspendInfo info = suspend();

        Timer t = new Timer();
        t.schedule(new TimerTask() {
            @Override
            public void run() {
                try {
                    info.writeAndResume(new Event(milli, "Polling: Delayed event"));
                } catch (IOException e) {
View Full Code Here

    @Override
    protected void initialize(ServletContext context) {
        super.initialize(context);

        _tick = new Timer("AtmosphereContinuationBayeux-" + __id++, true);
        _timeout = new Timeout();

        _tick.schedule(new TimerTask() {
            @Override
            public void run() {
View Full Code Here

      public void run() {
        Thread.currentThread().setPriority(Thread.MIN_PRIORITY);                // don't disturb other things going on
        createXML();
      }
    };
    Timer timer = new Timer();
    timer.schedule(tt, (new GregorianCalendar()).getTime(), inter);
    instance=true;
    return retVal;
  }
View Full Code Here

     * @return the {@link Timer} for checking keyedPool's idle count.
     * @since Pool 1.3
     */
    private static synchronized Timer getMinIdleTimer() {
        if (MIN_IDLE_TIMER == null) {
            MIN_IDLE_TIMER = new Timer(true);
        }
        return MIN_IDLE_TIMER;
    }
View Full Code Here

TOP

Related Classes of java.util.Timer$Scheduler

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.