Skip to content

Commit

Permalink
Merge pull request #925 from wangqifan/feature/proxy-support-stop-server
Browse files Browse the repository at this point in the history
proxy support stop
  • Loading branch information
LanternLee authored Dec 27, 2024
2 parents b206cae + 9f23420 commit cabf3d3
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public void stop() {
if(tlsFuture != null) {
tlsFuture.channel().close();
}
tunnelManager.removeAll();
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.ctrip.xpipe.redis.proxy.controller;

import com.ctrip.xpipe.codec.JsonCodec;
import com.ctrip.xpipe.redis.proxy.ProxyServer;
import com.ctrip.xpipe.redis.proxy.Tunnel;
import com.ctrip.xpipe.redis.proxy.model.TunnelMeta;
import com.ctrip.xpipe.redis.proxy.monitor.TunnelMonitorManager;
Expand Down Expand Up @@ -30,6 +31,30 @@ public class ProxyController {
@Autowired
private TunnelMonitorManager tunnelMonitorManager;

@Autowired
private ProxyServer proxyServer;

@PostMapping(value = "/server/start")
public RetMessage startServer() {
try {
proxyServer.start();
return RetMessage.createSuccessMessage();
} catch (Throwable th) {
return RetMessage.createFailMessage(th.getMessage());
}
}

@PostMapping(value = "/server/stop")
public RetMessage stopServer() {
try {
proxyServer.stop();
return RetMessage.createSuccessMessage();
} catch (Throwable th) {
return RetMessage.createFailMessage(th.getMessage());
}
}


@RequestMapping(value = "/tunnels", method = RequestMethod.GET)
public String getTunnelMetas() {
List<Tunnel> tunnels = tunnelManager.tunnels();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -154,6 +155,14 @@ public void remove(Channel frontendChannel) {
}
}

@Override
public void removeAll() {
Set<Channel> toCloseChannels = new HashSet<>(cache.keySet());
for (Channel channel: toCloseChannels) {
remove(channel);
}
}

@Override
public List<Tunnel> tunnels() {
return Lists.newArrayList(cache.values());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public interface TunnelManager extends Releasable, Observer {

void remove(Channel frontendChannel);

void removeAll();

List<Tunnel> tunnels();

Tunnel getById(String id);
Expand Down

0 comments on commit cabf3d3

Please sign in to comment.