Search in sources :

Example 96 with TimeUnit

use of java.util.concurrent.TimeUnit in project tomee by apache.

the class Timeout$JAXB method _read.

public static final Timeout _read(final XoXMLStreamReader reader, RuntimeContext context) throws Exception {
    // Check for xsi:nil
    if (reader.isXsiNil()) {
        return null;
    }
    if (context == null) {
        context = new RuntimeContext();
    }
    final Timeout timeout = new Timeout();
    context.beforeUnmarshal(timeout, LifecycleCallback.NONE);
    // Check xsi:type
    final QName xsiType = reader.getXsiType();
    if (xsiType != null) {
        if (("access-timeoutType" != xsiType.getLocalPart()) || ("http://java.sun.com/xml/ns/javaee" != xsiType.getNamespaceURI())) {
            return context.unexpectedXsiType(reader, Timeout.class);
        }
    }
    // Read attributes
    for (final Attribute attribute : reader.getAttributes()) {
        if (("id" == attribute.getLocalName()) && (("" == attribute.getNamespace()) || (attribute.getNamespace() == null))) {
            // ATTRIBUTE: id
            final String id = Adapters.collapsedStringAdapterAdapter.unmarshal(attribute.getValue());
            context.addXmlId(reader, id, timeout);
            timeout.id = id;
        } else if (XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI != attribute.getNamespace()) {
            context.unexpectedAttribute(attribute, new QName("", "id"));
        }
    }
    // Read elements
    for (final XoXMLStreamReader elementReader : reader.getChildElements()) {
        if (("timeout" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
            // ELEMENT: timeout
            final Long timeout1 = Long.valueOf(elementReader.getElementAsString());
            timeout.timeout = timeout1;
        } else if (("unit" == elementReader.getLocalName()) && ("http://java.sun.com/xml/ns/javaee" == elementReader.getNamespaceURI())) {
            // ELEMENT: unit
            final String unitRaw = elementReader.getElementAsString();
            final TimeUnit unit;
            try {
                unit = Adapters.timeUnitAdapterAdapter.unmarshal(unitRaw);
            } catch (final Exception e) {
                context.xmlAdapterError(elementReader, TimeUnitAdapter.class, TimeUnit.class, TimeUnit.class, e);
                continue;
            }
            if (unit != null) {
                timeout.unit = unit;
            }
        } else {
            context.unexpectedElement(elementReader, new QName("http://java.sun.com/xml/ns/javaee", "timeout"), new QName("http://java.sun.com/xml/ns/javaee", "unit"));
        }
    }
    context.afterUnmarshal(timeout, LifecycleCallback.NONE);
    return timeout;
}
Also used : Attribute(org.metatype.sxc.util.Attribute) QName(javax.xml.namespace.QName) TimeUnit(java.util.concurrent.TimeUnit) RuntimeContext(org.metatype.sxc.jaxb.RuntimeContext) XoXMLStreamReader(org.metatype.sxc.util.XoXMLStreamReader)

Example 97 with TimeUnit

use of java.util.concurrent.TimeUnit in project camel by apache.

the class DefaultJolokiaCamelController method getCamelContextInformation.

@Override
public Map<String, Object> getCamelContextInformation(String camelContextName) throws Exception {
    if (jolokia == null) {
        throw new IllegalStateException("Need to connect to remote jolokia first");
    }
    Map<String, Object> answer = new LinkedHashMap<String, Object>();
    ObjectName found = lookupCamelContext(camelContextName);
    if (found != null) {
        String pattern = String.format("%s:context=%s,type=services,name=DefaultTypeConverter", found.getDomain(), found.getKeyProperty("context"));
        ObjectName tc = ObjectName.getInstance(pattern);
        String pattern2 = String.format("%s:context=%s,type=services,name=DefaultAsyncProcessorAwaitManager", found.getDomain(), found.getKeyProperty("context"));
        ObjectName am = ObjectName.getInstance(pattern2);
        List<J4pReadRequest> list = new ArrayList<J4pReadRequest>();
        list.add(new J4pReadRequest(found));
        list.add(new J4pReadRequest(tc));
        list.add(new J4pReadRequest(am));
        List<J4pReadResponse> rr = jolokia.execute(list);
        if (rr != null && rr.size() > 0) {
            // camel context attributes
            J4pReadResponse first = rr.get(0);
            for (String key : first.getAttributes()) {
                answer.put(asKey(key), first.getValue(key));
            }
            // type converter attributes
            if (rr.size() >= 2) {
                J4pReadResponse second = rr.get(1);
                for (String key : second.getAttributes()) {
                    answer.put("typeConverter." + asKey(key), second.getValue(key));
                }
            }
            // async processor await manager attributes
            if (rr.size() >= 3) {
                J4pReadResponse second = rr.get(2);
                for (String key : second.getAttributes()) {
                    answer.put("asyncProcessorAwaitManager." + asKey(key), second.getValue(key));
                }
            }
        }
        // would be great if there was an api in jolokia to read optional (eg ignore if an mbean does not exists)
        answer.put("streamCachingEnabled", false);
        try {
            pattern = String.format("%s:context=%s,type=services,name=DefaultStreamCachingStrategy", found.getDomain(), found.getKeyProperty("context"));
            ObjectName sc = ObjectName.getInstance(pattern);
            // there is only a mbean if stream caching is enabled
            J4pReadResponse rsc = jolokia.execute(new J4pReadRequest(sc));
            if (rsc != null) {
                for (String key : rsc.getAttributes()) {
                    answer.put("streamCaching." + asKey(key), rsc.getValue(key));
                }
            }
            answer.put("streamCachingEnabled", true);
        } catch (J4pRemoteException e) {
            // ignore
            boolean ignore = InstanceNotFoundException.class.getName().equals(e.getErrorType());
            if (!ignore) {
                throw e;
            }
        }
        // store some data using special names as that is what the core-commands expects
        answer.put("name", answer.get("camelId"));
        answer.put("status", answer.get("state"));
        answer.put("version", answer.get("camelVersion"));
        answer.put("suspended", "Suspended".equals(answer.get("state")));
        TimeUnit unit = TimeUnit.valueOf((String) answer.get("timeUnit"));
        long timeout = (Long) answer.get("timeout");
        answer.put("shutdownTimeout", "" + unit.toSeconds(timeout));
        answer.put("applicationContextClassLoader", answer.get("applicationContextClassName"));
    }
    return answer;
}
Also used : J4pReadRequest(org.jolokia.client.request.J4pReadRequest) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) ObjectName(javax.management.ObjectName) J4pRemoteException(org.jolokia.client.exception.J4pRemoteException) J4pReadResponse(org.jolokia.client.request.J4pReadResponse) TimeUnit(java.util.concurrent.TimeUnit) JSONObject(org.json.simple.JSONObject)

Example 98 with TimeUnit

use of java.util.concurrent.TimeUnit in project cassandra by apache.

the class DateTieredCompactionStrategy method strategyLogger.

public CompactionLogger.Strategy strategyLogger() {
    return new CompactionLogger.Strategy() {

        public JsonNode sstable(SSTableReader sstable) {
            ObjectNode node = JsonNodeFactory.instance.objectNode();
            node.put("min_timestamp", sstable.getMinTimestamp());
            node.put("max_timestamp", sstable.getMaxTimestamp());
            return node;
        }

        public JsonNode options() {
            ObjectNode node = JsonNodeFactory.instance.objectNode();
            TimeUnit resolution = DateTieredCompactionStrategy.this.options.timestampResolution;
            node.put(DateTieredCompactionStrategyOptions.TIMESTAMP_RESOLUTION_KEY, resolution.toString());
            node.put(DateTieredCompactionStrategyOptions.BASE_TIME_KEY, resolution.toSeconds(DateTieredCompactionStrategy.this.options.baseTime));
            node.put(DateTieredCompactionStrategyOptions.MAX_WINDOW_SIZE_KEY, resolution.toSeconds(DateTieredCompactionStrategy.this.options.maxWindowSize));
            return node;
        }
    };
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) ObjectNode(org.codehaus.jackson.node.ObjectNode) TimeUnit(java.util.concurrent.TimeUnit)

Example 99 with TimeUnit

use of java.util.concurrent.TimeUnit in project camel by apache.

the class CamelSpringTestContextLoader method handleShutdownTimeout.

/**
     * Handles updating shutdown timeouts on Camel contexts based on {@link ShutdownTimeout}.
     *
     * @param context the initialized Spring context
     * @param testClass the test class being executed
     */
protected void handleShutdownTimeout(GenericApplicationContext context, Class<?> testClass) throws Exception {
    final int shutdownTimeout;
    final TimeUnit shutdownTimeUnit;
    if (testClass.isAnnotationPresent(ShutdownTimeout.class)) {
        shutdownTimeout = testClass.getAnnotation(ShutdownTimeout.class).value();
        shutdownTimeUnit = testClass.getAnnotation(ShutdownTimeout.class).timeUnit();
    } else {
        shutdownTimeout = 10;
        shutdownTimeUnit = TimeUnit.SECONDS;
    }
    CamelSpringTestHelper.doToSpringCamelContexts(context, new DoToSpringCamelContextsStrategy() {

        @Override
        public void execute(String contextName, SpringCamelContext camelContext) throws Exception {
            LOG.info("Setting shutdown timeout to [{} {}] on CamelContext with name [{}].", new Object[] { shutdownTimeout, shutdownTimeUnit, contextName });
            camelContext.getShutdownStrategy().setTimeout(shutdownTimeout);
            camelContext.getShutdownStrategy().setTimeUnit(shutdownTimeUnit);
        }
    });
}
Also used : SpringCamelContext(org.apache.camel.spring.SpringCamelContext) TimeUnit(java.util.concurrent.TimeUnit) DoToSpringCamelContextsStrategy(org.apache.camel.test.spring.CamelSpringTestHelper.DoToSpringCamelContextsStrategy) Breakpoint(org.apache.camel.spi.Breakpoint)

Example 100 with TimeUnit

use of java.util.concurrent.TimeUnit in project storm by apache.

the class CsvPreparableReporter method prepare.

@Override
public void prepare(MetricRegistry metricsRegistry, Map stormConf) {
    LOG.debug("Preparing...");
    CsvReporter.Builder builder = CsvReporter.forRegistry(metricsRegistry);
    Locale locale = MetricsUtils.getMetricsReporterLocale(stormConf);
    if (locale != null) {
        builder.formatFor(locale);
    }
    TimeUnit rateUnit = MetricsUtils.getMetricsRateUnit(stormConf);
    if (rateUnit != null) {
        builder.convertRatesTo(rateUnit);
    }
    TimeUnit durationUnit = MetricsUtils.getMetricsDurationUnit(stormConf);
    if (durationUnit != null) {
        builder.convertDurationsTo(durationUnit);
    }
    File csvMetricsDir = MetricsUtils.getCsvLogDir(stormConf);
    reporter = builder.build(csvMetricsDir);
}
Also used : Locale(java.util.Locale) TimeUnit(java.util.concurrent.TimeUnit) CsvReporter(com.codahale.metrics.CsvReporter) File(java.io.File)

Aggregations

TimeUnit (java.util.concurrent.TimeUnit)190 Test (org.junit.Test)28 ExecutionException (java.util.concurrent.ExecutionException)16 IOException (java.io.IOException)11 TimeoutException (java.util.concurrent.TimeoutException)11 Future (java.util.concurrent.Future)10 HashMap (java.util.HashMap)7 TimeSpec (com.linkedin.thirdeye.api.TimeSpec)6 ArrayList (java.util.ArrayList)6 TimeValue (org.elasticsearch.common.unit.TimeValue)6 DataType (com.linkedin.pinot.common.data.FieldSpec.DataType)5 File (java.io.File)5 HashSet (java.util.HashSet)5 Matcher (java.util.regex.Matcher)5 WaitUntilGatewaySenderFlushedCoordinatorJUnitTest (org.apache.geode.internal.cache.wan.WaitUntilGatewaySenderFlushedCoordinatorJUnitTest)5 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)5 TimeGranularity (com.linkedin.thirdeye.api.TimeGranularity)4 GwtIncompatible (com.google.common.annotations.GwtIncompatible)3 RestException (com.linkedin.r2.message.rest.RestException)3 Map (java.util.Map)3