Package org.osgi.service.remoteserviceadmin

Examples of org.osgi.service.remoteserviceadmin.ImportRegistration


        EasyMock.expect(bc.registerService((String)EasyMock.anyObject(), EasyMock.anyObject(), (Dictionary)EasyMock.anyObject())).andReturn(sreg).anyTimes();
        
       
        EndpointDescription epd = c.createMock(EndpointDescription.class);
        RemoteServiceAdmin rsa  = c.createMock(RemoteServiceAdmin.class);
        final ImportRegistration ireg = c.createMock(ImportRegistration.class);
        ImportReference iref = c.createMock(ImportReference.class);
       
        EasyMock.expect(rsa.importService(EasyMock.eq(epd))).andAnswer(new IAnswer<ImportRegistration>( ) {

            public ImportRegistration answer() throws Throwable {
                sema.release();
                return ireg;
            }
        }).once();
        EasyMock.expect(ireg.getImportReference()).andReturn(iref).anyTimes();
        EasyMock.expect(iref.getImportedEndpoint()).andReturn(epd).anyTimes();
        c.replay();
       
       
        RemoteServiceAdminList rsaList = new RemoteServiceAdminList(bc);
View Full Code Here


        if (irs.size() > 0) { // remove old services that are not available anymore
            List<EndpointDescription> ips = importPossibilities.get(filter);
            Iterator<ImportRegistration> it = irs.iterator();
            while (it.hasNext()) {
                ImportRegistration ir = it.next();
                EndpointDescription ep = ir.getImportReference().getImportedEndpoint();

                // if service is already imported, check if endpoint is still in the list of
                // possible imports
                if ((ips != null && !ips.contains(ep)) || ips == null) {
                    // unexport service
                    ir.close();
                    it.remove();
                }

            }
        }

        for (EndpointDescription epd : importPossibilities.get(filter)) {
            if (!irs.contains(epd)) {
                // service not imported yet -> import it now
                ImportRegistration ir = importService(epd);
                if (ir != null) {
                    // import was successful
                    irs.add(ir);
                }
            }
View Full Code Here

            List<ImportRegistration> irs = importedServices.get(filter);
            List<EndpointDescription> ips = importPossibilities.get(filter);

            Iterator<ImportRegistration> it = irs.iterator();
            while (it.hasNext()) {
                ImportRegistration ir = it.next();
                EndpointDescription ep = ir.getImportReference().getImportedEndpoint();

                // if service is already imported, check if endpoint is still in the list of
                // possible imports
                if ((ips != null && !ips.contains(ep)) || ips == null) {
                    // unexport service
                    ir.close();
                    it.remove();
                }
            }

            if (irs.size() == 0) {
                // if there are other import possibilities available, try to import them...
                if (ips != null && ips.size() > 0) {
                    triggerImport(filter);
                }
            }

            // TODO but optional: if the service is already imported and the endpoint is still
            // in the list
            // of possible imports check if a "better" endpoint is now in the list ?

        } else {
            // if the service is not yet imported, try ...
            if (importPossibilities.get(filter).size() > 0) {
                for (EndpointDescription ep : importPossibilities.get(filter)) {
                    ImportRegistration ir = importService(ep);
                    if (ir != null) {
                        // import was successful
                        List<ImportRegistration> irs = importedServices.get(filter);
                        if (irs == null) {
                            irs = new ArrayList<ImportRegistration>(1);
View Full Code Here

    }

    private ImportRegistration importService(EndpointDescription ep) {
        synchronized (remoteServiceAdminList) {
            for (RemoteServiceAdmin rsa : remoteServiceAdminList) {
                ImportRegistration ir = rsa.importService(ep);
                if (ir != null && ir.getException() == null) {
                    // successful
                    LOG.fine("service impoort was successful: " + ir);
                    return ir;
                } else {
                    // failed -> next RSA
View Full Code Here

                if (closed)
                    return null;

                synchronized (importedServices) {
                    ImportRegistration ir = rsaCore.importService(epd);
                    if (ir != null)
                        importedServices.add(ir);
                    return ir;
                }
            }
View Full Code Here

        assertEquals(0, rsaCore.getImportedEndpoints().size());

        p.put(RemoteConstants.SERVICE_IMPORTED_CONFIGS, "org.apache.cxf.ws");
        endpoint = new EndpointDescription(p);

        ImportRegistration ireg = rsaCore.importService(endpoint);
        assertNotNull(ireg);

        assertEquals(1, rsaCore.getImportedEndpoints().size());

        // lets import the same endpoint once more -> should get a copy of the ImportRegistration
        ImportRegistration ireg2 = rsaCore.importService(endpoint);
        assertNotNull(ireg2);
        assertEquals(2,rsaCore.getImportedEndpoints().size());

        assertEquals(ireg, (rsaCore.getImportedEndpoints().toArray())[0]);

        assertEquals(ireg.getImportReference().getImportedEndpoint(), ireg2.getImportReference()
            .getImportedEndpoint());

        // remove the registration ....

        // first call shouldn't remove the import ...
        ireg2.close();
        assertEquals(1, rsaCore.getImportedEndpoints().size());

        // second call should really close and remove the import ...
        ireg.close();
        assertEquals(0, rsaCore.getImportedEndpoints().size());
View Full Code Here

            EndpointDescription description = new EndpointDescription(props);

            if (admins != null) {
                for (Object ra : admins) {
                    RemoteServiceAdmin remoteAdmin = (RemoteServiceAdmin)ra;
                    ImportRegistration importRegistration = remoteAdmin.importService(description);
                    if (importRegistration != null) {
                        importedServices.putValue(new ImportKey(description, listener), importRegistration);
                    }
                }
            }
View Full Code Here

        // Call remote admin to unimport the service
        Collection<ImportRegistration> importRegistrations =
            importedServices.get(new ImportKey(endpoint, listenerInfo));
        if (importRegistrations != null) {
            for (Iterator<ImportRegistration> i = importRegistrations.iterator(); i.hasNext();) {
                ImportRegistration imported = i.next();
                imported.close();
                i.remove();
            }
        }
    }
View Full Code Here

    /**
     * @see org.osgi.remoteserviceadmin.RemoteServiceAdmin#importService(org.apache.tuscany.sca.dosgi.discovery.EndpointDescription)
     */
    public ImportRegistration importService(EndpointDescription endpoint) {
        Bundle bundle = (Bundle)endpoint.getProperties().get(Bundle.class.getName());
        ImportRegistration importReg = importer.importService(bundle, endpoint);
        if (importReg != null) {
            fireImportEvents(bundle, importReg);
            importRegistrations.add(importReg);
        }
        return importReg;
View Full Code Here

    /**
     * @see org.osgi.remoteserviceadmin.RemoteServiceAdmin#importService(org.apache.tuscany.sca.dosgi.discovery.EndpointDescription)
     */
    public ImportRegistration importService(EndpointDescription endpoint) {
        Bundle bundle = (Bundle)endpoint.getProperties().get(Bundle.class.getName());
        ImportRegistration importReg = importer.importService(bundle, endpoint);
        if (importReg != null) {
            fireImportEvents(bundle, importReg);
            importRegistrations.add(importReg);
        }
        return importReg;
View Full Code Here

TOP

Related Classes of org.osgi.service.remoteserviceadmin.ImportRegistration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.