|
2 | 2 |
|
3 | 3 | import com.xxdb.DBConnection;
|
4 | 4 | import com.xxdb.comm.ErrorCodeInfo;
|
| 5 | +import com.xxdb.data.BasicInt; |
| 6 | +import com.xxdb.data.BasicString; |
5 | 7 | import com.xxdb.data.Entity;
|
6 | 8 | import com.xxdb.data.Utils;
|
7 | 9 | import com.xxdb.streaming.client.AbstractClient;
|
|
12 | 14 | import java.io.IOException;
|
13 | 15 | import java.net.SocketException;
|
14 | 16 | import java.util.ArrayList;
|
| 17 | +import java.util.Arrays; |
15 | 18 | import java.util.List;
|
16 | 19 | import java.util.concurrent.BlockingQueue;
|
17 | 20 |
|
@@ -83,6 +86,52 @@ public void unsubscribe(String host, int port, String tableName, String actionNa
|
83 | 86 | unsubscribeInternal(host, port, tableName, actionName);
|
84 | 87 | }
|
85 | 88 |
|
| 89 | + @Override |
| 90 | + protected void unsubscribeInternal(String host, int port, String tableName, String actionName) throws IOException { |
| 91 | + DBConnection dbConn = new DBConnection(); |
| 92 | + List<String> tp = Arrays.asList(host, String.valueOf(port), tableName, actionName); |
| 93 | + List<String> usr = users.get(tp); |
| 94 | + String user = usr.get(0); |
| 95 | + String pwd = usr.get(1); |
| 96 | + if (!user.equals("")) |
| 97 | + dbConn.connect(host, port, user, pwd); |
| 98 | + else |
| 99 | + dbConn.connect(host, port); |
| 100 | + try { |
| 101 | + String localIP = this.listeningHost; |
| 102 | + if(localIP.equals("")) |
| 103 | + localIP = dbConn.getLocalAddress().getHostAddress(); |
| 104 | + List<Entity> params = new ArrayList<Entity>(); |
| 105 | + params.add(new BasicString(localIP)); |
| 106 | + params.add(new BasicInt(this.listeningPort)); |
| 107 | + params.add(new BasicString(tableName)); |
| 108 | + params.add(new BasicString(actionName)); |
| 109 | + |
| 110 | + dbConn.run("stopPublishTable", params); |
| 111 | + String topic = null; |
| 112 | + String fullTableName = host + ":" + port + "/" + tableName + "/" + actionName; |
| 113 | + synchronized (tableNameToTrueTopic) { |
| 114 | + topic = tableNameToTrueTopic.get(fullTableName); |
| 115 | + } |
| 116 | + synchronized (trueTopicToSites) { |
| 117 | + Site[] sites = trueTopicToSites.get(topic); |
| 118 | + if (sites == null || sites.length == 0) |
| 119 | + ; |
| 120 | + for (int i = 0; i < sites.length; i++) |
| 121 | + sites[i].closed = true; |
| 122 | + } |
| 123 | + synchronized (queueManager) { |
| 124 | + queueManager.removeQueue(topic); |
| 125 | + } |
| 126 | + log.info("Successfully unsubscribed table " + fullTableName); |
| 127 | + } catch (Exception ex) { |
| 128 | + throw ex; |
| 129 | + } finally { |
| 130 | + dbConn.close(); |
| 131 | + } |
| 132 | + return; |
| 133 | + } |
| 134 | + |
86 | 135 |
|
87 | 136 | @Override
|
88 | 137 | protected boolean doReconnect(Site site) {
|
|
0 commit comments