Preconditions.checkArgument(reply != null);
final GroupFeaturesBuilder groupFeature = new GroupFeaturesBuilder();
groupFeature.setMaxGroups(reply.getMaxGroups());
+
final List<Class<? extends GroupType>> supportedGroups = new ArrayList<>();
- if (reply.getTypes().isOFPGTALL()) {
- supportedGroups.add(GroupAll.class);
- }
- if (reply.getTypes().isOFPGTSELECT()) {
- supportedGroups.add(GroupSelect.class);
- }
- if (reply.getTypes().isOFPGTINDIRECT()) {
- supportedGroups.add(GroupIndirect.class);
- }
- if (reply.getTypes().isOFPGTFF()) {
- supportedGroups.add(GroupFf.class);
- }
+ addSupportedGroups(reply, supportedGroups);
groupFeature.setGroupTypesSupported(supportedGroups);
final List<Class<? extends GroupCapability>> gCapability = new ArrayList<>();
- if (reply.getCapabilities().isOFPGFCCHAINING()) {
- gCapability.add(Chaining.class);
- }
- if (reply.getCapabilities().isOFPGFCCHAININGCHECKS()) {
- gCapability.add(ChainingChecks.class);
- }
- if (reply.getCapabilities().isOFPGFCSELECTLIVENESS()) {
- gCapability.add(SelectLiveness.class);
- }
- if (reply.getCapabilities().isOFPGFCSELECTWEIGHT()) {
- gCapability.add(SelectWeight.class);
- }
+ addGroupCapabilities(reply, gCapability);
groupFeature.setGroupCapabilitiesSupported(gCapability);
final List<Long> supportActionByGroups = new ArrayList<>();
return new NodeGroupFeaturesBuilder().setGroupFeatures(groupFeature.build()).build();
}
+ private static void addGroupCapabilities(final MultipartReplyGroupFeatures reply, final List<Class<? extends GroupCapability>> gCapability) {
+ if (reply.getCapabilities().isOFPGFCCHAINING()) {
+ gCapability.add(Chaining.class);
+ }
+ if (reply.getCapabilities().isOFPGFCCHAININGCHECKS()) {
+ gCapability.add(ChainingChecks.class);
+ }
+ if (reply.getCapabilities().isOFPGFCSELECTLIVENESS()) {
+ gCapability.add(SelectLiveness.class);
+ }
+ if (reply.getCapabilities().isOFPGFCSELECTWEIGHT()) {
+ gCapability.add(SelectWeight.class);
+ }
+ }
+
+ private static void addSupportedGroups(final MultipartReplyGroupFeatures reply, final List<Class<? extends GroupType>> supportedGroups) {
+ if (reply.getTypes().isOFPGTALL()) {
+ supportedGroups.add(GroupAll.class);
+ }
+ if (reply.getTypes().isOFPGTSELECT()) {
+ supportedGroups.add(GroupSelect.class);
+ }
+ if (reply.getTypes().isOFPGTINDIRECT()) {
+ supportedGroups.add(GroupIndirect.class);
+ }
+ if (reply.getTypes().isOFPGTFF()) {
+ supportedGroups.add(GroupFf.class);
+ }
+ }
+
/**
* Method transform {@link MultipartReplyTableFeatures} to list of {@link TableFeatures}. Every
* table can have List of TableFeatures so add it directly to
@Override
public void onSwitchIdleEvent(final SwitchIdleEvent notification) {
- threadPool.execute(() -> {
- boolean shouldBeDisconnected = true;
-
- final InetSocketAddress remoteAddress = connectionContext.getConnectionAdapter().getRemoteAddress();
-
- if (ConnectionContext.CONNECTION_STATE.WORKING.equals(connectionContext.getConnectionState())) {
- FeaturesReply features = connectionContext.getFeatures();
- LOG.info("Switch Idle state occurred, node={}|auxId={}", remoteAddress, features.getAuxiliaryId());
- connectionContext.changeStateToTimeouting();
- EchoInputBuilder builder = new EchoInputBuilder();
- builder.setVersion(features.getVersion());
- Xid xid = new Xid(0L);
- builder.setXid(xid.getValue());
-
- Future<RpcResult<EchoOutput>> echoReplyFuture = connectionContext.getConnectionAdapter().echo(builder.build());
-
- try {
- RpcResult<EchoOutput> echoReplyValue = echoReplyFuture.get(echoReplyTimeout, TimeUnit.MILLISECONDS);
- if (echoReplyValue.isSuccessful()) {
- connectionContext.changeStateToWorking();
- shouldBeDisconnected = false;
- } else {
- for (RpcError replyError : echoReplyValue.getErrors()) {
- Throwable cause = replyError.getCause();
- if (LOG.isWarnEnabled()) {
- LOG.warn("Received EchoReply from [{}] in TIMEOUTING state, Error:{}", remoteAddress, cause.getMessage());
- }
-
- if (LOG.isTraceEnabled()) {
- LOG.trace("Received EchoReply from [{}] in TIMEOUTING state, Error:{}", remoteAddress, cause);
- }
-
- }
- }
- } catch (Exception e) {
- if (LOG.isWarnEnabled()) {
- LOG.warn("Exception while waiting for echoReply from [{}] in TIMEOUTING state: {}", remoteAddress, e.getMessage());
- }
-
- if (LOG.isTraceEnabled()) {
- LOG.trace("Exception while waiting for echoReply from [{}] in TIMEOUTING state: {}", remoteAddress, e);
- }
+ threadPool.execute(this::executeOnSwitchIdleEvent);
+ }
+
+ private void executeOnSwitchIdleEvent() {
+ boolean shouldBeDisconnected = true;
+
+ final InetSocketAddress remoteAddress = connectionContext.getConnectionAdapter().getRemoteAddress();
+
+ if (ConnectionContext.CONNECTION_STATE.WORKING.equals(connectionContext.getConnectionState())) {
+ FeaturesReply features = connectionContext.getFeatures();
+ LOG.info("Switch Idle state occurred, node={}|auxId={}", remoteAddress, features.getAuxiliaryId());
+ connectionContext.changeStateToTimeouting();
+ EchoInputBuilder builder = new EchoInputBuilder();
+ builder.setVersion(features.getVersion());
+ Xid xid = new Xid(0L);
+ builder.setXid(xid.getValue());
+ Future<RpcResult<EchoOutput>> echoReplyFuture = connectionContext.getConnectionAdapter().echo(builder.build());
+
+ try {
+ RpcResult<EchoOutput> echoReplyValue = echoReplyFuture.get(echoReplyTimeout, TimeUnit.MILLISECONDS);
+ if (echoReplyValue.isSuccessful()) {
+ connectionContext.changeStateToWorking();
+ shouldBeDisconnected = false;
+ } else {
+ logErrors(remoteAddress, echoReplyValue);
}
- }
- if (shouldBeDisconnected) {
- if (LOG.isInfoEnabled()) {
- LOG.info("ConnectionEvent:Closing connection as device is idle. Echo sent at {}. Device:{}, NodeId:{}",
- new Date(System.currentTimeMillis() - echoReplyTimeout), remoteAddress, connectionContext.getNodeId());
+ } catch (Exception e) {
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("Exception while waiting for echoReply from [{}] in TIMEOUTING state: {}", remoteAddress, e.getMessage());
+ }
+
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Exception while waiting for echoReply from [{}] in TIMEOUTING state: {}", remoteAddress, e);
}
- connectionContext.closeConnection(true);
}
- });
+ }
+ if (shouldBeDisconnected) {
+ if (LOG.isInfoEnabled()) {
+ LOG.info("ConnectionEvent:Closing connection as device is idle. Echo sent at {}. Device:{}, NodeId:{}",
+ new Date(System.currentTimeMillis() - echoReplyTimeout), remoteAddress, connectionContext.getNodeId());
+ }
+
+ connectionContext.closeConnection(true);
+ }
+ }
+
+ private void logErrors(InetSocketAddress remoteAddress, RpcResult<EchoOutput> echoReplyValue) {
+ for (RpcError replyError : echoReplyValue.getErrors()) {
+ Throwable cause = replyError.getCause();
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("Received EchoReply from [{}] in TIMEOUTING state, Error:{}", remoteAddress, cause.getMessage());
+ }
+
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Received EchoReply from [{}] in TIMEOUTING state, Error:{}", remoteAddress, cause);
+ }
+
+ }
}
}