import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
+import java.util.Objects;
import java.util.concurrent.CountDownLatch;
import javax.annotation.Nullable;
import javax.ws.rs.core.Response.Status;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.restconf.common.patch.PatchEntity;
import org.opendaylight.restconf.common.patch.PatchStatusContext;
import org.opendaylight.restconf.common.patch.PatchStatusEntity;
+import org.opendaylight.restconf.common.util.DataChangeScope;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.RpcError;
@SuppressWarnings("checkstyle:FinalClass")
public class BrokerFacade implements Closeable {
private static final Logger LOG = LoggerFactory.getLogger(BrokerFacade.class);
- private static final BrokerFacade INSTANCE = new BrokerFacade();
private volatile DOMRpcService rpcService;
- private DOMDataBroker domDataBroker;
- private DOMNotificationService domNotification;
- private ControllerContext controllerContext;
-
- // Temporary until the static instance is removed.
- @Deprecated
- private BrokerFacade() {
- }
+ private final DOMDataBroker domDataBroker;
+ private final DOMNotificationService domNotification;
+ private final ControllerContext controllerContext;
private BrokerFacade(DOMRpcService rpcService, DOMDataBroker domDataBroker, DOMNotificationService domNotification,
ControllerContext controllerContext) {
- this.rpcService = rpcService;
- this.domDataBroker = domDataBroker;
- this.domNotification = domNotification;
- this.controllerContext = controllerContext;
- }
-
- @Deprecated
- public static BrokerFacade getInstance() {
- return BrokerFacade.INSTANCE;
+ this.rpcService = Objects.requireNonNull(rpcService);
+ this.domDataBroker = Objects.requireNonNull(domDataBroker);
+ this.domNotification = Objects.requireNonNull(domNotification);
+ this.controllerContext = Objects.requireNonNull(controllerContext);
}
public static BrokerFacade newInstance(DOMRpcService rpcService, DOMDataBroker domDataBroker,
DOMNotificationService domNotification, ControllerContext controllerContext) {
- INSTANCE.rpcService = rpcService;
- INSTANCE.domDataBroker = domDataBroker;
- INSTANCE.controllerContext = controllerContext;
- INSTANCE.domNotification = domNotification;
- return INSTANCE;
- //return new BrokerFacade(pcService, domDataBroker, controllerContext);
+ return new BrokerFacade(rpcService, domDataBroker, domNotification, controllerContext);
}
@Override
public void close() {
- domDataBroker = null;
- }
-
- private void checkPreconditions() {
- if (this.domDataBroker == null) {
- throw new RestconfDocumentedException(Status.SERVICE_UNAVAILABLE);
- }
}
/**
* @return read date
*/
public NormalizedNode<?, ?> readConfigurationData(final YangInstanceIdentifier path, final String withDefa) {
- checkPreconditions();
try (DOMDataReadOnlyTransaction tx = this.domDataBroker.newReadOnlyTransaction()) {
return readDataViaTransaction(tx, CONFIGURATION, path, withDefa);
}
* @return read data
*/
public NormalizedNode<?, ?> readOperationalData(final YangInstanceIdentifier path) {
- checkPreconditions();
-
try (DOMDataReadOnlyTransaction tx = this.domDataBroker.newReadOnlyTransaction()) {
return readDataViaTransaction(tx, OPERATIONAL, path);
}
Preconditions.checkNotNull(path);
Preconditions.checkNotNull(payload);
- checkPreconditions();
-
final DOMDataReadWriteTransaction newReadWriteTransaction = this.domDataBroker.newReadWriteTransaction();
final Status status = readDataViaTransaction(newReadWriteTransaction, CONFIGURATION, path) != null ? Status.OK
: Status.CREATED;
public CheckedFuture<Void, TransactionCommitFailedException> commitConfigurationDataPost(
final SchemaContext globalSchema, final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload,
final String insert, final String point) {
- checkPreconditions();
return postDataViaTransaction(this.domDataBroker.newReadWriteTransaction(), CONFIGURATION, path, payload,
globalSchema, insert, point);
}
// DELETE configuration
public CheckedFuture<Void, TransactionCommitFailedException> commitConfigurationDataDelete(
final YangInstanceIdentifier path) {
- checkPreconditions();
return deleteDataViaTransaction(this.domDataBroker.newReadWriteTransaction(), CONFIGURATION, path);
}
// RPC
public CheckedFuture<DOMRpcResult, DOMRpcException> invokeRpc(final SchemaPath type,
final NormalizedNode<?, ?> input) {
- checkPreconditions();
if (this.rpcService == null) {
throw new RestconfDocumentedException(Status.SERVICE_UNAVAILABLE);
}
public void registerToListenDataChanges(final LogicalDatastoreType datastore, final DataChangeScope scope,
final ListenerAdapter listener) {
- checkPreconditions();
-
if (listener.isListening()) {
return;
}
builder.withChild(childBuilder.build());
} else if (child instanceof LeafNode) {
final Object defaultVal = ((LeafSchemaNode) childSchema).getType().getDefaultValue().orElse(null);
- final Object nodeVal = ((LeafNode<?>) child).getValue();
+ final Object nodeVal = child.getValue();
final NormalizedNodeAttrBuilder<NodeIdentifier, Object, LeafNode<Object>> leafBuilder =
Builders.leafBuilder((LeafSchemaNode) childSchema);
if (keys.contains(child.getNodeType())) {
- leafBuilder.withValue(((LeafNode<?>) child).getValue());
+ leafBuilder.withValue(child.getValue());
builder.withChild(leafBuilder.build());
} else {
if (trim) {
if (defaultVal == null || !defaultVal.equals(nodeVal)) {
- leafBuilder.withValue(((LeafNode<?>) child).getValue());
+ leafBuilder.withValue(child.getValue());
builder.withChild(leafBuilder.build());
}
} else {
if (defaultVal != null && defaultVal.equals(nodeVal)) {
- leafBuilder.withValue(((LeafNode<?>) child).getValue());
+ leafBuilder.withValue(child.getValue());
builder.withChild(leafBuilder.build());
}
}
builder.withChild(childBuilder.build());
} else if (child instanceof LeafNode) {
final Object defaultVal = ((LeafSchemaNode) childSchema).getType().getDefaultValue().orElse(null);
- final Object nodeVal = ((LeafNode<?>) child).getValue();
+ final Object nodeVal = child.getValue();
final NormalizedNodeAttrBuilder<NodeIdentifier, Object, LeafNode<Object>> leafBuilder =
Builders.leafBuilder((LeafSchemaNode) childSchema);
if (trim) {
if (defaultVal == null || !defaultVal.equals(nodeVal)) {
- leafBuilder.withValue(((LeafNode<?>) child).getValue());
+ leafBuilder.withValue(child.getValue());
builder.withChild(leafBuilder.build());
}
} else {
if (defaultVal != null && defaultVal.equals(nodeVal)) {
- leafBuilder.withValue(((LeafNode<?>) child).getValue());
+ leafBuilder.withValue(child.getValue());
builder.withChild(leafBuilder.build());
}
}
}
public void registerToListenNotification(final NotificationListenerAdapter listener) {
- checkPreconditions();
-
if (listener.isListening()) {
return;
}