StatefulProxyConnector.java

  1. /*
  2.  * Copyright (C) 2018, Thomas Wolf <thomas.wolf@paranor.ch> and others
  3.  *
  4.  * This program and the accompanying materials are made available under the
  5.  * terms of the Eclipse Distribution License v. 1.0 which is available at
  6.  * https://www.eclipse.org/org/documents/edl-v10.php.
  7.  *
  8.  * SPDX-License-Identifier: BSD-3-Clause
  9.  */
  10. package org.eclipse.jgit.internal.transport.sshd.proxy;

  11. import java.util.concurrent.Callable;

  12. import org.apache.sshd.client.session.ClientProxyConnector;
  13. import org.apache.sshd.common.io.IoSession;
  14. import org.apache.sshd.common.util.Readable;

  15. /**
  16.  * Some proxy connections are stateful and require the exchange of multiple
  17.  * request-reply messages. The default {@link ClientProxyConnector} has only
  18.  * support for sending a message; replies get routed through the Ssh session,
  19.  * and don't get back to this proxy connector. Augment the interface so that the
  20.  * session can know when to route messages received to the proxy connector, and
  21.  * when to start handling them itself.
  22.  */
  23. public interface StatefulProxyConnector extends ClientProxyConnector {

  24.     /**
  25.      * A property key for a session property defining the timeout for setting up
  26.      * the proxy connection.
  27.      */
  28.     static final String TIMEOUT_PROPERTY = StatefulProxyConnector.class
  29.             .getName() + "-timeout"; //$NON-NLS-1$

  30.     /**
  31.      * Handle a received message.
  32.      *
  33.      * @param session
  34.      *            to use for writing data
  35.      * @param buffer
  36.      *            received data
  37.      * @throws Exception
  38.      *             if data cannot be read, or the connection attempt fails
  39.      */
  40.     void messageReceived(IoSession session, Readable buffer) throws Exception;

  41.     /**
  42.      * Runs {@code command} once the proxy connection is established. May be
  43.      * called multiple times; commands are run sequentially. If the proxy
  44.      * connection is already established, {@code command} is executed directly
  45.      * synchronously.
  46.      *
  47.      * @param command
  48.      *            operation to run
  49.      * @throws Exception
  50.      *             if the operation is run synchronously and throws an exception
  51.      */
  52.     void runWhenDone(Callable<Void> command) throws Exception;
  53. }