use of javax.xml.datatype.Duration in project apache-kafka-on-k8s by banzaicloud.
the class StreamsResetter method maybeReset.
private void maybeReset(final String groupId, final Consumer<byte[], byte[]> client, final Set<TopicPartition> inputTopicPartitions) throws Exception {
if (inputTopicPartitions.size() > 0) {
System.out.println("Following input topics offsets will be reset to (for consumer group " + groupId + ")");
if (options.has(toOffsetOption)) {
resetOffsetsTo(client, inputTopicPartitions, options.valueOf(toOffsetOption));
} else if (options.has(toEarliestOption)) {
client.seekToBeginning(inputTopicPartitions);
} else if (options.has(toLatestOption)) {
client.seekToEnd(inputTopicPartitions);
} else if (options.has(shiftByOption)) {
shiftOffsetsBy(client, inputTopicPartitions, options.valueOf(shiftByOption));
} else if (options.has(toDatetimeOption)) {
final String ts = options.valueOf(toDatetimeOption);
final long timestamp = getDateTime(ts);
resetToDatetime(client, inputTopicPartitions, timestamp);
} else if (options.has(byDurationOption)) {
final String duration = options.valueOf(byDurationOption);
final Duration durationParsed = DatatypeFactory.newInstance().newDuration(duration);
resetByDuration(client, inputTopicPartitions, durationParsed);
} else if (options.has(fromFileOption)) {
final String resetPlanPath = options.valueOf(fromFileOption);
final Map<TopicPartition, Long> topicPartitionsAndOffset = getTopicPartitionOffsetFromResetPlan(resetPlanPath);
resetOffsetsFromResetPlan(client, inputTopicPartitions, topicPartitionsAndOffset);
} else {
client.seekToBeginning(inputTopicPartitions);
}
for (final TopicPartition p : inputTopicPartitions) {
System.out.println("Topic: " + p.topic() + " Partition: " + p.partition() + " Offset: " + client.position(p));
}
}
}
use of javax.xml.datatype.Duration in project msgraph-sdk-java by microsoftgraph.
the class OutlookTests method testGetFindMeetingTimes.
@Test
public void testGetFindMeetingTimes() {
TestBase testBase = new TestBase();
// Get the first user in the tenant
User me = testBase.graphClient.me().buildRequest().get();
IUserCollectionPage users = testBase.graphClient.users().buildRequest().get();
User tenantUser = users.getCurrentPage().get(0);
// Ensure that the user grabbed is not the logged-in user
if (tenantUser.mail.equals(me.mail)) {
tenantUser = users.getCurrentPage().get(1);
}
ArrayList<AttendeeBase> attendees = new ArrayList<AttendeeBase>();
AttendeeBase attendeeBase = new AttendeeBase();
EmailAddress email = new EmailAddress();
email.address = tenantUser.mail;
attendeeBase.emailAddress = email;
attendees.add(attendeeBase);
try {
DatatypeFactory.newInstance().newDuration("PT30M");
Duration duration = DatatypeFactory.newInstance().newDuration("PT30M");
MeetingTimeSuggestionsResult result = testBase.graphClient.me().findMeetingTimes(attendees, null, null, duration, 10, true, false, 10.0).buildRequest().post();
assertNotNull(result);
} catch (Exception e) {
Assert.fail("Duration could not be created from String");
}
}
use of javax.xml.datatype.Duration in project OpenTripPlanner by opentripplanner.
the class TimetableHelper method createUpdatedTripTimes.
/**
* Apply the TripUpdate to the appropriate TripTimes from this Timetable. The existing TripTimes
* must not be modified directly because they may be shared with the underlying
* scheduledTimetable, or other updated Timetables. The {@link TimetableSnapshot} performs the
* protective copying of this Timetable. It is not done in this update method to avoid
* repeatedly cloning the same Timetable when several updates are applied to it at once. We
* assume here that all trips in a timetable are from the same feed, which should always be the
* case.
*
* @param activity SIRI-VM VehicleActivity
* @param timeZone time zone of trip update
* @param tripId
* @return new copy of updated TripTimes after TripUpdate has been applied on TripTimes of trip
* with the id specified in the trip descriptor of the TripUpdate; null if something
* went wrong
*/
public static TripTimes createUpdatedTripTimes(Timetable timetable, Graph graph, VehicleActivityStructure activity, TimeZone timeZone, FeedScopedId tripId) {
if (activity == null) {
return null;
}
MonitoredVehicleJourneyStructure mvj = activity.getMonitoredVehicleJourney();
int tripIndex = timetable.getTripIndex(tripId);
if (tripIndex == -1) {
LOG.trace("tripId {} not found in pattern.", tripId);
return null;
}
final TripTimes existingTripTimes = timetable.getTripTimes(tripIndex);
TripTimes newTimes = new TripTimes(existingTripTimes);
MonitoredCallStructure update = mvj.getMonitoredCall();
if (update == null) {
return null;
}
final List<Stop> stops = timetable.pattern.getStops();
VehicleActivityStructure.MonitoredVehicleJourney monitoredVehicleJourney = activity.getMonitoredVehicleJourney();
Duration delay = null;
if (monitoredVehicleJourney != null) {
delay = monitoredVehicleJourney.getDelay();
int updatedDelay = 0;
if (delay != null) {
updatedDelay = delay.getSign() * (delay.getHours() * 3600 + delay.getMinutes() * 60 + delay.getSeconds());
}
MonitoredCallStructure monitoredCall = monitoredVehicleJourney.getMonitoredCall();
if (monitoredCall != null && monitoredCall.getStopPointRef() != null) {
boolean matchFound = false;
int arrivalDelay = 0;
int departureDelay = 0;
for (int index = 0; index < newTimes.getNumStops(); ++index) {
if (!matchFound) {
// Delay is set on a single stop at a time. When match is found - propagate delay on all following stops
final Stop stop = stops.get(index);
matchFound = stop.getId().getId().equals(monitoredCall.getStopPointRef().getValue());
if (!matchFound && stop.isPartOfStation()) {
FeedScopedId alternativeId = new FeedScopedId(stop.getId().getFeedId(), monitoredCall.getStopPointRef().getValue());
Stop alternativeStop = graph.index.getStopForId(alternativeId);
if (alternativeStop != null && alternativeStop.isPartOfStation()) {
matchFound = stop.isPartOfSameStationAs(alternativeStop);
}
}
if (matchFound) {
arrivalDelay = departureDelay = updatedDelay;
} else {
/*
* If updated delay is less than previously set delay, the existing delay needs to be adjusted to avoid
* non-increasing times causing updates to be rejected. Will only affect historical data.
*/
arrivalDelay = Math.min(existingTripTimes.getArrivalDelay(index), updatedDelay);
departureDelay = Math.min(existingTripTimes.getDepartureDelay(index), updatedDelay);
}
}
newTimes.updateArrivalDelay(index, arrivalDelay);
newTimes.updateDepartureDelay(index, departureDelay);
}
}
}
if (!newTimes.timesIncreasing()) {
LOG.info("TripTimes are non-increasing after applying SIRI delay propagation - delay: {}", delay);
return null;
}
// If state is already MODIFIED - keep existing state
if (newTimes.getRealTimeState() != RealTimeState.MODIFIED) {
// Make sure that updated trip times have the correct real time state
newTimes.setRealTimeState(RealTimeState.UPDATED);
}
return newTimes;
}
use of javax.xml.datatype.Duration in project Tundra by Permafrost.
the class service method retry.
public static final void retry(IData pipeline) throws ServiceException {
// --- <<IS-START(retry)>> ---
// @subtype unknown
// @sigtype java 3.5
// [i] field:0:required $service
// [i] record:0:optional $pipeline
// [i] field:0:optional $retry.limit
// [i] field:0:optional $retry.wait
// [i] field:0:optional $retry.factor
// [i] field:0:optional $thread.priority
// [o] record:0:optional $pipeline
// [o] field:0:optional $duration
// [o] field:0:optional $retry.count
IDataCursor cursor = pipeline.getCursor();
Thread currentThread = Thread.currentThread();
int currentThreadPriority = currentThread.getPriority();
boolean changeThreadPriority = false;
try {
IData scope = IDataHelper.remove(cursor, "$pipeline", IData.class);
boolean scoped = scope != null;
if (!scoped)
scope = IDataHelper.clone(pipeline, "$service", "$mode", "$raise?", "$retry.limit", "$retry.wait", "$retry.factor");
String service = IDataHelper.get(cursor, "$service", String.class);
int retryLimit = IDataHelper.getOrDefault(cursor, "$retry.limit", Integer.class, 0);
Duration retryWait = IDataHelper.get(cursor, "$retry.wait", Duration.class);
float retryFactor = IDataHelper.getOrDefault(cursor, "$retry.factor", Float.class, 1.0f);
BigDecimal newThreadPriority = IDataHelper.get(cursor, "$thread.priority", BigDecimal.class);
if (newThreadPriority != null) {
int priority = ThreadHelper.normalizePriority(newThreadPriority.intValue());
changeThreadPriority = priority != currentThreadPriority;
if (changeThreadPriority)
currentThread.setPriority(priority);
}
int retryCount = 0;
long retryWaitMilliseconds = retryWait == null ? 0 : retryWait.getTimeInMillis(Calendar.getInstance());
long start = System.nanoTime();
while (!Thread.interrupted()) {
IData invokePipeline = IDataHelper.clone(scope);
try {
invokePipeline = ServiceHelper.invoke(service, invokePipeline, true, false, true);
scope = invokePipeline;
break;
} catch (ServiceException ex) {
if (retryCount < retryLimit) {
long wait = retryWaitMilliseconds * Double.valueOf(Math.pow(retryFactor, retryCount - 1)).longValue();
retryCount++;
Thread.sleep(wait);
} else {
throw ex;
}
}
}
long end = System.nanoTime();
if (scoped) {
IDataHelper.put(cursor, "$pipeline", scope);
} else {
IDataHelper.mergeInto(pipeline, scope);
}
IDataHelper.put(cursor, "$duration", DurationHelper.format(end - start, DurationPattern.NANOSECONDS, DurationPattern.XML_MILLISECONDS));
IDataHelper.put(cursor, "$retry.count", retryCount, String.class);
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
ExceptionHelper.raiseUnchecked(ex);
} finally {
if (changeThreadPriority)
currentThread.setPriority(currentThreadPriority);
cursor.destroy();
}
// --- <<IS-END>> ---
}
use of javax.xml.datatype.Duration in project Tundra by Permafrost.
the class file method purge.
public static final void purge(IData pipeline) throws ServiceException {
// --- <<IS-START(purge)>> ---
// @subtype unknown
// @sigtype java 3.5
// [i] field:0:required $directory
// [i] field:0:required $duration
// [i] field:0:optional $duration.pattern {"xml","milliseconds","seconds","minutes","hours","days","weeks","months","years"}
// [o] field:0:required $purged?
// [o] field:0:optional $count
IDataCursor cursor = pipeline.getCursor();
try {
File directory = IDataHelper.get(cursor, "$directory", File.class);
String durationString = IDataHelper.get(cursor, "$duration", String.class);
String durationPattern = IDataHelper.get(cursor, "$duration.pattern", String.class);
Duration duration = DurationHelper.parse(durationString, durationPattern);
boolean shouldPurge = shouldPurge(directory, duration);
if (shouldPurge) {
long count = DirectoryHelper.purge(directory, duration, null, false);
hasPurged(directory);
IDataHelper.put(cursor, "$count", count, String.class);
}
IDataHelper.put(cursor, "$purged?", shouldPurge, String.class);
} catch (FileNotFoundException ex) {
ExceptionHelper.raise(ex);
} finally {
cursor.destroy();
}
// --- <<IS-END>> ---
}
Aggregations