Hi Vladimir,

When you add an init method which takes a map of  tow strings as the
parameter and mark that with postconstruct you can easily access the
isis.properties values.

@DomainService
public class MyDomainService
    private Map<String, String> properties

    @Programmatic
    @PostConstruct
    public void init(final Map<String,String> properties) {
        this.properties = properties;
    }

    ....

}

On Wed, Sep 24, 2014 at 9:33 AM, Vladimir Nišević <[email protected]>
wrote:

> Hi Dan, yes I saw the Settings add-on.  Bur I need to use the
> configuration parameter when instantiating my domain service (Isis
> biotstrap?).
>
> As far I understand,the way would be to use ApplicationSettingsService (
> https://github.com/isisaddons/isis-module-settings/blob/master/dom/src/main/java/org/isisaddons/module/settings/dom/ApplicationSettingsService.java
> )
>
> What I don't undersand is the order
> how Isis creates the domain services. Can I use the AppSettigsService in
> this early Isis bootstrapping phase?
>
> Hope I explained this clearly...
>
> BR,Vladimir
>
>
> > Am 23.09.2014 um 15:53 schrieb Dan Haywood <[email protected]
> >:
> >
> > Hi Vladimir,
> >
> > Not quite sure how the second doc helped you, but perhaps I misunderstood
> > your original question.
> >
> > But at any rate, if you want to do is to store application-settings, then
> > check out the "Settings module add-on" [1]...  that'll let you store such
> > stuff in the database.
> >
> > Other add-ons listed at [2]
> >
> > Cheers
> > Dan
> >
> > [1] https://github.com/isisaddons/isis-module-settings
> > [2] http://www.isisaddons.org/
> >
> >
> >> On 23 September 2014 14:08, Vladimir Nišević <[email protected]>
> wrote:
> >>
> >> Found on my own the answer in documentation (
> >>
> >>
> https://isis.apache.org/more-advanced-topics/how-to-09-020-How-to-write-a-typical-domain-service.html
> >> )
> >>
> >>
> >> Sorry and thanks!
> >> Vladimir
> >>
> >> 2014-09-23 14:54 GMT+02:00 Vladimir Nišević <[email protected]>:
> >>
> >>> Hi guys, I have question how to deal with application specific
> >>> configuration parameters...
> >>>
> >>>
> >>> I use elasticsearch to put/get specific documents and use them in a
> >> domain
> >>> model.
> >>>
> >>> So I defined a domain service "EsClient" to access to elasticsearch - I
> >>> use service lifecycle to connect/disconnect to elasticseach.
> >>>
> >>>
> >>>
> >>> According to ((
> >> https://isis.apache.org/reference/configuration-files.html)
> >>> ) my first idea was to:
> >>>
> >>> - put the configuration parameters into isis.properites
> >>> - get the parameter value in a domain service by
> >>> container.getProperty("propertyName");
> >>>
> >>> Currently I get null value here...
> >>>
> >>> Thanks,Vladimir
> >>>
> >>>
> >>>
> >>> Here my code (relevant parts)
> >>>
> >>> ....
> >>> @Named("Elasticsearch")
> >>> @DomainService(menuOrder = "1.2")
> >>> public class EsClient {
> >>>
> >>> private static final String ES_CLUSTER_PROPERTY_NAME =
> >>> "elasticsearch.cluster";
> >>> private static final String ES_SERVER_PROPERTY_NAME =
> >>> "elasticsearch.server";
> >>> private static final String ES_SERVER_PORT_PROPERTY_NAME =
> >>> "elasticsearch.port";
> >>> ..
> >>> ...
> >>>
> >>>  @SuppressWarnings("resource")
> >>>    @PostConstruct
> >>>    @Programmatic
> >>>    public void connectToEs() {
> >>>
> >>>        final String esClusterName =
> >>> container.getProperty(ES_CLUSTER_PROPERTY_NAME);
> >>>        container.getUser()
> >>>        final String esServer =
> >>> container.getProperty(ES_SERVER_PROPERTY_NAME);
> >>>        final String esPort =
> >>> container.getProperty(ES_SERVER_PORT_PROPERTY_NAME);
> >>>
> >>>        logger.info("Using elasticsearch properties from
> >> isis.poperties:"
> >>> + " server=" + esServer + "," + " port=" + esPort + "," + " cluster=" +
> >>> esClusterName);
> >>>
> >>>        final Settings settings =
> >> ImmutableSettings.settingsBuilder().put("
> >>> cluster.name", esClusterName)
> >>>        // .put("node.name", ES_LOCAL_NODE_NAME)
> >>>                .put("client.transport.nodes_sampler_interval", "10") //
> >> 10
> >>>                                                                      //
> >>> seconds
> >>>                                                                      //
> >>> ping
> >>>                .put("client.transport.sniff", false).build();
> >>>        client = new TransportClient(settings).addTransportAddress(new
> >>> InetSocketTransportAddress(esServer, Integer.valueOf(esPort)));
> >>>
> >>>        logger.info("Connected to elasticsearch:" + "  server=" +
> >>> esServer + "," + " port=" + esPort + "," + " cluster=" +
> esClusterName);
> >>>
> >>>        // instance a json mapper
> >>>        mapper = new ObjectMapper(); // create once, reuse
> >>>
> >>>    }
> >>>
> >>>    @PreDestroy
> >>>    @Programmatic
> >>>    public void disconnectFromES() {
> >>>        node.close();
> >>>    }
> >>> ....
> >>>
> >>> // //////////////////////////////////////
> >>>    // Injected Services
> >>>    // //////////////////////////////////////
> >>>
> >>>    @javax.inject.Inject
> >>>    private DomainObjectContainer container;
> >>
>

Reply via email to