开发者

Best API for modeling networked devices with arbitrary attributes to learn from?

开发者 https://www.devze.com 2022-12-12 11:38 出处:网络
I need to design a new API which models networked devices which have a large amount of attributes which vary quite a lot based on the device\'s type. The attribute set is not totally arbitrary though,

I need to design a new API which models networked devices which have a large amount of attributes which vary quite a lot based on the device's type. The attribute set is not totally arbitrary though, it is a big set of known attributes. That said, with new devices come new attributes so the situation is never totally fixed. 开发者_开发知识库

The network devices themselves come and go all the time so that's a central part of the API design. Also, it would be preferable to get updates on the attributes/attribute sets via some variant of the Observer pattern.

Note: I'm not talking about network management, although this might sound like that. That said, the APIs on those systems might very well be suitable/worth looking at.

So my question is, do you know any good APIs out there in the Open Source world from which I could learn and derive some inspiration from?

The system will be Java-based so the examples would preferably be from close relative languages, e.g. Java (of course :)), C#, Scala and other similar statically typed languages.


I'm not sure what exactly your API is intended to do, but I'm guessing that since the network devices "come and go all the time" and that you wanted to use the observer pattern, you're looking for something that can get updates on the current state of stuff out on the network.

Have you looked at SLP? It's a pub/sub protocol that may do what you want: it lets network devices broadcast their presence and properties out over the network and also listen for other people. It works over TCP and UDP (unicast and multicast).

There's a couple of java implementations around (like jslp for example), but I was never entirely satisfied with them (so I ended up writing my own). As far as C# goes, I couldn't find one easily.


Not positive that I understand your question completely, but I'll give it a shot.

Are you looking for a way to allow a device to publicize its attributes when it is on a network? If so, there really isn't a good way unless you write code that understands now to interact with the device. After you have something like that, all you need to have is a class which holds attribute data in some type of data structure of your liking. For updating, you will probably need to poll the devices periodically unless they have a way of reporting when their attributes change:

Dictionary<string, Dictionary<string, string>> deviceAttributes = new 
   Dictionary<string, Dictionary<string, string>>();

void AddAttribute(string deviceIdentifier, string attribute, string value)
{
   if(!deviceAttributes.Keys.Contains(deviceIdentifier))
      deviceAttributes.Add(deviceIdentifier, new Dictionary(attribute, value);
   else
      deviceAttributes[deviceIdentifier].Add(attribute, value);
}

If each device has some kind of standard method for retrieving the attributes of interest, you can write code that would accept an array of whatever and add that to the data structure using a for or foreach loop. I can't really say more without more specific knowledge of what you are trying to do.


I might look at LDAP/ActiveDirectory/ADAM(User Mode Active Directory) . . . TheEruditeTroglodyte

0

精彩评论

暂无评论...
验证码 换一张
取 消