forked from opengoofy/hippo4j
-
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.
Complete the agent of springboot1.x version in config mode. (opengoof…
- Loading branch information
1 parent
e188855
commit f132105
Showing
55 changed files
with
1,322 additions
and
59 deletions.
There are no files selected for viewing
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
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
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
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
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
52 changes: 52 additions & 0 deletions
52
...gent-core/src/main/java/cn/hippo4j/agent/core/registry/AgentThreadPoolExecutorHolder.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,52 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package cn.hippo4j.agent.core.registry; | ||
|
||
import cn.hippo4j.agent.core.logging.api.ILog; | ||
import cn.hippo4j.agent.core.logging.api.LogManager; | ||
import cn.hippo4j.common.config.ExecutorProperties; | ||
import lombok.Data; | ||
|
||
import java.util.concurrent.ThreadPoolExecutor; | ||
|
||
@Data | ||
public class AgentThreadPoolExecutorHolder { | ||
|
||
private static final ILog LOGGER = LogManager.getLogger(AgentThreadPoolExecutorHolder.class); | ||
|
||
public static final AgentThreadPoolExecutorHolder EMPTY = new AgentThreadPoolExecutorHolder(); | ||
|
||
private String executorName; | ||
|
||
private ThreadPoolExecutor executor; | ||
|
||
private ExecutorProperties properties; | ||
|
||
public AgentThreadPoolExecutorHolder() { | ||
} | ||
|
||
public AgentThreadPoolExecutorHolder(String executorName, ThreadPoolExecutor executor, ExecutorProperties properties) { | ||
this.executorName = executorName; | ||
this.executor = executor; | ||
this.properties = properties; | ||
} | ||
|
||
public boolean isEmpty() { | ||
return this == EMPTY; | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...nt-core/src/main/java/cn/hippo4j/agent/core/registry/AgentThreadPoolInstanceRegistry.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,63 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package cn.hippo4j.agent.core.registry; | ||
|
||
import cn.hippo4j.agent.core.logging.api.ILog; | ||
import cn.hippo4j.agent.core.logging.api.LogManager; | ||
import cn.hippo4j.common.config.ExecutorProperties; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.ThreadPoolExecutor; | ||
|
||
public class AgentThreadPoolInstanceRegistry { | ||
|
||
private static final ILog LOGGER = LogManager.getLogger(AgentThreadPoolInstanceRegistry.class); | ||
|
||
private final Map<String, AgentThreadPoolExecutorHolder> holderMap = new ConcurrentHashMap<>(); | ||
|
||
private volatile static AgentThreadPoolInstanceRegistry INSTANCE; | ||
|
||
private AgentThreadPoolInstanceRegistry() { | ||
} | ||
|
||
public static AgentThreadPoolInstanceRegistry getInstance() { | ||
if (INSTANCE == null) { | ||
synchronized (AgentThreadPoolInstanceRegistry.class) { | ||
if (INSTANCE == null) { | ||
INSTANCE = new AgentThreadPoolInstanceRegistry(); | ||
} | ||
} | ||
} | ||
return INSTANCE; | ||
} | ||
|
||
public Map<String, AgentThreadPoolExecutorHolder> getHolderMap() { | ||
return holderMap; | ||
} | ||
|
||
public void putHolder(String executorName, ThreadPoolExecutor executor, ExecutorProperties properties) { | ||
AgentThreadPoolExecutorHolder holder = new AgentThreadPoolExecutorHolder(executorName, executor, properties); | ||
holderMap.put(executorName, holder); | ||
} | ||
|
||
public AgentThreadPoolExecutorHolder getHolder(String executorName) { | ||
return Optional.ofNullable(holderMap.get(executorName)).orElse(AgentThreadPoolExecutorHolder.EMPTY); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/AgentThreadPoolConstants.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,27 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package cn.hippo4j.agent.core.util; | ||
|
||
public interface AgentThreadPoolConstants { | ||
|
||
String TOMCAT_NAME_PREFIX = "namePrefix"; | ||
String DUBBO_NAME_PREFIX = "mPrefix"; | ||
String DUBBO_THREAD_NAME = "DubboServerHandler"; | ||
String THREAD_POOL_NAME_DUBBO = "dubbo"; | ||
|
||
} |
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
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
44 changes: 44 additions & 0 deletions
44
...j-agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/ExecutorNameUtil.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,44 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package cn.hippo4j.agent.core.util; | ||
|
||
import cn.hippo4j.agent.core.logging.api.ILog; | ||
import cn.hippo4j.agent.core.logging.api.LogManager; | ||
|
||
import java.lang.reflect.Field; | ||
|
||
public class ExecutorNameUtil { | ||
|
||
private static final ILog LOGGER = LogManager.getLogger(ExecutorNameUtil.class); | ||
|
||
public static boolean isTomcatExecutor(Object threadFactory) { | ||
try { | ||
if ("org.apache.tomcat.util.threads.TaskThreadFactory".equals(threadFactory.getClass().getName())) { | ||
Field namePrefixField = threadFactory.getClass().getDeclaredField(AgentThreadPoolConstants.TOMCAT_NAME_PREFIX); | ||
namePrefixField.setAccessible(true); | ||
String namePrefix = (String) namePrefixField.get(threadFactory); | ||
if (RegexUtil.isTomcatNameMatch(namePrefix)) { | ||
return true; | ||
} | ||
} | ||
} catch (Throwable t) { | ||
LOGGER.error("Fail to put tomcat executor", t); | ||
} | ||
return false; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
hippo4j-agent/hippo4j-agent-core/src/main/java/cn/hippo4j/agent/core/util/ReflectUtil.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,43 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package cn.hippo4j.agent.core.util; | ||
|
||
import cn.hippo4j.agent.core.logging.api.ILog; | ||
import cn.hippo4j.agent.core.logging.api.LogManager; | ||
|
||
import java.lang.reflect.Field; | ||
import java.lang.reflect.Modifier; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class ReflectUtil { | ||
|
||
private static final ILog LOGGER = LogManager.getLogger(ReflectUtil.class); | ||
|
||
public static List<Field> getStaticFieldsFromType(Class<?> clazz, Class<?> declaredType) { | ||
Field[] fields = clazz.getFields(); | ||
List<Field> result = new ArrayList<>(); | ||
for (Field field : fields) { | ||
if (field.getType().isAssignableFrom(declaredType) && | ||
Modifier.isStatic(field.getModifiers())) { | ||
result.add(field); | ||
} | ||
} | ||
return result; | ||
} | ||
} |
Oops, something went wrong.