mercredi 18 avril 2018

Comparing Events with each other

So I have events coming in in this format

TransactionID, MicroserviceName, Direction,EpochTimeStamp.

For each call to a microservice and event is generates with a timestamp with direction of "in". Then when completed it generates with a timestamp with direction of "out".

I need to calculate latency for both the microservices per transactions and for the entire transaction.

Example Data (TransactionID, MicroserviceName, Direction,EpochTimeStamp)

1,A,in,1700 1,B,in,1702 1,B,out,1704 1,C,in,1704 1,D,in,1705 1,D,out,1706 1,C,out,1709 1,A,out,1710

Look for a pattern to handle this.

Something like this

        Pattern<MetricsEvent,?> pattern = Pattern.<MetricsEvent>begin("myBegin").where(
            new SimpleCondition<MetricsEvent>() {
                public boolean filter(MetricsEvent metricsEvent) throws Exception {
                    return metricsEvent.getDirection().equals("in");
                }
            }
    ).followedBy("myNext").where(
            new SimpleCondition<MetricsEvent>() {
                public boolean filter(MetricsEvent metricsEvent) throws Exception {
                    metricsEvent.getApplication().equals(//PREVIOUS EVENT.getApplication()))
                    return false;
                }
            }
    )

I'm note sure how to get the previous event to compare too.

Then how to calculate the latency between the two events?

Improper name for Spring "prototype" scope?

I recently found this article http://www.baeldung.com/spring-interview-questions which states that the Prototype Pattern has been applied by Spring to Prototype-scoped beans (Q17). I've been using Spring for quite some time now, but never actually stopped to think about why the creators of Spring have chosen this name. Now that I saw the above statement in the article I can only think that:

The creators of Spring did not choose the name "prototype" with the Prototype Design Pattern in mind and that the author of the above article is wrong, because the Prototype Design Pattern is not only about creating new objects every time but rather about keeping a cache of objects that are expensive to create, thus using them as "prototypes" for every newly created object, not having to perform the time consuming/expensive initialization part every time. Which is not what Spring does with prototype scoped beans.

What do you think? Am I missing something?

What is this software design pattern called? Is this Presentation-Abstraction-Control?

This is a pattern I've been using for a while. It looks like a variant of MVC but I'm not exactly sure what it's called.

See the diagram attached here: Data-View-Logic diagram

Here's a brief description of how the pattern works:

  • The Logic is like the Model in MVC in that it manages the logic and the rules of the application. The difference here is that all data is kept on the Data object.
  • The View is the V in MVC. Here it accepts an immutable version of the Data object when it's constructed by the Logic object. The View initializes its state from the Data and then listens for change events from the Data object.
  • The Data is... the data. An object with a bunch of getters and setters, it dispatches the necessary change events when properties are updated. The view has an immutable reference to this object and refreshes it's state when change events are heard.

From what I've read on wikipedia it sounds a lot like Presentation-Abstraction-Control but I'm not sure?

Fabricjs move background when panning

I've been trying for the last week to make this work, please give me a hand.

I'm currently panning the canvas (relativePan), but I can't move the background aswell. I've tried with pattern background but when modify the offset the entire background moves.

var canvas = new fabric.Canvas('c');
canvas.selection = false;

var pattern = new fabric.Pattern({
    source: 'https://cdn.seats.io/static/version/v198/chart-        designer/grid.png',
  repeat: 'repeat'
});

canvas.backgroundColor = pattern;
setTimeout(function(){canvas.renderAll();}, 10);

var circle = new fabric.Circle({
    radius: 20,
    fill: 'green',
    left: 100,
    top: 100,
    selectable: false
});

var triangle = new fabric.Triangle({
    fill: 'green',
    left: 200,
    top: 200,
    selectable: false
});

canvas.add(circle, triangle);

var panning = false;
canvas.on('mouse:up', function (e) {
    panning = false;
});

canvas.on('mouse:down', function (e) {
    panning = true;
});
canvas.on('mouse:move', function (e) {
    if (panning && e && e.e) {
        var delta = new fabric.Point(e.e.movementX, e.e.movementY);
        canvas.relativePan(delta);
        pattern.offsetX += e.e.movementX;
        pattern.offsetY += e.e.movementY;
        canvas.renderAll();
    }
});    

http://jsfiddle.net/w8xr15Lf/

I just need the backround to move the same way the objects do.

Thanks a lot!

How can GOF Patterns still have usage in modern days?

I've started researching about these guys recently and I think it's amazing how come they have wrote the GOF book back in 94 and still be considerated a good practice to implement. shouldn't there be a lot of new ways to approach problems without using these old methods and implementations?

Pass variable to awk pattern

I am writing a shell script which calls an awk script and then I take some user input in the BEGIN using getline, and I save the input to some variables.

BEGIN {printf "What's the word?"
getline word < "-"
}

Now, one of these variables is called "word" and I want to use it in another pattern in the script to print all lines containing the word given. I tried something like this:

/(^| )word( |$)/ 

which will print all lines containing the word "word", and I know that it's not gonna work because it's not recognized as being a variable. I'd searched a lot and found patterns starting with

$0~

but it's not working either in my case. Is there a way I could pass a variable to this pattern and print all lines containing the word stored in the variable?

Right way to choose and instantiate C# class depends on string value?

I have base class

public abstract class HostBehavior : SiteHost
{
    public abstract List<string> ParseNews(string url);
}

And many derived classes...

What is the best way to choose which constructor should be called depends on url?

Right now I have long sequence of "if else" statements like this example:

public static HostBehavior ResolveHost(string url)
{
    if (uri.IndexOf("stackoverflow.com") > 0)
    {
        return new stackoverflowBehavior();
    }
    else if(uri.IndexOf("google.com") > 0)
    {
        return new googleBehavior();
    }
    // and so on...
    else
    {
        throw new Exception...
    }
}