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