@@ -174,6 +174,7 @@ void setClosing(Exception ex) {
174174 this .queue = new ArrayBlockingQueue <>(DEFAULT_QUEUE_SIZE );
175175 this .batch = new Batch (DEFAULT_BATCH_SIZE , maxSizeBytes );
176176 setState (CLOSED );
177+
177178 }
178179
179180 /** Add {@link WeaviateObject} to the batch. */
@@ -701,9 +702,6 @@ public void onEnter(State prev) {
701702 * Reconnecting state is entererd either by the server finishing a shutdown
702703 * and closing it's end of the stream or an unexpected stream hangup.
703704 *
704- * <p>
705- *
706- *
707705 * @see Recv#onCompleted graceful server shutdown
708706 * @see Recv#onError stream hangup
709707 */
@@ -781,7 +779,6 @@ private void reconnectAfter(long delaySeconds) {
781779 } catch (ExecutionException e ) {
782780 onEvent (new Event .ClientError (e ));
783781 }
784-
785782 }, delaySeconds , TimeUnit .SECONDS );
786783 }
787784 }
@@ -844,4 +841,32 @@ public void onEnter(State prev) {
844841 closed = true ;
845842 }
846843 };
844+
845+ // --------------------------------------------------------------------------
846+
847+ private final ScheduledExecutorService reconnectExec = Executors .newScheduledThreadPool (1 );
848+
849+ void scheduleReconnect (int reconnectIntervalSeconds ) {
850+ reconnectExec .scheduleWithFixedDelay (() -> {
851+ if (Thread .currentThread ().isInterrupted ()) {
852+ onEvent (Event .SHUTTING_DOWN );
853+ }
854+ if (Thread .currentThread ().isInterrupted ()) {
855+ onEvent (Event .EOF );
856+ }
857+
858+ // We want to count down from the moment we re-opened the stream,
859+ // not from the moment we initialited the sequence.
860+ lock .lock ();
861+ try {
862+ while (state != ACTIVE ) {
863+ stateChanged .await ();
864+ }
865+ } catch (InterruptedException ignored ) {
866+ // Let the process exit normally.
867+ } finally {
868+ lock .unlock ();
869+ }
870+ }, reconnectIntervalSeconds , reconnectIntervalSeconds , TimeUnit .SECONDS );
871+ }
847872}
0 commit comments