use of jmri.Reporter in project JMRI by JMRI.
the class DefaultIdTagTest method testHasBeenSeen.
@Test
public void testHasBeenSeen() throws InterruptedException {
IdTag r = new DefaultIdTag("ID0413276BC1");
Reporter rep = new AbstractReporter("IR1") {
@Override
public int getState() {
return state;
}
@Override
public void setState(int s) {
state = s;
}
int state = 0;
};
Date timeBefore = Calendar.getInstance().getTime();
Thread.sleep(5);
r.setWhereLastSeen(rep);
Thread.sleep(5);
Date timeAfter = Calendar.getInstance().getTime();
Assert.assertEquals("Where last seen is 'IR1'", rep, r.getWhereLastSeen());
Assert.assertNotNull("When last seen is not null", r.getWhenLastSeen());
Assert.assertEquals("Status is SEEN", IdTag.SEEN, r.getState());
Assert.assertTrue("Time when last seen is later than 'timeBefore'", r.getWhenLastSeen().after(timeBefore));
Assert.assertTrue("Time when last seen is earlier than 'timeAfter'", r.getWhenLastSeen().before(timeAfter));
r.setWhereLastSeen(null);
Assert.assertNull("After setWhereLastSeen(null), Reporter where seen is null", r.getWhereLastSeen());
Assert.assertNull("After setWhereLastSeen(null), Date when seen is null", r.getWhenLastSeen());
Assert.assertEquals("After setWhereLastSeen(null), IdTag status is UNSEEN", IdTag.UNSEEN, r.getState());
}
use of jmri.Reporter in project JMRI by JMRI.
the class DefaultIdTag method setWhereLastSeen.
@Override
public final void setWhereLastSeen(Reporter r) {
Reporter oldWhere = this.whereLastSeen;
Date oldWhen = this.whenLastSeen;
this.whereLastSeen = r;
if (r != null) {
this.whenLastSeen = InstanceManager.getDefault(IdTagManager.class).isFastClockUsed() ? InstanceManager.getDefault(jmri.ClockControl.class).getTime() : Calendar.getInstance().getTime();
} else {
this.whenLastSeen = null;
}
setCurrentState(r != null ? SEEN : UNSEEN);
//NOI18N
firePropertyChange("whereLastSeen", oldWhere, this.whereLastSeen);
//NOI18N
firePropertyChange("whenLastSeen", oldWhen, this.whenLastSeen);
}
use of jmri.Reporter in project JMRI by JMRI.
the class AbstractReporterServer method initReporter.
public Reporter initReporter(String reporterName) throws IllegalArgumentException {
Reporter reporter = InstanceManager.getDefault(jmri.ReporterManager.class).provideReporter(reporterName);
this.addReporterToList(reporterName);
return reporter;
}
use of jmri.Reporter in project JMRI by JMRI.
the class AbstractReporterServer method setReporterReport.
/*
* Set the report state of a reporter
*
* @parm reporterName - the name of a reporter
* @parm r - the object containing the report (currently a string).
*/
public void setReporterReport(String reporterName, Object r) {
Reporter reporter;
// load address from reporterAddrTextField
try {
addReporterToList(reporterName);
reporter = InstanceManager.getDefault(jmri.ReporterManager.class).getReporter(reporterName);
if (reporter == null) {
log.error("Reporter {} is not available", reporterName);
} else {
log.debug("about to set reporter State");
reporter.setReport(r);
}
} catch (Exception ex) {
log.error("set reporter report", ex);
}
}
use of jmri.Reporter in project JMRI by JMRI.
the class SimpleReporterServer method parseStatus.
@Override
public void parseStatus(String statusString) throws JmriException, IOException {
int index, index2;
index = statusString.indexOf(" ") + 1;
index2 = statusString.indexOf(" ", index + 1);
int newlinepos = statusString.indexOf("\n");
String reporterName = statusString.substring(index, index2 > 0 ? index2 : newlinepos).toUpperCase();
initReporter(reporterName);
// the report, which may contain spaces.
if (index2 > 0 && (newlinepos - (index2 + 1) > 0)) {
setReporterReport(reporterName, statusString.substring(index2 + 1, newlinepos));
// setReporterReport ALSO triggers sending the status report, so
// no further action is required to echo the status to the client.
} else {
// send the current status if the report
try {
Reporter reporter = InstanceManager.getDefault(jmri.ReporterManager.class).provideReporter(reporterName);
sendReport(reporterName, reporter.getCurrentReport());
} catch (IllegalArgumentException ex) {
log.warn("Failed to provide Reporter \"{}\" in parseStatus", reporterName);
}
}
}
Aggregations