use of jmri.IdTag in project JMRI by JMRI.
the class ConcentratorReporterManager method processReply.
private void processReply(ConcentratorReply r) {
if (!tc.getAdapterMemo().getProtocol().isValid(r)) {
log.warn("Invalid message - skipping " + r);
return;
}
if (!r.isInRange()) {
log.warn("Invalid concentrator reader range - skipping " + r);
return;
}
IdTag idTag = InstanceManager.getDefault(IdTagManager.class).provideIdTag(tc.getAdapterMemo().getProtocol().getTag(r));
TimeoutRfidReporter report = (TimeoutRfidReporter) provideReporter(prefix + typeLetter() + r.getReaderPort());
report.notify(idTag);
}
use of jmri.IdTag in project JMRI by JMRI.
the class DefaultIdTagManager method newIdTag.
@Override
public IdTag newIdTag(@Nonnull String systemName, @CheckForNull String userName) {
if (!initialised && !loading) {
init();
}
if (log.isDebugEnabled()) {
log.debug("new IdTag:" + // NOI18N
((systemName == null) ? "null" : systemName) + ";" + // NOI18N
((userName == null) ? "null" : userName));
}
checkSystemName(systemName, userName);
// return existing if there is one
IdTag s;
if ((userName != null) && ((s = getByUserName(userName)) != null)) {
if (getBySystemName(systemName) != s) {
log.error("inconsistent user (" + userName + ") and system name (" + systemName + ") results; userName related to (" + s.getSystemName() + ")");
}
return s;
}
if ((s = getBySystemName(systemName)) != null) {
if ((s.getUserName() == null) && (userName != null)) {
s.setUserName(userName);
} else if (userName != null) {
log.warn("Found IdTag via system name (" + systemName + ") with non-null user name (" + userName + // NOI18N
")");
}
return s;
}
// doesn't exist, make a new one
s = createNewIdTag(systemName, userName);
// save in the maps
register(s);
// if that failed, blame it on the input arguements
if (s == null) {
throw new IllegalArgumentException();
}
return s;
}
use of jmri.IdTag in project JMRI by JMRI.
the class DefaultIdTagManager method getIdTag.
@Override
public IdTag getIdTag(String name) {
if (!initialised && !loading) {
init();
}
IdTag t = getBySystemName(makeSystemName(name));
if (t != null) {
return t;
}
t = getByUserName(name);
if (t != null) {
return t;
}
return getBySystemName(name);
}
use of jmri.IdTag in project JMRI by JMRI.
the class DefaultRailComManager method getTagsForReporter.
@Override
public List<IdTag> getTagsForReporter(Reporter reporter, long threshold) {
List<IdTag> out = new ArrayList<>();
Date lastWhenLastSeen = new Date(0);
// and record the time most recently seen
for (NamedBean n : _tsys.values()) {
IdTag t = (IdTag) n;
if (t.getWhereLastSeen() == reporter) {
out.add(t);
if (t.getWhenLastSeen().after(lastWhenLastSeen)) {
lastWhenLastSeen = t.getWhenLastSeen();
}
}
}
if (out.size() > 0) {
// Calculate the threshold time based on the most recently seen tag
Date thresholdTime = new Date(lastWhenLastSeen.getTime() - threshold);
// Now remove from the list all tags seen prior to the threshold time
for (IdTag t : out) {
if (t.getWhenLastSeen().before(thresholdTime)) {
out.remove(t);
}
}
}
return out;
}
Aggregations