Skip to content

Commit

Permalink
optimize AgentAware
Browse files Browse the repository at this point in the history
  • Loading branch information
yanhom1314 committed Jun 13, 2024
1 parent fcece9e commit 4763828
Show file tree
Hide file tree
Showing 14 changed files with 114 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ default void afterExecute(Executor executor, Runnable r, Throwable t) {
}

default Runnable afterExecuteWrap(Executor executor, Runnable r, Throwable t) {
// default no Operation
afterExecute(executor, r, t);
return r;
}
Expand Down Expand Up @@ -151,7 +150,6 @@ default void beforeReject(Runnable r, Executor executor) {
}

default Runnable beforeRejectWrap(Runnable r, Executor executor) {
// default no Operation
beforeReject(r, executor);
return r;
}
Expand All @@ -166,7 +164,6 @@ default void afterReject(Runnable r, Executor executor) {
}

default Runnable afterRejectWrap(Runnable r, Executor executor) {
// default no Operation
afterReject(r, executor);
return r;
}
Expand Down
2 changes: 1 addition & 1 deletion dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<url>https://github.com/yanhom1314/dynamic-tp</url>

<properties>
<revision>1.1.7</revision>
<revision>1.1.8-beta</revision>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<lombok.version>1.18.24</lombok.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

package org.dromara.dynamictp.core.aware;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ArrayUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.dromara.dynamictp.core.support.task.runnable.DtpRunnable;

import java.lang.ref.SoftReference;
Expand All @@ -40,7 +40,14 @@
* @author txbao
*/
@Slf4j
@SuppressWarnings("all")
public class AgentAware extends TaskStatAware {

/**
* dtpRunnableCache key -> Runnable value -> DtpRunnable
*/
private final Map<Runnable, SoftReference<DtpRunnable>> dtpRunnableCache = new ConcurrentHashMap<>();

@Override
public int getOrder() {
return Integer.MIN_VALUE;
Expand All @@ -51,18 +58,11 @@ public String getName() {
return "agent";
}

/**
* dtpRunnableCache key -> Runnable value -> DtpRunnable
*/
private final Map<Runnable, SoftReference<DtpRunnable>> dtpRunnableCache = new ConcurrentHashMap<>();

private DtpRunnable determineDtpRunnable(List<Field> conditionalFields, Runnable r) throws IllegalAccessException {

for (Field field : conditionalFields) {
if (Objects.isNull(field)) {
continue;
}

field.setAccessible(true);
Runnable o = (Runnable) field.get(r);
if (o instanceof DtpRunnable) {
Expand All @@ -84,7 +84,7 @@ private DtpRunnable getDtpRunnable(Class<? extends Runnable> rClass, Runnable r)
List<Field> conditionFields = Arrays.stream(declaredFields)
.filter(ele -> Runnable.class.isAssignableFrom(ele.getType()))
.collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(conditionFields)) {
if (CollectionUtils.isNotEmpty(conditionFields)) {
DtpRunnable dtpRunnable = determineDtpRunnable(conditionFields, r);
if (Objects.nonNull(dtpRunnable)) {
return dtpRunnable;
Expand All @@ -103,22 +103,19 @@ private Runnable getDtpRunnableInstance(Runnable r) {
if (r instanceof DtpRunnable) {
return r;
}

DtpRunnable dtpRunnable = null;
Class<? extends Runnable> rClass = r.getClass();
try {
dtpRunnable = getDtpRunnable(rClass, r);
} catch (IllegalAccessException e) {
log.error("getDtpRunnable Error", e);
}

if (dtpRunnable == null) {
if (log.isWarnEnabled()) {
log.warn("DynamicTp aware [{}], can not find DtpRunnable.", getName());
}
return r;
}

return dtpRunnable;
}

Expand Down Expand Up @@ -151,13 +148,4 @@ public Runnable beforeRejectWrap(Runnable r, Executor executor) {
}
return getDtpRunnableInstance(r);
}

@Override
public Runnable afterRejectWrap(Runnable r, Executor executor) {
SoftReference<DtpRunnable> remove = dtpRunnableCache.remove(r);
if (remove != null) {
return remove.get();
}
return getDtpRunnableInstance(r);
}
}
5 changes: 0 additions & 5 deletions extension/extension-skywalking/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>

<dependency>
<groupId>org.dromara.dynamictp</groupId>
<artifactId>dynamic-tp-jvmti-runtime</artifactId>
</dependency>
</dependencies>

</project>

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<url>https://github.com/yanhom1314/dynamic-tp</url>

<properties>
<revision>1.1.7</revision>
<revision>1.1.8-beta</revision>

<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
Expand Down
1 change: 1 addition & 0 deletions test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<module>test-core</module>
<module>test-logging</module>
<module>test-configcenter</module>
<module>test-extension</module>
</modules>

<properties>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
* 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 org.dromara.dynamictp.agent;

import org.dromara.dynamictp.core.aware.AgentAware;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
* 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 org.dromara.dynamictp.agent;

public class MyAgentTwoPathRunnableChildWrapper implements Runnable {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
* 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 org.dromara.dynamictp.agent;

public class MyAgentTwoPathRunnableWrapper implements Runnable {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
* 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 org.dromara.dynamictp.agent;

public class MyAgentWrapper implements Runnable {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
* 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 org.dromara.dynamictp.agent;

public class MyAgentWrapperChild extends MyAgentWrapper {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
* 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 org.dromara.dynamictp.agent;

public class MyAgentWrapperTwoRunnable implements Runnable {
Expand Down

0 comments on commit 4763828

Please sign in to comment.