Java Code Examples for org.osgi.util.tracker.ServiceTracker#close()
The following examples show how to use
org.osgi.util.tracker.ServiceTracker#close() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MutualSSLAuthenticator.java From carbon-identity with Apache License 2.0 | 6 votes |
private void handleAuthenticationCompleted(int tenantId, boolean isSuccessful) { BundleContext bundleContext = MutualSSLAuthenticatorServiceComponent.getBundleContext(); if (bundleContext != null) { ServiceTracker tracker = new ServiceTracker(bundleContext, AuthenticationObserver.class.getName(), null); tracker.open(); Object[] services = tracker.getServices(); if (services != null) { for (Object service : services) { ((AuthenticationObserver) service).completedAuthentication( tenantId, isSuccessful); } } tracker.close(); } }
Example 2
Source File: SignedJWTAuthenticator.java From attic-stratos with Apache License 2.0 | 6 votes |
private void handleAuthenticationCompleted(int tenantId, boolean isSuccessful) { BundleContext bundleContext = SignedJWTAuthenticatorServiceComponent.getBundleContext(); if (bundleContext != null) { ServiceTracker tracker = new ServiceTracker(bundleContext, AuthenticationObserver.class.getName(), null); tracker.open(); Object[] services = tracker.getServices(); if (services != null) { for (Object service : services) { ((AuthenticationObserver) service).completedAuthentication( tenantId, isSuccessful); } } tracker.close(); } }
Example 3
Source File: SignedJWTAuthenticator.java From attic-stratos with Apache License 2.0 | 6 votes |
private void handleAuthenticationStarted(int tenantId) { BundleContext bundleContext = SignedJWTAuthenticatorServiceComponent.getBundleContext(); if (bundleContext != null) { ServiceTracker tracker = new ServiceTracker(bundleContext, AuthenticationObserver.class.getName(), null); tracker.open(); Object[] services = tracker.getServices(); if (services != null) { for (Object service : services) { ((AuthenticationObserver) service).startedAuthentication(tenantId); } } tracker.close(); } }
Example 4
Source File: OIDCAuthenticator.java From carbon-apimgt with Apache License 2.0 | 6 votes |
private void handleAuthenticationCompleted(int tenantId, boolean isSuccessful) { BundleContext bundleContext = OIDCAuthBEDataHolder.getInstance().getBundleContext(); if (bundleContext != null) { ServiceTracker tracker = new ServiceTracker(bundleContext, AuthenticationObserver.class.getName(), null); tracker.open(); Object[] services = tracker.getServices(); if (services != null) { for (Object service : services) { ((AuthenticationObserver) service).completedAuthentication( tenantId, isSuccessful); } } tracker.close(); } }
Example 5
Source File: DatabaseService.java From translationstudio8 with GNU General Public License v2.0 | 6 votes |
/** * 获取数据处理对象{@link DBOperator},该数据处理对象用于访问指定的数据库中的数据<br> * 在访问数据库时,根据不同数据库类型获取相应的处理对象.这些数据库被封装在{@link MetaData}中 * @param metaData * 当前数据库的元数据,封装了连接数据库的一系列参数 * @return 返回null时,表示未获取到数据处理对象; */ public static DBOperator getDBOperator(MetaData metaData) { DBOperator dbOperator = null; @SuppressWarnings({ "rawtypes", "unchecked" }) ServiceTracker tracker = new ServiceTracker(Activator.context, DBServiceProvider.class.getName(), null); tracker.open(); try { Object[] services = tracker.getServices(); for (Object i : services) { DBServiceProvider serviceProvider = (DBServiceProvider) i; DBOperator temp = serviceProvider.getTmDatabaseInstance(); if (temp == null) { continue; } if (temp.getDbConfig().getDefaultType().equals(metaData.getDbType())) { dbOperator = temp; dbOperator.setMetaData(metaData); } } } finally { tracker.close(); } return dbOperator; }
Example 6
Source File: SignedJWTAuthenticator.java From carbon-identity with Apache License 2.0 | 6 votes |
private void handleAuthenticationCompleted(int tenantId, boolean isSuccessful) { BundleContext bundleContext = SignedJWTAuthenticatorServiceComponent.getBundleContext(); if (bundleContext != null) { ServiceTracker tracker = new ServiceTracker(bundleContext, AuthenticationObserver.class.getName(), null); tracker.open(); Object[] services = tracker.getServices(); if (services != null) { for (Object service : services) { ((AuthenticationObserver) service).completedAuthentication( tenantId, isSuccessful); } } tracker.close(); } }
Example 7
Source File: SignedJWTAuthenticator.java From carbon-identity with Apache License 2.0 | 6 votes |
private void handleAuthenticationStarted(int tenantId) { BundleContext bundleContext = SignedJWTAuthenticatorServiceComponent.getBundleContext(); if (bundleContext != null) { ServiceTracker tracker = new ServiceTracker(bundleContext, AuthenticationObserver.class.getName(), null); tracker.open(); Object[] services = tracker.getServices(); if (services != null) { for (Object service : services) { ((AuthenticationObserver) service).startedAuthentication(tenantId); } } tracker.close(); } }
Example 8
Source File: GenericArtifactUnloader.java From micro-integrator with Apache License 2.0 | 6 votes |
@Override public void run() { BundleContext bundleContext = CarbonCoreDataHolder.getInstance().getBundleContext(); if (bundleContext != null) { ServiceTracker tracker = new ServiceTracker(bundleContext, ArtifactUnloader.class.getName(), null); tracker.open(); Object[] services = tracker.getServices(); if (services != null) { for (Object service : services) { ((ArtifactUnloader) service).unload(); } } tracker.close(); } }
Example 9
Source File: MutualSSLAuthenticator.java From carbon-identity with Apache License 2.0 | 6 votes |
private void handleAuthenticationStarted(int tenantId) { BundleContext bundleContext = MutualSSLAuthenticatorServiceComponent.getBundleContext(); if (bundleContext != null) { ServiceTracker tracker = new ServiceTracker(bundleContext, AuthenticationObserver.class.getName(), null); tracker.open(); Object[] services = tracker.getServices(); if (services != null) { for (Object service : services) { ((AuthenticationObserver) service).startedAuthentication(tenantId); } } tracker.close(); } }
Example 10
Source File: SAML2SSOAuthenticator.java From carbon-identity with Apache License 2.0 | 6 votes |
private void handleAuthenticationCompleted(int tenantId, boolean isSuccessful) { BundleContext bundleContext = SAML2SSOAuthBEDataHolder.getInstance().getBundleContext(); if (bundleContext != null) { ServiceTracker tracker = new ServiceTracker(bundleContext, AuthenticationObserver.class.getName(), null); tracker.open(); Object[] services = tracker.getServices(); if (services != null) { for (Object service : services) { ((AuthenticationObserver) service).completedAuthentication( tenantId, isSuccessful); } } tracker.close(); } }
Example 11
Source File: OsgiConfigurationServiceImpl.java From publick-sling-blog with Apache License 2.0 | 6 votes |
/** * Wait for an OSGi service to become active. * * @param serviceImpl The service implementation class * @param timeout The length of time to wait for the service */ private void waitForService(Class serviceImpl, long timeout) { Class serviceInterface = serviceImpl.getInterfaces()[0]; BundleContext bundleContext = FrameworkUtil.getBundle(serviceInterface).getBundleContext(); ServiceReference factoryRef = bundleContext.getServiceReference(serviceInterface.getName()); ServiceTracker serviceTracker = new ServiceTracker(bundleContext, factoryRef, null); serviceTracker.open(); try { serviceTracker.waitForService(timeout); } catch (InterruptedException e) { LOGGER.error("Could not get service", e); } serviceTracker.close(); }
Example 12
Source File: DatabaseService.java From tmxeditor8 with GNU General Public License v2.0 | 6 votes |
/** * 获取数据处理对象{@link DBOperator},该数据处理对象用于访问指定的数据库中的数据<br> * 在访问数据库时,根据不同数据库类型获取相应的处理对象.这些数据库被封装在{@link MetaData}中 * @param metaData * 当前数据库的元数据,封装了连接数据库的一系列参数 * @return 返回null时,表示未获取到数据处理对象; */ public static DBOperator getDBOperator(MetaData metaData) { DBOperator dbOperator = null; @SuppressWarnings({ "rawtypes", "unchecked" }) ServiceTracker tracker = new ServiceTracker(Activator.context, DBServiceProvider.class.getName(), null); tracker.open(); try { Object[] services = tracker.getServices(); for (Object i : services) { DBServiceProvider serviceProvider = (DBServiceProvider) i; DBOperator temp = serviceProvider.getTmDatabaseInstance(); if (temp == null) { continue; } if (temp.getDbConfig().getDefaultType().equals(metaData.getDbType())) { dbOperator = temp; dbOperator.setMetaData(metaData); } } } finally { tracker.close(); } return dbOperator; }
Example 13
Source File: SocketListener.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void destroy() { if (!httpConfig.isSecure()) { uninit(); } else { final ServiceTracker<?, ?> tempTr = this.securityTracker; this.securityTracker = null; if (tempTr != null) { try { tempTr.close(); } catch (final Exception excpt) { } } } }
Example 14
Source File: AbstractServerActivator.java From cxf with Apache License 2.0 | 5 votes |
public static void awaitService(BundleContext bundleContext, String filter, long timeout) throws InvalidSyntaxException, InterruptedException { Filter serviceFilter = bundleContext.createFilter(filter); ServiceTracker<Object, ?> tracker = new ServiceTracker<>(bundleContext, serviceFilter, null); tracker.open(); Object service = tracker.waitForService(timeout); tracker.close(); if (service == null) { throw new IllegalStateException("Expected service with filter " + filter + " was not found"); } }
Example 15
Source File: ArtemisFeatureTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
protected Object waitForService(String filter, long timeout) throws InvalidSyntaxException, InterruptedException { ServiceTracker<Object, Object> st = new ServiceTracker<>(bundleContext, bundleContext.createFilter(filter), null); try { st.open(); return st.waitForService(timeout); } finally { st.close(); } }
Example 16
Source File: DatabaseService.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
/** * 通过数据库元数据库获取数据库连接,主要取数据库类型 * @param metaData * @return ; */ public static SystemDBOperator getSysDbOperateByMetaData(MetaData metaData) { @SuppressWarnings({ "rawtypes", "unchecked" }) ServiceTracker tracker = new ServiceTracker(Activator.context, DBServiceProvider.class.getName(), null); tracker.open(); try { Object[] services = tracker.getServices(); for (Object i : services) { DBServiceProvider serviceProvider = (DBServiceProvider) i; SystemDBOperator temp = serviceProvider.getOperateDBInstance(); if (temp == null) { continue; } MetaData tempMetaData = temp.getMetaData(); if (tempMetaData.getDbType().equals(metaData.getDbType())) { tempMetaData.setDatabaseName(metaData.getDatabaseName()); tempMetaData.setDataPath(metaData.getDataPath()); tempMetaData.setInstance(metaData.getInstance()); tempMetaData.setPassword(metaData.getPassword()); tempMetaData.setPort(metaData.getPort()); tempMetaData.setServerName(metaData.getServerName()); tempMetaData.setTB(metaData.isTB()); tempMetaData.setTM(metaData.isTM()); tempMetaData.setUserName(metaData.getUserName()); return temp; } } } finally { tracker.close(); } return null; }
Example 17
Source File: DatabaseService.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
/** * 通过数据库元数据库获取数据库连接,主要取数据库类型 * @param metaData * @return ; */ public static SystemDBOperator getSysDbOperateByMetaData(MetaData metaData) { @SuppressWarnings({ "rawtypes", "unchecked" }) ServiceTracker tracker = new ServiceTracker(Activator.context, DBServiceProvider.class.getName(), null); tracker.open(); try { Object[] services = tracker.getServices(); for (Object i : services) { DBServiceProvider serviceProvider = (DBServiceProvider) i; SystemDBOperator temp = serviceProvider.getOperateDBInstance(); if (temp == null) { continue; } MetaData tempMetaData = temp.getMetaData(); if (tempMetaData.getDbType().equals(metaData.getDbType())) { tempMetaData.setDatabaseName(metaData.getDatabaseName()); tempMetaData.setDataPath(metaData.getDataPath()); tempMetaData.setInstance(metaData.getInstance()); tempMetaData.setPassword(metaData.getPassword()); tempMetaData.setPort(metaData.getPort()); tempMetaData.setServerName(metaData.getServerName()); tempMetaData.setTB(metaData.isTB()); tempMetaData.setTM(metaData.isTM()); tempMetaData.setUserName(metaData.getUserName()); return temp; } } } finally { tracker.close(); } return null; }
Example 18
Source File: KarafTestSupport.java From mobi with GNU Affero General Public License v3.0 | 5 votes |
protected void waitForService(String filter, long timeout) throws InvalidSyntaxException, InterruptedException { ServiceTracker st = new ServiceTracker(bundleContext, bundleContext.createFilter(filter), null); try { st.open(); st.waitForService(timeout); } finally { st.close(); } }
Example 19
Source File: PCEPTunnelClusterSingletonService.java From bgpcep with Eclipse Public License 1.0 | 4 votes |
public PCEPTunnelClusterSingletonService( final TunnelProviderDependencies dependencies, final InstanceIdentifier<Topology> pcepTopology, final TopologyId tunnelTopologyId ) { this.dependencies = requireNonNull(dependencies); this.tunnelTopologyId = requireNonNull(tunnelTopologyId); final TopologyId pcepTopologyId = pcepTopology.firstKeyOf(Topology.class).getTopologyId(); final InstructionScheduler scheduler; ServiceTracker<InstructionScheduler, ?> tracker = null; try { tracker = new ServiceTracker<>(dependencies.getBundleContext(), dependencies.getBundleContext().createFilter(String.format("(&(%s=%s)%s)", Constants.OBJECTCLASS, InstructionScheduler.class.getName(), "(" + InstructionScheduler.class.getName() + "=" + pcepTopologyId.getValue() + ")")), null); tracker.open(); scheduler = (InstructionScheduler) tracker.waitForService( TimeUnit.MILLISECONDS.convert(5, TimeUnit.MINUTES)); Preconditions.checkState(scheduler != null, "InstructionScheduler service not found"); } catch (InvalidSyntaxException | InterruptedException e) { throw new IllegalStateException("Error retrieving InstructionScheduler service", e); } finally { if (tracker != null) { tracker.close(); } } final InstanceIdentifier<Topology> tunnelTopology = InstanceIdentifier.builder(NetworkTopology.class) .child(Topology.class, new TopologyKey(tunnelTopologyId)).build(); this.ttp = new PCEPTunnelTopologyProvider(dependencies.getDataBroker(), pcepTopology, pcepTopologyId, tunnelTopology, tunnelTopologyId); this.sgi = scheduler.getIdentifier(); this.tp = new TunnelProgramming(scheduler, dependencies); final Dictionary<String, String> properties = new Hashtable<>(); properties.put(PCEPTunnelTopologyProvider.class.getName(), tunnelTopologyId.getValue()); this.serviceRegistration = dependencies.getBundleContext() .registerService(DefaultTopologyReference.class.getName(), this.ttp, properties); LOG.info("PCEP Tunnel Cluster Singleton service {} registered", getIdentifier().getName()); this.pcepTunnelCssReg = dependencies.getCssp().registerClusterSingletonService(this); }
Example 20
Source File: BootstrapListener.java From nexus-public with Eclipse Public License 1.0 | 4 votes |
private static void installNexusEdition(final BundleContext ctx, final Properties properties) throws Exception { String editionName = properties.getProperty(NEXUS_EDITION); if (editionName != null && editionName.length() > 0) { final ServiceTracker<?, FeaturesService> tracker = new ServiceTracker<>(ctx, FeaturesService.class, null); tracker.open(); try { FeaturesService featuresService = tracker.waitForService(1000); Feature editionFeature = featuresService.getFeature(editionName); properties.put(NEXUS_FULL_EDITION, editionFeature.toString()); Feature dbFeature = featuresService.getFeature(properties.getProperty(NEXUS_DB_FEATURE)); log.info("Installing: {} ({})", editionFeature, dbFeature); Set<String> featureIds = new LinkedHashSet<>(); if (!featuresService.isInstalled(editionFeature)) { featureIds.add(editionFeature.getId()); } if (!featuresService.isInstalled(dbFeature)) { featureIds.add(dbFeature.getId()); } if (detectMixedMode(properties)) { Feature mybatisFeature = featuresService.getFeature("nexus-datastore-mybatis"); if (!featuresService.isInstalled(mybatisFeature)) { featureIds.add(mybatisFeature.getId()); } } // edition might already be installed in the cache; if so then skip installation if (!featureIds.isEmpty()) { // avoid auto-refreshing bundles as that could trigger unwanted restart/lifecycle events EnumSet<Option> options = EnumSet.of(NoAutoRefreshBundles, NoAutoRefreshManagedBundles); featuresService.installFeatures(featureIds, options); } log.info("Installed: {} ({})", editionFeature, dbFeature); } finally { tracker.close(); } } }