Package jetbrains.buildServer
Class ExtendableServiceLocator
- java.lang.Object
-
- jetbrains.buildServer.ServiceLocatorImpl
-
- jetbrains.buildServer.ExtendableServiceLocator
-
- All Implemented Interfaces:
ExtensionHolder
,ExtensionsProvider
,ServiceLocator
- Direct Known Subclasses:
BuildServerServiceLocator
public class ExtendableServiceLocator extends ServiceLocatorImpl implements ExtensionHolder
Extensions holder which maintains local collection of extensions and is able to retrieve extensions from Spring bean factory. Also acts as service locator for Spring services.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface jetbrains.buildServer.ExtensionsProvider
ExtensionsProvider.ExtensionAction<T extends TeamCityExtension>
-
-
Constructor Summary
Constructors Constructor Description ExtendableServiceLocator()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T extends TeamCityExtension>
voidforeachExtension(Class<T> agentExtensionClass, ExtensionsProvider.ExtensionAction<T> action)
Iterates over extensions of some class and executes some action on them.ExtensionAccessor
getAccessor()
<T extends TeamCityExtension>
TgetExtension(Class<T> extensionClass, String sourceId)
Retrieves extension registered with specified type and id<T extends TeamCityExtension>
Collection<T>getExtensions(Class<T> extensionClass)
Returns collection of extensions of the specified type.<T extends TeamCityExtension>
ExtensionsCollection<T>getExtensionsCollection(Class<T> extensionClass)
Live collection of extensions.<T extends TeamCityExtension>
Collection<String>getExtensionSources(Class<T> extensionClass)
Returns identifiers of the extensions of specified type<T extends TeamCityExtension,CONTEXT,TARGET>
StampedExtensionsSupplier<CONTEXT,TARGET>getStampedExtensionsSupplier(Class<T> extensionClass, Function<StampedExtensionsSupplier.StoredData<CONTEXT,Collection<T>>,TARGET> converter)
Live suppler of extensions.<T extends TeamCityExtension>
voidregisterExtension(Class<T> extensionClass, String sourceId, T extension)
Registers an extension of the specified typevoid
setAccessor(ExtensionAccessor accessor)
void
setSpringAccessor(SpringAccessor springAccessor)
<T extends TeamCityExtension>
voidunregisterExtension(Class<T> extensionClass, String sourceId)
Unregisters extension.-
Methods inherited from class jetbrains.buildServer.ServiceLocatorImpl
findSingletonService, getServices, getSingletonService, getSpringAccessor, getSpringBeansOfType
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jetbrains.buildServer.ExtensionsProvider
getExtensionsCollection
-
Methods inherited from interface jetbrains.buildServer.ServiceLocator
findSingletonService, getServices, getSingletonService
-
-
-
-
Method Detail
-
setAccessor
@Autowired public void setAccessor(@NotNull ExtensionAccessor accessor)
-
getAccessor
public ExtensionAccessor getAccessor()
-
setSpringAccessor
@Autowired public void setSpringAccessor(@NotNull SpringAccessor springAccessor)
- Overrides:
setSpringAccessor
in classServiceLocatorImpl
-
registerExtension
public <T extends TeamCityExtension> void registerExtension(@NotNull Class<T> extensionClass, @NotNull String sourceId, @NotNull T extension)
Registers an extension of the specified type- Specified by:
registerExtension
in interfaceExtensionHolder
- Parameters:
extensionClass
- extension typesourceId
- unique id of the extension among other extensions of the same typeextension
- extension
-
unregisterExtension
public <T extends TeamCityExtension> void unregisterExtension(@NotNull Class<T> extensionClass, @NotNull String sourceId)
Unregisters extension.- Specified by:
unregisterExtension
in interfaceExtensionHolder
- Parameters:
extensionClass
- type of the extensionsourceId
- id of the extension
-
getExtensions
@NotNull public <T extends TeamCityExtension> Collection<T> getExtensions(@NotNull Class<T> extensionClass)
Returns collection of extensions of the specified type. Extensions that implementPositionAware
interface are sorted accordingly.- Specified by:
getExtensions
in interfaceExtensionsProvider
- Parameters:
extensionClass
- extension type- Returns:
- extensions
-
getExtensionsCollection
@NotNull public <T extends TeamCityExtension> ExtensionsCollection<T> getExtensionsCollection(@NotNull Class<T> extensionClass)
Description copied from interface:ExtensionsProvider
Live collection of extensions. This collection can be stored in a field of some class. It is updated automatically if a new extension of a given class is registered.- Specified by:
getExtensionsCollection
in interfaceExtensionsProvider
- Parameters:
extensionClass
- extension class- Returns:
- collection of extension
-
getStampedExtensionsSupplier
@NotNull public <T extends TeamCityExtension,CONTEXT,TARGET> StampedExtensionsSupplier<CONTEXT,TARGET> getStampedExtensionsSupplier(@NotNull Class<T> extensionClass, @NotNull Function<StampedExtensionsSupplier.StoredData<CONTEXT,Collection<T>>,TARGET> converter)
Description copied from interface:ExtensionsProvider
Live suppler of extensions. This supplier can be safely stored in a field of some class. It is updated automatically if a new extension of a given class is registered or if outer context was changed. For example this supplier is very useful if some internal property is used to select a single extension implementation which should be used:StampedExtensionsSupplier<String, MyExtension> supplier = extensionsProvider.getStampedExtensionsSupplier(MyExtension.class, extensions -> { for (MyExtension ext : extensions.data) { if (ext.getClass().getName().equals(extensions.context)) return ext; } return new DefaultMyExtension(); }); MyExtension currentlyUsedExtension = supplier.get(TeamCityProperties.getProperty("myextension.implementationClass"));
here with each change of the "myextension.implementationClass" property the supplier will reset the internal cache and will call the provided function with the registered extensions collection and with the current context (the parameter value in this example). The internal cache is also reset automatically if the registered extensions collection changes. Without the getStampedExtensionsSupplier method, same code could be implemented with getExtensionsCollection(), but will require filtering the collection each time:ExtensionsCollection<MyExtension> allExtensions = extensionsProvider.getExtensionsCollection(MyExtension.class); MyExtension currentlyUsedExtension = null; for (MyExtension ext : allExtensions.getExtensions()) { if (ext.getClass().getName().equals(TeamCityProperties.getProperty("myextension.implementationClass"))) { currentlyUsedExtension = ext; break; } } if (currentlyUsedExtension == null) currentlyUsedExtension = new DefaultMyExtension()
- Specified by:
getStampedExtensionsSupplier
in interfaceExtensionsProvider
- Parameters:
extensionClass
- extension classconverter
- function to convert the base extension. Will be automatically applied if underlying collection should be reset (eg if a new extension is registered).- Returns:
- collection of extension
-
foreachExtension
public <T extends TeamCityExtension> void foreachExtension(@NotNull Class<T> agentExtensionClass, @NotNull ExtensionsProvider.ExtensionAction<T> action)
Description copied from interface:ExtensionsProvider
Iterates over extensions of some class and executes some action on them. Exceptions fromExtensionsProvider.ExtensionAction.action(T)
are catched and logged- Specified by:
foreachExtension
in interfaceExtensionsProvider
- Parameters:
agentExtensionClass
- extension classaction
- action to execute
-
getExtensionSources
@NotNull public <T extends TeamCityExtension> Collection<String> getExtensionSources(@NotNull Class<T> extensionClass)
Returns identifiers of the extensions of specified type- Specified by:
getExtensionSources
in interfaceExtensionsProvider
- Parameters:
extensionClass
- type of the extension- Returns:
- identifiers
-
getExtension
@Nullable public <T extends TeamCityExtension> T getExtension(@NotNull Class<T> extensionClass, @NotNull String sourceId)
Retrieves extension registered with specified type and id- Specified by:
getExtension
in interfaceExtensionsProvider
- Parameters:
extensionClass
- extension typesourceId
- id- Returns:
- extension or null
-
-