use of org.opennms.core.ipc.sink.api.AggregationPolicy in project opennms by OpenNMS.
the class SyslogSinkModule method getAggregationPolicy.
@Override
public AggregationPolicy<SyslogConnection, SyslogMessageLogDTO, SyslogMessageLogDTO> getAggregationPolicy() {
final String systemId = distPollerDao.whoami().getId();
final String systemLocation = distPollerDao.whoami().getLocation();
return new AggregationPolicy<SyslogConnection, SyslogMessageLogDTO, SyslogMessageLogDTO>() {
@Override
public int getCompletionSize() {
return config.getBatchSize();
}
@Override
public int getCompletionIntervalMs() {
return config.getBatchIntervalMs();
}
@Override
public Object key(SyslogConnection syslogConnection) {
return syslogConnection.getSource();
}
@Override
public SyslogMessageLogDTO aggregate(SyslogMessageLogDTO accumulator, SyslogConnection connection) {
if (accumulator == null) {
accumulator = new SyslogMessageLogDTO(systemLocation, systemId, connection.getSource());
}
SyslogMessageDTO messageDTO = new SyslogMessageDTO(connection.getBuffer());
accumulator.getMessages().add(messageDTO);
return accumulator;
}
@Override
public SyslogMessageLogDTO build(SyslogMessageLogDTO accumulator) {
return accumulator;
}
};
}
use of org.opennms.core.ipc.sink.api.AggregationPolicy in project opennms by OpenNMS.
the class TrapSinkModule method getAggregationPolicy.
@Override
public AggregationPolicy<TrapInformationWrapper, TrapLogDTO, TrapLogDTO> getAggregationPolicy() {
return new AggregationPolicy<TrapInformationWrapper, TrapLogDTO, TrapLogDTO>() {
@Override
public int getCompletionSize() {
return config.getBatchSize();
}
@Override
public int getCompletionIntervalMs() {
return config.getBatchIntervalMs();
}
@Override
public Object key(TrapInformationWrapper message) {
return message.getTrapInformation().getTrapAddress();
}
@Override
public TrapLogDTO aggregate(TrapLogDTO accumulator, TrapInformationWrapper newMessage) {
final TrapInformation trapInfo = newMessage.getTrapInformation();
if (accumulator == null) {
// no log created yet
accumulator = new TrapLogDTO(distPoller.getId(), distPoller.getLocation(), TrapUtils.getEffectiveTrapAddress(trapInfo, config.shouldUseAddressFromVarbind()));
}
final TrapDTO trapDTO = new TrapDTO(trapInfo);
// include the raw message, if configured
if (config.isIncludeRawMessage()) {
byte[] rawMessage = convertToRawMessage(trapInfo);
if (rawMessage != null) {
trapDTO.setRawMessage(convertToRawMessage(trapInfo));
}
}
accumulator.addMessage(trapDTO);
return accumulator;
}
@Override
public TrapLogDTO build(TrapLogDTO accumulator) {
return accumulator;
}
};
}
use of org.opennms.core.ipc.sink.api.AggregationPolicy in project opennms by OpenNMS.
the class TelemetrySinkModule method getAggregationPolicy.
@Override
public AggregationPolicy<TelemetryMessage, TelemetryProtos.TelemetryMessageLog, TelemetryProtos.TelemetryMessageLog.Builder> getAggregationPolicy() {
final String systemId = distPollerDao.whoami().getId();
final String systemLocation = distPollerDao.whoami().getLocation();
return new AggregationPolicy<TelemetryMessage, TelemetryProtos.TelemetryMessageLog, TelemetryProtos.TelemetryMessageLog.Builder>() {
@Override
public int getCompletionSize() {
return protocol.getBatchSize().orElse(DEFAULT_BATCH_SIZE);
}
@Override
public int getCompletionIntervalMs() {
return protocol.getBatchIntervalMs().orElse(DEFAULT_BATCH_INTERVAL_MS);
}
@Override
public Object key(TelemetryMessage telemetryMessage) {
return telemetryMessage.getSource();
}
@Override
public TelemetryProtos.TelemetryMessageLog.Builder aggregate(TelemetryProtos.TelemetryMessageLog.Builder accumulator, TelemetryMessage message) {
if (accumulator == null) {
accumulator = TelemetryProtos.TelemetryMessageLog.newBuilder().setLocation(systemLocation).setSystemId(systemId).setSourceAddress(message.getSource().getHostString()).setSourcePort(message.getSource().getPort());
}
final TelemetryProtos.TelemetryMessage messageDto = TelemetryProtos.TelemetryMessage.newBuilder().setTimestamp(message.getReceivedAt().getTime()).setBytes(ByteString.copyFrom(message.getBuffer())).build();
// Append
accumulator.addMessage(messageDto);
return accumulator;
}
@Override
public TelemetryProtos.TelemetryMessageLog build(TelemetryProtos.TelemetryMessageLog.Builder accumulator) {
return accumulator.build();
}
};
}
Aggregations