Esempio n. 1
0
 @Override
 public void send(Event e, Port p) {
   if (p.getName().equals("IOStream")) {
     IOStreamPort_out.send(e);
   } else { // Internal channel managed by ThingML
     super.send(e, p);
   }
 }
Esempio n. 2
0
  @Start
  public void start() {
    queue = new LinkedBlockingQueue<>(100000);
    BlockingQueue<Event> eventQueue = new LinkedBlockingQueue<>(1000);

    // Declare the host you want to connect to, the endpoint, and authentication (basic auth or
    // oauth)
    Hosts hosebirdHosts = new HttpHosts(Constants.STREAM_HOST);
    StatusesFilterEndpoint hosebirdEndpoint = new StatusesFilterEndpoint();

    // set up some track terms
    if (trackTerms != null && !trackTerms.isEmpty()) {
      hosebirdEndpoint.trackTerms(Lists.newArrayList(trackTerms.split(" ")));
    }
    // set up some followings
    if (followingIDs != null && !followingIDs.isEmpty()) {
      Set<Long> followings = new HashSet<>();
      for (String id : followingIDs.split(" ")) {
        followings.add(Long.parseLong(id));
      }
      hosebirdEndpoint.followings(Lists.newArrayList(followings));
    }

    // These secrets should be read from a config file
    Authentication hosebirdAuth = new OAuth1(consumerKey, consumerSecret, token, secret);

    ClientBuilder builder =
        new ClientBuilder()
            .name("twitter-client")
            .hosts(hosebirdHosts)
            .authentication(hosebirdAuth)
            .endpoint(hosebirdEndpoint)
            .processor(new StringDelimitedProcessor(queue))
            .eventMessageQueue(eventQueue);

    client = builder.build();
    // Attempts to establish a connection.
    client.connect();

    executor.submit(
        () -> {
          while (client != null && !client.isDone()) {
            try {
              String msg = queue.poll(5000, TimeUnit.MILLISECONDS);
              if (msg != null) {
                out.send(msg, null);
              }
            } catch (InterruptedException e) {
              Log.warn("Twitter messages blocking queue interrupted while waiting.");
            }
          }
        });
  }
Esempio n. 3
0
 @Input
 public void in(Object i) {
   out.send(getLastSortedRdv());
 }
 public String getPath() {
   return port.getPath();
 }
 @Override
 public void onMessage(String channel, String message) {
   port.send(message);
 }