Minor change, just added MapDB groovy toy script
This commit is contained in:
@@ -84,7 +84,7 @@ public class MapDBPersistentStore implements IMessagesStore, ISessionsStore {
|
|||||||
LOG.error(null, ex);
|
LOG.error(null, ex);
|
||||||
throw new MQTTException("Can't create temp file for subscriptions storage [" + m_storePath + "]", ex);
|
throw new MQTTException("Can't create temp file for subscriptions storage [" + m_storePath + "]", ex);
|
||||||
}
|
}
|
||||||
m_db = DBMaker.newFileDB(tmpFile).make();
|
m_db = DBMaker.newFileDB(tmpFile).closeOnJvmShutdown().make();
|
||||||
}
|
}
|
||||||
m_retainedStore = m_db.getHashMap("retained");
|
m_retainedStore = m_db.getHashMap("retained");
|
||||||
m_persistentMessageStore = m_db.getHashMap("persistedMessages");
|
m_persistentMessageStore = m_db.getHashMap("persistedMessages");
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
@Grab(group='org.mapdb', module='mapdb', version='1.0.8')
|
||||||
|
import org.mapdb.DB
|
||||||
|
import org.mapdb.DBMaker
|
||||||
|
|
||||||
|
class User implements Serializable {
|
||||||
|
String name
|
||||||
|
String surname
|
||||||
|
}
|
||||||
|
|
||||||
|
def writeSomeData(Map m) {
|
||||||
|
m.put(1, new User(name: "mario", surname: "rossi"))
|
||||||
|
m.put(2, new User(name: "gianni", surname: "bianchi"))
|
||||||
|
m.put(3, new User(name: "pino", surname: "verdi"))
|
||||||
|
}
|
||||||
|
|
||||||
|
def readSomeData(Map m) {
|
||||||
|
m.each {k, v ->
|
||||||
|
println "id: $k, value: $v"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.size() != 1) {
|
||||||
|
println "groovy mapdbWalTest.groovy [writer|reader]"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
String mode = args[0]
|
||||||
|
File tmpFile = new File("test_store.mapdb")
|
||||||
|
tmpFile.createNewFile()
|
||||||
|
DB db = DBMaker.newFileDB(tmpFile).make()
|
||||||
|
Map mapStore = db.getHashMap("storageMap")
|
||||||
|
|
||||||
|
switch (mode) {
|
||||||
|
case "writer":
|
||||||
|
writeSomeData(mapStore)
|
||||||
|
db.commit()
|
||||||
|
return
|
||||||
|
case "reader":
|
||||||
|
readSomeData(mapStore)
|
||||||
|
return
|
||||||
|
default:
|
||||||
|
println "Error option not recognized must be one of [writer|reader]"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user