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;
}
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;
}
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;
}
};
}
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);
}
});
}
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);
}
Aggregations