forked from pinpoint-apm/pinpoint
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pinpoint-apm#195] implemented application type detector
- Loading branch information
Showing
20 changed files
with
1,049 additions
and
297 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
72 changes: 72 additions & 0 deletions
72
...n/java/com/navercorp/pinpoint/bootstrap/resolver/ApplicationServerTypePluginResolver.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,72 @@ | ||
/* | ||
* Copyright 2015 NAVER Corp. | ||
* | ||
* Licensed 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 com.navercorp.pinpoint.bootstrap.resolver; | ||
|
||
import java.util.List; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
import com.navercorp.pinpoint.bootstrap.plugin.ServerTypeDetector; | ||
import com.navercorp.pinpoint.common.ServiceType; | ||
|
||
/** | ||
* This class attempts to resolve the current application type through {@link ServerTypeDetector}s. | ||
* The application type is resolved by checking the conditions defined in each of the loaded detector's {@code detect} method. | ||
* <p> | ||
* If no match is found, the application type defaults to {@code ServiceType.STAND_ALONE} | ||
* | ||
* @author HyunGil Jeong | ||
*/ | ||
public class ApplicationServerTypePluginResolver { | ||
|
||
private final Logger logger = Logger.getLogger(ApplicationServerTypePluginResolver.class.getName()); | ||
|
||
private final List<ServerTypeDetector> serverTypeDetectors; | ||
|
||
private final ConditionProvider conditionProvider; | ||
|
||
private static final ServiceType DEFAULT_SERVER_TYPE = ServiceType.STAND_ALONE; | ||
|
||
public ApplicationServerTypePluginResolver(List<ServerTypeDetector> serverTypeDetectors) { | ||
this(serverTypeDetectors, ConditionProvider.DEFAULT_CONDITION_PROVIDER); | ||
} | ||
|
||
public ApplicationServerTypePluginResolver(List<ServerTypeDetector> serverTypeDetectors, ConditionProvider conditionProvider) { | ||
if (serverTypeDetectors == null) { | ||
throw new IllegalArgumentException("serverTypeDetectors should not be null"); | ||
} | ||
if (conditionProvider == null) { | ||
throw new IllegalArgumentException("conditionProvider should not be null"); | ||
} | ||
this.serverTypeDetectors = serverTypeDetectors; | ||
this.conditionProvider = conditionProvider; | ||
} | ||
|
||
public ServiceType resolve() { | ||
for (ServerTypeDetector currentDetector : this.serverTypeDetectors) { | ||
logger.log(Level.INFO, "Attempting to resolve using " + currentDetector.getClass()); | ||
if (currentDetector.detect(this.conditionProvider)) { | ||
logger.log(Level.INFO, "Match found using " + currentDetector.getClass().getSimpleName()); | ||
return currentDetector.getServerType(); | ||
} else { | ||
logger.log(Level.INFO, "No match found using " + currentDetector.getClass()); | ||
} | ||
} | ||
logger.log(Level.INFO, "Server type not resolved. Defaulting to " + DEFAULT_SERVER_TYPE.getName()); | ||
return DEFAULT_SERVER_TYPE; | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/resolver/ConditionProvider.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,84 @@ | ||
/* | ||
* Copyright 2015 NAVER Corp. | ||
* | ||
* Licensed 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 com.navercorp.pinpoint.bootstrap.resolver; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import com.navercorp.pinpoint.bootstrap.resolver.condition.Condition; | ||
import com.navercorp.pinpoint.bootstrap.resolver.condition.LibraryClassCondition; | ||
import com.navercorp.pinpoint.bootstrap.resolver.condition.MainClassCondition; | ||
import com.navercorp.pinpoint.bootstrap.resolver.condition.SystemPropertyCondition; | ||
|
||
/** | ||
* @author HyunGil Jeong | ||
*/ | ||
public class ConditionProvider { | ||
|
||
public static final ConditionProvider DEFAULT_CONDITION_PROVIDER = new ConditionProvider(); | ||
|
||
private final Map<Class<? extends Condition<?>>, Condition<?>> conditions; | ||
|
||
public ConditionProvider() { | ||
this(new HashMap<Class<? extends Condition<?>>, Condition<?>>()); | ||
} | ||
|
||
public ConditionProvider(Map<Class<? extends Condition<?>>, Condition<?>> conditions) { | ||
this.conditions = conditions; | ||
addDefaultConditions(); | ||
} | ||
|
||
private void addDefaultConditions() { | ||
this.conditions.put(MainClassCondition.class, new MainClassCondition()); | ||
this.conditions.put(SystemPropertyCondition.class, new SystemPropertyCondition()); | ||
this.conditions.put(LibraryClassCondition.class, new LibraryClassCondition()); | ||
} | ||
|
||
public <T extends Condition<?>> T getCondition(Class<T> conditionClass) { | ||
@SuppressWarnings("unchecked") | ||
T condition = (T)this.conditions.get(conditionClass); | ||
return condition; | ||
} | ||
|
||
/** | ||
* Returns {@link MainClassCondition} that allows plugins to check for the application's bootstrap main class. | ||
* | ||
* @return the {@link MainClassCondition} | ||
*/ | ||
public MainClassCondition getMainClassCondition() { | ||
return (MainClassCondition)this.conditions.get(MainClassCondition.class); | ||
} | ||
|
||
/** | ||
* Returns {@link SystemPropertyCondition} that allows plugins to check for system property keys. | ||
* | ||
* @return the {@link SystemPropertyCondition} | ||
*/ | ||
public SystemPropertyCondition getSystemPropertyCondition() { | ||
return (SystemPropertyCondition)this.conditions.get(SystemPropertyCondition.class); | ||
} | ||
|
||
/** | ||
* Returns {@link LibraryClassCondition} that allows plugins to check for classes accessible by | ||
* the system class loader. | ||
* | ||
* @return the {@link LibraryClassCondition} | ||
*/ | ||
public LibraryClassCondition getLibraryClassCondition() { | ||
return (LibraryClassCondition)this.conditions.get(LibraryClassCondition.class); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/resolver/condition/Condition.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,26 @@ | ||
/* | ||
* Copyright 2015 NAVER Corp. | ||
* | ||
* Licensed 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 com.navercorp.pinpoint.bootstrap.resolver.condition; | ||
|
||
/** | ||
* @author HyunGil Jeong | ||
*/ | ||
public interface Condition<T> { | ||
|
||
public boolean matches(T condition); | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
...rap/src/main/java/com/navercorp/pinpoint/bootstrap/resolver/condition/ConditionValue.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,26 @@ | ||
/* | ||
* Copyright 2015 NAVER Corp. | ||
* | ||
* Licensed 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 com.navercorp.pinpoint.bootstrap.resolver.condition; | ||
|
||
/** | ||
* @author HyunGil Jeong | ||
*/ | ||
public interface ConditionValue<V> { | ||
|
||
public V getValue(); | ||
|
||
} |
Oops, something went wrong.