import com.google.common.base.Optional;
import com.google.common.util.concurrent.ListenableFuture;
+/**
+ * A transaction that provides read access to a logical data store.
+ * <p>
+ * For more information on usage and examples, please see the documentation in {@link AsyncReadTransaction}.
+ */
public interface ReadTransaction extends AsyncReadTransaction<InstanceIdentifier<?>, DataObject> {
- @Override
- ListenableFuture<Optional<DataObject>> read(LogicalDatastoreType store, InstanceIdentifier<?> path);
+
+ /**
+ * Reads data from the provided logical data store located at the provided path.
+ *<p>
+ * If the target is a subtree, then the whole subtree is read (and will be
+ * accessible from the returned data object).
+ *
+ * @param store
+ * Logical data store from which read should occur.
+ * @param path
+ * Path which uniquely identifies subtree which client want to
+ * read
+ * @return Listenable Future which contains read result
+ * <ul>
+ * <li>If data at supplied path exists the
+ * {@link ListeblaFuture#get()} returns Optional object containing
+ * data once read is done.
+ * <li>If data at supplied path does not exists the
+ * {@link ListenbleFuture#get()} returns {@link Optional#absent()}.
+ * </ul>
+ */
+ <T extends DataObject> ListenableFuture<Optional<T>> read(LogicalDatastoreType store, InstanceIdentifier<T> path);
}
return codec;
}
- protected final ListenableFuture<Optional<DataObject>> doRead(final DOMDataReadTransaction readTx,
- final LogicalDatastoreType store, final org.opendaylight.yangtools.yang.binding.InstanceIdentifier<?> path) {
+ protected final <T extends DataObject> ListenableFuture<Optional<T>> doRead(final DOMDataReadTransaction readTx,
+ final LogicalDatastoreType store, final org.opendaylight.yangtools.yang.binding.InstanceIdentifier<T> path) {
return Futures.transform(readTx.read(store, codec.toNormalized(path)), codec.deserializeFunction(path));
}
}
}
@Override
- public ListenableFuture<Optional<DataObject>> read(final LogicalDatastoreType store,
- final InstanceIdentifier<?> path) {
+ public <T extends DataObject> ListenableFuture<Optional<T>> read(final LogicalDatastoreType store,
+ final InstanceIdentifier<T> path) {
return doRead(getDelegate(),store, path);
}
}
@Override
- public ListenableFuture<Optional<DataObject>> read(final LogicalDatastoreType store,
- final InstanceIdentifier<?> path) {
+ public <T extends DataObject> ListenableFuture<Optional<T>> read(final LogicalDatastoreType store,
+ final InstanceIdentifier<T> path) {
return doRead(getDelegate(), store, path);
}
}
\ No newline at end of file
*/
public Optional<InstanceIdentifier<? extends DataObject>> toBinding(
final org.opendaylight.yangtools.yang.data.api.InstanceIdentifier normalized)
- throws DeserializationException {
+ throws DeserializationException {
PathArgument lastArgument = Iterables.getLast(normalized.getPathArguments());
// Used instance-identifier codec do not support serialization of last
private Optional<InstanceIdentifier<? extends DataObject>> toBindingAugmented(
final org.opendaylight.yangtools.yang.data.api.InstanceIdentifier normalized)
- throws DeserializationException {
+ throws DeserializationException {
Optional<InstanceIdentifier<? extends DataObject>> potential = toBindingImpl(normalized);
// Shorthand check, if codec already supports deserialization
// of AugmentationIdentifier we will return
private Optional<InstanceIdentifier<? extends DataObject>> toBindingImpl(
final org.opendaylight.yangtools.yang.data.api.InstanceIdentifier normalized)
- throws DeserializationException {
+ throws DeserializationException {
org.opendaylight.yangtools.yang.data.api.InstanceIdentifier legacyPath;
try {
private DataNormalizationOperation<?> findNormalizationOperation(
final org.opendaylight.yangtools.yang.data.api.InstanceIdentifier normalized)
- throws DataNormalizationException {
+ throws DataNormalizationException {
DataNormalizationOperation<?> current = legacyToNormalized.getRootOperation();
for (PathArgument arg : normalized.getPathArguments()) {
current = current.getChild(arg);
public Optional<Entry<org.opendaylight.yangtools.yang.binding.InstanceIdentifier<? extends DataObject>, DataObject>> toBinding(
final Entry<org.opendaylight.yangtools.yang.data.api.InstanceIdentifier, ? extends NormalizedNode<?, ?>> normalized)
- throws DeserializationException {
+ throws DeserializationException {
Optional<InstanceIdentifier<? extends DataObject>> potentialPath = toBinding(normalized.getKey());
if (potentialPath.isPresent()) {
InstanceIdentifier<? extends DataObject> bindingPath = potentialPath.get();
return Optional.absent();
}
- private Optional<AugmentationSchema> findAugmentation(final Class targetType,
+ private Optional<AugmentationSchema> findAugmentation(final Class<?> targetType,
final Set<AugmentationSchema> augmentations) {
YangModuleInfo moduleInfo;
try {
if (isAugmentation(arg.getType())) {
count++;
}
+
}
return count;
}
return count;
}
- public Function<Optional<NormalizedNode<?, ?>>, Optional<DataObject>> deserializeFunction(
- final InstanceIdentifier<?> path) {
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ public <T extends DataObject> Function<Optional<NormalizedNode<?, ?>>, Optional<T>> deserializeFunction(final InstanceIdentifier<T> path) {
return new DeserializeFunction(this, path);
}
- private static class DeserializeFunction implements Function<Optional<NormalizedNode<?, ?>>, Optional<DataObject>> {
+ private static class DeserializeFunction<T extends DataObject> implements Function<Optional<NormalizedNode<?, ?>>, Optional<T>> {
private final BindingToNormalizedNodeCodec codec;
private final InstanceIdentifier<?> path;
this.path = Preconditions.checkNotNull(path, "Path must not be null");
}
+ @SuppressWarnings("rawtypes")
@Nullable
@Override
- public Optional<DataObject> apply(@Nullable final Optional<NormalizedNode<?, ?>> normalizedNode) {
+ public Optional apply(@Nullable final Optional<NormalizedNode<?, ?>> normalizedNode) {
if (normalizedNode.isPresent()) {
final DataObject dataObject;
try {
/**
* Returns an default object according to YANG schema for supplied path.
*
- * @param path
- * DOM Path
+ * @param path DOM Path
* @return Node with defaults set on.
*/
public NormalizedNode<?, ?> getDefaultNodeFor(final org.opendaylight.yangtools.yang.data.api.InstanceIdentifier path) {
import java.util.Map;
import java.util.concurrent.ConcurrentMap;
+
import org.opendaylight.controller.md.sal.common.api.data.DataCommitHandler;
import org.opendaylight.controller.md.sal.common.api.data.DataModification;
import org.opendaylight.controller.sal.common.util.CommitHandlerTransactions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+/**
+ * @deprecated This is part of the legacy DataBrokerService
+ */
+@Deprecated
class BindingToDomCommitHandler implements
DataCommitHandler<InstanceIdentifier<? extends DataObject>, DataObject> {
this.biDataService = biDataService;
}
- public void setMappingService(BindingIndependentMappingService mappingService) {
+ public void setMappingService(final BindingIndependentMappingService mappingService) {
this.mappingService = mappingService;
}
import java.util.Map;
import java.util.concurrent.ConcurrentMap;
+
import org.opendaylight.controller.md.sal.common.api.RegistrationListener;
import org.opendaylight.controller.md.sal.common.api.data.DataCommitHandler;
import org.opendaylight.controller.md.sal.common.api.data.DataCommitHandlerRegistration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+/**
+ * @deprecated This is part of the legacy DataBrokerService
+ */
+@Deprecated
class DomToBindingCommitHandler implements //
RegistrationListener<DataCommitHandlerRegistration<InstanceIdentifier<? extends DataObject>, DataObject>>, //
DataCommitHandler<org.opendaylight.yangtools.yang.data.api.InstanceIdentifier, CompositeNode> {
private DataProviderService baDataService;
private BindingIndependentMappingService mappingService;
- public void setBindingAwareDataService(DataProviderService baDataService) {
+ public void setBindingAwareDataService(final DataProviderService baDataService) {
this.baDataService = baDataService;
}
- public void setMappingService(BindingIndependentMappingService mappingService) {
+ public void setMappingService(final BindingIndependentMappingService mappingService) {
this.mappingService = mappingService;
}
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+/**
+ *
+ *
+ * @deprecated Use
+ * {@link org.opendaylight.controller.md.sal.binding.api.ReadTransaction#read(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType, InstanceIdentifier)}
+ * instead.
+ */
+@Deprecated
public final class TypeSafeDataReader {
private final DataReader<InstanceIdentifier<? extends DataObject>, DataObject> delegate;
return delegate;
}
- public TypeSafeDataReader(DataReader<InstanceIdentifier<? extends DataObject>, DataObject> delegate) {
+ public TypeSafeDataReader(
+ final DataReader<InstanceIdentifier<? extends DataObject>, DataObject> delegate) {
this.delegate = delegate;
}
@SuppressWarnings("unchecked")
- public <D extends DataObject> D readConfigurationData(InstanceIdentifier<D> path) {
+ public <D extends DataObject> D readConfigurationData(
+ final InstanceIdentifier<D> path) {
return (D) delegate.readConfigurationData(path);
}
@SuppressWarnings("unchecked")
- public <D extends DataObject> D readOperationalData(InstanceIdentifier<D> path) {
+ public <D extends DataObject> D readOperationalData(
+ final InstanceIdentifier<D> path) {
return (D) delegate.readOperationalData(path);
}
- public static TypeSafeDataReader forReader(DataReader<InstanceIdentifier<? extends DataObject>, DataObject> delegate) {
+ public static TypeSafeDataReader forReader(
+ final DataReader<InstanceIdentifier<? extends DataObject>, DataObject> delegate) {
return new TypeSafeDataReader(delegate);
}
}
import org.opendaylight.yangtools.concepts.Path;
/**
- * Read-only transaction, which provides stable view of data
- * and is {@link AutoCloseable} resource.
+ * Marker interface for a read-only view of the data tree.
*
* @see AsyncReadTransaction
*
-* @param <P>
+ * @param <P>
* Type of path (subtree identifier), which represents location in
* tree
* @param <D>
import org.opendaylight.yangtools.concepts.Path;
-import com.google.common.base.Optional;
-import com.google.common.util.concurrent.ListenableFuture;
-
/**
*
- * Provides a stateful read view of the data tree.
+ * Marker interface for stateful read view of the data tree.
*
* <p>
* View of the data tree is a stable point-in-time snapshot of the current data tree state when
* <p>
* <b>Note:</b> example contains blocking calls on future only to illustrate
* that action happened after other asynchronous action. Use of blocking call
- * {@link ListenableFuture#get()} is discouraged for most uses and you should
- * use
- * {@link com.google.common.util.concurrent.Futures#addCallback(ListenableFuture, com.google.common.util.concurrent.FutureCallback)}
+ * {@link com.google.common.util.concurrent.ListenableFuture#get()} is discouraged for most
+ * uses and you should use
+ * {@link com.google.common.util.concurrent.Futures#addCallback(com.google.common.util.concurrent.ListenableFuture, com.google.common.util.concurrent.FutureCallback)}
* or other functions from {@link com.google.common.util.concurrent.Futures} to
* register more specific listeners.
*
* tree
* @param <D>
* Type of data (payload), which represents data payload
+ *
+ * @see org.opendaylight.controller.md.sal.binding.api.ReadTransaction
+ * @see org.opendaylight.controller.md.sal.dom.api.DOMDataReadTransaction
*/
public interface AsyncReadTransaction<P extends Path<P>, D> extends AsyncTransaction<P, D> {
- /**
- *
- * Reads data from provided logical data store located at the provided path.
- *<p>
- * If the target is a subtree, then the whole subtree is read (and will be
- * accessible from the returned data object).
- *
- * @param store
- * Logical data store from which read should occur.
- * @param path
- * Path which uniquely identifies subtree which client want to
- * read
- * @return Listenable Future which contains read result
- * <ul>
- * <li>If data at supplied path exists the
- * {@link ListeblaFuture#get()} returns Optional object containing
- * data once read is done.
- * <li>If data at supplied path does not exists the
- * {@link ListenbleFuture#get()} returns {@link Optional#absent()}.
- * </ul>
- */
- ListenableFuture<Optional<D>> read(LogicalDatastoreType store, P path);
-
}
package org.opendaylight.controller.md.sal.dom.api;
import org.opendaylight.controller.md.sal.common.api.data.AsyncReadTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import com.google.common.base.Optional;
+import com.google.common.util.concurrent.ListenableFuture;
+
+/**
+ * A transaction that provides read access to a logical data store.
+ * <p>
+ * For more information on usage and examples, please see the documentation in {@link AsyncReadTransaction}.
+ */
public interface DOMDataReadTransaction extends AsyncReadTransaction<InstanceIdentifier, NormalizedNode<?, ?>> {
+ /**
+ * Reads data from provided logical data store located at the provided path.
+ *<p>
+ * If the target is a subtree, then the whole subtree is read (and will be
+ * accessible from the returned data object).
+ *
+ * @param store
+ * Logical data store from which read should occur.
+ * @param path
+ * Path which uniquely identifies subtree which client want to
+ * read
+ * @return Listenable Future which contains read result
+ * <ul>
+ * <li>If data at supplied path exists the
+ * {@link ListeblaFuture#get()} returns Optional object containing
+ * data once read is done.
+ * <li>If data at supplied path does not exists the
+ * {@link ListenbleFuture#get()} returns {@link Optional#absent()}.
+ * </ul>
+ */
+ ListenableFuture<Optional<NormalizedNode<?,?>>> read(LogicalDatastoreType store,InstanceIdentifier path);
}
ListenableFuture<RpcResult<TransactionStatus>> future = t.commit();
Futures.addCallback( future, new FutureCallback<RpcResult<TransactionStatus>>() {
@Override
- public void onSuccess( RpcResult<TransactionStatus> result ) {
+ public void onSuccess( final RpcResult<TransactionStatus> result ) {
LOG.debug( "Delete Toaster commit result: " + result );
}
@Override
- public void onFailure( Throwable t ) {
+ public void onFailure( final Throwable t ) {
LOG.error( "Delete of Toaster failed", t );
}
} );
}
}
- private Toaster buildToaster( ToasterStatus status ) {
+ private Toaster buildToaster( final ToasterStatus status ) {
// note - we are simulating a device whose manufacture and model are
// fixed (embedded) into the hardware.
// to make toast.
final ReadWriteTransaction tx = dataProvider.newReadWriteTransaction();
- ListenableFuture<Optional<DataObject>> readFuture =
+ ListenableFuture<Optional<Toaster>> readFuture =
tx.read( LogicalDatastoreType.OPERATIONAL, TOASTER_IID );
final ListenableFuture<RpcResult<TransactionStatus>> commitFuture =
- Futures.transform( readFuture, new AsyncFunction<Optional<DataObject>,
+ Futures.transform( readFuture, new AsyncFunction<Optional<Toaster>,
RpcResult<TransactionStatus>>() {
@Override
public ListenableFuture<RpcResult<TransactionStatus>> apply(
- Optional<DataObject> toasterData ) throws Exception {
+ final Optional<Toaster> toasterData ) throws Exception {
ToasterStatus toasterStatus = ToasterStatus.Up;
if( toasterData.isPresent() ) {
- toasterStatus = ((Toaster)toasterData.get()).getToasterStatus();
+ toasterStatus = toasterData.get().getToasterStatus();
}
LOG.debug( "Read toaster status: {}", toasterStatus );
Futures.addCallback( commitFuture, new FutureCallback<RpcResult<TransactionStatus>>() {
@Override
- public void onSuccess( RpcResult<TransactionStatus> result ) {
+ public void onSuccess( final RpcResult<TransactionStatus> result ) {
if( result.getResult() == TransactionStatus.COMMITED ) {
// OK to make toast
}
@Override
- public void onFailure( Throwable ex ) {
+ public void onFailure( final Throwable ex ) {
if( ex instanceof OptimisticLockFailedException ) {
// Another thread is likely trying to make toast simultaneously and updated the
Futures.addCallback( commitFuture, new FutureCallback<RpcResult<TransactionStatus>>() {
@Override
- public void onSuccess( RpcResult<TransactionStatus> result ) {
+ public void onSuccess( final RpcResult<TransactionStatus> result ) {
if( result.getResult() != TransactionStatus.COMMITED ) {
LOG.error( "Failed to update toaster status: " + result.getErrors() );
}
}
@Override
- public void onFailure( Throwable t ) {
+ public void onFailure( final Throwable t ) {
// We shouldn't get an OptimisticLockFailedException (or any ex) as no
// other component should be updating the operational state.
LOG.error( "Failed to update toaster status", t );
notifyCallback( false );
}
- void notifyCallback( boolean result ) {
+ void notifyCallback( final boolean result ) {
if( resultCallback != null ) {
resultCallback.apply( result );
}
setToasterStatusUp( new Function<Boolean,Void>() {
@Override
- public Void apply( Boolean result ) {
+ public Void apply( final Boolean result ) {
currentMakeToastTask.set( null );