Lets imagine demo situation that we have such simple structure
struct service
{
std::string name
std::set<std::string> depends_on_service_name;
};
We have some raw data (text file, io stream or what ewer) coming into our parser that turns it into service struct instances and puts them into std::map<service> services we need a way to chack if all map items have all there depends_on_service_name resolved (meaning there shall be services[item].name in map for each service[other_item].depends_on_service_name). Is there any standart way to check for such things in boost of manual for_each is the way to go each time parser appends new item(s) into map?
The "way to go" here is to solve this problem during input verification and abstraction. You are representing a directed (probably acyclic) graph with the service map, and you should represent it as such (e.g. using Boost.Graph) instead of rolling your own graph structure with sets and maps. While you are building this explicit graph structure, missing services will naturally be discovered.
Related
There's a pattern I haven't figured out for Component yet:
I have some "live" configuration that requires disk IO (a component) on system-start, and has a dependency on a map of static config (.edn), and after this "live" configuration is instantiated, it won't change or side-effect anything anymore.
For ex: I need to set this up once, and it depends on static config:
(buddy.core.backends/jws
{:secret (buddy.core.keys/public-key
path-to-public-key-from-static-config)})
I would then reuse that backend ad-infinitum, (ex: in buddy.auth.middleware/wrap-authentication), and it doesn't change, nor side-effect.
Possible Solutions
I could make a component that stores this backend at system-start. But this gives up generality, because when I want to add similar "live config", it would have to be explicitly written into the component, and that gives up the spirit of generality that I think Component champions (eg Duct says components define side-effects, and create boundaries to access them)
I could pass a generic component a map of keys - [fn & args] and the fn+args get evaluated and stored in the component. But this feels like it offloads computation to my configuration .edn, and is an anti-pattern. For example:
(private-key priv-path-from-static
(slurp :password-path-from-static))
Should I encode the notion of slurping in my .edn config? I don't want to offload computation to a config file...
The backend and keys can be instantiated on a per-need basis within each component that requires them. IMO, that's too much of computing the exact same thing, when I'd rather it be stored in memory once.
I could have an atom component that holds a map of these "live" config objects, but then they get destructively added in, and my code has lost it's declarative nature.
TL;DR
What's the best way to create configuration at system-start, possibly needing dependencies, and then becoming available to other components as a component, while not giving up the generality which components should have?
In an ideal world, I think the component itself should describe what type of configuration data it needs. (This could be done with a protocol extending the component in question.). When the config component is started, it should look at all other components, get the list of config requirements and resolve it somehow (from a file, a database, etc.).
I've not seen such a library, but Aviso's config library comes close, maybe you can adapt it to your needs.
I'm trying to use the write_graphml function from the Boost Graph Library. The relevant things to know are that this function takes in a dynamic property map composed of property maps for each vertex and edge property, and assumes that all properties on the vertices and edges can be resolved to character types for writing to the file. This makes sense and works for most of my properties. However, I have 1 edge property that is an enum, and so it refuses to compile.
I think what I need is to create a custom PropertyMap that basically acts as a wrapper around the one for that edge property, intercepts the accesses, and returns a character representation in place of the enum values.
Is this the right way to solve this, and if so where can I look for how to define my own custom PropertyMap? I've been digging through the docs and code and so far I'm lost.
Got some help from someone else looking closer at the error messages, and it turns out defining << for std::ostream and >> for std::istream for my custom type enabled boost to write everything properly.
I have authored a WSDL and the consumer/client that implements operation AddCar that has data for model and colour. Now one WS producer/server wants to also have data for length. I assume that other producers have difficulties to adapt to this change due to implementation outsourcing. My options include:
Make new operation AddCarWithLength
Make 2 versions of WSDL and consumer code with same operation
Just update the WSDL with optional length and include it operation data only for producer that wants it.
Just update the WSDL with 0-N name-vaue pair elements and include it operation data only for producer that wants it.
Demand customers that they get the company that implemented the WS producer to update it.
Options:
is out of the question
I have generated C# classes in consumer/client so there would be two code sets. i still would have to know (maybe with config parameter or smthn) which version producer/server uses
Means that I only have to know which producer/server i talk with.
Same as 3 but would allow future extensibility
Can be problematic
Question:
What is the correct / best way to do this when demanding all producers to be updated can be unrealistic?
WSDL are known for the precious definitions. At first services should always designed with a clear picture of usage and future in mind. Anyhow, now my understanding is adding a attribute (data element - length) to your existing WCF service. My suggestion would be,
Analyse and add a custom class of yours and name it as a data contract and add to your WCF operation and expose it as a new interface / operation contract.
Eg.
with in Class car , have a data member as Properties.
With in properties define all your analysis result elements like, length, width, color, weight etc.
Also add a Dictionary<string,string> CustomAttributes; so in future you can use it.
Similar to above, but if you don't have much time.
with out any analysis just add a Dictionary<string,string> Parameters; and expose a new contract and utilize that.
I have a problem in my project i have to create orchestration and base o first node of xml file i have to decide what map will be use. Any idea how to do it?
I try to use decide shape and in decide shape use xslt query to find first node equal particular node decide shape will send it to particular map.
is that a good approach?
Here's some suggestions:
If the schema can be resolved by the XmlDisassembler, the engine will apply the matching Map on the Receive Port automatically.
If the number of different Maps is manageable, say 4 or 5, and very unlikely to change, then sure, the decide shape is a workable approach.
Be sure to carefully examine the differences in the Maps. I've had times when the planners believed the maps were significantly more different then in reality. If the difference is a handful of differing codes or conditional fields, maybe one Map can handle all cases.
Another option that would use a receive location for each type of message would be to use a Listen shape in the orchestration. Each branch of the listen would be expecting a different message type (or root node as you put it) and you could apply the appropriate map. Then, assuming you are mapping to a canonical schema, the rest of the orchestration would be the same regardless of input message type.
In the image the orchestration is using a listen shape to listen for 3 types of message. It's mostly for replay-ability for when the orchestration fails at different stages, I can inject it back into the flow after a fix is made.
i am trying to create a REST service that accepts a List of objects from a client and gives back a zip file.
i understand how to give back the zip file alright.
But i am right now trying to figure out a way i can pass a List of objects from a REST client/browser to the Rest service and how do i accept the List in the REST service.
Should this be done via XML input ?
or maybe the #consumes annotation could help?
Much thanks .
Som
You need to think out more clearly what you wish to do. There's no really good reason for taking a list of objects and returning a ZIP of them; you might as well use a local zip program (which just about all computers already have). That indicates that we instead need to be looking at something sensible: for example, a list of names of objects that you'll return a ZIP of, that makes a lot of sense. There are other sensible things you could be doing too, but you have to work it out in your mind what you want to happen.
Because you mention “#consumes annotation”, I'm going to assume you're using JAX-RS (i.e., Java). That's nice, because it's entirely possible to do on-the-fly ZIP generation with that; the content type you want to produce is application/zip. The easiest way I've found to handle the specification of the list of descriptions of things to return is as a wrapped list, where you use something like JAXB to do the mapping (which gives you XML support; some frameworks also support JSON off the same data models). To do a wrapped list, you use something like this:
#XmlRootElement
public class Wrapper {
#XmlElement
public List<String> item;
}
That then produces/handles XML documents like this (a three item list):
<wrapper>
<item>foo</item>
<item>...</item>
<item>bar</item>
</wrapper>
You'll need to set up the #Consumes annotation so that the content type accepted is application/xml (at least), and also consider what type of operation is involved and on what resource.
[EDIT]: In order to create a REST service that takes a list of strings as arguments, the easiest method is indeed to use a wrapper object, much as above. (You can't take a raw list; it needs to be a well-formed XML document when it's on the wire.) We then set up the annotated service method like this:
#POST
#Path("somewhere/{id}")
#Consumes("application/xml")
#Produces("application/zip")
public Response getSomeBytesForList(#PathParam("id") String id, Wrapper req) {
List<String> items = req.item; // For example...
byte[] zip = generateZipBytes(id, items); // or however
return Response.ok(zip).type("application/zip").build();
}
The key is that the req argument (the name is arbitrary, of course) is the only argument that is not annotated, that it is of a type that is JAXB-enabled, and there is an overall #Consumes ("application/xml") annotation to enable the JAXB processing of the request body. (I handle the returning of a ZIP by generating the Response directly rather than relying on the framework to do the processing for me; this lets me control the content type handling a little more precisely.)
Also note that some frameworks can also transfer JAXB-annotated objects as JSON documents, just by having a bit of extra annotation; you just state that the method can accept both "application/xml" and "application/json" in the #Consumes annotation. I do not know whether this applies to the framework you are using (I've only tested it with Apache CXF).