|
|
@@ -15,9 +15,7 @@ |
|
|
|
*/ |
|
|
|
package com.alibaba.csp.sentinel.transport.init; |
|
|
|
|
|
|
|
import java.util.Iterator; |
|
|
|
import java.util.ServiceLoader; |
|
|
|
|
|
|
|
import com.alibaba.csp.sentinel.command.CommandCenterProvider; |
|
|
|
import com.alibaba.csp.sentinel.init.InitFunc; |
|
|
|
import com.alibaba.csp.sentinel.init.InitOrder; |
|
|
|
import com.alibaba.csp.sentinel.log.RecordLog; |
|
|
@@ -31,18 +29,16 @@ public class CommandCenterInitFunc implements InitFunc { |
|
|
|
|
|
|
|
@Override |
|
|
|
public void init() throws Exception { |
|
|
|
ServiceLoader<CommandCenter> loader = ServiceLoader.load(CommandCenter.class); |
|
|
|
Iterator<CommandCenter> iterator = loader.iterator(); |
|
|
|
if (iterator.hasNext()) { |
|
|
|
CommandCenter commandCenter = iterator.next(); |
|
|
|
if (iterator.hasNext()) { |
|
|
|
throw new IllegalStateException("Only single command center can be started"); |
|
|
|
} else { |
|
|
|
commandCenter.beforeStart(); |
|
|
|
commandCenter.start(); |
|
|
|
RecordLog.info("[CommandCenterInit] Starting command center: " |
|
|
|
+ commandCenter.getClass().getCanonicalName()); |
|
|
|
} |
|
|
|
CommandCenter commandCenter = CommandCenterProvider.getCommandCenter(); |
|
|
|
|
|
|
|
if (commandCenter == null) { |
|
|
|
RecordLog.warn("[CommandCenterInitFunc] Cannot resolve CommandCenter"); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
commandCenter.beforeStart(); |
|
|
|
commandCenter.start(); |
|
|
|
RecordLog.info("[CommandCenterInit] Starting command center: " |
|
|
|
+ commandCenter.getClass().getCanonicalName()); |
|
|
|
} |
|
|
|
} |