@Override public void initializeChannel(final SocketChannel ch, final Promise<NetconfClientSession> sessionPromise) { new SshClientChannelInitializer(currentConfiguration.getAuthHandler(), getNegotiatorFactory(currentConfiguration), currentConfiguration.getSessionListener()) .initialize(ch, sessionPromise); }
@Override public void initializeChannel(final SocketChannel ch, final Promise<NetconfClientSession> promise) { initialize(ch, promise); }
private void initialize(final SocketChannel ch, final Promise<NetconfClientSession> promise) { new TcpClientChannelInitializer(getNegotiatorFactory(currentConfiguration), currentConfiguration .getSessionListener()).initialize(ch, promise); } });
private Future<Void> createReconnectingSshClient(final NetconfReconnectingClientConfiguration currentConfiguration) { LOG.debug("Creating reconnecting SSH client with configuration: {}", currentConfiguration); final SshClientChannelInitializer init = new SshClientChannelInitializer(currentConfiguration.getAuthHandler(), getNegotiatorFactory(currentConfiguration), currentConfiguration.getSessionListener()); return super.createReconnectingClient(currentConfiguration.getAddress(), currentConfiguration.getConnectStrategyFactory(), currentConfiguration.getReconnectStrategy(), new PipelineInitializer<NetconfClientSession>() { @Override public void initializeChannel(final SocketChannel ch, final Promise<NetconfClientSession> promise) { init.initialize(ch, promise); } }); }
protected NetconfClientSessionNegotiatorFactory getNegotiatorFactory(final NetconfClientConfiguration cfg) { return new NetconfClientSessionNegotiatorFactory(timer, cfg.getAdditionalHeader(), cfg.getConnectionTimeoutMillis()); } }
private Future<Void> createReconnectingTcpClient(final NetconfReconnectingClientConfiguration currentConfiguration) { LOG.debug("Creating reconnecting TCP client with configuration: {}", currentConfiguration); final TcpClientChannelInitializer init = new TcpClientChannelInitializer(getNegotiatorFactory(currentConfiguration), currentConfiguration.getSessionListener()); return super.createReconnectingClient(currentConfiguration.getAddress(), currentConfiguration.getConnectStrategyFactory(), currentConfiguration.getReconnectStrategy(), new PipelineInitializer<NetconfClientSession>() { @Override public void initializeChannel(final SocketChannel ch, final Promise<NetconfClientSession> promise) { init.initialize(ch, promise); } }); }
@Override public Future<Void> createReconnectingClient(final NetconfReconnectingClientConfiguration clientConfiguration) { switch (clientConfiguration.getProtocol()) { case TCP: return createReconnectingTcpClient(clientConfiguration); case SSH: return createReconnectingSshClient(clientConfiguration); default: throw new IllegalArgumentException("Unknown client protocol " + clientConfiguration.getProtocol()); } }
public void disconnect() { if(session != null) { session.close(); } }
@Override protected void addExiHandlers(final ByteToMessageDecoder decoder, final MessageToByteEncoder<NetconfMessage> encoder) { // TODO used only in negotiator, client supports only auto start-exi replaceMessageDecoder(decoder); replaceMessageEncoder(encoder); }
public final synchronized Future<NetconfMessage> sendRequest(NetconfMessage message) { final RequestEntry req = new RequestEntry(GlobalEventExecutor.INSTANCE.<NetconfMessage>newPromise(), message); requests.add(req); if (clientSession != null) { dispatchRequest(); } return req.promise; } }
public void initializeRemoteConnection(final NetconfClientDispatcher dispatcher, final NetconfClientConfiguration config) { // TODO 2313 extract listener from configuration if(config instanceof NetconfReconnectingClientConfiguration) { initFuture = dispatcher.createReconnectingClient((NetconfReconnectingClientConfiguration) config); } else { initFuture = dispatcher.createClient(config); } initFuture.addListener(new GenericFutureListener<Future<Object>>(){ @Override public void operationComplete(Future<Object> future) throws Exception { if (!future.isSuccess() && !future.isCancelled()) { logger.debug("{}: Connection failed", id, future.cause()); NetconfDeviceCommunicator.this.remoteDevice.onRemoteSessionFailed(future.cause()); } } }); }
@Override protected NetconfClientSession getSession(final NetconfClientSessionListener sessionListener, final Channel channel, final NetconfHelloMessage message) throws NetconfDocumentedException { long sessionId = extractSessionId(message.getDocument()); // Copy here is important: it disconnects the strings from the document Collection<String> capabilities = ImmutableList.copyOf(NetconfMessageUtil.extractCapabilitiesFromHello(message.getDocument())); // FIXME: scalability: we could instantiate a cache to share the same collections return new NetconfClientSession(sessionListener, channel, sessionId, capabilities); }
@Override public void initializeChannel(final SocketChannel ch, final Promise<NetconfClientSession> promise) { init.initialize(ch, promise); } });
@Override public void initializeChannel(final SocketChannel ch, final Promise<NetconfClientSession> promise) { init.initialize(ch, promise); } });
@Override public final void onSessionDown(NetconfClientSession clientSession, Exception e) { LOG.debug("Client Session {} went down unexpectedly", clientSession, e); tearDown(e); }
public static NetconfSessionPreferences fromNetconfSession(final NetconfClientSession session) { return fromStrings(session.getServerCapabilities()); }
@Override protected void initializeSessionNegotiator(final Channel ch, final Promise<NetconfClientSession> promise) { ch.pipeline().addAfter(NETCONF_MESSAGE_DECODER, AbstractChannelInitializer.NETCONF_SESSION_NEGOTIATOR, negotiatorFactory.getSessionNegotiator(new SessionListenerFactory<NetconfClientSessionListener>() { @Override public NetconfClientSessionListener getSessionListener() { return sessionListener; } }, ch, promise)); } }
@Override public Boolean call() throws Exception { executionStrategy.invoke(); netconfClientSession.close(); return true; }
@Override public void stopExiCommunication() { // TODO never used, Netconf client does not support stop-exi replaceMessageDecoder(new NetconfXMLToMessageDecoder()); replaceMessageEncoder(new NetconfMessageToXMLEncoder()); } }
@Override public void close() { // Cancel reconnect if in progress if(initFuture != null) { initFuture.cancel(false); } // Disconnect from device if(session != null) { session.close(); // tear down not necessary, called indirectly by above close } }