none
Is it possible to modify an output adapter configuration at runtime?

    问题

  • Hello,

    I have a mail output adapter wich takes some configuration parameters ( a config class with target mail, port, smtp host...). When i initialize the output adapter and create streams, it works fine: the output adapter send an email to the target specified into the config class. But i would like to change the target during runtime so the adapter can send the email to an other person. But once the output adapter is configured and has started, i cannot see any way to modify it. Is this possible or should i recreate a new adapter with a complete stream procedure?

    Thank you for your help,


    2012年2月23日 18:35

答案

  • What is it exactly that you are trying to change? You won't be able to change the fields in the payload, just some of the settings associated with it. The fields in the payload are tied to the query that the adapter is serving so unless you change the query, you can't change the fields. You could, however, change things like the event frequency, etc.

    Remember: There's no problem that can't be solved with another layer of abstraction. You'll want to abstract the settings class.

    Here is a way that you can do it:

    1. Add a name to uniquely associate the adapter/settings combination. You could use the name of the query, a GUID, or something else entirely, depending on what you want to do.
    2. For your adapter settings, keep an application-level list of the settings classes. For example, a static singleton Dictionary.
    3. In your adapter, you pass in the adapter configuration class, which includes the name of the adapter/settings combination. Or you could just pass in a string that identifies the adapter/settings combination. Either would actually work. You could add the configuration class to the static dictionary at this time or before passing it in when you create the query. (not CreateInputAdapter).
    4. Abstract access to the settings class in the adapter itself to reference the singleton dictionary rather than storing an instance of it. You can't simple add the configuration to the list and then pass the reference as StreamInsight serializes the configuration class before the adapter actually gets it so it would be de-referenced.
    5. Make changes to the shared instance in the static singleton dictionary. Since the adapter now has abstracted access to the settings class to use the singleton dictionary, this will now be the same instance.

    Note that you cannot share instances of a concrete adapter between two different queries, so don't be tempted to get tricky and share instances via the AdapterFactory. It won't work ... only the last-created query will actually get the events.

    Caveat: I've not actually implemented this but this is how I would attack the problem should it be required to do something like that.


    DevBiker (aka J Sawyer)
    My Blog
    My Bike - Concours 14


    If I answered your question, please mark as answer.
    If my post was helpful, please mark as helpful.

    2012年3月5日 16:24
    版主

全部回复

  • Since your adapter is running code, it is possible. You would, however, have to implement that as a part of your adapter. There is no direct way to do it but something that you would have to implement as extra functionality.

    DevBiker (aka J Sawyer)
    My Blog
    My Bike - Concours 14


    If I answered your question, please mark as answer.
    If my post was helpful, please mark as helpful.

    2012年2月23日 19:11
    版主
  • Well, using the DataGenerator from the StreamInsight samples, i tried to implement a specific function into my adapter but how can i access it from outside?

    When i create my adapter, i use:

    InputAdapter iAdapter = application.CreateInputAdapter<GeneratorFactory>("InputDataGenerator", "generates new data periodically");

    And i need to have a GeneratorAdapterPoint to call the new function modifyPayloadDescription() i implemented in it.But i can't cast iAdapter into a GeneratorAdapterPoint.


    2012年3月5日 9:18
  • What is it exactly that you are trying to change? You won't be able to change the fields in the payload, just some of the settings associated with it. The fields in the payload are tied to the query that the adapter is serving so unless you change the query, you can't change the fields. You could, however, change things like the event frequency, etc.

    Remember: There's no problem that can't be solved with another layer of abstraction. You'll want to abstract the settings class.

    Here is a way that you can do it:

    1. Add a name to uniquely associate the adapter/settings combination. You could use the name of the query, a GUID, or something else entirely, depending on what you want to do.
    2. For your adapter settings, keep an application-level list of the settings classes. For example, a static singleton Dictionary.
    3. In your adapter, you pass in the adapter configuration class, which includes the name of the adapter/settings combination. Or you could just pass in a string that identifies the adapter/settings combination. Either would actually work. You could add the configuration class to the static dictionary at this time or before passing it in when you create the query. (not CreateInputAdapter).
    4. Abstract access to the settings class in the adapter itself to reference the singleton dictionary rather than storing an instance of it. You can't simple add the configuration to the list and then pass the reference as StreamInsight serializes the configuration class before the adapter actually gets it so it would be de-referenced.
    5. Make changes to the shared instance in the static singleton dictionary. Since the adapter now has abstracted access to the settings class to use the singleton dictionary, this will now be the same instance.

    Note that you cannot share instances of a concrete adapter between two different queries, so don't be tempted to get tricky and share instances via the AdapterFactory. It won't work ... only the last-created query will actually get the events.

    Caveat: I've not actually implemented this but this is how I would attack the problem should it be required to do something like that.


    DevBiker (aka J Sawyer)
    My Blog
    My Bike - Concours 14


    If I answered your question, please mark as answer.
    If my post was helpful, please mark as helpful.

    2012年3月5日 16:24
    版主
  • Hello,

    Well, I tried the singleton method and it usually works pretty well. I also have noticed that i cannot share instances of a concrete "output" adapter, as i tested it and it did'nt work. But you can share an "input" adapter.

    I also tried something which went wrong when i was working on this feature:

    Before i changed for the singleton version, I used a member in my configuration class which was an EntityObject from the entity Framework. First, the serialization of the configuration class took a lot of time (like 10s to serialize and then bind the queries!). Then, the query didn't appear into StreamInsight's flow debuger, but it was working anymay.


    2012年3月15日 16:06
  • For the configuation class performance (or lack thereof), what does it look like? Is it a simple, relatively flat object or do you have nested collections? Also, are you using DataContract and DataMembers? If not, you really should ... I've seen the Xml Serializer have issues occassionally if you don't.

    On another thought, it should also be possible to pass in a string that represents the key to the configuration class in the singleton collection. Remember too that you'll need to properly synchronize read/writes to the object as any writes to the config will be on separate threads from the adapter actually reading the config. This can get potentially even more interesting if you are setting multiple properties on the config - you could get inconsistent state in the output adapter.


    DevBiker (aka J Sawyer)
    My Blog
    My Bike - Concours 14


    If I answered your question, please mark as answer.
    If my post was helpful, please mark as helpful.

    2012年3月16日 16:04
    版主