Search in sources :

Example 6 with Holding

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;
}
Also used : FiniteDuration(scala.concurrent.duration.FiniteDuration) Holding(org.checkerframework.checker.lock.qual.Holding)

Example 7 with Holding

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));
}
Also used : BGPTerminationReason(org.opendaylight.protocol.bgp.rib.spi.BGPTerminationReason) Holding(org.checkerframework.checker.lock.qual.Holding)

Example 8 with Holding

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);
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) EffectiveStatementInference(org.opendaylight.yangtools.yang.model.api.EffectiveStatementInference) IOException(java.io.IOException) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Holding(org.checkerframework.checker.lock.qual.Holding)

Example 9 with Holding

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();
}
Also used : XmlParserStream(org.opendaylight.yangtools.yang.data.codec.xml.XmlParserStream) XMLStreamReader(javax.xml.stream.XMLStreamReader) FileChannel(java.nio.channels.FileChannel) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Stopwatch(com.google.common.base.Stopwatch) ImmutableNormalizedNodeStreamWriter(org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeStreamWriter) NormalizedNodeStreamWriter(org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) SAXException(org.xml.sax.SAXException) RandomAccessFile(java.io.RandomAccessFile) XMLStreamException(javax.xml.stream.XMLStreamException) NormalizedNodeResult(org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult) FileLock(java.nio.channels.FileLock) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Holding(org.checkerframework.checker.lock.qual.Holding)

Example 10 with Holding

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;
}
Also used : Srp(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.srp.object.Srp) Srp1(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.initiated.rev200720.Srp1) Lsp(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.lsp.object.Lsp) ReportedLsp(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.pcep.client.attributes.path.computation.client.ReportedLsp) SrpIdNumber(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.SrpIdNumber) ReportedLspBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.pcep.client.attributes.path.computation.client.ReportedLspBuilder) LspDbVersion(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev200720.lsp.db.version.tlv.LspDbVersion) PathComputationClientBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.pcep.client.attributes.PathComputationClientBuilder) PathComputationClient1Builder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev200720.PathComputationClient1Builder) PlspId(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.PlspId) Holding(org.checkerframework.checker.lock.qual.Holding)

Aggregations

Holding (org.checkerframework.checker.lock.qual.Holding)16 IOException (java.io.IOException)3 ActorSelection (akka.actor.ActorSelection)2 File (java.io.File)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 BGPTerminationReason (org.opendaylight.protocol.bgp.rib.spi.BGPTerminationReason)2 ActorRef (akka.actor.ActorRef)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Stopwatch (com.google.common.base.Stopwatch)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 RandomAccessFile (java.io.RandomAccessFile)1 Cleaner (java.lang.ref.Cleaner)1 Cleanable (java.lang.ref.Cleaner.Cleanable)1 URISyntaxException (java.net.URISyntaxException)1 FileChannel (java.nio.channels.FileChannel)1 FileLock (java.nio.channels.FileLock)1 ExecutionException (java.util.concurrent.ExecutionException)1