Package nl.justobjects.pushlet.core

Examples of nl.justobjects.pushlet.core.Event


    public Event pullEvent() {
      int cityNumber = Rand.randomInt(0, (cities.length) / 2 - 1);
      int nextCityIndex = 2 * cityNumber;

      Event event = Event.createDataEvent("/temperature");

      event.setField("number", "" + cityNumber);
      event.setField("city", cities[nextCityIndex]);
      if (cities[nextCityIndex + 1] == null) {
        cities[nextCityIndex + 1] = "" + Rand.randomInt(5, 10);
      }
      int currentCityValue = new Integer(cities[nextCityIndex + 1]).intValue();
      int newCityValue = currentCityValue + Rand.randomInt(-2, 2);

      event.setField("value", "" + newCityValue);
      return event;
    }
View Full Code Here


    public long getSleepTime() {
      return 4000;
    }

    public Event pullEvent() {
      Event event = Event.createDataEvent("/system/jvm");
      event.setField("totalMemory", "" + runtime.totalMemory());
      event.setField("freeMemory", "" + runtime.freeMemory());
      event.setField("maxMemory", "" + runtime.maxMemory());
      int activeCount = Thread.activeCount();
      event.setField("threads", "" + activeCount);

      return event;
    }
View Full Code Here

    public long getSleepTime() {
      return 5000;
    }

    public Event pullEvent() {
      Event event = Event.createDataEvent("/system/pushlet");
      // p(Dispatcher.getStatus());
      event.setField("publisher", "" + SessionManager.getInstance().getStatus());
      return event;
    }
View Full Code Here

    public long getSleepTime() {
      return Rand.randomLong(2000, 4000);
    }

    public Event pullEvent() {
      Event event = Event.createDataEvent("/stocks/aex");
      int stockNumber = Rand.randomInt(0, (stocks.length) / 2 - 1);
      int nextStockIndex = 2 * stockNumber;

      event.setField("number", "" + stockNumber);
      event.setField("name", stocks[nextStockIndex]);
      if (stocks[nextStockIndex + 1] == null) {
        stocks[nextStockIndex + 1] = "" + Rand.randomInt(50, 150);
      }
      int currentStockValue = new Integer(stocks[nextStockIndex + 1]).intValue();
      int newStockValue = currentStockValue + Rand.randomInt(-2, 2);

      event.setField("rate", "" + newStockValue + "." + Rand.randomInt(0, 99));
      return event;
    }
View Full Code Here

    public long getSleepTime() {
      return 5000;
    }

    public Event pullEvent() {
      Event event = Event.createDataEvent("/webpres/auto");
      event.setField("url", slideRootDir + slideURLs[nextSlideNumber++]);
      if (nextSlideNumber == slideURLs.length) {
        nextSlideNumber = 0;
      }
      // Log.debug("Sending next slide url=" + event.getField("url"));
      return event;
View Full Code Here

    public long getSleepTime() {
      return 2000;
    }

    public Event pullEvent() {
      Event event = Event.createDataEvent("/system/test");
      // p(Dispatcher.getInstance()..getStatus());
      event.setField("nr", "" + (number++));
      event.setField("time", "" + System.currentTimeMillis());
      return event;
    }
View Full Code Here

  /**
   * Join server, starts session.
   */
  public void join() throws PushletException {
    Event event = new Event(E_JOIN);
    event.setField(P_FORMAT, FORMAT_XML);
    Event response = doControl(event);
    throwOnNack(response);

    // Join Ack received
    id = response.getField(P_ID);
  }
View Full Code Here

   * Leave server, stops session.
   */
  public void leave() throws PushletException {
    stopListen();
    throwOnInvalidSession();
    Event event = new Event(E_LEAVE);
    event.setField(P_ID, id);
    Event response = doControl(event);

    throwOnNack(response);
    id = null;
  }
View Full Code Here

  /**
   * Publish an event through server.
   */
  public void publish(String aSubject, Map theAttributes) throws PushletException {
    throwOnInvalidSession();
    Event event = new Event(E_PUBLISH, theAttributes);
    event.setField(P_SUBJECT, aSubject);
    event.setField(P_ID, id);
    Event response = doControl(event);
    throwOnNack(response);
  }
View Full Code Here

  /**
   * Subscribes, returning subscription id.
   */
  public String subscribe(String aSubject, String aLabel) throws PushletException {
    throwOnInvalidSession();
    Event event = new Event(E_SUBSCRIBE);
    event.setField(P_ID, id);
    event.setField(P_SUBJECT, aSubject);

    // Optional label, is returned in data events
    if (aLabel != null) {
      event.setField(P_SUBSCRIPTION_LABEL, aLabel);
    }

    // Send request
    Event response = doControl(event);
    throwOnNack(response);

    return response.getField(P_SUBSCRIPTION_ID);
  }
View Full Code Here

TOP

Related Classes of nl.justobjects.pushlet.core.Event

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.