Currently i am using the REST interface to query vespa, which seems to work great but something tells me that i should be using searchers in the application to make the client(server side code) a bit lighter (bundle the jar file in the application package) to make it a bit smoother. I have managed to do some simple searcher/processor applications. But this is a bit overwhelming.
So are there any readily available examples ?
Basicially i want to:
Send to /search?query=someId
Do a ordinary search for the weighted set on this documentID (I guess this one can be handy: https://docs.vespa.ai/documentation/reference/inspecting-structured-data.html)
Take those items in the response and add it to a wand item(s) and query for a wand with wandsearcher on a given field. Similar to the yql:
"select * from sources * where wand(interest, some weightedsets));","ranking":"combined_score" and return the matches.
Just curious also, apart from the trouble of string building with the http request i am doing at the moment are there any performance gains of using a searcher or go the java route vs rest?
thanks for any insight or code help i can start with.
There is an example of using the WandItem (YQL wand)here https://docs.vespa.ai/documentation/advanced-ranking.html and see also https://docs.vespa.ai/documentation/using-wand-with-vespa.html as there are two wand implementations available in Vespa, it sounds from the description that the wand() is what you want to use for this use case. For the first call you probably want to have a dedicated document summary to reduce the amount of data fetched for your first query and also the option of serving it out of memory only (See https://docs.vespa.ai/documentation/document-summaries.html)
Also see https://docs.vespa.ai/documentation/searcher-development.html as a general resource on writing searchers.
For your use case it makes a lot of sense to write a searcher to perform these two queries as your second query depends on the first and you avoid the cost of rendering/http/yql parsing which might matter if your client is remote with high network latency.
I am developing a web distributed application to let any user to play the Klondike (solitaire) game. I want to develop a API REST but I am not sure how the resources URL should look like.
At the server, I have the 'game', 'stock', 'waste', 'tableau', 'foundation' classes among others. The game class has the method moveFromStockToWaste, moveFromTableauToTableu... which implements the movements of the game.
What I have read about REST API is that the resources URL should look like a hierarchy of nouns while the operations (verbs) over this nouns are the HTTP methods (GET, PUT, POST, PATCH).
I am not sure if the way to move a card from stock to waste via API REST should look like this though moveFromTableauToTableau resource is a verb and not a noun:
UPDATE /player/{playerId}/game/{gameId}/moveFromTableauToTableau
Other way I have though is having this tableau piles cards resources:
URL: /player/{playerId}/game/{gameId}/TableauPile/1/
than in turn have resources like the number of not upturned cards and the upturned cards (all the information needed about the tableaus).
Then update this tableau pile resource by deleting the last card:
DELETE /player/{playerId}/game/{gameId}/TableauPile/1/upTurnedCard/3
And then put the card deleted in the target passing the new card suit and value:
POST /player/{playerId}/game/{gameId}/TableauPile/3/upTurnedCard
But this way the REST API would let to move a card from the tableau to the waste and this is not a valid movement.
I always think designing a REST API as a pretty uneasy task.
The second approach seems cleaner in naming convention terms, but I think you should never compromise the integrity of your targeted system to be compliant with such things. As you allow making one atomic operation in two http calls, it is in fact no longer atomic and you expose your system to unpredictable state in case of network failure or if any call fail for some reason. Avoid this kind of problem must be the top priority.
One idea could be thinking moves in terms of moves collection. So for a game you have a moves ressources. And then you can refine the move nature with some additional request parameters such like
POST/players/{playerId}/games/{gameId}/moves?type=TABLEAU_TO_TABLEAU
Body:
{
"src": "stock",
"dest": "waste"
}
This way you should have enough flexibilty to handle the different types of move.
Besides, may I suggest you to use plural form for resource naming :
player -> players
game -> games
so
GET /players naturally means give me all values of the player resource
GET /players/1 means give me the player of the players resource with the restriction playerId=1
I am developing a web distributed application to let any user to play the Klondike (solitaire) game. I want to develop a API REST but I am not sure how the resources URL should look like.
Oracle: how would you implement this as a website?
At the server, I have the 'game', 'stock', 'waste', 'tableau', 'foundation' classes among others. The game class has the method moveFromStockToWaste, moveFromTableauToTableu... which implements the movements of the game.
One important thing to realize is that the classes in your implementation don't matter; REST is about manipulating documents, the changes that happen to the game are side effects of manipulating the "documents".
In other words, the REST API is a mask that your game wears so that it looks like a web site.
See Jim Webber's talk DDD In the Large.
Klondike is effectively a state machine; any given tableau has some limited number of legal moves to make, each of which takes you to a new position.
So one way you might model the API is a representation of the tableau plus affordances (links) for each move, and the game progresses from one state to the next as you follow the links that describe a possible legal move.
There are "only" 8*10^67 or so deals to worry about, and for each of them you effectively have a graph of all of the reachable positions, and order them by traversal order, and then just link them all together.
/76543210987654321098765432109876543210987654321098765432109876543210/0
/76543210987654321098765432109876543210987654321098765432109876543210/1
/76543210987654321098765432109876543210987654321098765432109876543210/2
/76543210987654321098765432109876543210987654321098765432109876543210/3
And so on.
It's not an impossible arrangement, although it may be impractical, and since the URL describes the entire state of the game, the player has access to hidden state.
I'd suggest first trying this approach on something less complicated, like tic-tac-toe.
Hiding the state is relatively straight forward, because the mapping of the current game to a specific seed can be done on the server. That is, you send a POST to the start game end point, and that generates some random identifier, and maps the random identifier to a seed position, and off you go.
But a potential problem in this design is that HTTP is a stateless protocol; there's no way for the server to "know", when the player requests GET /games/000/152, that the client was previously in a position that could legally move to position 152. You can make the URI hard to guess, but that's about it.
What you likely want is the ability to ensure that the moves made by the player are legal, which means that the server needs to be tracking the current state of the game, and the player gets a view of the open information only.
The simplest HTML model of this would have the representation of the game show the information that the player is allowed, and a form with a list of the legal moves. The player selects one move and submits the form, which is a POST back to the game resource (directly back to the same resource, because we want the cache invalidation properties). Your implementation could then check that the received move is legal, refresh its own local state, and send an appropriate response.
That's the basic pattern we should be considering; GET the game, then send an unsafe request to modify the server's copy of the game.
The basic plan isn't all that different if you want to use a remote authoring approach. GET fetches a representation of the revealed information, the client makes legal edits to that representation, and PUTs the new representation to the same URL. The server verifies that the new position is reachable from the old position, and accepts the move, using its own copy of the hidden information to update the representation of the player's view.
(Pay careful attention to the meta data used in the response to PUT; the server is supposed to be communicating carefully whether the new representation is adopted as is, or if the server has transformed the proposed representation to make it consistent with the server's constraints).
You could, of course, also use PATCH to communicate the changes made to the representation by the client.
If messages were lost, or duplicated, the client's view and the server's view might not be aligned. So you may want to have your representation of the game include a clock/timer/turn number, so that the server can be certain that the players move is intended for the current state of the game.
EDIT As Roman notes, HTTP already has built into it the concept of validators, which allow you to lift data from your domain specific clock into the headers, so that generic components can understand and act appropriately to conditional requests
Another way of thinking about the game is to consider event sourcing; the client and the server are taking turns appending entries to a log, and the view of the game itself is computed by applying the events in the log. The client's moves would be limited to the set that manipulate the open information, the server's moves would reveal previously hidden information.
So you could use Atom Pub, or something very similar to it, to write new entries into the log. This in effect gives you two different representations of the game - the view, that shows you what you see when you look at the tableau, and the feed, which shows you the moves made to reach that point.
(If you squint, you'll see that this is really just a variation on "let the client pick a legal move".)
You could, I suppose, treat each of the elements in your domain model as a resource, and try to design an API to allow the client to manipulate those directly, but it isn't at all clear to me what benefit you get from that.
Firstly, I know about the duplicates. We're not talking about iOs/Android/KindOfDevice-only, as the others & cookies are not the way I want to go.
So I want to bypass the need of a password or something by "binding" my service (which is only an idea by now) to the device used.
An E-Mail and stuff would be needed of course, to keep your devices bundled.
What would your approaches be?
My thoughts so far
My first idea was using the mac-adress, because I heard that they're unique. But a quick google told me that's not really true.
On Phones I could use the phone number or the IMEI, but I don't want it to be restricted to phones, it should be usable by web, too.
I guess when we talk about a web-solution, stuff would get even more tricky because browsers won't let the service go really deep into the system and stuff?
Of course I guess there needs to be a combination of two or more things. So two not-so-unique things combine to an 99%-unique-thing?
I just need some help about how to go on with this problem, a direction, because if you google terms like "unique device identification" you only get this medicine-thing..
In my project I use
var secureUDID = (UIDevice.current.identifierForVendor?.uuidString)!
which - Returns a string created from the UUID, such as “E621E1F8-C36C-495A-93FC-0C247A3E6E5F”.
UUID - An alphanumeric string that uniquely identifies a device to the app’s vendor.
I am trying to obtain handle key for socket-filter for registering packet filtration. I have already register it for TCP packets now I want to register it for UDP packet. This handle key needs to be unique from another applications.
sflt_filter.sf_handle = 0xAACAF333;
I have obtained it before about 2 years ago using the link (http://developer.apple.com/datatype/) but it get redirected to different link now.
I have read the link it says that Creator Codes are ignored by 10.6 and above. But for implementing kext for packet-filtration we need that code to be unique.
Does any one know how to obtain the unique key?
OR it is not required to obtain the unique key?
OR their is different way to use handle now?
Thanks in advance.
I know the question is very outdated, but I faced the same problem, and just for next one who will too:
now you can register and obtain unique handle for filter calling kev_vendor_code_find function from sys/kern_event.h, passing bundle id and pointer to uint32 variable.
After that, in user space you can get this handle by SIOCGKEVVENDOR ioctl, passing pointer to kev_vendor_code structure with same bundle id in vendor_string field.
You should not do any things to "unregister" this handle (but you should unregister the filter with this handle in driver::stop() )
iOS 6.0 has added a couple of new instance methods to the class GKTurnBasedMatch. I am not sure how to use them:
acceptInviteWithCompletionHandler
declineInviteWithCompletionHandler
Are they supposed to be used in response to receiving a turn-based match invite? Turn-based match invites are received through the GKTurnBasedEventHandlerDelegate protocol method: handleInviteFromGameCenter.
- (void) handleInviteFromGameCenter:(NSArray *)playersToInvite
handleInviteFromGameCenter does not provide a GKTurnBasedMatch instance to use for the purposes of accepting or declining. Consequently I do not know how to use them in response to an invite.
The only methods that provide GKTurnBasedMatch instances are:
+ loadMatchesWithCompletionHandler
+ findMatchForRequest:withCompletionHandler
I am not sure why I would use acceptInviteWithCompletionHandler on the results of loadMatchesWithCompletionHandler, because they are matches I am already participating in.
I am not sure why I would use either of them with findMatchForRequest:withCompletionHandler, because this is being called to find a match. Am I supposed to accept the match after finding it?
<- Update ->
I have found one use for declineInviteWithCompletionHandler. If a user requests to delete a match they have not taken a turn in, I call declineInviteWithCompletionHandler. This way they are not recorded as having quit the match.
When a player has not yet taken a turn, their GKTurnBasedParticipant.lastTurnDate is null
If a user requests to play a match (that I have displayed in a list using loadMatchesWithCompletionHandler) and if the local player has not taken a turn in the match, I am calling acceptInviteWithCompletionHandler, before I display the match to the player. I'm not sure if this is necessary, it just seemed like the right thing to do.