List of usage examples for org.apache.commons.configuration Configuration getBoolean
boolean getBoolean(String key);
From source file:com.springrts.springls.agreement.Activator.java
@Override public void start(BundleContext context) { Context springLsContext = Context.getService(context, Context.class); Agreement agreement = new Agreement(); boolean contentAvailable = false; Configuration conf = springLsContext.getService(Configuration.class); // TODO needs adjusting due to new LAN mode accounts service if (!conf.getBoolean(ServerConfiguration.LAN_MODE)) { contentAvailable = agreement.read(); } else {// www . j av a 2 s .c o m log.info("Terms of use agreement not used because we are running in" + " LAN mode."); } if (contentAvailable) { context.registerService(Agreement.class.getName(), agreement, null); } }
From source file:com.nesscomputing.config.SystemPropertiesTest.java
@Test public void testDB2Configuration() { Assert.assertThat(cfg.getConfiguration().getBoolean("production", false), is(true)); Configuration config = cfg.getConfiguration(); Assert.assertThat(config.getString("t_s_d"), is("t_s")); Assert.assertThat(config.getInt("c.m_s"), is(2)); Assert.assertThat(config.getBoolean("b.a"), is(true)); Assert.assertThat(config.getBoolean("y.a"), is(false)); Assert.assertThat(config.getString("s.f-l.u"), is("zzz")); Assert.assertThat(config.getBoolean("c.c.a"), is(true)); }
From source file:com.springrts.springls.ServerNotifications.java
/** * NOTE: This method may be called from multiple threads simultaneously! */// w w w. j a v a 2 s .c o m public boolean addNotification(ServerNotification sn) { Configuration conf = context.getService(Configuration.class); if (conf.getBoolean(ServerConfiguration.LAN_MODE)) { // ignore notifications if server is running in LAN mode! return false; } ensureNotifsDirExists(); DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd"); final String baseFileName = notificationsDir + "/" + dateFormat.format(new Date()); File notifFile = findWriteableNotifFile(baseFileName); if (notifFile == null) { LOG.error("Unable to find/create a notification file. Server" + " notification will not be saved!"); context.getClients().sendToAllAdministrators( "SERVERMSG [broadcast" + " to all admins]: Serious problem: Unable to find/create" + " a notification file (notification dropped)"); return false; } Writer outF = null; BufferedWriter out = null; try { outF = new FileWriter(notifFile, true); out = new BufferedWriter(outF); out.write(NOTIFICATION_SYSTEM_VERSION); out.write(Misc.EOL); out.write(sn.toString()); out.close(); } catch (IOException ex) { LOG.error("Unable to write file <" + notifFile + ">. Server notification will not be saved!", ex); context.getClients().sendToAllAdministrators( "SERVERMSG [broadcast" + " to all admins]: Serious problem: Unable to save server" + " notification (notification dropped)."); return false; } finally { try { if (out != null) { out.close(); } else if (outF != null) { outF.close(); } } catch (IOException ex) { LOG.warn("Failed to close notification file writer: " + notifFile.getAbsolutePath(), ex); } } return true; }
From source file:com.springrts.springls.TASServer.java
public static void startServerInstance(Configuration configuration) { Framework framework = createFramework(); if (framework == null) { return;//from w w w. j a va 2s. c o m } try { framework.start(); } catch (BundleException ex) { LOG.error("Failed to start the OSGi framework", ex); return; } framework.getBundleContext().registerService(Configuration.class.getName(), configuration, null); Context context = new Context(); context.setFramework(framework); context.init(); framework.getBundleContext().registerService(Context.class.getName(), context, null); new com.springrts.springls.floodprotection.Activator().start(context.getFramework().getBundleContext()); new com.springrts.springls.accounts.Activator().start(context.getFramework().getBundleContext()); new com.springrts.springls.bans.Activator().start(context.getFramework().getBundleContext()); new com.springrts.springls.agreement.Activator().start(context.getFramework().getBundleContext()); new com.springrts.springls.motd.Activator().start(context.getFramework().getBundleContext()); context.push(); // TODO needs adjusting due to new LAN mode accounts service if (configuration.getBoolean(ServerConfiguration.LAN_MODE)) { LOG.info("LAN mode enabled"); } context.getServer().setStartTime(System.currentTimeMillis()); new com.springrts.springls.updateproperties.Activator().start(context.getFramework().getBundleContext()); new com.springrts.springls.ip2country.Activator().start(context.getFramework().getBundleContext()); new com.springrts.springls.nat.Activator().start(context.getFramework().getBundleContext()); new com.springrts.springls.statistics.Activator().start(context.getFramework().getBundleContext()); // start server: if (!context.getServerThread().startServer()) { context.getServerThread().closeServerAndExit(); } context.getCommandProcessors().init(); context.getServerThread().run(); }
From source file:com.kixeye.chassis.bootstrap.configuration.zookeeper.CuratorFrameworkBuilder.java
private CuratorFramework buildCuratorWithExhibitor(Configuration configuration) { LOGGER.debug("configuring zookeeper connection through Exhibitor..."); ExhibitorEnsembleProvider ensembleProvider = new KixeyeExhibitorEnsembleProvider(exhibitors, new KixeyeExhibitorRestClient(configuration.getBoolean(EXHIBITOR_USE_HTTPS.getPropertyName())), configuration.getString(EXHIBITOR_URI_PATH.getPropertyName()), configuration.getInt(EXHIBITOR_POLL_INTERVAL.getPropertyName()), new ExponentialBackoffRetry(configuration.getInt(EXHIBITOR_INITIAL_SLEEP_MILLIS.getPropertyName()), configuration.getInt(EXHIBITOR_MAX_RETRIES.getPropertyName()), configuration.getInt(EXHIBITOR_RETRIES_MAX_MILLIS.getPropertyName()))); //without this (undocumented) step, curator will attempt (and fail) to connect to a local instance of zookeeper (default behavior if no zookeeper connection string is provided) for //several seconds until the EnsembleProvider polls to get the SERVER list from Exhibitor. Polling before staring curator //ensures that the SERVER list from Exhibitor is already downloaded before curator attempts to connect to zookeeper. try {// www . j a v a 2s .c om ensembleProvider.pollForInitialEnsemble(); } catch (Exception e) { try { Closeables.close(ensembleProvider, true); } catch (IOException e1) { } throw new BootstrapException("Failed to initialize Exhibitor with host(s) " + exhibitors.getHostnames(), e); } CuratorFramework curator = CuratorFrameworkFactory.builder().ensembleProvider(ensembleProvider) .retryPolicy(buildZookeeperRetryPolicy(configuration)).build(); curator.getConnectionStateListenable().addListener(new ConnectionStateListener() { public void stateChanged(CuratorFramework client, ConnectionState newState) { LOGGER.debug("Connection state to ZooKeeper changed: " + newState); } }); return curator; }
From source file:de.nec.nle.siafu.output.CSVPrinter.java
/** * Builds a <code>CVSPrinter</code> object. If history is to be kept, this * already initializes the output file./* w w w .j ava2 s. co m*/ * * @param world * the world to print about * @param config * the simulation configuration file */ public CSVPrinter(final World world, final Configuration config) { this.world = world; this.outputPath = config.getString("output.csv.path"); this.keepHistory = config.getBoolean("output.csv.keephistory"); this.intervalInMillis = SECOND_TO_MS_FACTOR * config.getInt("output.csv.interval"); this.header = createHeader(); if (keepHistory) { initializeFile(outputPath); } }
From source file:es.udc.gii.common.eaf.algorithm.operator.reproduction.mutation.de.mutationStrategy.CurrentToPBestMutationStrategy.java
@Override public void configure(Configuration conf) { ConfWarning w = null;// w w w . jav a 2s. c o m super.configure(conf); if (conf.containsKey("p")) { this.p = conf.getDouble("p"); } else { w = new ConfWarning(this.getClass().getSimpleName() + ".p", this.p); } if (conf.containsKey("archive")) { this.archive = conf.getBoolean("archive"); } else { w = new ConfWarning(this.getClass().getSimpleName() + ".archive", Boolean.toString(this.archive)); } if (w != null) { w.warn(); } }
From source file:com.springrts.springls.Clients.java
/** * This method disconnects and removes a client from the clients list. * Also cleans up after him (channels, battles) and notifies other * users of his departure.//from ww w . ja va 2 s .co m * @param reason is used with LEFT command to notify other users on same * channel of this client's departure reason. It may be left blank ("") or * be set to <code>null</code> to give no reason. */ public boolean killClient(Client client, String reason) { int index = clients.indexOf(client); if (index == -1 || !client.isAlive()) { return false; } client.disconnect(); clients.remove(index); client.setAlive(false); String reasonNonNull = ((reason == null) || reason.trim().isEmpty()) ? "Quit" : reason; // let's remove client from all channels he is participating in: client.leaveAllChannels(reasonNonNull); if (client.getBattleID() != Battle.NO_BATTLE_ID) { Battle battle = context.getBattles().getBattleByID(client.getBattleID()); if (battle == null) { LOG.error("Invalid battle ID. Server will now exit!"); context.getServerThread().closeServerAndExit(); } // internally checks if the client is the founder and closes the // battle in that case context.getBattles().leaveBattle(client, battle); } if (client.getAccount().getAccess() != Account.Access.NONE) { sendToAllRegisteredUsers("REMOVEUSER " + client.getAccount().getName()); LOG.debug("Registered user killed: {}", client.getAccount().getName()); } else { LOG.debug("Unregistered user killed"); } Configuration conf = context.getService(Configuration.class); if (conf.getBoolean(ServerConfiguration.LAN_MODE)) { context.getAccountsService().removeAccount(client.getAccount()); } return true; }
From source file:com.evolveum.midpoint.init.TestConfigurationLoad.java
@Test public void test010SimpleConfigTest() { LOGGER.info("---------------- test010SimpleConfigTest -----------------"); System.clearProperty("midpoint.home"); LOGGER.info("midpoint.home => " + System.getProperty("midpoint.home")); assertNull(System.getProperty("midpoint.home"), "midpoint.home"); StartupConfiguration sc = new StartupConfiguration(); assertNotNull(sc);/* w w w . j a va2 s. c o m*/ sc.init(); Configuration c = sc.getConfiguration("midpoint.repository"); assertEquals(c.getString("repositoryServiceFactoryClass"), "com.evolveum.midpoint.repo.sql.SqlRepositoryFactory"); LOGGER.info(sc.toString()); @SuppressWarnings("unchecked") Iterator<String> i = c.getKeys(); while (i.hasNext()) { String key = i.next(); LOGGER.info(" " + key + " = " + c.getString(key)); } assertEquals(c.getBoolean("asServer"), true); assertEquals(c.getString("baseDir"), System.getProperty("midpoint.home")); }
From source file:com.springrts.springls.ServerThread.java
/** * Adds a default administrator account, if not running in LAN mode, * and if there are no accounts in the active accounts service. *///from w w w .j av a2 s. co m private void createAdminIfNoUsers() { Configuration conf = context.getService(Configuration.class); if (!conf.getBoolean(ServerConfiguration.LAN_MODE)) { AccountsService accountsService = context.getAccountsService(); if (accountsService.getAccountsSize() == 0) { Configuration defaults = ServerConfiguration.getDefaults(); String username = defaults.getString(ServerConfiguration.LAN_ADMIN_USERNAME); String password = defaults.getString(ServerConfiguration.LAN_ADMIN_PASSWORD); LOG.info("As there are no accounts yet, we are creating an" + " admin account: username=\"{}\", password=\"{}\"", username, password); Account admin = createAdmin(username, password); accountsService.addAccount(admin); accountsService.saveAccountsIfNeeded(); } } }