Java Code Examples for org.osgi.util.tracker.ServiceTracker#getServices()

The following examples show how to use org.osgi.util.tracker.ServiceTracker#getServices() . 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: GenericArtifactUnloader.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
@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 2
Source File: SAML2SSOAuthenticator.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
private void handleAuthenticationStarted(int tenantId) {
    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).startedAuthentication(tenantId);
            }
        }
        tracker.close();
    }
}
 
Example 3
Source File: SAML2SSOAuthenticator.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
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 4
Source File: MutualSSLAuthenticator.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
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 5
Source File: MutualSSLAuthenticator.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
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 6
Source File: SignedJWTAuthenticator.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
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 7
Source File: SignedJWTAuthenticator.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
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 8
Source File: DatabaseService.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 获取数据处理对象{@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 9
Source File: OIDCAuthenticator.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
private void handleAuthenticationStarted(int tenantId) {
    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).startedAuthentication(tenantId);
            }
        }
        tracker.close();
    }
}
 
Example 10
Source File: OIDCAuthenticator.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
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 11
Source File: SignedJWTAuthenticator.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
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 12
Source File: SignedJWTAuthenticator.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
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 13
Source File: DatabaseService.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 获取数据处理对象{@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 14
Source File: DatabaseService.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 通过数据库元数据库获取数据库连接,主要取数据库类型
 * @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 15
Source File: DatabaseService.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 通过数据库元数据库获取数据库连接,主要取数据库类型
 * @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;
}