Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

Gliffy Diagram
borderfalse
sizeL
namesingleton
pageFELIX:Apache Felix Dependency Manager - OSGi Design Patterns
pageid9374247aligncenter
spaceFELIX

Code Example

Code Block
public class Activator extends DependencyActivatorBase {
    public void init(BundleContext context, DependencyManager manager) throws Exception {
        manager.add(createComponent()
            .setInterface(UserStore.class, new Properties() {{ put("store.id", "users"); }})
            .setImplementation(UserStoreImpl.class)
            .add(createServiceDependency()
                .setService(Store.class)
                .setRequired(true)
            )
            .add(createServiceDependency()
                .setService(LogService.class)
                .setRequired(false)
            )
        );
    }
    
    public void destroy(BundleContext context, DependencyManager manager) throws Exception {}
}

...

Gliffy Diagram
borderfalse
sizeL
nameaspect
pageFELIX:Apache Felix Dependency Manager - OSGi Design Patterns
pageid9374247aligncenter
spaceFELIX

Code Example

Code Block
public class Activator extends DependencyActivatorBase {
    public void init(BundleContext context, DependencyManager manager) throws Exception {
        manager.add(createAspectService(Manageable.class, "(monitor=true)", 50)
            .setImplementation(ManageableMonitor.class)
        );
    }
    
    public void destroy(BundleContext context, DependencyManager manager) throws Exception {}
}

public interface Manageable {
    public void setProperty(String key, String value);
}

public class ManageableMonitor implements Manageable {
    private volatile Manageable m_manageable;

    public void setProperty(String key, String value) {
        System.out.println("Someone set " + key + " to " + value);
        m_manageable.setProperty(key, value);
    }
}

...

Gliffy Diagram
borderfalse
sizeL
nameadapter
pageFELIX:Apache Felix Dependency Manager - OSGi Design Patterns
pageid9374247aligncenter
spaceFELIX

Code Example

Code Block
public class Activator extends DependencyActivatorBase {
    public void init(BundleContext context, DependencyManager manager) throws Exception {
        manager.add(createAdapterService(Manageable.class, "(publish=servlet)")
            .setInterface(HttpServlet.class.getName(), null)
            .setImplementation(ManageableServlet.class)
        );
    }
    
    public void destroy(BundleContext context, DependencyManager manager) throws Exception {}
}

public interface Manageable {
    public void setProperty(String key, String value);
}

public class ManageableServlet implements HttpServlet {
    private volatile Manageable m_manageable;

    public void doPost(HttpRequest req, HttpResponse response) {
        String key = req.getProperty("key");
        String value = req.getProperty("value");
        m_manageable.setProperty(key, value);
    }
}

...

Gliffy Diagram
borderfalse
sizeL
nameresource-adapter
pageFELIX:Apache Felix Dependency Manager - OSGi Design Patterns
pageid9374247aligncenter
spaceFELIX

Temporal Dependency

...