Example usage for twitter4j StallWarning getMessage

List of usage examples for twitter4j StallWarning getMessage

Introduction

In this page you can find the example usage for twitter4j StallWarning getMessage.

Prototype

public String getMessage() 

Source Link

Usage

From source file:be.ugent.tiwi.sleroux.newsrec.newsreclib.twitter.StatusListenerAdapter.java

License:Apache License

@Override
public void onStallWarning(StallWarning sw) {
    logger.warn(sw.getMessage());
}

From source file:birdseye.Sample.java

License:Apache License

public List<TweetData> execute(String[] args) throws TwitterException {

    final List<TweetData> statuses = new ArrayList();

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setOAuthAccessToken("14538839-3MX2UoCEUaA6u95iWoYweTKRbhBjqEVuK1SPbCjDV");
    cb.setOAuthAccessTokenSecret("nox7eYyOJpyiDiISHRDou90bGkHKasuw1IMqqJUZMaAbj");

    TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance();

    StatusListener listener = new StatusListener() {

        public void onStatus(Status status) {
            String user = status.getUser().getScreenName();
            String content = status.getText();
            TweetData newTweet = new TweetData(user, content);

            statuses.add(newTweet);//  w  w  w. j a v a 2s . co  m
            System.out.println(statuses.size() + ":" + status.getText());
            if (statuses.size() > 15) {
                synchronized (lock) {
                    lock.notify();
                }
                System.out.println("unlocked");
            }
        }

        public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
            System.out.println("Got a status deletion notice id:" + statusDeletionNotice.getStatusId());
        }

        public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
            System.out.println("Got track limitation notice:" + numberOfLimitedStatuses);
        }

        public void onScrubGeo(long userId, long upToStatusId) {
            System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId);
        }

        public void onException(Exception ex) {
            ex.printStackTrace();
        }

        @Override
        public void onStallWarning(StallWarning sw) {
            System.out.println(sw.getMessage());

        }
    };

    FilterQuery fq = new FilterQuery();
    String[] keywords = args;

    fq.track(keywords);

    twitterStream.addListener(listener);
    twitterStream.filter(fq);

    try {
        synchronized (lock) {
            lock.wait();
        }
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    System.out.println("returning statuses");
    twitterStream.shutdown();
    return statuses;
}

From source file:CollectionOfMentions.ControllerCollectionOfMentions.java

License:Open Source License

public void run() {

    startDateTime = new DateTime();

    //checks on dates to make sure it's not abobe 7 days
    if (numberOfMinutes < 0) {
        numberOfMinutes = 0;/* w ww .  j a va 2  s . c  o  m*/
    }
    if (numberOfMinutes > 59) {
        numberOfMinutes = 59;
    }
    if (numberOfHours > 24) {
        numberOfHours = 24;
    }
    if (numberOfHours < 0) {
        numberOfHours = 0;
    }
    if (numberOfDays > 7) {
        numberOfDays = 7;
    }
    if (numberOfDays < 0) {
        numberOfDays = 0;
    }

    stopTime = startDateTime.getMillis() + numberOfMinutes * 60000 + numberOfHours * 3600000
            + numberOfDays * 3600000 * 24;
    if (stopTime - startDateTime.getMillis() > 3600000 * 24 * 7) {
        stopTime = startDateTime.getMillis() + 3600000 * 24 * 7;
    }

    //registers actual start time in the status field
    opsJobInfo = dsJobsInfo.createUpdateOperations(JobInfo.class).set("status",
            String.valueOf(startDateTime.getMillis()));
    dsJobsInfo.update(updateQueryJobInfo, opsJobInfo, false, WriteConcern.UNACKNOWLEDGED);

    //registers actual end time in the end field
    opsJobInfo = dsJobsInfo.createUpdateOperations(JobInfo.class).set("end", String.valueOf(stopTime));
    dsJobsInfo.update(updateQueryJobInfo, opsJobInfo, false, WriteConcern.UNACKNOWLEDGED);

    final Object lock = new Object();

    StatusListener listener;
    listener = new StatusListener() {
        @Override
        public void onStatus(Status status) {
            nbTweets++;

            if (System.currentTimeMillis() > stopTime) {

                //updating the job a last time;
                //**************************************
                //saving statuses to the db.
                //                    if (!twitterStatuses.isEmpty()) {
                //                        opsJob = dsJobs.createUpdateOperations(Job.class).addAll("statuses", statusesIds, true);
                //                        dsJobs.update(updateQueryJob, opsJob);
                //
                //                        dsTweets.save(twitterStatuses);
                //                    }
                // 91 is the code for twitter stream has stopped collecting.
                progress = 91;

                //recording the progress, nbTweets and end time of the job
                opsJobInfo = dsJobsInfo.createUpdateOperations(JobInfo.class).set("progress", progress)
                        .set("nbTweets", nbTweets).set("end", System.currentTimeMillis());
                dsJobsInfo.update(updateQueryJobInfo, opsJobInfo);

                synchronized (lock) {
                    lock.notify();
                }

            } else {

                tweet = new Tweet();
                tweet.setStatus(TwitterObjectFactory.getRawJSON(status));
                tweet.setIdTweet(nbTweets);
                tweet.setJobId(jobUUID);
                ////                    System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText());
                //                    twitterStatus = convertStatus.convertOneToTwitterStatus(status);
                //                    twitterStatus.setJobId(jobUUID);
                //                    twitterStatuses.add(twitterStatus);
                //                    
                //                    
                //
                //                    statusesIds.add(status.getId());
                //                    timeSinceLastStatus = System.currentTimeMillis() - timeLastStatus;
                //
                //                    //**************************************
                //                    //adjusting the frequency of saves to DB, function of number of statuses received per second
                //                    if (timeSinceLastStatus < 200) {
                //                        sizeBatch = 100;
                //                    } else {
                //                        sizeBatch = 25;
                //                    }
                //                    timeLastStatus = System.currentTimeMillis();
                //                    progressLong = (Long) ((System.currentTimeMillis() - startDateTime.getMillis()) * 98 / (stopTime - startDateTime.getMillis()));

                //                    if (statusesIds.size() > sizeBatch || progressLong.intValue() > progress) {
                //**************************************
                //saving statuses to the db.
                try {
                    dsTweets.save(tweet, WriteConcern.UNACKNOWLEDGED);
                    opsJobInfo = dsJobsInfo.createUpdateOperations(JobInfo.class).set("nbTweets", nbTweets);
                    dsJobsInfo.update(updateQueryJobInfo, opsJobInfo, false, WriteConcern.UNACKNOWLEDGED);
                } catch (MongoException m) {
                    System.out.println("saving of statuses to the db failed");
                }
                //                        twitterStatuses = new ArrayList();
                //
                //                        //**************************************
                //                        //updating list of status ids of the job.
                //                        opsJob = dsJobs.createUpdateOperations(Job.class).addAll("statuses", statusesIds, true);
                //                        dsJobs.update(updateQueryJob, opsJob);
                //                        statusesIds = new ArrayList();
                //
                //                        //updating progress.
                //                        System.out.println("progress: " + progressLong);
                //                        progress = progressLong.intValue();
                //                        opsJobInfo = dsJobsInfo.createUpdateOperations(JobInfo.class).set("progress", progress).set("nbTweets", nbTweets);
                //                        dsJobsInfo.update(updateQueryJobInfo, opsJobInfo);

                //**************************************
                //                    }
            }
        }

        @Override
        public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
            System.out.println("Got a status deletion notice id:" + statusDeletionNotice.getStatusId());
        }

        @Override
        public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
            System.out.println("Got track limitation notice:" + numberOfLimitedStatuses);
        }

        @Override
        public void onScrubGeo(long userId, long upToStatusId) {
            System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId);
        }

        @Override
        public void onException(Exception ex) {
            System.out.println("Exception: " + ex);
        }

        @Override
        public void onStallWarning(StallWarning sw) {
            System.out.println("Got stall warning:" + sw.getMessage());

        }
    };
    twitterStream.addListener(listener);

    FilterQuery fq = new FilterQuery();
    String[] mentions = mention.split(",");
    fq.track(mentions);

    //        twitterStream.filter(new FilterQuery(0, users, keywords));
    twitterStream.filter(fq);

    try {
        synchronized (lock) {
            lock.wait();
        }
    } catch (InterruptedException e) {
    }
    try {
        twitterStream.shutdown();
    } catch (Exception e) {
        System.out.println("exception when shutdown of twitter stream");
        System.out.println("error: " + e.getMessage());
    }
    System.out.println("shutdown of twitter stream was successful");

}

From source file:com.github.jcustenborder.kafka.connect.twitter.TwitterSourceTask.java

License:Apache License

@Override
public void onStallWarning(StallWarning stallWarning) {
    if (log.isWarnEnabled()) {
        log.warn("code = '{}' percentFull = '{}' - {}", stallWarning.getCode(), stallWarning.getPercentFull(),
                stallWarning.getMessage());
    }//w w w .ja va  2s .  c o m
}

From source file:com.narvis.frontend.twitter.input.Input.java

License:Open Source License

@Override
public void onStallWarning(StallWarning sw) {
    NarvisLogger.logInfo("Stallwarning received, code : " + sw.getCode() + " message : " + sw.getMessage());
}

From source file:com.tilab.ca.sda.ctw.connector.TwitterReceiver.java

@Override
public void onStart() {
    try {//w ww.ja  v  a  2  s .  c o m
        log.info(String.format("[%s] CALLED ONSTART on Twitter Receiver...", Constants.TW_RECEIVER_LOG_TAG));
        log.debug(String.format("[%s] Init twitterStreamFactory...", Constants.TW_RECEIVER_LOG_TAG));

        TwitterStream twStream = new TwitterStreamFactory(twStreamConf).getInstance();

        log.debug(String.format("[%s] twitterStreamFactory initialized!", Constants.TW_RECEIVER_LOG_TAG));
        log.debug(String.format("[%s] adding status listener..", Constants.TW_RECEIVER_LOG_TAG));

        twStream.addListener(new StatusListener() {

            @Override
            public void onException(Exception e) {
                log.error(String.format("[%s] Exception on twitterStream", Constants.TW_RECEIVER_LOG_TAG), e);
                restart("Error on receiving tweets!", e);
            }

            @Override
            public void onTrackLimitationNotice(int notDelivered) {
                log.warn(String.format(
                        "[%s] WARNING:number of statuses matching keywords but not delivered => %d",
                        Constants.TW_RECEIVER_LOG_TAG, notDelivered));
            }

            @Override
            public void onStatus(Status status) {
                log.debug(String.format("[%s] new status received! storing on spark..",
                        Constants.TW_RECEIVER_LOG_TAG));
                store(status);
            }

            @Override
            public void onStallWarning(StallWarning stallW) {
                log.warn(String.format("[%s] WARNING: Received Stall Warning message: %s",
                        Constants.TW_RECEIVER_LOG_TAG, stallW.getMessage()));
            }

            @Override
            public void onScrubGeo(long arg0, long arg1) {
            }

            @Override
            public void onDeletionNotice(StatusDeletionNotice arg0) {
            }
        });

        log.debug(String.format("[%s] Creating filterquery", Constants.TW_RECEIVER_LOG_TAG));
        FilterQuery fq = new FilterQuery();
        if (trackArray != null) {
            log.debug(String.format("[%s] added keys to track", Constants.TW_RECEIVER_LOG_TAG));
            fq.track(trackArray);
        }
        if (locationFilterArray != null) {
            log.info(String.format("[%s] added geolocations to track", Constants.TW_RECEIVER_LOG_TAG));
            fq.locations(locationFilterArray);
        }
        if (user2FollowArray != null) {
            log.debug(String.format("[%s] Added users to track", Constants.TW_RECEIVER_LOG_TAG));
            fq.follow(user2FollowArray);
        }
        twStream.filter(fq);
        log.debug(String.format("[%s] Setting twitterStream..", Constants.TW_RECEIVER_LOG_TAG));

        setTwitterStream(twStream);

        log.info(String.format("[%s] Twitter Stream started", Constants.TW_RECEIVER_LOG_TAG));

    } catch (Throwable t) {
        log.error(String.format("[%s] Error starting twitter stream", Constants.TW_RECEIVER_LOG_TAG), t);
        restart("Error starting twitter stream", t);
    }
}

From source file:DataCollection.ActiveTrendsStatusListener.java

@Override
public void onStallWarning(StallWarning warning) {
    System.out.println("Just got a stall warning" + warning.getMessage());
}

From source file:io.rakam.datasource.twitter.TweetProcessor.java

License:Apache License

@Override
public void onStallWarning(StallWarning warning) {
    LOGGER.log(Level.WARNING, String.format("Warning while sending tweets to Rakam: %s", warning.getMessage()));
}

From source file:net.nokok.twitduke.core.twitter.PrintUserStreamListener.java

License:Open Source License

@Override
public void onStallWarning(StallWarning warning) {
    System.out.println("onStallWarning: " + warning.getMessage());
}

From source file:org.graylog2.inputs.twitter.TwitterTransport.java

License:Open Source License

@Override
public void launch(final MessageInput input) throws MisfireException {
    final ConfigurationBuilder cb = new ConfigurationBuilder()
            .setOAuthConsumerKey(configuration.getString(CK_OAUTH_CONSUMER_KEY))
            .setOAuthConsumerSecret(configuration.getString(CK_OAUTH_CONSUMER_SECRET))
            .setOAuthAccessToken(configuration.getString(CK_OAUTH_ACCESS_TOKEN))
            .setOAuthAccessTokenSecret(configuration.getString(CK_OAUTH_ACCESS_TOKEN_SECRET))
            .setJSONStoreEnabled(true);/*  w  ww. j  a v  a2  s.c o  m*/

    final StatusListener listener = new StatusListener() {
        public void onStatus(final Status status) {
            try {
                input.processRawMessage(createMessageFromStatus(status));
            } catch (IOException e) {
                LOG.debug("Error while processing tweet status", e);
            }
        }

        private RawMessage createMessageFromStatus(final Status status) throws IOException {
            return new RawMessage(TwitterObjectFactory.getRawJSON(status).getBytes(StandardCharsets.UTF_8));
        }

        public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
        }

        public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
        }

        public void onException(final Exception ex) {
            LOG.error("Error while reading Twitter stream", ex);
        }

        @Override
        public void onScrubGeo(long lon, long lat) {
        }

        @Override
        public void onStallWarning(StallWarning stallWarning) {
            LOG.info("Stall warning: {} ({}% full)", stallWarning.getMessage(), stallWarning.getPercentFull());
        }
    };

    final String[] track = Iterables.toArray(
            Splitter.on(',').omitEmptyStrings().trimResults().split(configuration.getString(CK_KEYWORDS)),
            String.class);
    final FilterQuery filterQuery = new FilterQuery();
    filterQuery.track(track);

    if (twitterStream == null) {
        twitterStream = new TwitterStreamFactory(cb.build()).getInstance();
    }

    twitterStream.addListener(listener);
    twitterStream.filter(filterQuery);
}