• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

HotelsDotCom / waggle-dance / #318

pending completion
#318

push

web-flow
Feature/upgrade springboot (#268)

* update springboot to 2.1.18

* update springboot to 2.2.13

* Upgrade to srping boot 2.7.11

* Update changelog

* Update changelog

* fix version

3 of 3 new or added lines in 2 files covered. (100.0%)

132 of 3058 relevant lines covered (4.32%)

0.04 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/waggle-dance-core/src/main/java/com/hotels/bdp/waggledance/server/TTransportMonitor.java
1
/**
2
 * Copyright (C) 2016-2019 Expedia, Inc.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 * http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package com.hotels.bdp.waggledance.server;
17

18
import java.io.Closeable;
19
import java.util.Iterator;
20
import java.util.concurrent.ConcurrentLinkedQueue;
21
import java.util.concurrent.Executors;
22
import java.util.concurrent.ScheduledExecutorService;
23

24
import javax.annotation.PreDestroy;
25
import javax.annotation.WillClose;
26

27
import org.apache.thrift.transport.TTransport;
28
import org.slf4j.Logger;
29
import org.slf4j.LoggerFactory;
30
import org.springframework.beans.factory.annotation.Autowired;
31
import org.springframework.stereotype.Component;
32

33
import com.google.common.annotations.VisibleForTesting;
34

35
import com.hotels.bdp.waggledance.conf.WaggleDanceConfiguration;
36

37
@Component
38
public class TTransportMonitor {
39

40
  private static final Logger LOG = LoggerFactory.getLogger(TTransportMonitor.class);
×
41

42
  private static class ActionContainer {
43
    private final TTransport transport;
44
    private final Closeable action;
45

46
    private ActionContainer(TTransport transport, Closeable action) {
×
47
      this.transport = transport;
×
48
      this.action = action;
×
49
    }
×
50
  }
51

52
  private final ScheduledExecutorService scheduler;
53
  private final ConcurrentLinkedQueue<ActionContainer> transports = new ConcurrentLinkedQueue<>();
×
54

55
  @Autowired
56
  public TTransportMonitor(WaggleDanceConfiguration waggleDanceConfiguration) {
57
    this(waggleDanceConfiguration, Executors.newScheduledThreadPool(1));
×
58
  }
×
59

60
  @VisibleForTesting
61
  TTransportMonitor(WaggleDanceConfiguration waggleDanceConfiguration, ScheduledExecutorService scheduler) {
×
62
    this.scheduler = scheduler;
×
63
    Runnable monitor = () -> {
×
64
      LOG.debug("Releasing disconnected sessions");
×
65
      Iterator<ActionContainer> iterator = transports.iterator();
×
66
      while (iterator.hasNext()) {
×
67
        ActionContainer actionContainer = iterator.next();
×
68
        if (actionContainer.transport.peek()) {
×
69
          continue;
×
70
        }
71
        try {
72
          actionContainer.action.close();
×
73
        } catch (Exception e) {
×
74
          LOG.warn("Error closing action", e);
×
75
        }
76
        try {
77
          actionContainer.transport.close();
×
78
        } catch (Exception e) {
×
79
          LOG.warn("Error closing transport", e);
×
80
        }
81
        iterator.remove();
×
82
      }
83
    };
×
84
    this.scheduler
×
85
        .scheduleAtFixedRate(monitor, waggleDanceConfiguration.getDisconnectConnectionDelay(),
×
86
            waggleDanceConfiguration.getDisconnectConnectionDelay(), waggleDanceConfiguration.getDisconnectTimeUnit());
×
87
  }
×
88

89
  @PreDestroy
90
  public void shutdown() {
91
    scheduler.shutdown();
×
92
  }
×
93

94
  public void monitor(@WillClose TTransport transport, @WillClose Closeable action) {
95
    transports.offer(new ActionContainer(transport, action));
×
96
  }
×
97

98
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc