Example usage for java.lang Long getLong

List of usage examples for java.lang Long getLong

Introduction

In this page you can find the example usage for java.lang Long getLong.

Prototype

public static Long getLong(String nm) 

Source Link

Document

Determines the long value of the system property with the specified name.

Usage

From source file:org.kuali.mobility.shared.controllers.FileControllerTest.java

@Test
public void testRemoveFileFailOnService() {
    MockHttpServletRequest request = new MockHttpServletRequest(servletContext);
    Model uiModel = new ExtendedModelMap();

    Long fileHash = Long.getLong("42");
    File file = new File();
    file.setId(fileHash);/* w w  w  . j a  va2s  .  co m*/

    when(getFileService().findFileById(fileHash)).thenReturn(file);
    when(getFileService().removeFile(file)).thenReturn(false);

    String viewName;
    try {
        viewName = getController().removeFile(uiModel, request, fileHash);
    } catch (Exception e) {
        LOG.error(e.getLocalizedMessage(), e);
        viewName = null;
    }
    assertTrue("Failed to remove file.", INDEX.equals(viewName));
}

From source file:org.sensapp.android.sensappdroid.api.SensAppHelper.java

private static JSONObject mergeData(JSONObject localData, JSONObject webData) {
    JSONObject merged = webData;//www.j  a  v  a  2s. com
    if (!webData.has("e")) {
        return localData;
    }

    try {
        Long btWeb = webData.getLong("bt");
        Long btLoc = localData.getLong("bt");
        Long dif = btWeb - btLoc;

        JSONArray eLoc = localData.getJSONArray("e");
        for (int i = 0; i < eLoc.length(); i++) {
            JSONObject entry = eLoc.getJSONObject(i);
            entry.wait(100);
            Long time = Long.getLong(entry.getString("t"));
            Long updatedTime = time - dif;
            entry.put("t", updatedTime.toString());
            merged.accumulate("e", entry);
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    return merged;
}

From source file:org.wisdom.configuration.ConfigurationImpl.java

@Override
public Long getLong(String key) {
    Long v = Long.getLong(key);
    if (v == null) {
        try {//  w w  w.  j  a  v a  2s .c o  m
            return configuration.getLong(key);
        } catch (NoSuchElementException e) { //NOSONAR
            return null;
        }
    } else {
        return v;
    }
}

From source file:org.wisdom.configuration.ConfigurationImpl.java

@Override
public Long getLongWithDefault(String key, Long defaultValue) {
    Long value = Long.getLong(key);
    if (value == null) {
        return configuration.getLong(key, defaultValue);
    }/*from w  w  w. j av  a  2s  .c  om*/
    return value;
}

From source file:com.tc.server.UpdateCheckAction.java

private static long checkPeriodMillis(int days) {
    Long minutes = Long.getLong("terracotta.update-checker.next-check-minutes");
    long nextCheckTime;

    if (minutes != null) {
        nextCheckTime = minutes.longValue() * 60 * 1000;
    } else {//from   w  w  w.ja  v a  2  s  . co m
        nextCheckTime = 1000L * 60 * 60 * 24 * days;
    }

    return nextCheckTime;
}

From source file:org.wisdom.configuration.ConfigurationImpl.java

@Override
public Long getLongOrDie(String key) {
    Long value = Long.getLong(key);
    if (value == null) {
        throw new IllegalArgumentException(String.format(ERROR_KEYNOTFOUND, key));
    } else {/*from  www  . j av a  2 s.c om*/
        return value;
    }
}

From source file:org.jasig.ssp.util.importer.job.validation.map.metadata.database.MapColumnMetadata.java

public Object convertValueToType(String columnValue, MapReference mapReference,
        DatabaseConstraintMapValidationContext validation) {
    Object propertyValue = null;//from   w ww. j av  a2s  .c  o  m
    String typeAsString = "";
    if (columnValue != null) {
        try {
            switch (javaSqlType) {
            case Types.BIGINT:
                typeAsString = "BIGINT";
                propertyValue = Long.parseLong(columnValue);
                break;
            case Types.INTEGER:
                typeAsString = "INTEGER";
                propertyValue = Integer.parseInt(columnValue);
                break;
            case Types.DECIMAL:
                typeAsString = "DECIMAL";
            case Types.DOUBLE:
                typeAsString = "DOUBLE";
            case Types.FLOAT:
                typeAsString = "FLOAT";
            case Types.NUMERIC:
                typeAsString = "NUMERIC";
                propertyValue = new BigDecimal(columnValue);
                break;

            case Types.DATE:
                typeAsString = "DATE";
                propertyValue = DateUtils.parseDateStrictly(columnValue, DATE_PATTERNS);
                break;
            case Types.TIMESTAMP:
                typeAsString = "TIMESTAMP";
                propertyValue = new java.sql.Timestamp(Long.getLong(columnValue));
                break;
            case Types.TIME:
                typeAsString = "TIME";
                propertyValue = new Time(DateUtils.parseDateStrictly(columnValue, TIME_PATTERNS).getTime());
                break;
            default:
                typeAsString = javaSqlType.toString();
                propertyValue = columnValue;
                break;

            }
        } catch (Exception exception) {
            validation.addViolation(new UnableToParseMapViolation(mapReference, columnValue, typeAsString));
            propertyValue = columnValue;
        }

    }
    return propertyValue;
}

From source file:org.apache.hadoop.hdfs.qjournal.client.TestQJMWithFaults.java

/**
 * Test case in which three JournalNodes randomly flip flop between
 * up and down states every time they get an RPC.
 * //  w  ww.ja  va2s . c o m
 * The writer keeps track of the latest ACKed edit, and on every
 * recovery operation, ensures that it recovers at least to that
 * point or higher. Since at any given point, a majority of JNs
 * may be injecting faults, any writer operation is allowed to fail,
 * so long as the exception message indicates it failed due to injected
 * faults.
 * 
 * Given a random seed, the test should be entirely deterministic.
 */
@Test
public void testRandomized() throws Exception {
    long seed;
    Long userSpecifiedSeed = Long.getLong(RAND_SEED_PROPERTY);
    if (userSpecifiedSeed != null) {
        LOG.info("Using seed specified in system property");
        seed = userSpecifiedSeed;

        // If the user specifies a seed, then we should gather all the
        // IPC trace information so that debugging is easier. This makes
        // the test run about 25% slower otherwise.
        ((Log4JLogger) ProtobufRpcEngine.LOG).getLogger().setLevel(Level.ALL);
    } else {
        seed = new Random().nextLong();
    }
    LOG.info("Random seed: " + seed);

    Random r = new Random(seed);

    MiniJournalCluster cluster = new MiniJournalCluster.Builder(conf).build();

    // Format the cluster using a non-faulty QJM.
    QuorumJournalManager qjmForInitialFormat = createInjectableQJM(cluster);
    qjmForInitialFormat.format(FAKE_NSINFO);
    qjmForInitialFormat.close();

    try {
        long txid = 0;
        long lastAcked = 0;

        for (int i = 0; i < NUM_WRITER_ITERS; i++) {
            LOG.info("Starting writer " + i + "\n-------------------");

            QuorumJournalManager qjm = createRandomFaultyQJM(cluster, r);
            try {
                long recovered;
                try {
                    recovered = QJMTestUtil.recoverAndReturnLastTxn(qjm);
                } catch (Throwable t) {
                    LOG.info("Failed recovery", t);
                    checkException(t);
                    continue;
                }
                assertTrue(
                        "Recovered only up to txnid " + recovered + " but had gotten an ack for " + lastAcked,
                        recovered >= lastAcked);

                txid = recovered + 1;

                // Periodically purge old data on disk so it's easier to look
                // at failure cases.
                if (txid > 100 && i % 10 == 1) {
                    qjm.purgeLogsOlderThan(txid - 100);
                }

                Holder<Throwable> thrown = new Holder<Throwable>(null);
                for (int j = 0; j < SEGMENTS_PER_WRITER; j++) {
                    lastAcked = writeSegmentUntilCrash(cluster, qjm, txid, 4, thrown);
                    if (thrown.held != null) {
                        LOG.info("Failed write", thrown.held);
                        checkException(thrown.held);
                        break;
                    }
                    txid += 4;
                }
            } finally {
                qjm.close();
            }
        }
    } finally {
        cluster.shutdown();
    }
}

From source file:er.extensions.appserver.ERXApplication.java

/**
 * The ERXApplication constructor.//ww w. j av a  2s  .co m
 */
public ERXApplication() {
    super();

    /* 
     * ERXComponentRequestHandler is a patched version of the original WOComponentRequestHandler
     * This method will tell Application to used the patched, the patched version will disallow direct component access by name
     * If you want to use the unpatched version set the property ERXDirectComponentAccessAllowed to true
     */
    if (!ERXProperties.booleanForKeyWithDefault("ERXDirectComponentAccessAllowed", false)) {
        ERXComponentRequestHandler erxComponentRequestHandler = new ERXComponentRequestHandler();
        registerRequestHandler(erxComponentRequestHandler, componentRequestHandlerKey());
    }

    ERXStats.initStatisticsIfNecessary();

    // WOFrameworksBaseURL and WOApplicationBaseURL properties are broken in 5.4.  
    // This is the workaround.
    frameworksBaseURL();
    applicationBaseURL();
    if (System.getProperty("WOFrameworksBaseURL") != null) {
        setFrameworksBaseURL(System.getProperty("WOFrameworksBaseURL"));
    }
    if (System.getProperty("WOApplicationBaseURL") != null) {
        setApplicationBaseURL(System.getProperty("WOApplicationBaseURL"));
    }

    if (!ERXConfigurationManager.defaultManager().isDeployedAsServlet()
            && (!wasERXApplicationMainInvoked || _loader == null)) {
        _displayMainMethodWarning();
    }
    // try {
    //    NSBundle.mainBundle().versionString();
    // } catch (NoSuchMethodError e) {
    //    throw new RuntimeException("No versionString() method in NSBundle found. \nThis means your class path is incorrect. Adjust it so that ERJars comes before JavaFoundation.");
    // }
    if (_loader == null) {
        System.out.println("No loader: " + System.getProperty("java.class.path"));
    } else if (!_loader.didLoad()) {
        throw new RuntimeException(
                "ERXExtensions have not been initialized. Debugging information can be enabled by adding the JVM argument: '-Der.extensions.appserver.projectBundleLoading=DEBUG'. Please report the classpath and the rest of the bundles to the Wonder mailing list: "
                        + "\nRemaining frameworks: " + (_loader == null ? "none" : _loader.allFrameworks)
                        + "\nClasspath: " + System.getProperty("java.class.path"));
    }
    if ("JavaFoundation".equals(NSBundle.mainBundle().name())) {
        throw new RuntimeException(
                "Your main bundle is \"JavaFoundation\".  You are not launching this WO application properly.  If you are using Eclipse, most likely you launched your WOA as a \"Java Application\" instead of a \"WO Application\".");
    }
    // ak: telling Log4J to re-init the Console appenders so we get logging
    // into WOOutputPath again
    for (Enumeration e = Logger.getRootLogger().getAllAppenders(); e.hasMoreElements();) {
        Appender appender = (Appender) e.nextElement();
        if (appender instanceof ConsoleAppender) {
            ConsoleAppender app = (ConsoleAppender) appender;
            app.activateOptions();
        }
    }
    if (_loader != null) {
        _loader._checker.reportErrors();
        _loader._checker = null;
    }
    didCreateApplication();
    NSNotificationCenter.defaultCenter()
            .postNotification(new NSNotification(ApplicationDidCreateNotification, this));
    installPatches();
    lowMemBufferSize = ERXProperties.intForKeyWithDefault("er.extensions.ERXApplication.lowMemBufferSize", 0);
    if (lowMemBufferSize > 0) {
        lowMemBuffer = new byte[lowMemBufferSize];
    }
    registerRequestHandler(new ERXDirectActionRequestHandler(), directActionRequestHandlerKey());
    if (_rapidTurnaroundActiveForAnyProject() && isDirectConnectEnabled()) {
        registerRequestHandler(new ERXStaticResourceRequestHandler(), "_wr_");
    }
    registerRequestHandler(new ERXDirectActionRequestHandler(ERXDirectAction.class.getName(), "stats", false),
            "erxadm");
    // AK: remove comment to get delayed request handling
    // registerRequestHandler(new DelayedRequestHandler(), DelayedRequestHandler.KEY);

    Long timestampLag = Long.getLong("EOEditingContextDefaultFetchTimestampLag");
    if (timestampLag != null)
        EOEditingContext.setDefaultFetchTimestampLag(timestampLag.longValue());

    String defaultEncoding = System.getProperty("er.extensions.ERXApplication.DefaultEncoding");
    if (defaultEncoding != null) {
        log.debug("Setting default encoding to \"" + defaultEncoding + "\"");
        setDefaultEncoding(defaultEncoding);
    }

    String defaultMessageEncoding = System.getProperty("er.extensions.ERXApplication.DefaultMessageEncoding");
    if (defaultMessageEncoding != null) {
        log.debug("Setting WOMessage default encoding to \"" + defaultMessageEncoding + "\"");
        WOMessage.setDefaultEncoding(defaultMessageEncoding);
    }

    log.info("Wonder version: " + ERXProperties.wonderVersion());

    // Configure the WOStatistics CLFF logging since it can't be controlled
    // by a property, grrr.
    configureStatisticsLogging();

    NSNotificationCenter.defaultCenter().addObserver(this,
            new NSSelector("finishInitialization", ERXConstant.NotificationClassArray),
            WOApplication.ApplicationWillFinishLaunchingNotification, null);

    NSNotificationCenter.defaultCenter().addObserver(this,
            new NSSelector("didFinishLaunching", ERXConstant.NotificationClassArray),
            WOApplication.ApplicationDidFinishLaunchingNotification, null);

    Boolean useUnlocker = useEditingContextUnlocker();
    if (useUnlocker != null) {
        ERXEC.setUseUnlocker(useUnlocker);
    }
    Boolean traceOpenLocks = traceOpenEditingContextLocks();
    if (traceOpenLocks != null) {
        ERXEC.setTraceOpenLocks(traceOpenLocks);
    }

    // Signal handling support
    if (ERXGracefulShutdown.isEnabled()) {
        ERXGracefulShutdown.installHandler();
    }
    // AK: this makes it possible to retrieve the creating instance from an
    // NSData PK.
    // it should still be unique, as one host can only have one running
    // instance to a port
    EOTemporaryGlobalID._setProcessIdentificationBytesFromInt(port().intValue());

    _memoryStarvedThreshold = ERXProperties.bigDecimalForKey("er.extensions.ERXApplication.memoryThreshold"); // MS: Kept around for backwards compat, replaced by memoryStarvedThreshold now
    _memoryStarvedThreshold = ERXProperties.bigDecimalForKeyWithDefault(
            "er.extensions.ERXApplication.memoryStarvedThreshold", _memoryStarvedThreshold);
    _memoryLowThreshold = ERXProperties.bigDecimalForKeyWithDefault(
            "er.extensions.ERXApplication.memoryLowThreshold", _memoryLowThreshold);

    _replaceApplicationPathPattern = ERXProperties
            .stringForKey("er.extensions.ERXApplication.replaceApplicationPath.pattern");
    if (_replaceApplicationPathPattern != null && _replaceApplicationPathPattern.length() == 0) {
        _replaceApplicationPathPattern = null;
    }
    _replaceApplicationPathReplace = ERXProperties
            .stringForKey("er.extensions.ERXApplication.replaceApplicationPath.replace");

    if (_replaceApplicationPathPattern == null && rewriteDirectConnectURL()) {
        _replaceApplicationPathPattern = "/cgi-bin/WebObjects/" + name() + applicationExtension();
        if (_replaceApplicationPathReplace == null) {
            _replaceApplicationPathReplace = "";
        }
    }
}