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.
implemented application type detector - pinpoint-apm#195
- Loading branch information
Showing
28 changed files
with
1,646 additions
and
304 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
64 changes: 64 additions & 0 deletions
64
bootstrap/src/main/java/com/navercorp/pinpoint/bootstrap/resolver/ServerTypeResolver.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,64 @@ | ||
/* | ||
* 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}. | ||
* 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} | ||
* </li> | ||
* </ul> | ||
* | ||
* @author HyunGil Jeong | ||
*/ | ||
public class ServerTypeResolver { | ||
|
||
private final Logger logger = Logger.getLogger(ServerTypeResolver.class.getName()); | ||
|
||
private final List<ServerTypeDetector> serverTypeDetectors; | ||
|
||
private static final ServiceType DEFAULT_SERVER_TYPE = ServiceType.STAND_ALONE; | ||
|
||
public ServerTypeResolver(List<ServerTypeDetector> serverTypeDetectors) { | ||
if (serverTypeDetectors == null) { | ||
throw new IllegalArgumentException("serverTypeDetectors should not be null"); | ||
} | ||
this.serverTypeDetectors = serverTypeDetectors; | ||
} | ||
|
||
public ServiceType resolve() { | ||
for (ServerTypeDetector currentDetector : this.serverTypeDetectors) { | ||
logger.log(Level.INFO, "Attempting to resolve using " + currentDetector.getClass()); | ||
if (currentDetector.detect()) { | ||
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; | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
...trap/src/main/java/com/navercorp/pinpoint/bootstrap/resolver/condition/BaseCondition.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,73 @@ | ||
/* | ||
* 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; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
/** | ||
* @author HyunGil Jeong | ||
*/ | ||
public abstract class BaseCondition<T> implements Condition<T> { | ||
|
||
private final ConditionChecker<Condition<T>> conditionChecker; | ||
|
||
protected final List<T> requiredConditions; | ||
|
||
@SuppressWarnings("unchecked") | ||
protected BaseCondition(List<T> requiredConditions, ConditionChecker<? extends Condition<T>> conditionMatcher) { | ||
this.requiredConditions = Collections.unmodifiableList(requiredConditions); | ||
this.conditionChecker = (ConditionChecker<Condition<T>>)conditionMatcher; | ||
} | ||
|
||
@Override | ||
public boolean matches() { | ||
return this.conditionChecker.check(this); | ||
} | ||
|
||
public abstract static class ConditionBuilder<C extends Condition<T>, T> { | ||
|
||
private final Set<T> requiredConditions = new HashSet<T>(); | ||
|
||
protected ConditionBuilder(T requiredCondition) { | ||
if (requiredCondition == null) { | ||
throw new IllegalArgumentException("requiredCondition may not be null"); | ||
} | ||
this.or(requiredCondition); | ||
} | ||
|
||
public ConditionBuilder<C, T> or(T requiredCondition) { | ||
if (requiredCondition != null) { | ||
this.requiredConditions.add(requiredCondition); | ||
} | ||
return this; | ||
} | ||
|
||
public final C done() { | ||
if (this.requiredConditions.isEmpty()) { | ||
return build(Collections.<T>emptyList()); | ||
} | ||
return build(new ArrayList<T>(this.requiredConditions)); | ||
} | ||
|
||
protected abstract C build(List<T> requiredConditions); | ||
} | ||
|
||
} |
81 changes: 81 additions & 0 deletions
81
...p/src/main/java/com/navercorp/pinpoint/bootstrap/resolver/condition/BaseConditionSet.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,81 @@ | ||
/* | ||
* 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; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
/** | ||
* @author HyunGil Jeong | ||
*/ | ||
public abstract class BaseConditionSet<T> implements ConditionSet<T> { | ||
|
||
private final ConditionChecker<ConditionSet<T>> conditionSetMatcher; | ||
|
||
protected final List<Set<T>> requiredConditionSets; | ||
|
||
@SuppressWarnings("unchecked") | ||
protected BaseConditionSet(List<Set<T>> requiredConditionSets, ConditionChecker<? extends ConditionSet<T>> conditionSetMatcher) { | ||
this.requiredConditionSets = Collections.unmodifiableList(requiredConditionSets); | ||
this.conditionSetMatcher = (ConditionChecker<ConditionSet<T>>)conditionSetMatcher; | ||
} | ||
|
||
@Override | ||
public boolean matches() { | ||
return this.conditionSetMatcher.check(this); | ||
} | ||
|
||
public abstract static class ConditionSetBuilder<C extends ConditionSet<T>, T> { | ||
|
||
private final Set<Set<T>> requiredConditionSets = new HashSet<Set<T>>(); | ||
|
||
protected ConditionSetBuilder(T ... requiredConditions) { | ||
if (requiredConditions == null) { | ||
throw new IllegalArgumentException("requiredConditions may not be null"); | ||
} | ||
this.or(requiredConditions); | ||
} | ||
|
||
public ConditionSetBuilder<C, T> or(T ... requiredConditions) { | ||
if (requiredConditions != null) { | ||
Set<T> requiredConditionSet = new HashSet<T>(requiredConditions.length); | ||
for (T requiredCondition : requiredConditions) { | ||
if (requiredCondition != null) { | ||
requiredConditionSet.add(requiredCondition); | ||
} | ||
} | ||
if (!requiredConditionSet.isEmpty()) { | ||
this.requiredConditionSets.add(requiredConditionSet); | ||
} | ||
} | ||
return this; | ||
} | ||
|
||
public final C done() { | ||
if (this.requiredConditionSets.isEmpty()) { | ||
return build(Collections.<Set<T>>emptyList()); | ||
} | ||
return build(new ArrayList<Set<T>>(this.requiredConditionSets)); | ||
} | ||
|
||
protected abstract C build(List<Set<T>> requiredConditionSets); | ||
} | ||
|
||
} |
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(); | ||
|
||
} |
Oops, something went wrong.