Refine search
static Xnio doGetOsgiService() { Bundle bundle = FrameworkUtil.getBundle(Xnio.class); BundleContext context = bundle.getBundleContext(); if (context == null) { throw new IllegalStateException("Bundle not started"); } ServiceReference<Xnio> sr = context.getServiceReference(Xnio.class); if (sr == null) { return null; } return context.getService(sr); }
public void start(final BundleContext context) throws Exception { startLevelServiceReference = context.getServiceReference(StartLevel.class.getName()); startLevel = (StartLevel) context.getService(startLevelServiceReference); for (final Bundle bundle : context.getBundles()) { final String value = bundle.getHeaders().get("Service-Component");
@Override public void start(BundleContext context) throws Exception { bc = context; eaRef = bc.getServiceReference(EventAdmin.class.getName()); if (eaRef != null) { setEa((EventAdmin) bc.getService(eaRef)); } }
@Override public void start(BundleContext bundleContext) throws Exception { Bundle bundle = bundleContext.getBundle(); pluginId = bundle.getSymbolicName(); pluginHealthService = bundleContext.getService(bundleContext.getServiceReference(PluginHealthService.class)); LoggingService loggingService = bundleContext.getService(bundleContext.getServiceReference(LoggingService.class)); Logger.initialize(loggingService); getImplementersAndRegister(bundleContext, bundle); reportErrorsToHealthService(); }
private void sendAdminEvent() { ServiceReference eaRef = bc.getServiceReference(EventAdmin.class.getName()); if (eaRef != null) { EventAdmin ea = (EventAdmin) bc.getService(eaRef); ea.sendEvent(new Event("jersey/test/DEPLOYED", new HashMap<String, String>() { { put("context-path", "/"); } })); bc.ungetService(eaRef); } }
@Override public void configAdminUpdate(String pid, Map<String, String> data) { ServiceReference sref = bundleContext.getServiceReference(ConfigurationAdmin.class.getName()); if (sref == null) { throw new IllegalStateException("The configuration admin service cannot be found."); } try { ConfigurationAdmin ca = (ConfigurationAdmin) bundleContext.getService(sref); if (ca == null) { throw new IllegalStateException("The configuration admin service cannot be found."); } Configuration config = ca.getConfiguration(pid, null); config.update(new Hashtable<String, String>(data)); } catch (IOException ioe) { throw new RuntimeException(ioe); } finally { bundleContext.ungetService(sref); } } }
private SessionFactory getSessionFactory() { if ( sf == null ) { Bundle thisBundle = FrameworkUtil.getBundle( HibernateUtil.class ); BundleContext context = thisBundle.getBundleContext(); ServiceReference sr = context.getServiceReference( SessionFactory.class.getName() ); sf = ( SessionFactory ) context.getService( sr ); } return sf; } }
@Before public void setUp() { initMocks(this); when(context.getServiceReference(PluginHealthService.class)).thenReturn(pluginHealthServiceReference); when(context.getServiceReference(LoggingService.class)).thenReturn(loggingServiceReference); when(context.getService(pluginHealthServiceReference)).thenReturn(pluginHealthService); when(context.getService(loggingServiceReference)).thenReturn(loggingService); when(context.getBundle()).thenReturn(bundle); when(bundle.getSymbolicName()).thenReturn(PLUGIN_ID); when(bundle.findEntries("/", "*.class", true)).thenReturn(emptyListOfClassesInBundle); activator = new DefaultGoPluginActivator(); }
public void decorate(Map<String, Object> result) throws Exception { try { ServiceReference<ConfigurationAdmin> cmRef = bundleContext.getServiceReference(ConfigurationAdmin.class); ServiceReference<JMXSecurityMBean> jmxSecRef = bundleContext.getServiceReference(JMXSecurityMBean.class); if (cmRef == null || jmxSecRef == null) { return; ConfigurationAdmin configAdmin = bundleContext.getService(cmRef); JMXSecurityMBean jmxSec = bundleContext.getService(jmxSecRef); if (configAdmin == null || jmxSec == null) { return;
private EntityManagerFactory getEntityManagerFactory() { if ( emf == null ) { Bundle thisBundle = FrameworkUtil.getBundle( HibernateUtil.class ); BundleContext context = thisBundle.getBundleContext(); ServiceReference serviceReference = context.getServiceReference( PersistenceProvider.class.getName() ); PersistenceProvider persistenceProvider = ( PersistenceProvider ) context .getService( serviceReference ); emf = persistenceProvider.createEntityManagerFactory( "YourPersistenceUnitName", null ); } return emf; } }
@Test public void testServiceContributorDiscovery() throws Exception { final ServiceReference sr = bundleContext.getServiceReference( SessionFactory.class.getName() ); final SessionFactoryImplementor sfi = (SessionFactoryImplementor) bundleContext.getService( sr ); assertNotNull( sfi.getServiceRegistry().getService( SomeService.class ) ); }
@Test public void testJpa() throws Exception { final ServiceReference serviceReference = bundleContext.getServiceReference( PersistenceProvider.class.getName() ); final PersistenceProvider persistenceProvider = (PersistenceProvider) bundleContext.getService( serviceReference ); final EntityManagerFactory emf = persistenceProvider.createEntityManagerFactory( "hibernate-osgi-test", null );
@Test public void testJpaEnvers() throws Exception { final ServiceReference serviceReference = bundleContext.getServiceReference( PersistenceProvider.class.getName() ); final PersistenceProvider persistenceProvider = (PersistenceProvider) bundleContext.getService( serviceReference ); final EntityManagerFactory emf = persistenceProvider.createEntityManagerFactory( "hibernate-osgi-test", null ); final Integer adpId; EntityManager em = emf.createEntityManager(); em.getTransaction().begin(); AuditedDataPoint adp = new AuditedDataPoint( "Chris" ); em.persist( adp ); em.getTransaction().commit(); adpId = adp.getId(); em.close(); em = emf.createEntityManager(); em.getTransaction().begin(); adp = em.find( AuditedDataPoint.class, adpId ); adp.setName( "Chris2" ); em.getTransaction().commit(); em.close(); em = emf.createEntityManager(); AuditReader ar = AuditReaderFactory.get( em ); assertEquals( 2, ar.getRevisions( AuditedDataPoint.class, adpId ).size() ); AuditedDataPoint rev1 = ar.find( AuditedDataPoint.class, adpId, 1 ); AuditedDataPoint rev2 = ar.find( AuditedDataPoint.class, adpId, 2 ); assertEquals( new AuditedDataPoint( adpId, "Chris" ), rev1 ); assertEquals( new AuditedDataPoint( adpId, "Chris2" ), rev2 ); em.close(); }
@Test public void testExtensionPoints() throws Exception { final ServiceReference sr = bundleContext.getServiceReference( SessionFactory.class.getName() ); final SessionFactoryImplementor sfi = (SessionFactoryImplementor) bundleContext.getService( sr ); assertTrue( TestIntegrator.passed() ); Class impl = sfi.getServiceRegistry().getService( StrategySelector.class ).selectStrategyImplementor( Calendar.class, TestStrategyRegistrationProvider.GREGORIAN ); assertNotNull( impl ); BasicType basicType = sfi.getTypeResolver().basic( TestTypeContributor.NAME ); assertNotNull( basicType ); }
@Test public void testNativeEnvers() throws Exception { final ServiceReference sr = bundleContext.getServiceReference( SessionFactory.class.getName() ); final SessionFactory sf = ( SessionFactory )bundleContext.getService( sr ); final Integer adpId; Session s = sf.openSession(); s.getTransaction().begin(); AuditedDataPoint adp = new AuditedDataPoint( "Chris" ); s.persist( adp ); s.getTransaction().commit(); adpId = adp.getId(); s.close(); s = sf.openSession(); s.getTransaction().begin(); adp = s.get( AuditedDataPoint.class, adpId ); adp.setName( "Chris2" ); s.getTransaction().commit(); s.close(); s = sf.openSession(); AuditReader ar = AuditReaderFactory.get( s ); assertEquals( 2, ar.getRevisions( AuditedDataPoint.class, adpId ).size() ); AuditedDataPoint rev1 = ar.find( AuditedDataPoint.class, adpId, 1 ); AuditedDataPoint rev2 = ar.find( AuditedDataPoint.class, adpId, 2 ); assertEquals( new AuditedDataPoint( adpId, "Chris" ), rev1 ); assertEquals( new AuditedDataPoint( adpId, "Chris2" ), rev2 ); s.close(); }
@Test public void testNative() throws Exception { final ServiceReference sr = bundleContext.getServiceReference( SessionFactory.class.getName() ); final SessionFactory sf = (SessionFactory) bundleContext.getService( sr );
public PlatformAdmin getPlatformAdmin() { if (context == null) return null; ServiceReference<PlatformAdmin> platformAdminReference = context.getServiceReference(PlatformAdmin.class); if (platformAdminReference == null) return null; return context.getService(platformAdminReference); }
@SuppressWarnings("unchecked") public ResourceBundleTracker(BundleContext bundleContext, LocaleProvider localeProvider) { super(bundleContext, Bundle.RESOLVED | Bundle.STARTING | Bundle.STOPPING | Bundle.ACTIVE, null); this.localeProvider = localeProvider; pkgAdmin = (PackageAdmin) bundleContext .getService(bundleContext.getServiceReference(PackageAdmin.class.getName())); this.bundleLanguageResourceMap = new LinkedHashMap<Bundle, LanguageResourceBundleManager>(); }
/** * This method is used to obtain access to <code>DmtAdmin</code>, which * enables applications to manipulate the Device Management Tree. * * @return a DmtAdmin service object */ public static DmtAdmin getDmtAdmin() { if(context == null) throw new IllegalStateException("Cannot retrieve Dmt Admin " + "service, implementation bundle not started yet."); ServiceReference dmtAdminRef = context.getServiceReference(DmtAdmin.class.getName()); if(dmtAdminRef == null) throw new IllegalStateException("Dmt Admin service not found in " + "service registry."); DmtAdmin dmtAdmin = (DmtAdmin) context.getService(dmtAdminRef); if(dmtAdmin == null) throw new IllegalStateException("Dmt Admin service not found in " + "service registry."); return dmtAdmin; }
/** * Log error to a logging service (if available), otherwise log to std error * * @param pBundleContext bundle context to lookup LogService * @param pMessage message to log * @param pThrowable an exception to log */ public static void logError(BundleContext pBundleContext, String pMessage, Throwable pThrowable) { final ServiceReference lRef = pBundleContext.getServiceReference(LogService.class.getName()); if (lRef != null) { try { final LogService logService = (LogService) pBundleContext.getService(lRef); if (logService != null) { logService.log(LogService.LOG_ERROR, pMessage, pThrowable); return; } } finally { pBundleContext.ungetService(lRef); } } System.err.println("Jolokia-Error: " + pMessage + " : " + pThrowable.getMessage()); } }