com.davfx.ninio.snmp.FromMapSnmpServerHandler Maven / Gradle / Ivy
package com.davfx.ninio.snmp;
import java.io.IOException;
import java.util.Map;
import java.util.SortedMap;
import com.davfx.ninio.core.Address;
public final class FromMapSnmpServerHandler implements SnmpServerHandler {
private final SortedMap map;
private final SnmpServerHandler wrappee;
public FromMapSnmpServerHandler(SortedMap map, SnmpServerHandler wrappee) {
this.map = map;
this.wrappee = wrappee;
}
@Override
public void from(Oid oid, SnmpServerHandler.Callback callback) {
SortedMap tail = map.tailMap(oid);
for (Map.Entry e : tail.entrySet()) {
if (!callback.handle(new SnmpResult(e.getKey(), e.getValue()))) {
break;
}
}
}
@Override
public void connected(Address address) {
if (wrappee != null) {
wrappee.connected(address);
}
}
@Override
public void closed() {
if (wrappee != null) {
wrappee.closed();
}
}
@Override
public void failed(IOException ioe) {
if (wrappee != null) {
wrappee.failed(ioe);
}
}
}