- SessionBuilder builder = new SessionBuilder();
-
- builder.setSessionId(getSessionId());
- builder.setSourceHost(new Host(new DomainName(header.getAddress())));
-
- Preconditions.checkState(DateAndTime.PATTERN_CONSTANTS.size() == 1);
- String formattedDateTime = dateFormatter.format(loginTime);
-
- Matcher matcher = dateTimePattern.matcher(formattedDateTime);
- Preconditions.checkState(matcher.matches(), "Formatted datetime %s does not match pattern %s", formattedDateTime, dateTimePattern);
- builder.setLoginTime(new DateAndTime(formattedDateTime));
-
- builder.setInBadRpcs(new ZeroBasedCounter32(inRpcFail));
- builder.setInRpcs(new ZeroBasedCounter32(inRpcSuccess));
- builder.setOutRpcErrors(new ZeroBasedCounter32(outRpcError));
-
- builder.setUsername(header.getUserName());
- builder.setTransport(getTransportForString(header.getTransport()));
-
- builder.setOutNotifications(new ZeroBasedCounter32(0L));
-
- builder.setKey(new SessionKey(getSessionId()));
-
- Session1Builder builder1 = new Session1Builder();
- builder1.setSessionIdentifier(header.getSessionIdentifier());
- builder.addAugmentation(Session1.class, builder1.build());
-
- return builder.build();
+ final SessionBuilder builder = new SessionBuilder()
+ .withKey(new SessionKey(Uint32.valueOf(getSessionId())));
+ final InetAddress address1 = InetAddresses.forString(header.getAddress());
+ final IpAddress address;
+ if (address1 instanceof Inet4Address) {
+ address = new IpAddress(new Ipv4Address(header.getAddress()));
+ } else {
+ address = new IpAddress(new Ipv6Address(header.getAddress()));
+ }
+ builder.setSourceHost(new Host(address));
+
+ final String formattedDateTime = DATE_FORMATTER.format(loginTime);
+ checkState(DATE_TIME_PATTERN.matcher(formattedDateTime).matches(),
+ "Formatted datetime %s does not match pattern %s", formattedDateTime, DATE_TIME_PATTERN);
+
+ return builder
+ .setLoginTime(new DateAndTime(formattedDateTime))
+ .setInBadRpcs(new ZeroBasedCounter32(Uint32.valueOf(inRpcFail)))
+ .setInRpcs(new ZeroBasedCounter32(Uint32.valueOf(inRpcSuccess)))
+ .setOutRpcErrors(new ZeroBasedCounter32(Uint32.valueOf(outRpcError)))
+ .setUsername(header.getUserName())
+ .setTransport(getTransportForString(header.getTransport()))
+ .setOutNotifications(new ZeroBasedCounter32(Uint32.valueOf(outNotification)))
+ .addAugmentation(new Session1Builder().setSessionIdentifier(header.getSessionIdentifier()).build())
+ .build();