Skip to content

Commit

Permalink
Update log
Browse files Browse the repository at this point in the history
  • Loading branch information
hexiaofeng committed Jul 26, 2024
1 parent f2eb962 commit 438469e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.jd.live.agent.core.event.Subscription;
import com.jd.live.agent.core.exception.ParseException;
import com.jd.live.agent.core.extension.ExtensibleDesc;
import com.jd.live.agent.core.extension.ExtensionDesc;
import com.jd.live.agent.core.extension.ExtensionEvent.EventType;
import com.jd.live.agent.core.extension.ExtensionManager;
import com.jd.live.agent.core.extension.condition.ConditionManager;
Expand Down Expand Up @@ -197,7 +198,7 @@ public class Bootstrap implements AgentLifecycle {
/**
* Manages extensions to the agent.
*/
private ExtensionManager extensionManager;
private JExtensionManager extensionManager;

/**
* Supplies bytecode for instrumentation.
Expand Down Expand Up @@ -276,6 +277,7 @@ public void install() {
commandManager = createCommandManager();
subscriptions = createSubscriptions();
subscribe();
printExtensions();
serviceManager.start().join();
// TODO In AgentMain mode, it is necessary to enhance the registry first to obtain the service strategy, and then enhance the routing plugin
if (pluginManager.install(dynamic)) {
Expand Down Expand Up @@ -373,6 +375,24 @@ public void addReadyHook(Callable<?> callable, ClassLoader classLoader) {
}
}

private void printExtensions() {
StringBuilder builder = new StringBuilder();
extensionManager.forEach(extensible -> {
builder.delete(0, builder.length());
builder.append(extensible.getName().getClazz().getName()).append(": ");
Iterable<? extends ExtensionDesc<?>> extensionDescs = extensible.getExtensionDescs();
int i = 0;
for (ExtensionDesc<?> extensionDesc : extensionDescs) {
if (i++ > 0) {
builder.append(", ");
}
builder.append(extensionDesc.getName().getName());
}
logger.info("Load extensions " + builder);
});

}

/**
* Creates an {@link AgentPath} instance using environment variables.
* This includes paths for the agent's root, log, and output directories.
Expand Down Expand Up @@ -551,7 +571,7 @@ private ConditionMatcher createConditionMatcher() {
DEPEND_ON_LOADER.negate());
}

private ExtensionManager createExtensionManager() {
private JExtensionManager createExtensionManager() {
return new JExtensionManager(conditionMatcher);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
package com.jd.live.agent.core.extension.jplug;

import com.jd.live.agent.bootstrap.logger.Logger;
import com.jd.live.agent.bootstrap.logger.LoggerFactory;
import com.jd.live.agent.core.extension.*;
import com.jd.live.agent.core.extension.ExtensionEvent.EventType;
import com.jd.live.agent.core.extension.annotation.Extensible;
Expand All @@ -27,6 +25,7 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.function.Consumer;

/**
* JExtensionManager
Expand All @@ -36,8 +35,6 @@
*/
public class JExtensionManager implements ExtensionManager {

private static final Logger logger = LoggerFactory.getLogger(JExtensionManager.class);

private final ConditionMatcher matcher;

private final Map<Class<?>, ExtensibleDesc<?>> extensibles = new ConcurrentHashMap<>();
Expand Down Expand Up @@ -157,9 +154,6 @@ public <T> ExtensibleDesc<T> loadExtensible(Class<T> extensible, ExtensionLoader
// Sort
Comparator<ExtensionDesc<?>> c = ExtensionDesc.AscendingComparator.INSTANCE;
extensionDescList.sort(c);
if (logger.isInfoEnabled()) {
logger.info("Load extensible {} success", name);
}
// No need to cache objects in the loading method
return new JExtensible<>(name, extensionDescList);
}
Expand Down Expand Up @@ -204,4 +198,10 @@ public void removeListener(ExtensionListener listener) {
listeners.remove(listener);
}
}

public void forEach(Consumer<? super ExtensibleDesc<?>> consumer) {
if (consumer != null) {
extensibles.values().forEach(consumer);
}
}
}

0 comments on commit 438469e

Please sign in to comment.