<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yang-common</artifactId>
</dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- </dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<groupId>org.opendaylight.mdsal.binding.model.ietf</groupId>
<artifactId>rfc6991-ietf-inet-types</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>osgi.cmpn</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.guicedee.services</groupId>
+ <artifactId>javax.inject</artifactId>
+ <optional>true</optional>
+ </dependency>
</dependencies>
</project>
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.bgpcep.pcep.server.provider;
-import com.google.common.base.Preconditions;
+import static java.util.Objects.requireNonNull;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.algo.PathComputationProvider;
import org.opendaylight.bgpcep.pcep.server.PceServerProvider;
import org.opendaylight.graph.ConnectedGraph;
import org.opendaylight.graph.ConnectedGraphProvider;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
-public class PceServerFactory implements PceServerProvider {
-
+@Singleton
+@Component(immediate = true)
+public final class DefaultPceServerProvider implements PceServerProvider {
private final ConnectedGraphProvider graphProvider;
private final PathComputationProvider algoProvider;
- private ConnectedGraph tedGraph = null;
- public PceServerFactory(ConnectedGraphProvider graphProvider, PathComputationProvider pathComputationProvider) {
- Preconditions.checkArgument(graphProvider != null);
- this.graphProvider = graphProvider;
- this.algoProvider = pathComputationProvider;
- setTedGraph();
- }
+ private volatile ConnectedGraph tedGraph;
- /**
- * Set Traffic Engineering Graph. This method is necessary as the TedGraph could be available
- * after the PathComputationFactory start e.g. manual insertion of a ted Graph, or late tedGraph fulfillment
- * from BGP Link State.
- */
- private void setTedGraph() {
- for (ConnectedGraph cgraph : this.graphProvider.getConnectedGraphs()) {
- if (cgraph.getGraph().getName().startsWith("ted://")) {
- this.tedGraph = cgraph;
- break;
- }
- }
+ @Inject
+ @Activate
+ public DefaultPceServerProvider(@Reference final ConnectedGraphProvider graphProvider,
+ @Reference final PathComputationProvider pathComputationProvider) {
+ this.graphProvider = requireNonNull(graphProvider);
+ this.algoProvider = requireNonNull(pathComputationProvider);
+ setTedGraph();
}
@Override
public @Nullable PathComputationImpl getPathComputation() {
/* Check that we have a valid graph */
- if (getTedGraph() == null) {
- return null;
- }
- return new PathComputationImpl(tedGraph, algoProvider);
+ final ConnectedGraph graph = getTedGraph();
+ return graph == null ? null : new PathComputationImpl(tedGraph, algoProvider);
}
@Override
if (tedGraph == null) {
setTedGraph();
}
- return this.tedGraph;
+ return tedGraph;
+ }
+
+ /**
+ * Set Traffic Engineering Graph. This method is necessary as the TedGraph could be available
+ * after the PathComputationFactory start e.g. manual insertion of a ted Graph, or late tedGraph fulfillment
+ * from BGP Link State.
+ */
+ private void setTedGraph() {
+ tedGraph = graphProvider.getConnectedGraphs().stream()
+ .filter(graph -> graph.getGraph().getName().startsWith("ted://"))
+ .findFirst()
+ .orElse(null);
}
}
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.bgpcep.pcep.server.provider;
-import com.google.common.base.Preconditions;
+import static java.util.Objects.requireNonNull;
+
import java.math.BigDecimal;
import java.nio.ByteBuffer;
import java.util.List;
private final PathComputationProvider algoProvider;
public PathComputationImpl(final ConnectedGraph tedGraph, final PathComputationProvider algoProvider) {
- Preconditions.checkArgument(tedGraph != null);
- this.tedGraph = tedGraph;
- this.algoProvider = algoProvider;
+ this.tedGraph = requireNonNull(tedGraph);
+ this.algoProvider = requireNonNull(algoProvider);
}
@Override
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- Copyright (c) 2020 Orange. All rights reserved.
-
- This program and the accompanying materials are made available under the
- terms of the Eclipse Public License v1.0 which accompanies this distribution,
- and is available at http://www.eclipse.org/legal/epl-v10.html
--->
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
-
- <reference id="pathComputationProvider" interface="org.opendaylight.algo.PathComputationProvider"/>
- <reference id="connectedGraphProvider" interface="org.opendaylight.graph.ConnectedGraphProvider" />
-
- <bean id="pceServerProvider" class="org.opendaylight.bgpcep.pcep.server.provider.PceServerFactory">
- <argument ref="connectedGraphProvider"/>
- <argument ref="pathComputationProvider"/>
- </bean>
-
- <service ref="pceServerProvider" interface="org.opendaylight.bgpcep.pcep.server.PceServerProvider"/>
-
-</blueprint>