package org.opendaylight.controller.sal.connector.api;
import java.util.concurrent.Future;
-
import org.opendaylight.yangtools.concepts.Immutable;
public interface BindingAwareRpcRouter extends RpcRouter<String, String, String, byte[]> {
this.payload = payload;
}
+ @Override
public BindingAwareRouteIdentifier getRoutingInformation() {
return this.routingInformation;
}
}
/**
- * Java class name of Rpc Context
- *
- *
+ * Java class name of Rpc Context.
*/
@Override
public String getContext() {
}
/**
- * Java class name of Rpc Type e.g org.opendaylight.AddFlowInput
- *
+ * Java class name of Rpc Type e.g org.opendaylight.AddFlowInput.
*/
@Override
public String getType() {
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + ((content == null) ? 0 : content.hashCode());
- result = prime * result + ((route == null) ? 0 : route.hashCode());
- result = prime * result + ((type == null) ? 0 : type.hashCode());
+ result = prime * result + (content == null ? 0 : content.hashCode());
+ result = prime * result + (route == null ? 0 : route.hashCode());
+ result = prime * result + (type == null ? 0 : type.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
- if (this == obj)
+ if (this == obj) {
return true;
- if (obj == null)
+ }
+ if (obj == null) {
return false;
- if (getClass() != obj.getClass())
+ }
+ if (getClass() != obj.getClass()) {
return false;
+ }
BindingAwareRouteIdentifier other = (BindingAwareRouteIdentifier) obj;
if (content == null) {
- if (other.content != null)
+ if (other.content != null) {
return false;
- } else if (!content.equals(other.content))
+ }
+ } else if (!content.equals(other.content)) {
return false;
+ }
if (route == null) {
- if (other.route != null)
+ if (other.route != null) {
return false;
- } else if (!route.equals(other.route))
+ }
+ } else if (!route.equals(other.route)) {
return false;
+ }
if (type == null) {
- if (other.type != null)
+ if (other.type != null) {
return false;
- } else if (!type.equals(other.type))
+ }
+ } else if (!type.equals(other.type)) {
return false;
+ }
return true;
}
-
}
-
}
package org.opendaylight.controller.sal.connector.api;
import java.util.Set;
-
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
public interface ConnectorListener {
-
void onPrefixesAnnounced(Set<YangInstanceIdentifier> prefixes);
- void onPrefixesWithdrawn(Set<YangInstanceIdentifier> prefixes);
+ void onPrefixesWithdrawn(Set<YangInstanceIdentifier> prefixes);
}
import java.util.concurrent.Future;
/**
+ * Interface for an RPC router.
*
* @author ttkacik
*
* @param <D> Data Type
*/
public interface RpcRouter<C,T,R,D> {
-
-
-
Future<RpcReply<D>> sendRpc(RpcRequest<C, T, R, D> input);
/**
- *
- * @author
+ * Interface for an RPC request.
*
* @param <C> Routing Context Identifier
- * @param <R> Route Type
- * @param <T> Rpc Type
- * @param <D> Data Type
+ * @param <R> Route Type
+ * @param <T> Rpc Type
+ * @param <D> Data Type
*/
interface RpcRequest<C,T,R,D> {
RouteIdentifier<C,T,R> getRoutingInformation();
+
D getPayload();
}
interface RouteIdentifier<C,T,R> {
C getContext(); // defines a routing table (e.g. NodeContext)
+
T getType(); // rpc type
+
R getRoute(); // e.g. (node identity)
}
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class DummyShard extends UntypedActor{
+public class DummyShard extends UntypedActor {
+ private static final Logger LOG = LoggerFactory.getLogger(DummyShard.class);
+
private final Configuration configuration;
private final String followerId;
- private final Logger LOG = LoggerFactory.getLogger(DummyShard.class);
private long lastMessageIndex = -1;
private long lastMessageSize = 0;
private Stopwatch appendEntriesWatch;
}
@Override
- public void onReceive(Object o) throws Exception {
- if(o instanceof RequestVote){
- RequestVote req = (RequestVote) o;
+ public void onReceive(Object message) throws Exception {
+ if (message instanceof RequestVote) {
+ RequestVote req = (RequestVote) message;
sender().tell(new RequestVoteReply(req.getTerm(), true), self());
- } else if(o instanceof AppendEntries) {
- handleAppendEntries((AppendEntries)o);
- } else if(o instanceof InstallSnapshot){
- handleInstallSnapshot((InstallSnapshot) o);
+ } else if (message instanceof AppendEntries) {
+ handleAppendEntries((AppendEntries) message);
+ } else if (message instanceof InstallSnapshot) {
+ handleInstallSnapshot((InstallSnapshot) message);
} else {
- LOG.error("Unknown message : {}", o.getClass());
+ LOG.error("Unknown message : {}", message.getClass());
}
}
LOG.info("{} - Received AppendEntries message : leader term = {}, index = {}, prevLogIndex = {}, size = {}",
followerId, req.getTerm(),req.getLeaderCommit(), req.getPrevLogIndex(), req.getEntries().size());
- if(appendEntriesWatch != null){
+ if (appendEntriesWatch != null) {
long elapsed = appendEntriesWatch.elapsed(TimeUnit.SECONDS);
- if(elapsed >= 5){
- LOG.error("More than 5 seconds since last append entry, elapsed Time = {} seconds" +
- ", leaderCommit = {}, prevLogIndex = {}, size = {}",
+ if (elapsed >= 5) {
+ LOG.error("More than 5 seconds since last append entry, elapsed Time = {} seconds"
+ + ", leaderCommit = {}, prevLogIndex = {}, size = {}",
elapsed, req.getLeaderCommit(), req.getPrevLogIndex(), req.getEntries().size());
}
appendEntriesWatch.reset().start();
appendEntriesWatch = Stopwatch.createStarted();
}
- if(lastMessageIndex == req.getLeaderCommit() && req.getEntries().size() > 0 && lastMessageSize > 0){
- LOG.error("{} - Duplicate message with leaderCommit = {} prevLogIndex = {} received", followerId, req.getLeaderCommit(), req.getPrevLogIndex());
+ if (lastMessageIndex == req.getLeaderCommit() && req.getEntries().size() > 0 && lastMessageSize > 0) {
+ LOG.error("{} - Duplicate message with leaderCommit = {} prevLogIndex = {} received", followerId,
+ req.getLeaderCommit(), req.getPrevLogIndex());
}
lastMessageIndex = req.getLeaderCommit();
long lastIndex = req.getLeaderCommit();
if (req.getEntries().size() > 0) {
- for(ReplicatedLogEntry entry : req.getEntries()) {
+ for (ReplicatedLogEntry entry : req.getEntries()) {
lastIndex = entry.getIndex();
}
}
return new DummyShard(configuration, followerId);
}
}
-
}
import akka.japi.Creator;
public class DummyShardManager extends UntypedActor {
- public DummyShardManager(Configuration configuration, String memberName, String[] shardNames, String type) throws Exception {
+ public DummyShardManager(Configuration configuration, String memberName, String[] shardNames,
+ String type) throws Exception {
new DummyShardsCreator(configuration, context(), memberName, shardNames, type).create();
}
@Override
- public void onReceive(Object o) throws Exception {
+ public void onReceive(Object message) throws Exception {
}
- public static Props props(Configuration configuration, String memberName, String[] shardNames, String type){
+ public static Props props(Configuration configuration, String memberName, String[] shardNames, String type) {
return Props.create(new DummyShardManagerCreator(configuration, memberName, shardNames, type));
}
private final String[] shardNames;
private final String type;
- public DummyShardManagerCreator(Configuration configuration, String memberName, String[] shardNames, String type) {
+ DummyShardManagerCreator(Configuration configuration, String memberName, String[] shardNames, String type) {
this.configuration = configuration;
this.memberName = memberName;
this.shardNames = shardNames;
@Override
public DummyShardManager create() throws Exception {
- return new DummyShardManager(configuration, memberName, shardNames, type );
+ return new DummyShardManager(configuration, memberName, shardNames, type);
}
}
private final String[] shardNames;
private final String type;
- DummyShardsCreator(Configuration configuration, ActorContext actorSystem, String memberName, String[] shardNames, String type){
+ DummyShardsCreator(Configuration configuration, ActorContext actorSystem, String memberName,
+ String[] shardNames, String type) {
this.configuration = configuration;
this.actorSystem = actorSystem;
this.memberName = memberName;
this.type = type;
}
- void create(){
- for(String shardName : shardNames){
+ void create() {
+ for (String shardName : shardNames) {
String shardId = memberName + "-shard-" + shardName + "-" + type;
actorSystem.actorOf(DummyShard.props(configuration, shardId), shardId);
}
import akka.actor.ActorSystem;
import com.typesafe.config.ConfigFactory;
+import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.CmdLineParser;
import org.kohsuke.args4j.Option;
public class Main {
- @Option(name="-member-name", usage="Sets the member name", required = true)
+ @Option(name = "-member-name", usage = "Sets the member name", required = true)
public String memberName;
- @Option(name="-max-delay-millis", usage = "Sets the maximum delay that should be applied for any append entry. Only applies when cause-trouble is present.")
+ @Option(name = "-max-delay-millis", usage = "Sets the maximum delay that should be applied for any append entry. "
+ + "Only applies when cause-trouble is present.")
public int maxDelayInMillis = 500;
- @Option(name="-cause-trouble", usage="If present turns on artificial failures")
+ @Option(name = "-cause-trouble", usage = "If present turns on artificial failures")
public boolean causeTrouble = false;
- @Option(name="-drop-replies", usage = "If present drops replies. Only applies when cause-trouble is present.")
+ @Option(name = "-drop-replies", usage = "If present drops replies. Only applies when cause-trouble is present.")
public boolean dropReplies = false;
- public void run(){
- ActorSystem actorSystem = ActorSystem.create("opendaylight-cluster-data", ConfigFactory.load(memberName).getConfig("odl-cluster-data"));
+ public void run() {
+ ActorSystem actorSystem = ActorSystem.create("opendaylight-cluster-data",
+ ConfigFactory.load(memberName).getConfig("odl-cluster-data"));
Configuration configuration = new Configuration(maxDelayInMillis, dropReplies, causeTrouble);
- actorSystem.actorOf(DummyShardManager.props(configuration, memberName, new String[] {"inventory", "default", "toaster", "topology"}, "operational"), "shardmanager-operational");
- actorSystem.actorOf(DummyShardManager.props(configuration, memberName, new String[] {"inventory", "default", "toaster", "topology"}, "config"), "shardmanager-config");
+ actorSystem.actorOf(DummyShardManager.props(configuration, memberName,
+ new String[] {"inventory", "default", "toaster", "topology"}, "operational"),
+ "shardmanager-operational");
+ actorSystem.actorOf(DummyShardManager.props(configuration, memberName,
+ new String[] {"inventory", "default", "toaster", "topology"}, "config"), "shardmanager-config");
}
@Override
public String toString() {
- return "Main{" +
- "memberName='" + memberName + '\'' +
- ", maxDelayInMillis=" + maxDelayInMillis +
- ", causeTrouble=" + causeTrouble +
- ", dropReplies=" + dropReplies +
- '}';
+ return "Main{" + "memberName='" + memberName + '\'' + ", maxDelayInMillis=" + maxDelayInMillis
+ + ", causeTrouble=" + causeTrouble + ", dropReplies=" + dropReplies + '}';
}
- public static void main(String[] args){
+ @SuppressWarnings("checkstyle:RegexpSingleLineJava")
+ public static void main(String[] args) {
Main bean = new Main();
CmdLineParser parser = new CmdLineParser(bean);
parser.parseArgument(args);
System.out.println(bean.toString());
bean.run();
- } catch(Exception e){
+ } catch (CmdLineException e) {
System.err.println(e.getMessage());
parser.printUsage(System.err);
}
}
-
}