|
57 | 57 | import triple.Response;
|
58 | 58 |
|
59 | 59 | import java.lang.reflect.Method;
|
60 |
| - |
61 | 60 | import java.util.ArrayList;
|
62 | 61 | import java.util.Collection;
|
63 | 62 | import java.util.List;
|
|
66 | 65 | import java.util.concurrent.ConcurrentHashMap;
|
67 | 66 | import java.util.concurrent.ThreadPoolExecutor;
|
68 | 67 | import java.util.concurrent.TimeUnit;
|
69 |
| -import java.util.concurrent.atomic.AtomicInteger; |
70 | 68 | import java.util.concurrent.locks.Lock;
|
71 | 69 | import java.util.concurrent.locks.ReentrantLock;
|
72 | 70 |
|
@@ -107,20 +105,14 @@ public class TripleServer implements Server {
|
107 | 105 | protected MutableHandlerRegistry handlerRegistry = new MutableHandlerRegistry();
|
108 | 106 |
|
109 | 107 | /**
|
110 |
| - * The mapping relationship between BindableService and ServerServiceDefinition |
| 108 | + * The mapping relationship between interface BindableService and ServerServiceDefinition |
111 | 109 | */
|
112 |
| - protected ConcurrentHashMap<ProviderConfig, ServerServiceDefinition> serviceInfo = new ConcurrentHashMap<ProviderConfig, |
113 |
| - ServerServiceDefinition>(); |
| 110 | + protected ConcurrentHashMap<String, ServerServiceDefinition> serviceInfo = new ConcurrentHashMap<>(); |
114 | 111 | /**
|
115 | 112 | * The mapping relationship between service name and unique id invoker
|
116 | 113 | */
|
117 | 114 | protected Map<String, UniqueIdInvoker> invokerMap = new ConcurrentHashMap<>();
|
118 | 115 |
|
119 |
| - /** |
120 |
| - * invoker count |
121 |
| - */ |
122 |
| - protected AtomicInteger invokerCnt = new AtomicInteger(); |
123 |
| - |
124 | 116 | /**
|
125 | 117 | * Thread pool
|
126 | 118 | * @param serverConfig ServerConfig
|
@@ -274,17 +266,15 @@ public void registerProcessor(ProviderConfig providerConfig, Invoker instance) {
|
274 | 266 | }
|
275 | 267 |
|
276 | 268 | ServerServiceDefinition serviceDefinition = getServerServiceDefinition(providerConfig, uniqueIdInvoker);
|
277 |
| - this.serviceInfo.put(providerConfig, serviceDefinition); |
| 269 | + this.serviceInfo.put(providerConfig.getInterfaceId(), serviceDefinition); |
278 | 270 | ServerServiceDefinition ssd = this.handlerRegistry.addService(serviceDefinition);
|
279 | 271 | if (ssd != null) {
|
280 | 272 | throw new IllegalStateException("Can not expose service with same name:" +
|
281 | 273 | serviceDefinition.getServiceDescriptor().getName());
|
282 | 274 | }
|
283 |
| - this.invokerCnt.incrementAndGet(); |
284 | 275 | } catch (Exception e) {
|
285 | 276 | String msg = "Register triple service error";
|
286 | 277 | LOGGER.error(msg, e);
|
287 |
| - this.serviceInfo.remove(providerConfig); |
288 | 278 | throw new SofaRpcRuntimeException(msg, e);
|
289 | 279 | } finally {
|
290 | 280 | this.lock.unlock();
|
@@ -413,24 +403,24 @@ public void unRegisterProcessor(ProviderConfig providerConfig, boolean closeIfNo
|
413 | 403 | this.lock.lock();
|
414 | 404 | cleanReflectCache(providerConfig);
|
415 | 405 | try {
|
416 |
| - ServerServiceDefinition serverServiceDefinition = this.serviceInfo.get(providerConfig); |
| 406 | + ServerServiceDefinition serverServiceDefinition = this.serviceInfo.get(providerConfig.getInterfaceId()); |
417 | 407 | UniqueIdInvoker uniqueIdInvoker = this.invokerMap.get(providerConfig.getInterfaceId());
|
418 | 408 | if (null != uniqueIdInvoker) {
|
419 | 409 | uniqueIdInvoker.unRegisterInvoker(providerConfig);
|
420 | 410 | if (!uniqueIdInvoker.hasInvoker()) {
|
421 | 411 | this.invokerMap.remove(providerConfig.getInterfaceId());
|
422 | 412 | this.handlerRegistry.removeService(serverServiceDefinition);
|
| 413 | + this.serviceInfo.remove(providerConfig.getInterfaceId()); |
423 | 414 | }
|
424 | 415 | } else {
|
425 | 416 | this.handlerRegistry.removeService(serverServiceDefinition);
|
426 | 417 | }
|
427 |
| - invokerCnt.decrementAndGet(); |
428 | 418 | } catch (Exception e) {
|
429 | 419 | LOGGER.error("Unregister triple service error", e);
|
430 | 420 | } finally {
|
431 | 421 | this.lock.unlock();
|
432 | 422 | }
|
433 |
| - if (closeIfNoEntry && invokerCnt.get() == 0) { |
| 423 | + if (closeIfNoEntry && invokerMap.isEmpty()) { |
434 | 424 | stop();
|
435 | 425 | }
|
436 | 426 | }
|
|
0 commit comments