Java Code Examples for org.apache.brooklyn.util.time.Time#makeTimeStringRounded()

The following examples show how to use org.apache.brooklyn.util.time.Time#makeTimeStringRounded() . 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: JmxHelper.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
/**
 * Reconnects. If it already is connected, it disconnects first.
 *
 * @throws IOException
 */
public synchronized void reconnectWithRetryDampened() throws IOException {
    // If we've already tried reconnecting very recently, don't try again immediately
    if (failedReconnecting) {
        long timeSince = (System.currentTimeMillis() - failedReconnectingTime);
        if (timeSince < minTimeBetweenReconnectAttempts) {
            String msg = "Not reconnecting to JMX at "+url+" because attempt failed "+Time.makeTimeStringRounded(timeSince)+" ago";
            throw new IllegalStateException(msg);
        }
    }
    
    reconnect();
}
 
Example 2
Source File: EntityCleanupLongevityTestFixture.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
protected void doTestManyTimesAndAssertNoMemoryLeak(String testName, Runnable iterationBody) {
        int iterations = numIterations();
        Stopwatch timer = Stopwatch.createStarted();
        long last = timer.elapsed(TimeUnit.MILLISECONDS);
        
        long memUsedNearStart = -1;
        
        for (int i = 0; i < iterations; i++) {
            if (i % 100 == 0 || i<5) {
                long now = timer.elapsed(TimeUnit.MILLISECONDS);
                System.gc(); System.gc();
                String msg = testName+" iteration " + i + " at " + Time.makeTimeStringRounded(now) + " (delta "+Time.makeTimeStringRounded(now-last)+"), using "+
                    ((AbstractManagementContext)managementContext).getGarbageCollector().getUsageString()+
                    "; weak-refs app="+Iterables.size(weakApps.keySet())+" and locs="+Iterables.size(weakLocs.keySet());
                LOG.info(msg);
                if (i>=100 && memUsedNearStart<0) {
                    // set this the first time we've run 100 times (let that create a baseline with classes loaded etc)
                    memUsedNearStart = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
                }
                last = timer.elapsed(TimeUnit.MILLISECONDS);
            }
            iterationBody.run();
        }
        
        BrooklynStorage storage = ((ManagementContextInternal)managementContext).getStorage();
        Assert.assertTrue(storage.isMostlyEmpty(), "Not empty storage: "+storage);
        
        ConcurrentMap<Object, TaskScheduler> schedulers = ((BasicExecutionManager)managementContext.getExecutionManager()).getSchedulerByTag();
        // TODO would like to assert this
//        Assert.assertTrue( schedulers.isEmpty(), "Not empty schedulers: "+schedulers);
        // but weaker form for now
        Assert.assertTrue( schedulers.size() <= 3*iterations, "Not empty schedulers: "+schedulers.size()+" after "+iterations+", "+schedulers);
        
        // memory leak detection only applies to subclasses who run lots of iterations
        if (checkMemoryLeaks())
            assertNoMemoryLeak(memUsedNearStart, iterations);
    }
 
Example 3
Source File: JcloudsLocation.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
protected void waitForReachable(Callable<Boolean> checker, String hostAndPort, Iterable<LoginCredentials> credentialsToLog, ConfigBag setup, Duration timeout) {
    if (LOG.isDebugEnabled()) {
        List<String> credsToString = Lists.newArrayList();
        for (LoginCredentials creds : credentialsToLog) {
            String user = creds.getUser();
            String password;
            String key;
            if (Boolean.TRUE.equals(setup.get(LOG_CREDENTIALS))) {
                password = creds.getOptionalPassword().or("<absent>");
                key = creds.getOptionalPrivateKey().or("<absent>");
            } else {
                password = creds.getOptionalPassword().isPresent() ? "******" : "<absent>";
                key = creds.getOptionalPrivateKey().isPresent() ? "******" : "<absent>";
            }
            credsToString.add("user="+user+", password="+password+", key="+key);
        }

        LOG.debug("VM {}: reported online, now waiting {} for it to be contactable on {}; trying {} credential{}: {}",
                new Object[] {
                        getCreationString(setup), timeout,
                        hostAndPort,
                        Iterables.size(credentialsToLog),
                        Strings.s(Iterables.size(credentialsToLog)),
                        (credsToString.size() == 1) ? credsToString.get(0) : "(multiple!):" + Joiner.on("\n\t").join(credsToString)
                });
    }

    Stopwatch stopwatch = Stopwatch.createStarted();

    ReferenceWithError<Boolean> reachable = new Repeater("reachable repeater ")
            .backoff(Duration.ONE_SECOND, 2, Duration.TEN_SECONDS) // exponential backoff, to 10 seconds
            .until(checker)
            .limitTimeTo(timeout)
            .runKeepingError();

    if (!reachable.getWithoutError()) {
        throw new IllegalStateException("Connection failed for "
                +hostAndPort+" ("+getCreationString(setup)+") after waiting "
                +Time.makeTimeStringRounded(timeout), reachable.getError());
    }

    LOG.debug("VM {}: connection succeeded after {} on {}",new Object[] {
            getCreationString(setup), Time.makeTimeStringRounded(stopwatch),
            hostAndPort});
}
 
Example 4
Source File: Strings.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
/** @deprecated use {@link Time#makeTimeStringRounded(long)} */
@Deprecated
public static String makeTimeString(long utcMillis) {
    return Time.makeTimeStringRounded(utcMillis);
}
 
Example 5
Source File: ServiceFailureDetector.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
private String getTimeStringSince(Long time) {
    return time == null ? null : Time.makeTimeStringRounded(System.currentTimeMillis() - time);
}
 
Example 6
Source File: AbstractFailureDetector.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
private String getTimeStringSince(Long time) {
    return time == null ? null : Time.makeTimeStringRounded(System.currentTimeMillis() - time);
}
 
Example 7
Source File: HighAvailabilityManagerImpl.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
private static String timestampString(Long remoteTimestamp) {
    if (remoteTimestamp==null) return null;
    return remoteTimestamp+" / "+Time.makeTimeStringRounded( Duration.sinceUtc(remoteTimestamp))+" ago";
}