use of jmri.MemoryManager in project JMRI by JMRI.
the class AbstractMemoryManagerConfigXML method loadMemories.
/**
* Utility method to load the individual Memory objects. If there's no
* additional info needed for a specific Memory type, invoke this with the
* parent of the set of Memory elements.
*
* @param memories Element containing the Memory elements to load.
*/
@SuppressWarnings("unchecked")
public void loadMemories(Element memories) {
List<Element> memoryList = memories.getChildren("memory");
if (log.isDebugEnabled()) {
log.debug("Found " + memoryList.size() + " Memory objects");
}
MemoryManager tm = InstanceManager.memoryManagerInstance();
for (int i = 0; i < memoryList.size(); i++) {
String sysName = getSystemName(memoryList.get(i));
if (sysName == null) {
log.warn("unexpected null in systemName " + (memoryList.get(i)));
break;
}
String userName = getUserName(memoryList.get(i));
checkNameNormalization(sysName, userName, tm);
if (log.isDebugEnabled()) {
log.debug("create Memory: (" + sysName + ")(" + (userName == null ? "<null>" : userName) + ")");
}
Memory m = tm.newMemory(sysName, userName);
if (memoryList.get(i).getAttribute("value") != null) {
loadValue(memoryList.get(i), m);
}
// load common parts
loadCommon(m, memoryList.get(i));
}
}
use of jmri.MemoryManager in project JMRI by JMRI.
the class JsonMemoryHttpServiceTest method testDoPut.
public void testDoPut() {
ObjectMapper mapper = new ObjectMapper();
JsonMemoryHttpService service = new JsonMemoryHttpService(mapper);
MemoryManager manager = InstanceManager.getDefault(MemoryManager.class);
JsonNode message;
try {
// add a memory
Assert.assertNull(manager.getMemory("IM1"));
message = mapper.createObjectNode().put(JSON.NAME, "IM1").put(JSON.VALUE, "close");
service.doPut(JsonMemory.MEMORY, "IM1", message, Locale.ENGLISH);
Assert.assertNotNull(manager.getMemory("IM1"));
} catch (JsonException ex) {
Assert.fail(ex.getMessage());
}
}
use of jmri.MemoryManager in project JMRI by JMRI.
the class JsonMemoryHttpServiceTest method testDoGet.
public void testDoGet() throws JmriException {
JsonMemoryHttpService service = new JsonMemoryHttpService(new ObjectMapper());
MemoryManager manager = InstanceManager.getDefault(MemoryManager.class);
// no value
Memory memory1 = manager.provideMemory("IM1");
JsonNode result;
try {
result = service.doGet(JsonMemory.MEMORY, "IM1", Locale.ENGLISH);
Assert.assertNotNull(result);
Assert.assertEquals(JsonMemory.MEMORY, result.path(JSON.TYPE).asText());
Assert.assertEquals("IM1", result.path(JSON.DATA).path(JSON.NAME).asText());
// JSON node has the text "null" if memory is null
Assert.assertEquals("null", result.path(JSON.DATA).path(JSON.VALUE).asText());
memory1.setValue("throw");
result = service.doGet(JsonMemory.MEMORY, "IM1", Locale.ENGLISH);
Assert.assertNotNull(result);
Assert.assertEquals("throw", result.path(JSON.DATA).path(JSON.VALUE).asText());
memory1.setValue("close");
result = service.doGet(JsonMemory.MEMORY, "IM1", Locale.ENGLISH);
Assert.assertNotNull(result);
Assert.assertEquals("close", result.path(JSON.DATA).path(JSON.VALUE).asText());
} catch (JsonException ex) {
Assert.fail(ex.getMessage());
}
}
use of jmri.MemoryManager in project JMRI by JMRI.
the class JsonMemorySocketServiceTest method testOnMessageChange.
public void testOnMessageChange() {
try {
JsonMockConnection connection = new JsonMockConnection((DataOutputStream) null);
JsonNode message;
JsonMemorySocketService service = new JsonMemorySocketService(connection);
MemoryManager manager = InstanceManager.getDefault(MemoryManager.class);
Memory memory1 = manager.provideMemory("IM1");
// Memory "close"
message = connection.getObjectMapper().createObjectNode().put(JSON.NAME, "IM1").put(JSON.VALUE, "close");
service.onMessage(JsonMemory.MEMORY, message, Locale.ENGLISH);
Assert.assertEquals("close", memory1.getValue());
// Memory "throw"
message = connection.getObjectMapper().createObjectNode().put(JSON.NAME, "IM1").put(JSON.VALUE, "throw");
service.onMessage(JsonMemory.MEMORY, message, Locale.ENGLISH);
Assert.assertEquals("throw", memory1.getValue());
// Memory UNKNOWN - remains ON
message = connection.getObjectMapper().createObjectNode().put(JSON.NAME, "IM1").putNull(JSON.VALUE);
service.onMessage(JsonMemory.MEMORY, message, Locale.ENGLISH);
Assert.assertEquals(null, memory1.getValue());
memory1.setValue("throw");
// Memory no value
message = connection.getObjectMapper().createObjectNode().put(JSON.NAME, "IM1");
JsonException exception = null;
try {
service.onMessage(JsonMemory.MEMORY, message, Locale.ENGLISH);
} catch (JsonException ex) {
exception = ex;
}
Assert.assertEquals("throw", memory1.getValue());
Assert.assertNull(exception);
} catch (IOException | JmriException | JsonException ex) {
Assert.fail(ex.getMessage());
}
}
use of jmri.MemoryManager in project JMRI by JMRI.
the class MemoryTrackerTest method testDirectCreate.
public void testDirectCreate() {
MemoryManager m = InstanceManager.memoryManagerInstance();
jmri.InstanceManager.store(new jmri.NamedBeanHandleManager(), jmri.NamedBeanHandleManager.class);
m.provideMemory("dummy");
// check for exception in ctor
new MemoryTracker(new Block("dummy"), "");
}
Aggregations