当前位置: 首页>>代码示例>>Java>>正文


Java FetcherEvent类代码示例

本文整理汇总了Java中com.rometools.fetcher.FetcherEvent的典型用法代码示例。如果您正苦于以下问题:Java FetcherEvent类的具体用法?Java FetcherEvent怎么用?Java FetcherEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


FetcherEvent类属于com.rometools.fetcher包,在下文中一共展示了FetcherEvent类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fetcherEvent

import com.rometools.fetcher.FetcherEvent; //导入依赖的package包/类
@Override
public void fetcherEvent(FetcherEvent event) {
    final String eventType = event.getEventType();
    if (FetcherEvent.EVENT_TYPE_FEED_POLLED.equals(eventType)) {
        log.debug("[hlds_announce] Feed polled from {}", event.getUrlString());
    } else if (FetcherEvent.EVENT_TYPE_FEED_RETRIEVED.equals(eventType)) {
        Instant lastPublishedDate = event.getFeed().getPublishedDate().toInstant();
        log.debug("[hlds_announce] Feed retrieved. Published at {}", lastPublishedDate);
        // news post might not be related to TF2!! always check before dispatching event
        if (lastSavedVersion == 0) {
            lastSavedVersion = condenserService.getLastCachedVersion();
        }
        if (lastSavedVersion < condenserService.getLatestVersion()) {
            lastSavedVersion = condenserService.getLastCachedVersion();
            publisher.publishEvent(new FeedUpdatedEvent(event.getFeed()));
        }
    } else if (FetcherEvent.EVENT_TYPE_FEED_UNCHANGED.equals(eventType)) {
        log.debug("[hlds_announce] Feed unchanged");
    }
}
 
开发者ID:quanticc,项目名称:ugc-bot-redux,代码行数:21,代码来源:UpdatesFeedService.java

示例2: fetcherEvent

import com.rometools.fetcher.FetcherEvent; //导入依赖的package包/类
@Override
public void fetcherEvent(final FetcherEvent event) {
    try {
        final String eventType = event.getEventType();
        if (FetcherEvent.EVENT_TYPE_FEED_RETRIEVED.equals(eventType)) {
            Log.debug("RETRIEVED " + event.getUrlString());
            final SyndFeed feeds = event.getFeed();
            if (feeds != null && feeds.getEntries() != null) {
                List<SyndEntry> feedsFiltered = feeds.getEntries().stream()
                        .filter((entry) -> getLastDate(entry) != null)
                        .filter((entry) ->
                                getLastDate(entry) != null && getLastDate(entry).after(currentDate))
                        .sorted((entry1, entry2) -> ObjectUtils.compare(getLastDate(entry1), getLastDate(entry2)))
                        .collect(Collectors.toList());

                if (!feedsFiltered.isEmpty()) {
                    currentDate = getLastDate(feedsFiltered.get(feedsFiltered.size() - 1));
                }

                feedsFiltered.forEach((entry) -> out.send(toJson(entry), null));
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:kevoree,项目名称:kevoree-library,代码行数:27,代码来源:RSSEventListener.java

示例3: getEventSetDescriptors

import com.rometools.fetcher.FetcherEvent; //导入依赖的package包/类
@Override
public EventSetDescriptor[] getEventSetDescriptors() {

    try {

        // get the class object which we'll describe
        final Class<AbstractFeedFetcher> clz = AbstractFeedFetcher.class;
        final Method addMethod = clz.getMethod("addFetcherEventListener", new Class[] { FetcherListener.class });
        final Method removeMethod = clz.getMethod("removeFetcherEventListener", new Class[] { FetcherListener.class });
        final Method listenerMethod = FetcherListener.class.getMethod("fetcherEvent", new Class[] { FetcherEvent.class });
        final EventSetDescriptor est = new EventSetDescriptor("fetcherEvent", clz, new Method[] { listenerMethod }, addMethod, removeMethod);
        return new EventSetDescriptor[] { est };

    } catch (final Exception e) {
        // IntrospectionException, SecurityException and/or NoSuchMethodException can be thrown
        // here. The best we can do is to convert them to runtime exceptions
        throw new RuntimeException(e);
    }

}
 
开发者ID:rometools,项目名称:rome,代码行数:21,代码来源:AbstractFeedFetcherBeanInfo.java

示例4: getFeed

import com.rometools.fetcher.FetcherEvent; //导入依赖的package包/类
private SyndFeed getFeed(final SyndFeedInfo syndFeedInfo, final String urlStr, final HttpMethod method, final int statusCode) throws IOException,
        HttpException, FetcherException, FeedException {

    if (statusCode == HttpURLConnection.HTTP_NOT_MODIFIED && syndFeedInfo != null) {
        fireEvent(FetcherEvent.EVENT_TYPE_FEED_UNCHANGED, urlStr);
        return syndFeedInfo.getSyndFeed();
    }

    final SyndFeed feed = retrieveFeed(urlStr, method);
    fireEvent(FetcherEvent.EVENT_TYPE_FEED_RETRIEVED, urlStr, feed);
    return feed;
}
 
开发者ID:rometools,项目名称:rome,代码行数:13,代码来源:HttpClientFeedFetcher.java

示例5: fireEvent

import com.rometools.fetcher.FetcherEvent; //导入依赖的package包/类
/**
 * @param eventType The event type to fire
 * @param urlStr the current url as a string
 * @param feed The feed to pass to the event
 */
protected void fireEvent(final String eventType, final String urlStr, final SyndFeed feed) {
    final FetcherEvent fetcherEvent = new FetcherEvent(this, urlStr, eventType, feed);
    synchronized (listeners) {
        for (final FetcherListener fetcherEventListener : listeners) {
            fetcherEventListener.fetcherEvent(fetcherEvent);
        }
    }
}
 
开发者ID:rometools,项目名称:rome,代码行数:14,代码来源:AbstractFeedFetcher.java

示例6: fetcherEvent

import com.rometools.fetcher.FetcherEvent; //导入依赖的package包/类
/**
 * @see com.rometools.rome.fetcher.FetcherListener#fetcherEvent(com.rometools.rome.fetcher.FetcherEvent)
 */
@Override
public void fetcherEvent(final FetcherEvent event) {
    final String eventType = event.getEventType();
    if (FetcherEvent.EVENT_TYPE_FEED_POLLED.equals(eventType)) {
        System.err.println("\tEVENT: Feed Polled. URL = " + event.getUrlString());
    } else if (FetcherEvent.EVENT_TYPE_FEED_RETRIEVED.equals(eventType)) {
        System.err.println("\tEVENT: Feed Retrieved. URL = " + event.getUrlString());
    } else if (FetcherEvent.EVENT_TYPE_FEED_UNCHANGED.equals(eventType)) {
        System.err.println("\tEVENT: Feed Unchanged. URL = " + event.getUrlString());
    }
}
 
开发者ID:rometools,项目名称:rome,代码行数:15,代码来源:FeedReader.java

示例7: retrieveFeed

import com.rometools.fetcher.FetcherEvent; //导入依赖的package包/类
/**
 * Retrieve a feed over HTTP
 *
 * @param feedUrl A non-null URL of a RSS/Atom feed to retrieve
 * @return A {@link com.rometools.rome.feed.synd.SyndFeed} object
 * @throws IllegalArgumentException if the URL is null;
 * @throws IOException if a TCP error occurs
 * @throws FeedException if the feed is not valid
 * @throws FetcherException if a HTTP error occurred
 */
@Override
public SyndFeed retrieveFeed(final String userAgent, final URL feedUrl) throws IllegalArgumentException, IOException, FeedException, FetcherException {
    if (feedUrl == null) {
        throw new IllegalArgumentException("null is not a valid URL");
    }

    final URLConnection connection = feedUrl.openConnection();
    if (!(connection instanceof HttpURLConnection)) {
        throw new IllegalArgumentException(feedUrl.toExternalForm() + " is not a valid HTTP Url");
    }
    final HttpURLConnection httpConnection = (HttpURLConnection) connection;
    if (connectTimeout >= 0) {
        httpConnection.setConnectTimeout(connectTimeout);
    }
    // httpConnection.setInstanceFollowRedirects(true); // this is true by default, but can be
    // changed on a claswide basis

    final FeedFetcherCache cache = getFeedInfoCache();
    if (cache != null) {
        SyndFeedInfo syndFeedInfo = cache.getFeedInfo(feedUrl);
        setRequestHeaders(connection, syndFeedInfo, userAgent);
        httpConnection.connect();
        try {
            fireEvent(FetcherEvent.EVENT_TYPE_FEED_POLLED, connection);

            if (syndFeedInfo == null) {
                // this is a feed that hasn't been retrieved
                syndFeedInfo = new SyndFeedInfo();
                retrieveAndCacheFeed(feedUrl, syndFeedInfo, httpConnection);
            } else {
                // check the response code
                final int responseCode = httpConnection.getResponseCode();
                if (responseCode != HttpURLConnection.HTTP_NOT_MODIFIED) {
                    // the response code is not 304 NOT MODIFIED
                    // This is either because the feed server
                    // does not support condition gets
                    // or because the feed hasn't changed
                    retrieveAndCacheFeed(feedUrl, syndFeedInfo, httpConnection);
                } else {
                    // the feed does not need retrieving
                    fireEvent(FetcherEvent.EVENT_TYPE_FEED_UNCHANGED, connection);
                }
            }

            return syndFeedInfo.getSyndFeed();
        } finally {
            httpConnection.disconnect();
        }
    } else {
        fireEvent(FetcherEvent.EVENT_TYPE_FEED_POLLED, connection);
        InputStream inputStream = null;
        setRequestHeaders(connection, null, userAgent);

        httpConnection.connect();
        try {
            inputStream = httpConnection.getInputStream();
            return getSyndFeedFromStream(inputStream, connection);
        } catch (final java.io.IOException e) {
            handleErrorCodes(((HttpURLConnection) connection).getResponseCode());
        } finally {
            IO.close(inputStream);
            httpConnection.disconnect();
        }
        // we will never actually get to this line
        return null;
    }
}
 
开发者ID:rometools,项目名称:rome,代码行数:78,代码来源:HttpURLFeedFetcher.java

示例8: getSyndFeedFromStream

import com.rometools.fetcher.FetcherEvent; //导入依赖的package包/类
private SyndFeed getSyndFeedFromStream(final InputStream inputStream, final URLConnection connection) throws IOException, IllegalArgumentException,
        FeedException {
    final SyndFeed feed = readSyndFeedFromStream(inputStream, connection);
    fireEvent(FetcherEvent.EVENT_TYPE_FEED_RETRIEVED, connection, feed);
    return feed;
}
 
开发者ID:rometools,项目名称:rome,代码行数:7,代码来源:HttpURLFeedFetcher.java


注:本文中的com.rometools.fetcher.FetcherEvent类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。