Package com.volantis.osgi.cm.factory

Examples of com.volantis.osgi.cm.factory.FactoryAssociation


            }
            pid2Association.put(pid, association);
        } else {

            // Get the factory association.
            FactoryAssociation association = getFactoryAssociation(factoryPid);

            // Add a configuration object to the factory association.
            association.addConfiguration(configuration);
        }

        // Store the configuration away, making sure that it does not clash
        // with another configuration.
        if (pid2Configuration.containsKey(pid)) {
View Full Code Here


     * @param factoryPid The factory pid.
     * @return The {@link FactoryAssociation}.
     */
    private FactoryAssociation getFactoryAssociation(String factoryPid) {

        FactoryAssociation factoryAssociation;
        Association association = (Association)
                pid2Association.get(factoryPid);
        if (association == null) {
            // No association has been registered by anyone so it is ok to
            // use, without permission.
            factoryAssociation = new FactoryAssociation(log, factoryPid);

            pid2Association.put(factoryPid, factoryAssociation);

        } else if (association instanceof FactoryAssociation) {

View Full Code Here

        // Get the instance PID and perform a sanity check to make sure that it
        // is valid.
        String pid = configuration.getPid();
        ValidationHelper.checkPID(pid);

        FactoryAssociation association = getFactoryAssociation(factoryPid);

        if (!usingAdminMethod) {
            // Check to see if the factory PID is bound to a specific
            // location that is not the current bundle.
            String boundLocation = association.getBundleLocation();
            if (boundLocation == null) {
                // Binds to first bundle that registers
                // ManagedServiceFactory with the same factory PID.
            } else if (!callingLocation.equals(boundLocation)
                    && !hasConfigurationPermission) {

                // The association has been bound to another location but
                // the caller does not have permission to modify the
                // configuration of other bundles so this must fail.
                throw new SecurityException(
                        "Bundle '" + callingLocation +
                                "' does not have permission to create " +
                                "configuration for " +
                                FrameworkConstants.SERVICE_FACTORYPID +
                                " '" + factoryPid +
                                "' which is bound to bundle '" +
                                boundLocation + "'");
            } else {
                // A factory has already been registered with the pid that
                // matches this pid so bind it to the service immediately.
                configuration.bindToLocation(boundLocation);
            }
        }

        // Add the configuration to the set managed by the association.
        association.addConfiguration(configuration);

        // Create a mapping from pid to configuration.
        pid2Configuration.put(pid, configuration);

        return configuration;
View Full Code Here

                    // discard it to prevent it becoming a memory leak.
                    pid2Association.remove(pid);
                }
            }
        } else {
            FactoryAssociation association = (FactoryAssociation)
                    pid2Association.get(factoryPid);
            if (association == null) {
                // Shouldn't happen.
            } else {
                // Remove the configuration from the association.
                association.removeConfiguration(pid);

                if (association.hasConfiguration() ||
                        association.hasTargets()) {
                    dispatcher.managedServiceFactoryConfigurationDeleted(
                            factoryPid,
                            pid, association.getConfigurationTargets());
                } else {
                    // The association is not useful so discard it.
                    pid2Association.remove(factoryPid);
                }
            }
View Full Code Here

            dispatcher.managedServiceConfigurationUpdated(
                    association.getConfigurationTargets(),
                    configuration.createSnapshot());

        } else {
            FactoryAssociation association = getFactoryAssociation(factoryPid);

            // Bind the configuration to this bundle. If the configuration is
            // already bound to a different location then ignore it.
            //
            // OSGi Specification States:
            //     If a Managed Service is registered with a PID that is already
            //     bound to another location, the normal callback to
            //     ManagedService.updated must not take place.
            //
            // Although the specification is talking about a ManagedService it
            // is assumed that the same applies to ManagedServiceFactory.
            String bundleLocation = association.getBundleLocation();
            if (bundleLocation != null) {
                if (!configuration.bindToLocation(bundleLocation)) {
                    return;
                }
            }

            dispatcher.managedServiceFactoryConfigurationUpdated(
                    factoryPid, association.getConfigurationTargets(),
                    configuration.createSnapshot());
        }
    }
View Full Code Here

     * @param reference  The service reference.
     */
    private void factoryRegisteredInternal(
            String factoryPid, ServiceReference reference) {

        FactoryAssociation association = getFactoryAssociation(factoryPid);

        // Attempt to bind the target to the association if it cannot then
        // return immediately.
        if (!bindTargetToAssociation(association, reference)) {
            return;
        }

        ConfigurationSnapshot[] snapshots =
                association.createSnapshots(reference);

        dispatcher.managedServiceFactoryRegistered(
                factoryPid, reference, snapshots);
    }
View Full Code Here

        String newPid = getServicePID(reference);

        // The properties associated with the ManagedService have changed
        // so that could include the pid. Get the association that was used
        // for this reference.
        FactoryAssociation association =
                (FactoryAssociation) reference2Association.get(reference);
        if (association == null) {
            // When this service registered there was a problem attempting
            // to create an association so just return. It was probably
            // because it used a pid that it was already bound to some
            // other bundle. Just return silently as any warnings will
            // already have been logged.
            return;
        }

        String currentPid = association.getServicePid();

        // If the pid hasn't changed then this has no impact so the
        // service stays bound.
        if (currentPid.equals(newPid)) {
            return;
View Full Code Here

    // Javadoc inherited.
    public void factoryUnregistering(ServiceReference reference) {

        // Get the association for this service.
        FactoryAssociation association = (FactoryAssociation)
                reference2Association.get(reference);
        if (association == null) {
            // When this service registered there was a problem attempting
            // to create an association so just return. It was probably because
            // it used a pid that it was already bound to some other bundle.
View Full Code Here

TOP

Related Classes of com.volantis.osgi.cm.factory.FactoryAssociation

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.