James Carr
James Carr

Reputation: 807

Java OSGi Centralised Network Configuration

I'm looking to create an app based on the OSGi model. One of the elements of this will be network access (http and obr initially)

I am looking for a way of centralising the network config (proxying, encryption, etc) perhaps to a single bundle that the rest of the app can call into.

Has anybody done this/got ideas?

Thanks

Upvotes: 2

Views: 253

Answers (1)

Pavol Juhos
Pavol Juhos

Reputation: 1882

In that case one possibility would be to create an OSGi service or a set of services (possibly encapsulated in a separate bundle) that would provide all the required network access methods. The service(s) themselves could be configured through Configuration Admin Service that is part of OSGi Service Compendium.

Some of the methods provided by the service(s) can actually be factory methods for creating pre-configured network access objects like java.net.URLConnection or java.net.Socket. Example:

public interface NetworkService {
    public Socket createSocket();
}

class NetworkServiceImpl implements NetworkService {
    static final Proxy DEFAULT_PROXY = new Proxy(...);

    public Socket createSocket() {
        Socket s = new Socket(DEFAULT_PROXY);
        s.setReceiveBufferSize(4096);
        return s;
    } 
}

Upvotes: 4

Related Questions