use of org.checkerframework.checker.lock.qual.Holding in project controller by opendaylight.
the class AbstractClientConnection method scheduleTimer.
/**
* Schedule a timer to fire on the actor thread after a delay.
*
* @param delay Delay, in nanoseconds
*/
@Holding("lock")
private void scheduleTimer(final long delay) {
if (haveTimer) {
LOG.debug("{}: timer already scheduled on {}", context.persistenceId(), this);
return;
}
if (queue.hasSuccessor()) {
LOG.debug("{}: connection {} has a successor, not scheduling timer", context.persistenceId(), this);
return;
}
// If the delay is negative, we need to schedule an action immediately. While the caller could have checked
// for that condition and take appropriate action, but this is more convenient and less error-prone.
final long normalized = delay <= 0 ? 0 : Math.min(delay, context.config().getBackendAlivenessTimerInterval());
final FiniteDuration dur = FiniteDuration.fromNanos(normalized);
LOG.debug("{}: connection {} scheduling timeout in {}", context.persistenceId(), this, dur);
context.executeInActor(this::runTimer, dur);
haveTimer = true;
}
use of org.checkerframework.checker.lock.qual.Holding in project bgpcep by opendaylight.
the class BGPSessionImpl method notifyTerminationReasonAndCloseWithoutMessage.
@Holding({ "this.listener", "this" })
private void notifyTerminationReasonAndCloseWithoutMessage(final BGPError error) {
this.terminationReasonNotified = true;
this.closeWithoutMessage();
this.listener.onSessionTerminated(this, new BGPTerminationReason(error));
}
use of org.checkerframework.checker.lock.qual.Holding in project bgpcep by opendaylight.
the class AbstractConfigLoader method handleConfigFile.
@Holding("this")
private void handleConfigFile(final ProcessorContext context, final String filename) {
final EffectiveStatementInference schema = context.schema;
if (schema == null) {
LOG.info("No schema present for {}, ignoring file {}", context.processor.fileRootSchema(), filename);
return;
}
final NormalizedNode dto;
try {
dto = parseDefaultConfigFile(schema, filename);
} catch (final IOException | XMLStreamException e) {
LOG.warn("Failed to parse config file {}", filename, e);
return;
}
LOG.info("Loading initial config {}", filename);
context.processor.loadConfiguration(dto);
}
use of org.checkerframework.checker.lock.qual.Holding in project bgpcep by opendaylight.
the class AbstractConfigLoader method parseDefaultConfigFile.
@Holding("this")
private NormalizedNode parseDefaultConfigFile(final EffectiveStatementInference schema, final String filename) throws IOException, XMLStreamException {
final NormalizedNodeResult result = new NormalizedNodeResult();
final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
final File newFile = new File(directory(), filename);
try (RandomAccessFile raf = new RandomAccessFile(newFile, READ)) {
final FileChannel channel = raf.getChannel();
FileLock lock = null;
final Stopwatch stopwatch = Stopwatch.createStarted();
while (lock == null || stopwatch.elapsed(TimeUnit.NANOSECONDS) > TIMEOUT_NANOS) {
try {
lock = channel.tryLock();
} catch (final IllegalStateException e) {
// Ignore
}
if (lock == null) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
LOG.warn("Failed to lock xml", e);
}
}
}
try (InputStream resourceAsStream = new FileInputStream(newFile)) {
final XMLStreamReader reader = UntrustedXML.createXMLStreamReader(resourceAsStream);
try (XmlParserStream xmlParser = XmlParserStream.create(streamWriter, schema)) {
xmlParser.parse(reader);
} catch (final URISyntaxException | XMLStreamException | IOException | SAXException e) {
LOG.warn("Failed to parse xml", e);
} finally {
reader.close();
}
}
}
return result.getResult();
}
use of org.checkerframework.checker.lock.qual.Holding in project bgpcep by opendaylight.
the class PCEPTopologySessionListener method manageNextReport.
@Holding("this")
private boolean manageNextReport(final Reports report, final MessageContext ctx) {
final Lsp lsp = report.getLsp();
final PlspId plspid = lsp.getPlspId();
final Srp srp = report.getSrp();
if (!lsp.getSync() && (plspid == null || plspid.getValue().toJava() == 0)) {
purgeStaleLsps(ctx);
if (isTriggeredSyncInProcess()) {
if (srp == null) {
return false;
}
final SrpIdNumber id = srp.getOperationId();
if (id.getValue().toJava() == 0) {
return false;
}
final PCEPRequest req = removeRequest(id);
ctx.resolveRequest(req);
}
stateSynchronizationAchieved(ctx);
return true;
}
final ReportedLspBuilder rlb = new ReportedLspBuilder();
boolean solicited = false;
solicited = isSolicited(srp, lsp, ctx, rlb);
// if remove flag is set in SRP object, remove the tunnel immediately
if (solicited) {
final Srp1 initiatedSrp = srp.augmentation(Srp1.class);
if (initiatedSrp != null && initiatedSrp.getRemove()) {
super.removeLsp(ctx, plspid);
return false;
}
}
rlb.setPath(BindingMap.of(buildPath(report, srp, lsp)));
String name = lookupLspName(plspid);
if (lsp.getTlvs() != null && lsp.getTlvs().getSymbolicPathName() != null) {
name = StandardCharsets.UTF_8.decode(ByteBuffer.wrap(lsp.getTlvs().getSymbolicPathName().getPathName().getValue())).toString();
}
// get LspDB from LSP and write it to pcc's node
final LspDbVersion lspDbVersion = geLspDbVersionTlv(lsp);
if (lspDbVersion != null) {
updatePccNode(ctx, new PathComputationClientBuilder().addAugmentation(new PathComputationClient1Builder().setLspDbVersion(lspDbVersion).build()).build());
}
updateLsp(ctx, plspid, name, rlb, solicited, lsp.getRemove());
unmarkStaleLsp(plspid);
LOG.debug("LSP {} updated", lsp);
return true;
}
Aggregations