forked from alibaba/Sentinel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a CommandCenterProvider to resolve and cache the CommandCenter in…
…stance (alibaba#409)
- Loading branch information
Showing
2 changed files
with
48 additions
and
15 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
...ransport-common/src/main/java/com/alibaba/csp/sentinel/command/CommandCenterProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.alibaba.csp.sentinel.command; | ||
|
||
import com.alibaba.csp.sentinel.log.RecordLog; | ||
import com.alibaba.csp.sentinel.transport.CommandCenter; | ||
import com.alibaba.csp.sentinel.util.SpiLoader; | ||
|
||
/** | ||
* Provider for a universal {@link CommandCenter} instance. | ||
* | ||
* @author cdfive | ||
* @date 2019-01-11 | ||
*/ | ||
public class CommandCenterProvider { | ||
|
||
private static CommandCenter commandCenter = null; | ||
|
||
static { | ||
resolveInstance(); | ||
} | ||
|
||
private static void resolveInstance() { | ||
CommandCenter resolveCommandCenter = SpiLoader.loadFirstInstance(CommandCenter.class); | ||
|
||
if (resolveCommandCenter == null) { | ||
RecordLog.warn("[CommandCenterProvider] No existing CommandCenter, resolve failed"); | ||
} else { | ||
commandCenter = resolveCommandCenter; | ||
RecordLog.info("[CommandCenterProvider] CommandCenter resolved: " + resolveCommandCenter.getClass().getCanonicalName()); | ||
} | ||
} | ||
|
||
public static CommandCenter getCommandCenter() { | ||
return commandCenter; | ||
} | ||
|
||
private CommandCenterProvider() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters