use of org.eclipse.epp.mpc.core.service.ITransportFactory in project epp.mpc by eclipse.
the class TransportFactoryTest method getTransportServiceName.
private static String getTransportServiceName() {
BundleContext bundleContext = FrameworkUtil.getBundle(TransportFactory.class).getBundleContext();
ServiceReference<ITransportFactory> transportServiceReference = TransportFactory.getTransportServiceReference(bundleContext);
if (transportServiceReference != null) {
String transportServiceName = (String) transportServiceReference.getProperty(ComponentConstants.COMPONENT_NAME);
bundleContext.ungetService(transportServiceReference);
return transportServiceName;
}
return null;
}
use of org.eclipse.epp.mpc.core.service.ITransportFactory in project epp.mpc by eclipse.
the class TransportFactoryTest method testRegisteredFactories.
@Test
public void testRegisteredFactories() throws Exception {
BundleContext context = MarketplaceClientCorePlugin.getBundle().getBundleContext();
Collection<ServiceReference<ITransportFactory>> serviceReferences = context.getServiceReferences(ITransportFactory.class, null);
assertFalse(serviceReferences.isEmpty());
List<Class<?>> registeredFactoryTypes = new ArrayList<Class<?>>();
Set<ITransportFactory> registeredFactories = new LinkedHashSet<ITransportFactory>();
for (ServiceReference<ITransportFactory> serviceReference : serviceReferences) {
try {
ITransportFactory service = context.getService(serviceReference);
assertNotNull(service);
assertThat(registeredFactoryTypes, not(hasItem(service.getClass())));
assertThat(registeredFactories, not(hasItem(service)));
registeredFactoryTypes.add(service.getClass());
registeredFactories.add(service);
} finally {
context.ungetService(serviceReference);
}
}
List<ITransportFactory> legacyFactories = TransportFactory.listAvailableFactories();
for (ITransportFactory factory : legacyFactories) {
assertThat(registeredFactoryTypes, CoreMatchers.hasItem(factory.getClass()));
}
}
use of org.eclipse.epp.mpc.core.service.ITransportFactory in project epp.mpc by eclipse.
the class TransportFactoryTest method testLegacyServices.
@Test
public void testLegacyServices() {
BundleContext context = FrameworkUtil.getBundle(ITransportFactory.class).getBundleContext();
assertNotNull(context);
TransportFactory.LegacyTransportFactoryTracker legacyTransportFactoryTracker = new TransportFactory.LegacyTransportFactoryTracker(context);
legacyTransportFactoryTracker.open();
try {
Object[] services = legacyTransportFactoryTracker.getServices();
List<Class<?>> registeredFactoryTypes = new ArrayList<Class<?>>();
Set<Object> registeredFactories = new LinkedHashSet<Object>();
for (Object service : services) {
assertNotNull(service);
assertThat(service, instanceOf(TransportFactory.class));
assertThat(registeredFactoryTypes, not(hasItem(service.getClass())));
assertThat(registeredFactories, not(hasItem(service)));
registeredFactoryTypes.add(service.getClass());
registeredFactories.add(service);
}
List<ITransportFactory> legacyFactories = TransportFactory.listAvailableFactories();
for (ITransportFactory factory : legacyFactories) {
assertThat(registeredFactoryTypes, CoreMatchers.hasItem(factory.getClass()));
}
} finally {
legacyTransportFactoryTracker.close();
}
}
use of org.eclipse.epp.mpc.core.service.ITransportFactory in project epp.mpc by eclipse.
the class MappedTransportFactory method get.
public static synchronized MappedTransportFactory get() {
ITransportFactory transportFactory = ServiceHelper.getTransportFactory();
if (transportFactory instanceof MappedTransportFactory) {
return (MappedTransportFactory) transportFactory;
}
MappedTransportFactory factory = new MappedTransportFactory();
factory.register();
return factory;
}
use of org.eclipse.epp.mpc.core.service.ITransportFactory in project epp.mpc by eclipse.
the class FallbackTransportFactory method getFallbackFactory.
public ITransportFactory getFallbackFactory() {
ITransportFactory delegateFactory = this.secondaryFactory;
if (delegateFactory == null) {
BundleContext bundleContext = FrameworkUtil.getBundle(getClass()).getBundleContext();
try {
String disabledTransportsFilter = TransportFactory.computeDisabledTransportsFilter();
Collection<ServiceReference<ITransportFactory>> serviceReferences = bundleContext.getServiceReferences(ITransportFactory.class, // $NON-NLS-1$
"".equals(disabledTransportsFilter) ? null : disabledTransportsFilter);
if (!serviceReferences.isEmpty()) {
for (ServiceReference<ITransportFactory> serviceReference : serviceReferences) {
ITransportFactory service = bundleContext.getService(serviceReference);
if (service != this && service != primaryFactory && !// $NON-NLS-1$
"org.eclipse.epp.mpc.tests.service.MappedTransportFactory".equals(service.getClass().getName())) {
delegateFactory = service;
break;
} else {
bundleContext.ungetService(serviceReference);
}
}
}
} catch (InvalidSyntaxException e) {
// impossible
}
}
return delegateFactory;
}
Aggregations