Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

And as well as start your store with global scope (which means to sync remote updates):

Code Block
languagejava
try {

...


	this.syncService.registerStore("NameOfMyStore", Scope.GLOBAL);

...


	this.storeFT = this.syncService

...

.getStoreClient("NameOfMyStore",

...


					String.class,

...


					String.class);

...


	this.storeFT.addStoreListener(this);

...


} catch (SyncException e) {

...


	throw new FloodlightModuleException("Error while setting up sync service", e);
}

} 

To add some data in your store:

Code Block
languagejava
try {

...


	this.storeFT.put("Key Y", "Data X");
} catch (SyncException e) {
	e.printStackTrace();
}

To retrieve data from your store:

Code Block
languagejava
try {
	this.storeFT.get("Key Y").getValue().toString();
} catch (SyncException e) {

...


	e.printStackTrace();
}

} 

 


And finally, if you want monitor your store, it is necessary implement the interface IStoreListener<String>.
In this case our store has the string type.
In the example below we are just showing the remote sync events.
But you can uncomment the code and see local and remote updates from your sync store.
@Override
public void keysModified(Iterator<String> keys,
org.sdnplatform.sync.IStoreListener.UpdateType type) {
// TODO Auto-generated method stub
while(keys.hasNext()){
String k = keys.next();
try {
/*logger.debug("keysModified: Key:{}, Value:{}, Type: {}",
new Object[] {
k,
storeClient storeFT.get(k).getValue().toString(),
type.name()}
);*/
if(type.name().equals("REMOTE")){
String info = storeFT.get(k).getValue();
logger.debug("REMOTE: Key:{}, Value:{}", k, value);
}
} catch (SyncException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

...