Search in sources :

Example 41 with Reporter

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());
}
Also used : Reporter(jmri.Reporter) IdTag(jmri.IdTag) Date(java.util.Date) Test(org.junit.Test)

Example 42 with Reporter

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);
}
Also used : IdTagManager(jmri.IdTagManager) Reporter(jmri.Reporter) Date(java.util.Date)

Example 43 with Reporter

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;
}
Also used : Reporter(jmri.Reporter)

Example 44 with 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);
    }
}
Also used : Reporter(jmri.Reporter) JmriException(jmri.JmriException) IOException(java.io.IOException)

Example 45 with Reporter

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);
        }
    }
}
Also used : Reporter(jmri.Reporter)

Aggregations

Reporter (jmri.Reporter)55 Test (org.junit.Test)18 ReporterManager (jmri.ReporterManager)10 Block (jmri.Block)6 Element (org.jdom2.Element)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 IOException (java.io.IOException)4 BlockManager (jmri.BlockManager)4 JsonException (jmri.server.json.JsonException)4 Date (java.util.Date)3 JmriException (jmri.JmriException)3 Sensor (jmri.Sensor)3 OBlock (jmri.jmrit.logix.OBlock)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 ParseException (java.text.ParseException)2 PhysicalLocationReporter (jmri.PhysicalLocationReporter)2 Location (jmri.jmrit.operations.locations.Location)2 JsonMockConnection (jmri.server.json.JsonMockConnection)2 GuiLafPreferencesManager (apps.gui.GuiLafPreferencesManager)1