Search in sources :

Example 1 with Holding

use of org.checkerframework.checker.lock.qual.Holding in project controller by opendaylight.

the class AbstractClientHistory method createHistoryProxy.

/**
 * Create a new history proxy for a given shard.
 *
 * @param shard Shard cookie
 * @throws InversibleLockException if the shard is being reconnected
 */
@Holding("lock")
private ProxyHistory createHistoryProxy(final Long shard) {
    final AbstractClientConnection<ShardBackendInfo> connection = client.getConnection(shard);
    final LocalHistoryIdentifier proxyId = new LocalHistoryIdentifier(identifier.getClientId(), identifier.getHistoryId(), shard);
    LOG.debug("Created proxyId {} for history {} shard {}", proxyId, identifier, shard);
    final ProxyHistory ret = createHistoryProxy(proxyId, connection);
    // Request creation of the history, if it is not the single history
    if (ret.getIdentifier().getHistoryId() != 0) {
        connection.sendRequest(new CreateLocalHistoryRequest(ret.getIdentifier(), connection.localActor()), this::createHistoryCallback);
    }
    return ret;
}
Also used : CreateLocalHistoryRequest(org.opendaylight.controller.cluster.access.commands.CreateLocalHistoryRequest) LocalHistoryIdentifier(org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier) Holding(org.checkerframework.checker.lock.qual.Holding)

Example 2 with Holding

use of org.checkerframework.checker.lock.qual.Holding in project controller by opendaylight.

the class FileBackedOutputStream method possiblySwitchToFile.

/**
 * Checks if writing {@code len} bytes would go over threshold, and switches to file buffering if so.
 */
@Holding("this")
private void possiblySwitchToFile(final int len) throws IOException {
    if (out == null) {
        throw new IOException("Stream already closed");
    }
    if (file == null && memory.getCount() + len > fileThreshold) {
        final File temp = File.createTempFile("FileBackedOutputStream", null, fileDirectory == null ? null : new File(fileDirectory));
        temp.deleteOnExit();
        final Cleaner.Cleanable cleanup = FILE_CLEANER.register(this, () -> deleteFile(temp));
        LOG.debug("Byte count {} has exceeded threshold {} - switching to file: {}", memory.getCount() + len, fileThreshold, temp);
        final OutputStream transfer;
        try {
            transfer = Files.newOutputStream(temp.toPath());
            try {
                transfer.write(memory.getBuffer(), 0, memory.getCount());
                transfer.flush();
            } catch (IOException e) {
                try {
                    transfer.close();
                } catch (IOException ex) {
                    LOG.debug("Error closing temp file {}", temp, ex);
                }
                throw e;
            }
        } catch (IOException e) {
            cleanup.clean();
            throw e;
        }
        // We've successfully transferred the data; switch to writing to file
        out = transfer;
        file = temp;
        fileCleanup = cleanup;
        memory = null;
    }
}
Also used : OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) File(java.io.File) Cleanable(java.lang.ref.Cleaner.Cleanable) Cleaner(java.lang.ref.Cleaner) Holding(org.checkerframework.checker.lock.qual.Holding)

Example 3 with Holding

use of org.checkerframework.checker.lock.qual.Holding in project controller by opendaylight.

the class RootDataTreeChangeListenerProxy method onSuccessfulSubscription.

@Holding("this")
private void onSuccessfulSubscription(final Subscribed current, final String shardName, final RegisterDataTreeNotificationListenerReply reply) {
    final ActorSelection regActor = actorUtils.actorSelection(reply.getListenerRegistrationPath());
    LOG.debug("{}: Shard {} subscribed at {}", logContext(), shardName, regActor);
    current.subscriptions.add(regActor);
}
Also used : ActorSelection(akka.actor.ActorSelection) Holding(org.checkerframework.checker.lock.qual.Holding)

Example 4 with Holding

use of org.checkerframework.checker.lock.qual.Holding in project controller by opendaylight.

the class RootDataTreeChangeListenerProxy method terminate.

@Holding("this")
private void terminate(final Subscribed current) {
    // Terminate the listener
    current.dtclActor.tell(PoisonPill.getInstance(), ActorRef.noSender());
    // Terminate all subscriptions
    for (ActorSelection regActor : current.subscriptions) {
        regActor.tell(CloseDataTreeNotificationListenerRegistration.getInstance(), ActorRef.noSender());
    }
    state = new Terminated();
}
Also used : ActorSelection(akka.actor.ActorSelection) Holding(org.checkerframework.checker.lock.qual.Holding)

Example 5 with Holding

use of org.checkerframework.checker.lock.qual.Holding in project controller by opendaylight.

the class RootDataTreeChangeListenerProxy method subscribeToShards.

@Holding("this")
private void subscribeToShards(final Map<String, Object> localShards) {
    // Safety check before we start doing anything
    for (Entry<String, Object> entry : localShards.entrySet()) {
        final Object obj = entry.getValue();
        verify(obj instanceof ActorRef, "Unhandled response %s for shard %s", obj, entry.getKey());
    }
    // Instantiate the DTCL actor and update state
    final ActorRef dtclActor = actorUtils.getActorSystem().actorOf(RootDataTreeChangeListenerActor.props(getInstance(), localShards.size()).withDispatcher(actorUtils.getNotificationDispatcherPath()));
    state = new Subscribed(dtclActor, localShards.size());
    // Subscribe to all shards
    final RegisterDataTreeChangeListener regMessage = new RegisterDataTreeChangeListener(YangInstanceIdentifier.empty(), dtclActor, true);
    for (Entry<String, Object> entry : localShards.entrySet()) {
        // Do not retain references to localShards
        final String shardName = entry.getKey();
        final ActorRef shard = (ActorRef) entry.getValue();
        actorUtils.executeOperationAsync(shard, regMessage, actorUtils.getDatastoreContext().getShardInitializationTimeout()).onComplete(new OnComplete<>() {

            @Override
            public void onComplete(final Throwable failure, final Object result) {
                onShardSubscribed(shardName, failure, result);
            }
        }, actorUtils.getClientDispatcher());
    }
}
Also used : ActorRef(akka.actor.ActorRef) RegisterDataTreeChangeListener(org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeChangeListener) 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