List of usage examples for java.lang System getProperty
public static String getProperty(String key, String def)
From source file:com.clicktravel.cheddar.server.rest.application.RestApplication.java
/** * Starts the RestServer to listen on the given port and address combination * * @param args String arguments, {@code [context [service-port [status-port [bind-address] ] ] ]} where * <ul>//ww w . j ava 2s . c om * <li>{@code context} - Name of application, defaults to {@code UNKNOWN}</li> * <li>{@code service-port} - Port number for REST service endpoints, defaults to {@code 8080}</li> * <li>{@code status-port} - Port number for REST status endpoints ({@code /status} and * {@code /status/healthCheck}), defaults to {@code service-port + 100}</li> * <li>{@code bind-address} - Local IP address to bind server to, defaults to {@code 0.0.0.0}</li> * </ul> * * @throws Exception */ public static void main(final String... args) { final String context = args.length > 0 ? args[0] : "UNKNOWN"; final int servicePort = args.length > 1 ? Integer.parseInt(args[1]) : 8080; final int statusPort = args.length > 2 ? Integer.parseInt(args[2]) : servicePort + 100; final String bindAddress = args.length > 3 ? args[3] : "0.0.0.0"; MDC.put("context", context); MDC.put("hostId", System.getProperty("host.id", "UNKNOWN")); SLF4JBridgeHandler.removeHandlersForRootLogger(); SLF4JBridgeHandler.install(); final Logger logger = LoggerFactory.getLogger(RestApplication.class); try { logger.info("Java process starting"); logger.debug(String.format("java.version:[%s] java.vendor:[%s]", System.getProperty("java.version"), System.getProperty("java.vendor"))); @SuppressWarnings("resource") final ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext( "applicationContext.xml"); logger.debug("Finished getting ApplicationContext"); final ApplicationLifecycleController applicationLifecycleController = applicationContext .getBean(ApplicationLifecycleController.class); Runtime.getRuntime().addShutdownHook(new Thread(() -> { logger.info("Shutdown hook invoked - Commencing graceful termination of Java process"); applicationLifecycleController.shutdownApplication(); logger.info("Java process terminating"); })); applicationLifecycleController.startApplication(servicePort, statusPort, bindAddress); Thread.currentThread().join(); } catch (final InterruptedException e) { logger.info("Java process interrupted"); System.exit(1); } catch (final Exception e) { logger.error("Error starting Java process", e); System.exit(1); } }
From source file:androidimporter.AndroidImporter.java
public static void main(String[] args) throws ParseException { //"/usr/local/apache-ant/bin/ant" String antPath = System.getProperty("ANT_PATH", System.getenv("ANT_PATH")); if (antPath == null || !new File(antPath).exists()) { throw new RuntimeException("Cannot find ant at " + antPath + ". Please specify location to ant via the ANT_PATH environment variable or java system property."); }//w w w . j a v a 2s. com Options opts = new Options() .addOption("i", "android-resource-dir", true, "Android project res directory path") .addOption("o", "cn1-project-dir", true, "Path to the CN1 output project directory.") .addOption("r", "cn1-resource-file", false, "Path to CN1 output .res file. Defaults to theme.res in project dir") .addOption("p", "package", true, "Java package to place GUI forms in.") .addOption("h", "help", false, "Usage instructions"); CommandLineParser parser = new DefaultParser(); CommandLine line = parser.parse(opts, args); if (line.hasOption("help")) { showHelp(opts); System.exit(0); } args = line.getArgs(); if (args.length < 1) { System.out.println("No command provided."); showHelp(opts); System.exit(0); } switch (args[0]) { case "import-project": { if (!line.hasOption("android-resource-dir") || !line.hasOption("cn1-project-dir") || !line.hasOption("package")) { System.out.println("Please provide android-resource-dir, package, and cn1-project-dir options"); showHelp(opts); System.exit(1); } File resDir = findResDir(new File(line.getOptionValue("android-resource-dir"))); if (resDir == null || !resDir.isDirectory()) { System.out.println("Failed to find android resource directory from provided value"); showHelp(opts); System.exit(1); } File projDir = new File(line.getOptionValue("cn1-project-dir")); File resFile = new File(projDir, "src" + File.separator + "theme.res"); if (line.hasOption("cn1-resource-file")) { resFile = new File(line.getOptionValue("cn1-resource-file")); } JavaSEPort.setShowEDTViolationStacks(false); JavaSEPort.setShowEDTWarnings(false); JFrame frm = new JFrame("Placeholder"); frm.setVisible(false); Display.init(frm.getContentPane()); JavaSEPort.setBaseResourceDir(resFile.getParentFile()); try { System.out.println("About to import project at " + resDir.getAbsolutePath()); System.out.println("Codename One Output Project: " + projDir.getAbsolutePath()); System.out.println("Resource file: " + resFile.getAbsolutePath()); System.out.println("Java Package: " + line.getOptionValue("package")); AndroidProjectImporter.importProject(resDir, projDir, resFile, line.getOptionValue("package")); Runtime.getRuntime().exec(new String[] { antPath, "init" }, new String[] {}, resFile.getParentFile().getParentFile()); //runAnt(new File(resFile.getParentFile().getParentFile(), "build.xml"), "init"); System.exit(0); } catch (Exception ex) { ex.printStackTrace(); } finally { System.exit(0); } break; } default: System.out.println("Unknown command " + args[0]); showHelp(opts); break; } }
From source file:edu.duke.cabig.c3pr.webservice.subjectmanagement.client.Client.java
/** * @param args//from w w w.ja v a2s. com * @throws Exception */ public static void main(String[] args) throws Exception { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( new String[] { System.getProperty("context", "applicationContext.xml") }); SubjectManagement client = (SubjectManagement) context.getBean("subjectManagementClient"); QuerySubjectRequest request = new QuerySubjectRequest(); Subject subject = new Subject(); request.setSubject(subject); Person person = new Person(); subject.setEntity(person); // We need to set these to empties in order to pass schema validation on the server side // Need to revisit this issue and perhaps change the XSD: setting fields to empties each time // does not make a lot of sense. person.setAdministrativeGenderCode(new CD()); person.setBirthDate(new TSDateTime()); person.setDeathDate(new TSDateTime()); person.setDeathIndicator(new BL()); person.setEthnicGroupCode(new DSETCD()); person.setMaritalStatusCode(new CD()); person.setName(new DSETENPN()); person.setPostalAddress(new DSETAD()); person.setRaceCode(new DSETCD()); person.setTelecomAddress(new BAGTEL()); // make repeated requests in a loop to cache things, reduce swapping. for (int i = 0; i < 2; i++) { client.querySubject(request); } long start = System.currentTimeMillis(); QuerySubjectResponse response = executeAndGetResponse(client, request); long end = System.currentTimeMillis(); for (Subject subj : response.getSubjects().getItem()) { log.info("Found subject with ID: " + subj.getEntity().getBiologicEntityIdentifier().get(0).getIdentifier().getExtension()); } log.info("Total subjects: " + response.getSubjects().getItem().size()); log.info("Processing time: " + ((end - start) / 1000.0) + " seconds."); }
From source file:de.ingrid.interfaces.csw.admin.IndexDriver.java
/** * @param args//from w w w . j a v a 2s . c o m * @throws Exception */ public static void main(String[] args) throws Exception { if (!System.getProperties().containsKey("jetty.webapp")) log.warn("Property 'jetty.webapp' not defined! Using default webapp directory, which is '" + DEFAULT_WEBAPP_DIR + "'."); if (!System.getProperties().containsKey("jetty.port")) log.warn("Property 'jetty.port' not defined! Using default port, which is '" + DEFAULT_JETTY_PORT + "'."); WebAppContext webAppContext = new WebAppContext(System.getProperty("jetty.webapp", DEFAULT_WEBAPP_DIR), "/"); Server server = new Server(Integer.getInteger("jetty.port", DEFAULT_JETTY_PORT)); // fix slow startup time on virtual machine env. HashSessionIdManager hsim = new HashSessionIdManager(); hsim.setRandom(new Random()); server.setSessionIdManager(hsim); server.setHandler(webAppContext); server.start(); WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext( webAppContext.getServletContext(), "org.springframework.web.servlet.FrameworkServlet.CONTEXT.springapp"); IndexRunnable r = (IndexRunnable) wac.getBean("indexRunnable"); r.run(); System.out.println("Try to stopping the iPlug..."); server.stop(); System.out.println("iPlug is stopped."); }
From source file:org.zaizi.sensefy.ui.SensefySearchUiApplication.java
public static void main(String[] args) { // SpringApplication.run(SensefySearchUiApplication.class, args); SpringApplication.run(SensefySearchUiApplication.class, args); int port = Integer.parseInt(System.getProperty("jetty.port", "8080")); int requestHeaderSize = Integer.parseInt(System.getProperty("jetty.header.size", "65536")); Server server = new Server(port); ProtectionDomain domain = SensefySearchUiApplication.class.getProtectionDomain(); URL location = domain.getCodeSource().getLocation(); // Set request header size // server.getConnectors()[0].setRequestHeaderSize(requestHeaderSize); WebAppContext webapp = new WebAppContext(); webapp.setContextPath("/ui"); webapp.setDescriptor(location.toExternalForm() + "/WEB-INF/web.xml"); webapp.setServer(server);/*from www . j a v a2 s. c o m*/ webapp.setWar(location.toExternalForm()); // (Optional) Set the directory the war will extract to. // If not set, java.io.tmpdir will be used, which can cause problems // if the temp directory gets cleaned periodically. // Your build scripts should remove this directory between deployments // webapp.setTempDirectory(new File("/path/to/webapp-directory")); server.setHandler(webapp); try { server.start(); server.join(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:de.uniwue.dmir.heatmap.EntryPointIncremental.java
@SuppressWarnings({ "rawtypes", "unchecked" }) public static void main(String[] args) throws IOException, ParseException { DateFormat df = new SimpleDateFormat(DATE_FORMAT); SimpleDateFormat backupDf = new SimpleDateFormat(BACKUP_DATE_FORMAT); String workDir = System.getProperty("workDir", "."); LOGGER.debug("Work dir: {}", workDir); String configDir = System.getProperty("configDir", "."); LOGGER.debug("Config dir: {}", configDir); File seedDir = new File(workDir, SEED_DIR); LOGGER.debug("Seed dir: {}", seedDir); File currentDir = new File(workDir, CURRENT_DIR); LOGGER.debug("Current dir: {}", currentDir); File backupDir = new File(workDir, BACKUP_DIR); LOGGER.debug("Backup dir: {}", backupDir); String initialMinTimeString = System.getProperty("minTime"); LOGGER.debug("Initial minimal time parameter: {}", initialMinTimeString); Date initialMinTime = initialMinTimeString == null ? new Date(0) : df.parse(initialMinTimeString); LOGGER.debug("Initial minimal time: {}", df.format(initialMinTime)); String absoluteMaxTimeString = System.getProperty("maxTime"); LOGGER.debug("Absolute maximal time parameter: {}", absoluteMaxTimeString); Date absoluteMaxTime = absoluteMaxTimeString == null ? new Date() : new SimpleDateFormat(DATE_FORMAT).parse(absoluteMaxTimeString); LOGGER.debug("Absolute maximal time: {}", df.format(absoluteMaxTime)); String incrementalFile = new File("file:" + configDir, INCREMENTAL_FILE).getPath(); String settingsFile = new File("file:" + configDir, HEATMAP_PROCESSOR__FILE).getPath(); LOGGER.debug("Initializing incremental control file: {}", incrementalFile); FileSystemXmlApplicationContext incrementalContext = new FileSystemXmlApplicationContext(incrementalFile); // get point limit int pointLimit = Integer .parseInt(incrementalContext.getBeanFactory().resolveEmbeddedValue("${point.limit}")); LOGGER.debug("Print limit: {}", pointLimit); // get backups to keep int backupsToKeep = Integer .parseInt(incrementalContext.getBeanFactory().resolveEmbeddedValue("${backups.to.keep}")); LOGGER.debug("Backups to keep: {}", pointLimit); LOGGER.debug("Initializing process components (manager and limiter)."); IProcessManager processManager = incrementalContext.getBean(IProcessManager.class); IProcessLimiter processLimiter = incrementalContext.getBean(IProcessLimiter.class); LOGGER.debug("Starting incremental loop."); while (true) { // break as soon as no new points are available // cleanup --- just in case LOGGER.debug("Deleting \"current\" dir."); FileUtils.deleteDirectory(currentDir); // copy from seed to current LOGGER.debug("Copying seed."); seedDir.mkdirs();//from w ww . j ava 2 s. c o m FileUtils.copyDirectory(seedDir, currentDir); // get min time LOGGER.debug("Getting minimal time ..."); Date minTime = initialMinTime; ProcessManagerEntry entry = processManager.getEntry(); if (entry != null && entry.getMaxTime() != null) { minTime = entry.getMaxTime(); } LOGGER.debug("Minimal time: {}", new SimpleDateFormat(DATE_FORMAT).format(minTime)); // break if we processed all available points (minTime is greater than or equal to absoluteMaxTime) if (minTime.getTime() >= absoluteMaxTime.getTime()) { LOGGER.debug("Processed all points."); break; } // get the maximal time LOGGER.debug("Get maximal time."); // get the time from the newest point in our point range (pointMaxTime) ... Date pointMaxTime = processLimiter.getMaxTime(minTime, pointLimit); // ... and possibly break the loop if no new points are available if (pointMaxTime == null) break; // set the max time and make sure we are not taking to many points // (set max time to the minimum of pointMaxTime and absoluteMaxTime) Date maxTime = pointMaxTime.getTime() > absoluteMaxTime.getTime() ? absoluteMaxTime : pointMaxTime; LOGGER.debug("Maximal time: {}", new SimpleDateFormat(DATE_FORMAT).format(maxTime)); // start process processManager.start(minTime); System.setProperty("minTimestamp", new SimpleDateFormat(DATE_FORMAT).format(minTime)); System.setProperty("maxTimestamp", new SimpleDateFormat(DATE_FORMAT).format(maxTime)); FileSystemXmlApplicationContext heatmapContext = new FileSystemXmlApplicationContext(settingsFile); IHeatmap heatmap = heatmapContext.getBean(HEATMAP_BEAN, IHeatmap.class); ITileProcessor tileProcessor = heatmapContext.getBean(WRITER_BEAN, ITileProcessor.class); heatmap.processTiles(tileProcessor); tileProcessor.close(); heatmapContext.close(); // finish process processManager.finish(maxTime); // move old seed if (backupsToKeep > 0) { FileUtils.moveDirectory(seedDir, new File(backupDir, backupDf.format(minTime))); // minTime is the maxTime of the seed // cleanup backups String[] backups = backupDir.list(DirectoryFileFilter.DIRECTORY); File oldestBackup = null; if (backups.length > backupsToKeep) { for (String bs : backups) { File b = new File(backupDir, bs); if (oldestBackup == null || oldestBackup.lastModified() > b.lastModified()) { oldestBackup = b; } } FileUtils.deleteDirectory(oldestBackup); } } else { FileUtils.deleteDirectory(seedDir); } // move new seed FileUtils.moveDirectory(currentDir, seedDir); } incrementalContext.close(); }
From source file:com.cloudera.cli.validator.Main.java
public static void main(String[] args) throws IOException { String appName = System.getProperty("app.name", "app"); Main app = new Main(appName, System.out, System.err); int ret = app.run(args); System.exit(ret);/*from ww w .ja v a2s.com*/ }
From source file:org.zaizi.sensefy.auth.AuthServerApplication.java
public static void main(String[] args) { SpringApplication.run(AuthServerApplication.class, args); int port = Integer.parseInt(System.getProperty("jetty.port", "8080")); int requestHeaderSize = Integer.parseInt(System.getProperty("jetty.header.size", "65536")); Server server = new Server(port); server.setAttribute("org.eclipse.jetty.server.Request.maxFormContentSize", -1); ProtectionDomain domain = AuthServerApplication.class.getProtectionDomain(); URL location = domain.getCodeSource().getLocation(); // Set request header size // server.getConnectors()[0].setRequestHeaderSize(requestHeaderSize); WebAppContext webapp = new WebAppContext(); webapp.setContextPath("/auth"); webapp.setDescriptor(location.toExternalForm() + "/WEB-INF/web.xml"); webapp.setServer(server);//from ww w . j a v a 2 s.com webapp.setWar(location.toExternalForm()); // (Optional) Set the directory the war will extract to. // If not set, java.io.tmpdir will be used, which can cause problems // if the temp directory gets cleaned periodically. // Your build scripts should remove this directory between deployments // webapp.setTempDirectory(new File("/path/to/webapp-directory")); server.setHandler(webapp); try { server.start(); server.join(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:ffx.xray.TimerTest.java
public static void main(String args[]) { // Parameters collection from original Timer script String pdbname = System.getProperty("pdbFile", "1N7S.pdb"); String mtzname = System.getProperty("mtzFile", null); String cifname = System.getProperty("cifFile", null); final boolean ciOnly = false; final String info = "SNARE complex"; final double r = 19.412671496011; final double rfree = 21.555930987573; final double sigmaA = 0.9336853524690557; final double sigmaW = 0.13192537249786418; boolean ci = System.getProperty("ffx.ci", "false").equalsIgnoreCase("true"); if (!ci && ciOnly) { crystalStats = null;//from ww w . j a v a2s .com return; } int index = pdbname.lastIndexOf("."); String name = pdbname.substring(0, index); // load the structure MolecularAssembly molecularAssembly; File structure, mtzFile, cifFile; structure = new File(pdbname); PotentialsFileOpener opener = new PotentialsFileOpener(structure); opener.run(); molecularAssembly = opener.getAssembly(); mtzFile = new File(mtzname); cifFile = new File(cifname); // load any properties associated with it CompositeConfiguration properties = Keyword.loadProperties(structure); // read in Fo/sigFo/FreeR MTZFilter mtzFilter = new MTZFilter(); CIFFilter cifFilter = new CIFFilter(); Crystal crystal = Crystal.checkProperties(properties); Resolution resolution = Resolution.checkProperties(properties); if (crystal == null || resolution == null) { if (mtzname != null) { reflectionList = mtzFilter.getReflectionList(mtzFile); } else { reflectionList = cifFilter.getReflectionList(cifFile); } } else { reflectionList = new ReflectionList(crystal, resolution); } refinementData = new DiffractionRefinementData(properties, reflectionList); if (mtzname != null) { // assertTrue(info + " mtz file should be read in without errors", // mtzFilter.readFile(mtzFile, reflectionList, refinementData, // properties)); } else { // assertTrue(info + " cif file should be read in without errors", // cifFilter.readFile(cifFile, reflectionList, refinementData, // properties)); } ForceFieldFilter forceFieldFilter = new ForceFieldFilter(properties); ForceField forceField = forceFieldFilter.parse(); // associate molecular assembly with the structure, set up forcefield molecularAssembly.setForceField(forceField); PDBFilter pdbFile = new PDBFilter(structure, molecularAssembly, forceField, properties); pdbFile.readFile(); pdbFile.applyAtomProperties(); molecularAssembly.finalize(true, forceField); ForceFieldEnergy energy = new ForceFieldEnergy(molecularAssembly, pdbFile.getCoordRestraints()); List<Atom> atomList = molecularAssembly.getAtomList(); Atom atomArray[] = atomList.toArray(new Atom[atomList.size()]); // set up FFT and run it parallelTeam = new ParallelTeam(); CrystalReciprocalSpace crs = new CrystalReciprocalSpace(reflectionList, atomArray, parallelTeam, parallelTeam, false); crs.computeDensity(refinementData.fc); refinementData.setCrystalReciprocalSpace_fc(crs); crs = new CrystalReciprocalSpace(reflectionList, atomArray, parallelTeam, parallelTeam, true); crs.computeDensity(refinementData.fs); refinementData.setCrystalReciprocalSpace_fs(crs); ScaleBulkMinimize scaleBulkMinimize = new ScaleBulkMinimize(reflectionList, refinementData, crs, parallelTeam); scaleBulkMinimize.minimize(6, 1.0e-4); SigmaAMinimize sigmaAMinimize = new SigmaAMinimize(reflectionList, refinementData, parallelTeam); sigmaAMinimize.minimize(7, 2.0e-2); SplineMinimize splineMinimize = new SplineMinimize(reflectionList, refinementData, refinementData.spline, SplineEnergy.Type.FOFC); splineMinimize.minimize(7, 1e-5); crystalStats = new CrystalStats(reflectionList, refinementData); scaleBulkMinimize = new ScaleBulkMinimize(reflectionList, refinementData, refinementData.crs_fs, parallelTeam); ScaleBulkEnergy scaleBulkEnergy = scaleBulkMinimize.getScaleBulkEnergy(); int n = scaleBulkMinimize.getNumberOfVariables(); double x[] = new double[n]; double g[] = new double[n]; scaleBulkMinimize.getCoordinates(x); scaleBulkEnergy.energyAndGradient(x, g); double delta = 1.0e-4; double tolerance = 1.0e-4; logger.info(String.format("SCATTER TEST")); for (int i = 0; i < 30; i++) { long time = -System.nanoTime(); scaleBulkEnergy.energyAndGradient(x, g); time += System.nanoTime(); logger.info(String.format(" Time %12.8f", time * 1.0e-9)); } }
From source file:com.setronica.ucs.server.MessageServer.java
public static void main(String[] args) throws Exception { String hostname = System.getProperty("host", "localhost"); String portStr = System.getProperty("port", "1985"); Integer port = Integer.valueOf(portStr); String zkConnect = System.getProperty("zkConnect"); if (zkConnect != null && zkConnect.length() > 0) { MessageServer server = new MessageServer(); server.registerService(hostname, port, zkConnect); } else {/*from ww w . j ava2 s.c o m*/ ClassPathXmlApplicationContext applicationContext = bootstrapMemory(); EventLoop eventLoop = createMsgPackRPCServer(applicationContext, hostname, port); try { eventLoop.join(); } catch (InterruptedException e) { eventLoop.shutdown(); eventLoop.join(); } } }