All Downloads are FREE. Search and download functionalities are using the official Maven repository.

gr.iti.mklab.sfc.streams.impl.GooglePlusStream Maven / Gradle / Ivy

Go to download

Monitors a set of social streams (e.g. Twitter status updates) and collects the incoming content.

The newest version!
package gr.iti.mklab.sfc.streams.impl;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import gr.iti.mklab.framework.Credentials;
import gr.iti.mklab.framework.common.domain.Source;
import gr.iti.mklab.framework.common.domain.config.Configuration;
import gr.iti.mklab.framework.retrievers.impl.GooglePlusRetriever;
import gr.iti.mklab.sfc.streams.Stream;
import gr.iti.mklab.sfc.streams.StreamException;
import gr.iti.mklab.sfc.streams.monitors.RateLimitsMonitor;

/**
 * Class responsible for setting up the connection to Google API
 * for retrieving relevant Google+ content.
 * 
 * @author manosetro - [email protected]
 */
public class GooglePlusStream extends Stream {
	
	public static final Source SOURCE = Source.GooglePlus;
	
	private Logger logger = LogManager.getLogger(GooglePlusStream.class);
	
	private String key;

	@Override
	public void open(Configuration config) throws StreamException {
		logger.info("#GooglePlus : Open stream");
		
		if (config == null) {
			logger.error("#GooglePlus : Config file is null.");
			return;
		}
		
		key = config.getParameter(KEY);
		
		if (key == null) {
			logger.error("#GooglePlus : Stream requires authentication.");
			throw new StreamException("Stream requires authentication.");
		}
		
		Credentials credentials = new Credentials();
		credentials.setKey(key);
		
		maxRequests = Integer.parseInt(config.getParameter(MAX_REQUESTS));
		timeWindow = Long.parseLong(config.getParameter(TIME_WINDOW));
		
		rateLimitsMonitor = new RateLimitsMonitor(maxRequests, timeWindow);
		retriever = new GooglePlusRetriever(credentials);
		
	}
	
	@Override
	public String getName() {
		return SOURCE.name();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy