How to delete route entries from routing table using an agent in UnetStack - unetstack

In my routing protocol, I want to update the routing table dynamically at a periodic interval, as of now, I am adding route entries to the routing table from my agent, by sending the RouteDiscoveryNtf message to the router agent, which is similar to using addroute closure in the shell.
I want to know, How I can delete the route entries. So that, I can update the routing table with new entries. As the, delroute, delroutesto,delroutes closures, which works in shell, cannot be used in an agent.
Also I want to know is my approach is right for updating the routing table dynamically or is there any other better way for doing this. Kindly help.

The current version of UnetStack (1.4) does not define messages to delete routes, so there's no "correct" way to ask router to delete a route. Later versions might introduce messages for this. For now, you could do it in the same way as the delroute, delroutes and delroutesto shell functions do it, but bear in mind that you may need to update this in later versions of UnetStack.
The router agent exposes two unlisted parameters (removeRoute and removeRoutesTo) to allow deletion of routes. These may be removed in future versions once UnetStack defines messages for this purpose.
Code snippet showing how the 3 shell functions are implemented:
// remove route number n (0 based numbering)
void delroute(n) {
router.removeRoute = n-1
}
// remote all routes in routing table
void delroutes() {
router.removeRoute = -1
}
// remove all routes to node
void delroutesto(node) {
router.removeRoutesTo = node
}
If you're implementing in Groovy, you can use pretty much the same code with router being the AgentID or the router agent. If you're implementing in Java, you'll have to send the appropriate ParameterReq to set these parameters.

Related

Gatsby createPage actions vs {page.slug}.js

What is the main difference between creating static pages with createPage in Gatsby vs using {page.slug}.js. I was not able to find any documentation about this so I am not sure what to search for other than the documents encouraging the use of {page.slug}.js format.
Short answer: there's no difference at all between using gatsby-node.js and File System Route API ({page.slug}.js), they are different ways of achieving the same result: dynamic routes.
TL;DR
The File System Route API adds the simplicity that in most cases you lack using gatsby-node.js way of creating dynamic pages. For simple use-cases, I'd say that it's better to use the File System Route API but, because of some known limitations, for some complex scenarios, it's better to use gatsby-node.js (and maybe it's the only way).
The Filesystem Route API always filters by id as you can see in the docs:
allProduct {
nodes {
id # Gatsby always queries for id
fields {
sku
}
}
}
It may work in your scenario but if you need more complex filtering, the File System Route API may not be suitable.
For example, if you are writing a blog, you may think that the File System Route API works for you and it could be. But if at some point you want to filter the page creation some posts based on a complex and custom value (i.e: the typical isFuture field that checks if the date of the post is past or present and it's created customizing the GraphQL schema), you will find the "limitations" of the File System Route API.
In the end, it's all based on choosing what fill fit you better.
Summarizing (a lot)...
File System Route API
Simplicity: you get rid of gatsby-node.js and the code related
Limitations:
Always queries for the id
Can't pass custom properties to the view/template
Potential troubles by creating dynamic path segments based on a previously queried result
Path creation is a little bit complex for the same properties (i.e: slug): in this case, you will need to define a gatsbyPath for each property (docs)
gatsby-node.js
"Complexity": you always have a gatsby-node.js file with all the queries
Easy to manipulate the page creation (createPage) and to drill down any object or variable using the pageContext which gives you a lot of flexibility.
Path creation based on any desired value is easy to achieve.

CakePHP - Best way to persist application state?

I have an app that tracks and displays various stats for a local athletic league. One of my requirements is to be able to break down stats by game type, league id and location id. The user picks a value for each of those 3 items and then goes off to view various stats with the 3 variables stored in a session. This works fine, but my problem is that users can't link back to whatever stats they were viewing. I know I can extend the life of the session, but I'd rather pass the state of those 3 variables around in the URL so I can have the ability to link back to any specific stats page with any or none of those 3 variables defined.
Query strings seem like an obvious way to do this, but I can't tell if there's any way for me to 'automatically' append the query string to all links generated in the app, or if I manually need to go through and add the querystring parameters wherever I generate a link or do a redirect. That seems like the brute force approach and I feel like there must be a better way to do this sort of persistence that I'm missing. Any help appreciated!
For a number of reasons (linking, SEO...etc), use a URL, not sessions/cookies. And instead of IDs, use slugs instead:
www.mysite.com/league/football/youth/newyork
I'm sure there are many different ways to keep the url vars consistent across the board, but the way I can think to do it would be the following:
You can use Cake's route functionality to set each item to a variable and make nice looking URLs
In your AppController's beforeFilter(), set the Session of each item (type, league, location)
Make a custom MyHtmlHelper
in it, check if your Session for each contains data, and if it does, append to every link that needs it (could use only for specific controllers, actions...etc)
I hope there's a simpler way, but that's all I could think of offhand.

React-router: Passing data through routes

I'm trying to figure out the best way to pass data through my routes. I know I can use params but there are certain types of data that don't belong in params.
For example: I have an index page that displays a list of applications. Each application has a button next to it which will route you to the view for that application.
I want to pass the application itself to the Application handler. However, it doesn't make sense to pass the entire application through params. Though it does make sense to pass the application identifier to params (i.e. :id or :name)
So the way I think I should be doing this is pass the application identifier to params, then in the Application component search my ApplicationStore for the appropriate application given the identifier.
Though, wouldn't it be easier and faster to pass the application itself? Is there a way to do this. Is there a reason not to do this?
Here is some code:
<Link to="showApplication" params={{name: application.name}}>View</Link>
or
<Link to="showApplication" params={{application: application}}>View</Link>
Thanks in advance!
The problem is that when the person refreshes, or in some other way directly loads the url, it needs to show the correct view. Because URLs are just strings, you need to represent the route as a string. You can't (easily) shove an actual application into the url.
The job of a router is to take that string (the URL) and map it to the actual code (the handler), and provide any extra data (the params, query, and/or hash).
Your job as a router user is to ensure there's enough information in the URL for the router to pick the right handler, and for the handler to have enough information to do its job (e.g. which application to show).
If the url is something like mysite.com/showApplication, there's clearly not enough information.
If it's something like:
mysite.com/showApplication/React.createClass(%7Brender%3A%20function()%7Breturn%20React.createElement('div'%2C%20null%2C%20%22I'm%20an%20application!%22%7D%7D)%3B
i.e. putting an application in the url, that's too much information, and generally a very bad idea.
But mysite.com/showApplication/applicationName is just right :-)
I'll provide an easy and hacky way, have a global object which you use to share information across routes eg.
window.CONTEXT = {'share':'this'}
Note that it's quite important only to use this way if the object you want to share can be recreated by the route itself, as FakeRain mentioned above the route has to contain just enough information for it to give the user the same experience if they reload.
The only reason you'd use this is to save bandwidth if you need to request information for what you want to share but yet you don't want a huge link.

What's the difference between "direct:" and to() in Apache Camel?

The DirectComponent documentation gives the following example:
from("activemq:queue:order.in")
.to("bean:orderServer?method=validate")
.to("direct:processOrder");
from("direct:processOrder")
.to("bean:orderService?method=process")
.to("activemq:queue:order.out");
Is there any difference between that and the following?
from("activemq:queue:order.in")
.to("bean:orderServer?method=validate")
.to("bean:orderService?method=process")
.to("activemq:queue:order.out");
I've tried to find documentation on what the behaviour of the to() method is on the Java DSL, but beyond the RouteDefinition javadoc (which gives the very curt "Sends the exchange to the given endpoint") I've come up blank :(
In the very case above, you will not notice much difference. The "direct" component is much like a method call.
Once you start build a bit more complex routes, you will want to segment them in several different parts for multiple reasons.
You can, for instance, create "sub routes" that could be reused among multiple routes in your Camel context. Much like you segment out methods in regular programming to allow reusability and make code more clear. The same goes for sub routes using, for instance the direct component.
The same approach can be extended. Say you want multiple protocols to be used as endpoints to your route. You can use the direct endpoint to create the main route, something like this:
// Three endpoints to one "main" route.
from("activemq:queue:order.in")
.to("direct:processOrder");
from("file:some/file/path")
.to("direct:processOrder");
from("jetty:http://0.0.0.0/order/in")
.to("direct:processOrder");
from("direct:processOrder")
.to("bean:orderService?method=process")
.to("activemq:queue:order.out");
Another thing is that one route is created for each "from()" clause in DSL. A route is an artifact in Camel, and you could do certain administrative tasks towards it with the Camel API, such as start, stop, add, remove routes dynamically. The "to" clause is just an endpoint call.
Once starting to do some real cases with somewhat complexity in Camel, you will note that you cannot get too many "direct" routes.
Direct Component is used to name the logical segment of the route. This is similar process to naming procedures in structural programming.
In your example there is no difference in message flow. In the terms of structural programming, we could say that you make a kind of inline expansion to your route.
Another difference is Direct component doesn't has any thread pool, the direct consumer process method is invoked by the calling thread of direct producer.
Mainly its used for break the complex route configuration like in java we used to have method for reusability. And also by configuring threads at direct route we can reduce the work for calling thread .
from(A).to(B).to(OUT)
is chaining
A --- B --- OUT
But
from(A ).to( X)
from(B ).to( X)
from( X).to( OUT )
where X is a direct:?
is basically like a join
A
\____ OUT
/
B
obviously these are different behaviours, and with the second you could implement anylogic you wanted, not just a serial chain

Design question on dynamic Apache camel routes/context

We have ActiveMQ onto which the events that happen in the system are published. The project involves users adding entities to their watch-list and whenever there are events on those entities I would like an email to be sent out to the interested participants.
The use-case roughly translates to some one expressing an interest in a product information page on the catalog and an email being sent whenever any activity happens on that product (price goes down, there is a positive review etc.,). I had modelled this interaction as a Camel route.
So, for example, if the user says email me whenever this product's rating equals 5, then the following route would be added to the camel context:
from("activemq:topic:events.product.save").filter().xpath("/object[<object id>]/rating").isEqualTo("5").to("email:<user's email>")
Similarly if the user wants to be notified whenever there is a new comment on a product, another route would be created and so on. This could potentially, end up creating thousands of routes as each user starts adding their watches of interest.
Some questions that I have are:
Is this an acceptable way of creating dynamic routes? One option I am considering is to use recipient lists. But I haven't been able to come up with a solution that would make it elegant to route messages to the bean that would return the recipient list. For example for the case explained above would the bean have a bunch of if-else to see which recipient list to return?
The camelcontext has a method to load routes from a xml file but no method to persist the existing routes. What would be simplest (and efficient) way to persist these dynamically created routes? This thread in the camel-users list sums up my request.
Given the dynamic nature of your subscription requirements, you should use a database to store the information rather than trying to create dynamic routes. This is a much more scalable/appropriate use of technology...
Then you can only need a single static route or a POJO consumer (see below) that can process the product update messages using a simple POJO bean (bean-binding can help, etc). The POJO bean would then be responsible for querying the database to find all "interested" users and send an email using camel-mail
public class NotificationBean {
#Consume(uri="activemq:topic:events.product.save")
public void onUpdate(#XPath("/object/id") String id,
#XPath("/object/rating") String rating) {
//query database for subscriptions for this product ID/rating, etc.
//for each interested subscriber
//send email (camel-mail, etc)
}
public void addSubscription(String productID, Integer rating, String email) {
//create/update subscription entry in database, etc...
}
}

Resources