Search in sources :

Example 1 with ITransportFactory

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;
}
Also used : TransportFactory(org.eclipse.epp.internal.mpc.core.util.TransportFactory) ITransportFactory(org.eclipse.epp.mpc.core.service.ITransportFactory) HttpClientTransportFactory(org.eclipse.epp.internal.mpc.core.transport.httpclient.HttpClientTransportFactory) FallbackTransportFactory(org.eclipse.epp.internal.mpc.core.util.FallbackTransportFactory) ITransportFactory(org.eclipse.epp.mpc.core.service.ITransportFactory) BundleContext(org.osgi.framework.BundleContext)

Example 2 with ITransportFactory

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()));
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ArrayList(java.util.ArrayList) ITransportFactory(org.eclipse.epp.mpc.core.service.ITransportFactory) BundleContext(org.osgi.framework.BundleContext) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 3 with ITransportFactory

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();
    }
}
Also used : TransportFactory(org.eclipse.epp.internal.mpc.core.util.TransportFactory) ITransportFactory(org.eclipse.epp.mpc.core.service.ITransportFactory) HttpClientTransportFactory(org.eclipse.epp.internal.mpc.core.transport.httpclient.HttpClientTransportFactory) FallbackTransportFactory(org.eclipse.epp.internal.mpc.core.util.FallbackTransportFactory) LinkedHashSet(java.util.LinkedHashSet) ArrayList(java.util.ArrayList) ITransportFactory(org.eclipse.epp.mpc.core.service.ITransportFactory) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 4 with ITransportFactory

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;
}
Also used : ITransportFactory(org.eclipse.epp.mpc.core.service.ITransportFactory)

Example 5 with ITransportFactory

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;
}
Also used : InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) ITransportFactory(org.eclipse.epp.mpc.core.service.ITransportFactory) BundleContext(org.osgi.framework.BundleContext) ServiceReference(org.osgi.framework.ServiceReference)

Aggregations

ITransportFactory (org.eclipse.epp.mpc.core.service.ITransportFactory)11 BundleContext (org.osgi.framework.BundleContext)5 HttpClientTransportFactory (org.eclipse.epp.internal.mpc.core.transport.httpclient.HttpClientTransportFactory)4 FallbackTransportFactory (org.eclipse.epp.internal.mpc.core.util.FallbackTransportFactory)4 ServiceReference (org.osgi.framework.ServiceReference)4 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 Hashtable (java.util.Hashtable)2 LinkedHashSet (java.util.LinkedHashSet)2 IStatus (org.eclipse.core.runtime.IStatus)2 HttpClientTransport (org.eclipse.epp.internal.mpc.core.transport.httpclient.HttpClientTransport)2 TransportFactory (org.eclipse.epp.internal.mpc.core.util.TransportFactory)2 ITransport (org.eclipse.epp.mpc.core.service.ITransport)2 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1