@@ -43,6 +43,8 @@ public abstract class AbstractClient implements MessageDispatcher {
43
43
protected static Map <String , Long > lastExceptionTopicTimeMap = new ConcurrentHashMap <>();
44
44
protected static Integer resubTimeout ;
45
45
protected static boolean subOnce ;
46
+ // protected static boolean createSubInfo;
47
+ protected BlockingQueue <List <IMessage >> lastQueue ;
46
48
47
49
private Daemon daemon = null ;
48
50
@@ -175,7 +177,7 @@ public Site getCurrentSiteByName(String site) {
175
177
List <String > topics = this .getAllTopicsBySite (site );
176
178
if (topics .size () > 0 ) {
177
179
Site [] sites = trueTopicToSites .get (topics .get (0 ));
178
- Integer currentSiteIndex = currentSiteIndexMap .get (topics . get ( 0 ) );
180
+ Integer currentSiteIndex = currentSiteIndexMap .get (lastBackupSiteTopic );
179
181
return sites [currentSiteIndex ];
180
182
}
181
183
@@ -195,6 +197,12 @@ public void setMsgId(String topic, long msgId) {
195
197
return ;
196
198
if (sites .length == 1 )
197
199
sites [0 ].msgId = msgId ;
200
+
201
+ if (ifUseBackupSite ) {
202
+ for (Site site : sites ) {
203
+ site .msgId = msgId ;
204
+ }
205
+ }
198
206
}
199
207
}
200
208
@@ -243,7 +251,7 @@ public boolean tryReconnect(String topic) {
243
251
}
244
252
245
253
boolean reconnected = false ;
246
- Integer currentSiteIndex = currentSiteIndexMap .get (topic );
254
+ Integer currentSiteIndex = currentSiteIndexMap .get (lastBackupSiteTopic );
247
255
if (currentSiteIndex != null && currentSiteIndex != -1 ) {
248
256
int totalSites = sites .length ;
249
257
// set successfulSiteIndex init value to -1.
@@ -295,12 +303,13 @@ public boolean tryReconnect(String topic) {
295
303
}
296
304
}
297
305
298
- log .info ("Successfully switched to node: " + sites [currentSiteIndexMap .get (topic )].host + ":" + sites [currentSiteIndexMap .get (topic )].port );
306
+ // log.info("Successfully switched to node: " + sites[currentSiteIndexMap.get(topic)].host + ":" + sites[currentSiteIndexMap.get(topic)].port);
299
307
300
308
if (!reconnected ) {
301
309
waitReconnectTopic .add (topic );
302
310
return false ;
303
311
} else {
312
+ log .info ("Successfully switched to node: " + sites [currentSiteIndexMap .get (topic )].host + ":" + sites [currentSiteIndexMap .get (topic )].port );
304
313
reconnectTable .remove (topic .substring (0 , topic .indexOf ("/" )));
305
314
waitReconnectTopic .remove (topic );
306
315
return true ;
@@ -490,11 +499,19 @@ protected BlockingQueue<List<IMessage>> subscribeInternal(String host, int port,
490
499
return subscribeInternal (host , port , tableName , actionName , handler , offset , reconnect , filter , deserializer , allowExistTopic , userName , passWord , msgAsTable , null , 100 , false );
491
500
}
492
501
502
+ protected BlockingQueue <List <IMessage >> subscribeInternal (String host , int port ,
503
+ String tableName , String actionName , MessageHandler handler ,
504
+ long offset , boolean reconnect , Vector filter , StreamDeserializer deserializer ,
505
+ boolean allowExistTopic , String userName , String passWord , boolean msgAsTable , boolean createSubInfo )
506
+ throws IOException , RuntimeException {
507
+ return subscribeInternal (host , port , tableName , actionName , handler , offset , reconnect , filter , deserializer , allowExistTopic , userName , passWord , msgAsTable , null , 100 , false , createSubInfo );
508
+ }
509
+
493
510
protected BlockingQueue <List <IMessage >> subscribeInternal (String host , int port ,
494
511
String tableName , String actionName , MessageHandler handler ,
495
512
long offset , boolean reconnect , Vector filter , StreamDeserializer deserializer ,
496
513
boolean allowExistTopic , String userName , String passWord , boolean msgAsTable ,
497
- List <String > backupSites , int resubTimeout , boolean subOnce ) throws IOException , RuntimeException {
514
+ List <String > backupSites , int resubTimeout , boolean subOnce , boolean createSubInfo ) throws IOException , RuntimeException {
498
515
Entity re ;
499
516
String topic = "" ;
500
517
DBConnection dbConn ;
@@ -508,6 +525,7 @@ protected BlockingQueue<List<IMessage>> subscribeInternal(String host, int port,
508
525
AbstractClient .resubTimeout = resubTimeout ;
509
526
AbstractClient .subOnce = subOnce ;
510
527
AbstractClient .ifUseBackupSite = true ;
528
+ // AbstractClient.createSubInfo = createSubInfo;
511
529
// prepare backupSites
512
530
for (int i = 0 ; i < backupSites .size () + 1 ; i ++) {
513
531
if (i == 0 ) {
@@ -634,6 +652,7 @@ protected BlockingQueue<List<IMessage>> subscribeInternal(String host, int port,
634
652
subscribeInternalConnect (dbConn , host , port , userName , passWord );
635
653
re = dbConn .run ("getSubscriptionTopic" , params );
636
654
topic = ((BasicAnyVector ) re ).getEntity (0 ).getString ();
655
+ // lastBackupSiteTopic = topic;
637
656
params .clear ();
638
657
639
658
params .add (new BasicString (localIP ));
@@ -721,10 +740,25 @@ protected BlockingQueue<List<IMessage>> subscribeInternal(String host, int port,
721
740
}
722
741
}
723
742
724
- BlockingQueue <List <IMessage >> queue = queueManager .addQueue (topic );
743
+ BlockingQueue <List <IMessage >> queue ;
744
+ if (createSubInfo ) {
745
+ queue = queueManager .addQueue (topic );
746
+ lastQueue = queue ;
747
+ } else {
748
+ queue = lastQueue ;
749
+ }
750
+
725
751
return queue ;
726
752
}
727
753
754
+ protected BlockingQueue <List <IMessage >> subscribeInternal (String host , int port ,
755
+ String tableName , String actionName , MessageHandler handler ,
756
+ long offset , boolean reconnect , Vector filter , StreamDeserializer deserializer ,
757
+ boolean allowExistTopic , String userName , String passWord , boolean msgAsTable ,
758
+ List <String > backupSites , int resubTimeout , boolean subOnce ) throws IOException , RuntimeException {
759
+ return subscribeInternal (host , port , tableName , actionName , handler , offset , reconnect , filter , deserializer , allowExistTopic , userName , passWord , msgAsTable , backupSites , resubTimeout , subOnce , true );
760
+ }
761
+
728
762
protected BlockingQueue <List <IMessage >> subscribeInternal (String host , int port ,
729
763
String tableName , String actionName , long offset , boolean reconnect )
730
764
throws IOException , RuntimeException {
0 commit comments