Java Code Examples for org.apache.commons.configuration2.XMLConfiguration#getInt()

The following examples show how to use org.apache.commons.configuration2.XMLConfiguration#getInt() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MessageCounter.java    From vicinity-gateway-api with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Connector
 */
public MessageCounter(XMLConfiguration config, Logger logger) {
	
	this.config = config;
	this.logger = logger;
	
	nmConnector = new NeighbourhoodManagerConnector(config, logger);
	
	logger.info("Trying to load counters from file...");
	CountersPersistence = new Counters(config, logger);
	records = CountersPersistence.getRecords();
	count = CountersPersistence.getCountOfMessages();
	
	// Initialize max counters stored before sending - MAX 500 - DEFAULT 100
	countOfSendingRecords = config.getInt(CONFIG_PARAM_MAXRECORDS, CONFIG_DEF_MAXRECORDS);		
	if(countOfSendingRecords > 500) {
		countOfSendingRecords = 500;
	} 
}
 
Example 2
Source File: SecureServerComms.java    From vicinity-gateway-api with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Constructor.
 * 
 * @param config Configuration of the OGWAPI.
 * @param logger Logger of the OGWAPI.
 */
public SecureServerComms(XMLConfiguration config, Logger logger) {
	this.logger = logger;
	agid = config.getString(CONFIG_PARAM_PLATFORMIDENTITY, CONFIG_DEF_PLATFORMIDENTITY);
	ttl = config.getInt(CONFIG_PARAM_EXPIRE, CONFIG_DEF_EXPIRE);
	path = config.getString(CONFIG_PARAM_PATH, CONFIG_DEF_PATH);
	privKey = config.getString(CONFIG_PARAM_OGWAPI_PRIV_KEY, CONFIG_DEF_OGWAPI_PRIV_KEY);
	pubKey = config.getString(CONFIG_PARAM_OGWAPI_PUB_KEY, CONFIG_DEF_OGWAPI_PUB_KEY);
	platform_token_expiration = System.currentTimeMillis() + ttl;
}
 
Example 3
Source File: RestletThread.java    From vicinity-gateway-api with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Constructor, initialises the configuration and logger instances.
 * 
 * @param config OGWAPI configuration.
 * @param logger OGWAPI Logger.
 */
public RestletThread(XMLConfiguration config, Logger logger, MessageCounter messageCounter){
	
	this.config = config;
	this.logger = logger;
	this.messageCounter = messageCounter;
	
	threadRunning = true;
	
	enableHttps = config.getBoolean(CONF_PARAM_APIENABLEHTTPS, CONF_DEF_APIENABLEHTTPS);
	if (enableHttps) {
		logger.config("HTTPS enabled.");
		
		keystoreFile = config.getString(CONF_PARAM_KEYSTOREFILE, CONF_DEF_KEYSTOREFILE);
		logger.config("Path to keystore file: " + keystoreFile);
		
		keystorePassword = config.getString(CONF_PARAM_KEYSTOREPASSWORD, CONF_DEF_KEYSTOREPASSWORD);
		keyPassword = config.getString(CONF_PARAM_KEYPASSWORD, CONF_DEF_KEYPASSWORD);
		
		keystoreType = config.getString(CONF_PARAM_KEYSTORETYPE, CONF_DEF_KEYSTORETYPE);
		logger.config("Keystore type is " + keystoreType);
		
	} else {
		logger.config("HTTPS disabled.");
	}
	
	port = config.getInt(CONF_PARAM_APIPORT, CONF_DEF_APIPORT);
	logger.config("Set to listen on port " + port);
}
 
Example 4
Source File: Action.java    From vicinity-gateway-api with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Constructor, initialises field, loads configuration and starts timers.
 * 
 * @param config Configuration of the OGWAPI.
 * @param objectId Object ID of the object that owns this instance of the action class.
 * @param actionId Action ID.
 * @param connector Instance of the {@link eu.bavenir.ogwapi.commons.connectors.AgentConnector AgentConnector}. 
 * @param logger Logger of the OGWAPI.
 */
public Action(XMLConfiguration config, String objectId, String actionId, AgentConnector connector, Logger logger) {
	
	this.objectId = objectId;
	this.actionId = actionId;
	this.connector = connector;
	this.logger = logger;
	this.config = config;
	
	pendingTasks = Collections.synchronizedList(new LinkedList<Task>());
	
	finishedTasks = Collections.synchronizedSet(new HashSet<Task>());
	
	runningTask = null;
	
	// load configuration parameters
	timeToKeepReturnValues = // turn into ms
			config.getInt(CONF_PARAM_TIMETOKEEPRETURNVALUES, CONF_DEF_TIMETOKEEPRETURNVALUES) * MINUTE;
	
	logger.config("Action " + actionId + " time to keep return values set to (ms): " + timeToKeepReturnValues);
	
	pendingTaskTimeout = // turn into ms
			config.getInt(CONF_PARAM_PENDINGTASKTIMEOUT, CONF_DEF_PENDINGTASKTIMEOUT) * MINUTE;
	
	logger.config("Action " + actionId + " pending tasks timeout set to (ms): " + pendingTaskTimeout);
	
	maxNumberOfPendingTasks = config.getInt(CONF_PARAM_MAXNUMBEROFPENDINGTASKS, CONF_DEF_MAXNUMBEROFPENDINGTASKS);
	
	logger.config("Action " + actionId + " max number of pending tasks set to: " + maxNumberOfPendingTasks);
	
	// schedule a timer for running tasks that are queueing
	Timer timerForTaskScheduling = new Timer();
	
	timerForTaskScheduling.schedule(new TimerTask() {
		@Override
		public void run() {
			workThroughTasks();
			purgeOutdatedReturnValues();
			purgeTimedOutPendingTasks();
		}
	}, TIMER1_START, SECOND);
	
}
 
Example 5
Source File: CommunicationManager.java    From vicinity-gateway-api with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Constructor, initialises necessary objects. All parameters are mandatory, failure to include them can lead 
 * to a swift end of application.
 * 
 * @param config Configuration object.
 * @param logger Java logger.
 */
public CommunicationManager(XMLConfiguration config, Logger logger, MessageCounter messageCounter){
	
	logger.config("OGWAPI version: " + OGWAPI_VERSION);
	
	this.descriptorPool = Collections.synchronizedMap(new HashMap<String, ConnectionDescriptor>());
	
	this.nmConnector = new NeighbourhoodManagerConnector(config, logger);		
	
	// load the configuration for the pageSize param
	pageSize = config.getInt(CONFIG_PARAM_PAGE_SIZE, CONFIG_DEF_PAGE_SIZE);
	
	this.sessionExpiration = 0;
	
	this.config = config;
	this.logger = logger;
	this.messageCounter = messageCounter;
	
	// load the configuration for the session recovery policy
	String sessionRecoveryPolicyString = config.getString(CONFIG_PARAM_SESSIONRECOVERY, CONFIG_DEF_SESSIONRECOVERY);
	
	translateSessionRecoveryConf(sessionRecoveryPolicyString);
	
	if (sessionRecoveryPolicy == SESSIONRECOVERYPOLICY_INT_ERROR) {
		// wrong configuration parameter entered - set it to default
		logger.warning("Wrong parameter entered for " + CONFIG_PARAM_SESSIONRECOVERY + " in the configuration file: "  
				+ sessionRecoveryPolicyString + ". Setting to default: " + CONFIG_DEF_SESSIONRECOVERY);
		
		translateSessionRecoveryConf(CONFIG_DEF_SESSIONRECOVERY);
		
	} else {
		logger.config("The session recovery policy is set to " + sessionRecoveryPolicyString + ".");
	}
			
	// timer for session checking - N/A if the session recovery is set to none
	if (sessionRecoveryPolicy != SESSIONRECOVERYPOLICY_INT_NONE) {
		
		int checkInterval;
		
		switch(sessionRecoveryPolicy) {
		case SESSIONRECOVERYPOLICY_INT_PASSIVE:
			checkInterval = SESSIONRECOVERY_CHECKINTERVAL_PASSIVE;
			
			sessionExpiration = config.getInt(CONFIG_PARAM_SESSIONEXPIRATION, CONFIG_DEF_SESSIONEXPIRATION);
			
			// if somebody put there too small number, we will turn it to default
			if (sessionExpiration < SESSIONEXPIRATION_MINIMAL_VALUE) {
				logger.warning("Wrong parameter entered for " + CONFIG_PARAM_SESSIONEXPIRATION + " in the configuration file: "  
						+ sessionRecoveryPolicyString + ". Setting to default: " + CONFIG_DEF_SESSIONEXPIRATION);
				sessionExpiration = CONFIG_DEF_SESSIONEXPIRATION;
			}
			
			sessionExpiration = sessionExpiration * 1000;
			
			logger.config("Session expiration is set to " + sessionExpiration + "ms");
			break;
			
		case SESSIONRECOVERYPOLICY_INT_PROACTIVE:
			checkInterval = SESSIONRECOVERY_CHECKINTERVAL_PROACTIVE;
			break;
			
			default:
				// if something goes wrong, don't let the timer stand in our way
				checkInterval = Integer.MAX_VALUE;
		}
		
		
		Timer timerForSessionRecovery = new Timer();
		timerForSessionRecovery.schedule(new TimerTask() {
			@Override
			public void run() {
				recoverSessions();
			}
		}, checkInterval, checkInterval);
	}
}
 
Example 6
Source File: NeighbourhoodManagerConnector.java    From vicinity-gateway-api with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Constructor.
 * 
 * @param config Configuration of the OGWAPI.
 * @param logger Logger of the OGWAPI.
 */
public NeighbourhoodManagerConnector(XMLConfiguration config, Logger logger) {
	
	this.logger = logger;
	
	agid = config.getString(CONFIG_PARAM_PLATFORMIDENTITY, CONFIG_DEF_PLATFORMIDENTITY);
	
	neighbourhoodManagerServer = 
			config.getString(CONFIG_PARAM_NEIGHBORHOODMANAGERSERVER, CONFIG_DEF_NEIGHBORHOODMANAGERSERVER);
	
	port = config.getInt(CONFIG_PARAM_NEIGHBOURHOODMANAGERPORT, CONFIG_DEF_NEIGHBOURHOODMANAGERPORT);
	
	securityEnabled = config.getBoolean(CONFIG_PARAM_PLATFORMSECURITY, CONFIG_DEF_PLATFORMSECURITY);

	secureComms = new SecureServerComms(config, logger);
}
 
Example 7
Source File: RestAgentConnector.java    From vicinity-gateway-api with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Constructor. It is necessary to provide all parameters. If null is provided in place of any of them,
 * a storm of null pointer exceptions is imminent.
 *
 * @param config Configuration of the OGWAPI.
 * @param logger Logger of the OGWAPI.
 */
public RestAgentConnector(XMLConfiguration config, Logger logger){
	super(config, logger);

	// load configuration for dummy connector
	if (config.getBoolean(CONFIG_PARAM_CONNECTORRESTDUMMY, CONFIG_DEF_APIRESTAGENTDUMMY)) {
		logger.config("REST Agent Connector: Dummy payloads enabled, all calls to an Agent via this connector "
				+ "will be simulated.");
		dummyCalls = true;
	} else {
		logger.config("REST Agent Connector: Dummy payloads disabled, all calls to an Agent via this connector "
				+ "will be real.");
	}

	// load configuration for https
	if (config.getBoolean(CONFIG_PARAM_CONNECTORRESTUSEHTTPS, CONFIG_DEF_APIAGENTUSEHTTPS)){
		logger.config("REST Agent Connector: HTTPS protocol enabled for Agent communication.");
		useHttps = true;

		acceptSelfSigned = config.getBoolean(CONFIG_PARAM_HTTPSACCEPTSELFSIGNED, CONFIG_DEF_HTTPSACCEPTSELFSIGNED);

	} else {
		logger.config("REST Agent Connector: HTTPS protocol disabled for Agent communication.");
		useHttps = false;
		acceptSelfSigned = false;
	}

	// load authentication method
	agentAuthMethod = config.getString(CONFIG_PARAM_AUTHMETHOD, CONFIG_DEF_AUTHMETHOD);
	if (!agentAuthMethod.equals(CONFIG_DEF_AUTHMETHOD)) {
		// log it
	}
	agentUsername = config.getString(CONFIG_PARAM_AGENTUSERNAME, CONFIG_DEF_AGENTUSERNAME);
	agentPassword = config.getString(CONFIG_PARAM_AGENTPASSWORD, CONFIG_DEF_AGENTPASSWORD);

	// load timeout
	agentTimeout = config.getInt(CONFIG_PARAM_AGENTTIMEOUT, CONFIG_DEF_AGENTTIMEOUT);

	agentServiceUrl = assembleAgentServiceUrl();

	// initialize CloseableHttpClient
	initialize();
}