- getDeviceState().getNodeId());
-
- tearDown();
-
- primaryConnectionContext.closeConnection(false);
- }
-
- private synchronized void tearDown() {
- LOG.trace("tearDown method for node {}", deviceState.getNodeId());
- if (deviceState.isValid()) {
- deviceState.setValid(false);
-
- for (final ConnectionContext connectionContext : auxiliaryConnectionContexts.values()) {
- connectionContext.closeConnection(false);
- }
-
- deviceGroupRegistry.close();
- deviceFlowRegistry.close();
- deviceMeterRegistry.close();
-
- final CheckedFuture<Void, TransactionCommitFailedException> future = transactionChainManager.shuttingDown();
- Futures.addCallback(future, new FutureCallback<Void>() {
-
- @Override
- public void onSuccess(final Void result) {
- LOG.info("Delete Node {} was successfull.", deviceState.getNodeId());
- tearDownClean();
- }
-
- @Override
- public void onFailure(final Throwable t) {
- LOG.warn("Delete Node {} fail.", deviceState.getNodeId(), t);
- tearDownClean();
- }
- });
- }
- }
-
- synchronized void tearDownClean() {
- LOG.info("Closing transaction chain manager without cleaning inventory operational");
- Preconditions.checkState(!deviceState.isValid());
- transactionChainManager.close();
-
- final LinkedList<DeviceContextClosedHandler> reversedCloseHandlers = new LinkedList<>(closeHandlers);
- Collections.reverse(reversedCloseHandlers);
- for (final DeviceContextClosedHandler deviceContextClosedHandler : reversedCloseHandlers) {
- deviceContextClosedHandler.onDeviceContextClosed(this);
- }
- closeHandlers.clear();
- }
-
- @Override
- public void onDeviceDisconnected(final ConnectionContext connectionContext) {
- if (getPrimaryConnectionContext().equals(connectionContext)) {
- try {
- tearDown();
- } catch (final Exception e) {
- LOG.trace("Error closing device context.");
- }
- } else {
- LOG.debug("auxiliary connection dropped: {}, nodeId:{}",
- connectionContext.getConnectionAdapter().getRemoteAddress(),
- getDeviceState().getNodeId());
- final SwitchConnectionDistinguisher connectionDistinguisher = createConnectionDistinguisher(connectionContext);
- auxiliaryConnectionContexts.remove(connectionDistinguisher);
- }